DSA
    beginner

    Queue Data Structure

    Software Engineer path · lesson 5 of 99
    O(1) ops

    Syntax: enqueue n · dequeue · peek. Numbers from -99 to 99.

    Try:
    Buffer size

    Smaller buffers wrap sooner.

    buffer01234headtail
    EnqueuedDequeuedFrontFree slotFull

    Empty queue in a circular buffer of 5 slots.

    Code (running line highlighted)
    1. 1enqueue(x): if size == cap: full; buf[tail] = x; tail = (tail + 1) % cap
    2. 2dequeue(): if size == 0: empty; x = buf[head]; head = (head + 1) % cap
    3. 3peek(): return buf[head]
    Enqueues
    0 / 6
    Dequeues
    0 / 2
    Invariant: First in, first out: values leave from head in the order they arrived at tail.

    Tap any element in the diagram to inspect its state at this step.

    1 / 11

    Keys: ← → step, Space play/pause. Predict mode pauses before key steps and asks what happens next.

    Stack or queue?

    Sort

    Sort each system by the structure that fits it.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    Stack (LIFO)

    Drop items here

    Queue (FIFO)

    Drop items here
    6 pieces left to place

    Test your knowledge

    21 questions
    Question 1 of 21
    Score: 0

    Which data structure is best for Breadth-First Search (BFS)?

    When to reach for this

    • Breadth-First Search (BFS)
    • Processing items in the order they arrived
    • Sliding Window problems (sometimes used)
    • Buffer management

    Interview Questions

    Microsoft
    Bloomberg
    Valve (not FAANG but fun)
    Facebook
    Amazon
    Google
    Amazon
    Microsoft
    Facebook
    Apple
    Bloomberg

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required