Bird
Raised Fist0
DSA C#programming~20 mins

Enqueue Operation in DSA C# - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Enqueue Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Enqueue in Circular Queue
What is the printed state of the queue after these enqueue operations on a circular queue of size 5?

Operations:
Enqueue 10, Enqueue 20, Enqueue 30, Enqueue 40, Enqueue 50
DSA C#
class CircularQueue {
    private int[] arr;
    private int front, rear, size, capacity;

    public CircularQueue(int capacity) {
        this.capacity = capacity;
        arr = new int[capacity];
        front = 0;
        rear = -1;
        size = 0;
    }

    public void Enqueue(int item) {
        if (size == capacity) {
            Console.WriteLine("Queue is full");
            return;
        }
        rear = (rear + 1) % capacity;
        arr[rear] = item;
        size++;
    }

    public string PrintQueue() {
        if (size == 0) return "Queue is empty";
        string result = "";
        for (int i = 0; i < size; i++) {
            int index = (front + i) % capacity;
            result += arr[index] + " -> ";
        }
        return result + "null";
    }
}

var q = new CircularQueue(5);
q.Enqueue(10);
q.Enqueue(20);
q.Enqueue(30);
q.Enqueue(40);
q.Enqueue(50);
Console.WriteLine(q.PrintQueue());
AQueue is full
B50 -> 40 -> 30 -> 20 -> 10 -> null
C10 -> 20 -> 30 -> 40 -> 50 -> null
Dnull
Attempts:
2 left
💡 Hint
Remember that enqueue adds elements at the rear and the queue prints from front to rear.
❓ Predict Output
intermediate
2:00remaining
Enqueue Overflow Behavior
What will be the output after trying to enqueue an element into a full queue of capacity 3?

Operations:
Enqueue 1, Enqueue 2, Enqueue 3, Enqueue 4
DSA C#
class SimpleQueue {
    private int[] arr;
    private int front, rear, size, capacity;

    public SimpleQueue(int capacity) {
        this.capacity = capacity;
        arr = new int[capacity];
        front = 0;
        rear = -1;
        size = 0;
    }

    public void Enqueue(int item) {
        if (size == capacity) {
            Console.WriteLine("Queue is full");
            return;
        }
        rear++;
        arr[rear] = item;
        size++;
    }

    public string PrintQueue() {
        if (size == 0) return "Queue is empty";
        string result = "";
        for (int i = front; i <= rear; i++) {
            result += arr[i] + " -> ";
        }
        return result + "null";
    }
}

var q = new SimpleQueue(3);
q.Enqueue(1);
q.Enqueue(2);
q.Enqueue(3);
q.Enqueue(4);
Console.WriteLine(q.PrintQueue());
A
Queue is full
1 -&gt; 2 -&gt; 3 -&gt; null
B1 -> 2 -> 3 -> 4 -> null
C
Queue is full
null
D1 -> 2 -> null
Attempts:
2 left
💡 Hint
Check what happens when size equals capacity before adding a new element.
🔧 Debug
advanced
2:00remaining
Find the Bug in Enqueue Method
This enqueue method for a queue has a bug. What error will it cause when running?

Code snippet:
public void Enqueue(int item) {
    if (size == capacity) {
        Console.WriteLine("Queue is full");
        return;
    }
    rear = (rear + 1) % capacity;
    arr[rear] = item;
    size++;
}
DSA C#
public class Queue {
    private int[] arr;
    private int front, rear, size, capacity;

    public Queue(int capacity) {
        this.capacity = capacity;
        arr = new int[capacity];
        front = 0;
        rear = -1;
        size = 0;
    }

    public void Enqueue(int item) {
        if (size == capacity) {
            Console.WriteLine("Queue is full");
            return;
        }
        rear = (rear + 1) % capacity;
        arr[rear] = item;
        size++;
    }

    public int Dequeue() {
        if (size == 0) throw new InvalidOperationException("Queue is empty");
        int item = arr[front];
        front = (front + 1) % capacity;
        size--;
        return item;
    }
}

var q = new Queue(3);
q.Enqueue(10);
q.Enqueue(20);
q.Enqueue(30);
q.Enqueue(40);
AIndexOutOfRangeException at arr[rear] assignment
BNullReferenceException
CInvalidOperationException thrown
DNo error, prints "Queue is full" when full
Attempts:
2 left
💡 Hint
Check how rear is updated and how size is checked before enqueue.
🧠 Conceptual
advanced
1:00remaining
Enqueue Operation Complexity
What is the time complexity of the enqueue operation in a circular queue implemented with an array?
AO(1) - Constant time
BO(log n) - Logarithmic time
CO(n) - Linear time
DO(n^2) - Quadratic time
Attempts:
2 left
💡 Hint
Enqueue only updates a few variables and places one element.
🚀 Application
expert
3:00remaining
Resulting Queue After Mixed Operations
Given a circular queue of capacity 4, what is the printed queue after these operations?

Operations:
Enqueue 5, Enqueue 10, Enqueue 15, Dequeue, Enqueue 20, Enqueue 25
DSA C#
class CircularQueue {
    private int[] arr;
    private int front, rear, size, capacity;

    public CircularQueue(int capacity) {
        this.capacity = capacity;
        arr = new int[capacity];
        front = 0;
        rear = -1;
        size = 0;
    }

    public void Enqueue(int item) {
        if (size == capacity) {
            Console.WriteLine("Queue is full");
            return;
        }
        rear = (rear + 1) % capacity;
        arr[rear] = item;
        size++;
    }

    public int Dequeue() {
        if (size == 0) {
            Console.WriteLine("Queue is empty");
            return -1;
        }
        int item = arr[front];
        front = (front + 1) % capacity;
        size--;
        return item;
    }

    public string PrintQueue() {
        if (size == 0) return "Queue is empty";
        string result = "";
        for (int i = 0; i < size; i++) {
            int index = (front + i) % capacity;
            result += arr[index] + " -> ";
        }
        return result + "null";
    }
}

var q = new CircularQueue(4);
q.Enqueue(5);
q.Enqueue(10);
q.Enqueue(15);
q.Dequeue();
q.Enqueue(20);
q.Enqueue(25);
Console.WriteLine(q.PrintQueue());
A5 -> 10 -> 15 -> 20 -> null
B10 -> 15 -> 20 -> 25 -> null
C15 -> 20 -> 25 -> null
DQueue is full
Attempts:
2 left
💡 Hint
Track front and rear indices carefully after each operation.

Practice

(1/5)
1. What does the Enqueue operation do in a queue data structure?
easy
A. Adds an element to the end of the queue
B. Removes an element from the front of the queue
C. Checks if the queue is empty
D. Returns the size of the queue

Solution

  1. Step 1: Understand queue behavior

    A queue works like a line where new people join at the end.
  2. Step 2: Define enqueue operation

    Enqueue means adding a new element at the back of the queue.
  3. Final Answer:

    Adds an element to the end of the queue -> Option A
  4. Quick Check:

    Enqueue = Add at end [OK]
Hint: Enqueue means add at the back of the queue [OK]
Common Mistakes:
  • Confusing enqueue with dequeue
  • Thinking enqueue removes elements
  • Mixing enqueue with checking size
2. Which of the following is the correct syntax to enqueue an integer value 10 into a Queue<int> named q in C#?
easy
A. q.Enqueue(10);
B. q.Add(10);
C. q.Push(10);
D. q.Insert(10);

Solution

  1. Step 1: Recall C# Queue method

    The method to add elements in Queue<T> is Enqueue.
  2. Step 2: Match syntax

    Calling q.Enqueue(10); adds 10 to the queue correctly.
  3. Final Answer:

    q.Enqueue(10); -> Option A
  4. Quick Check:

    Use Enqueue() to add in C# Queue [OK]
Hint: Use Enqueue() method to add elements in C# Queue [OK]
Common Mistakes:
  • Using Add() which is not in Queue
  • Using Push() which is for stacks
  • Using Insert() which is not a Queue method
3. What will be the output of the following C# code?
Queue<string> q = new Queue<string>();
q.Enqueue("apple");
q.Enqueue("banana");
q.Enqueue("cherry");
Console.WriteLine(string.Join(", ", q));
medium
A. cherry, banana, apple
B. apple, banana, cherry
C. banana, cherry, apple
D. apple, cherry, banana

Solution

  1. Step 1: Trace enqueue order

    Elements are added in order: apple, then banana, then cherry.
  2. Step 2: Understand queue order

    Queue keeps order of insertion, so printing shows apple, banana, cherry.
  3. Final Answer:

    apple, banana, cherry -> Option B
  4. Quick Check:

    Queue prints in enqueue order [OK]
Hint: Queue keeps insertion order; output matches enqueue sequence [OK]
Common Mistakes:
  • Assuming reverse order output
  • Mixing enqueue with stack behavior
  • Confusing output order with dequeue
4. Identify the error in the following code snippet that tries to enqueue an element into a queue:
Queue<int> q = new Queue<int>();
q.Enqueue(5);
q.Enqueue(10);
q.Enqueue(15);
q.Enqueue();
medium
A. Cannot enqueue integer values
B. Queue is not initialized
C. Enqueue method does not exist
D. Missing argument in the last Enqueue call

Solution

  1. Step 1: Check method calls

    The last call q.Enqueue(); has no argument, but Enqueue requires one.
  2. Step 2: Confirm method signature

    Enqueue needs a value to add, so missing argument causes error.
  3. Final Answer:

    Missing argument in the last Enqueue call -> Option D
  4. Quick Check:

    Enqueue requires one argument [OK]
Hint: Enqueue always needs one argument to add [OK]
Common Mistakes:
  • Calling Enqueue without argument
  • Assuming Enqueue can be empty
  • Confusing initialization errors
5. You have a queue q with elements [1, 2, 3]. You want to enqueue elements 4 and 5, but only if the queue size is less than 5. Which code snippet correctly performs this conditional enqueue operation in C#?
hard
A. if (q.Count == 5) { q.Enqueue(4); q.Enqueue(5); }
B. if (q.Count <= 5) { q.Enqueue(4); q.Enqueue(5); }
C. if (q.Count < 5) { q.Enqueue(4); q.Enqueue(5); }
D. if (q.Count > 5) { q.Enqueue(4); q.Enqueue(5); }

Solution

  1. Step 1: Understand queue size condition

    We want to add only if size is less than 5, so condition is q.Count < 5.
  2. Step 2: Apply enqueue calls inside condition

    If condition is true, enqueue 4 and 5 to add them safely.
  3. Final Answer:

    if (q.Count < 5) { q.Enqueue(4); q.Enqueue(5); } -> Option C
  4. Quick Check:

    Use < 5 to check size before enqueue [OK]
Hint: Check queue size with Count before enqueueing [OK]
Common Mistakes:
  • Using <= instead of < causing overflow
  • Using > or == which are wrong conditions
  • Not checking size before enqueue
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard