Pape’s algorithm (also called Dequeue Algorithm):
The algorithm is the same as FIFO implementation except in the way of how to insert j to Q.
if j is in Q ⇒ do not add
if j has never been in Q ⇒ add to the bottom of Q
if j is not in Q but has previously been in Q ⇒ add to the top of Q
For the same example:
Top of Q