Implementing Queue Using Array in 100 Days of Code

🚀 Day 45 of #100DaysOfCode – Striver’s DSA Sheet 🚀 ✅ Topic Covered Today: Implement Queue Using Array 💡 Lesson of the Day (Approach-Focused): 🔹 Understanding the Core Idea A queue follows FIFO (First In, First Out) order. Using an array, we simulate this behavior by maintaining: front pointer (f) → points to the first element rear pointer (r) → points to the last inserted element size / capacity → fixed array length 🔹 1️⃣ Enqueue (Insert) Check if queue is full → rear == size - 1 Increment rear Insert element at arr[rear] 🧮 Time Complexity: O(1) 💾 Space Complexity: O(1) extra 🔹 2️⃣ Dequeue (Remove) Check if queue is empty → front == -1 Return element at arr[front] Move front forward If queue becomes empty again → reset front = rear = -1 🧮 Time Complexity: O(1) 🔹 3️⃣ Peek Return arr[front] without removing it. 🧮 Time Complexity: O(1) 🔹 4️⃣ isEmpty / isFull isEmpty: front == -1 isFull: rear == size - 1 ✨ Key Idea: Implementing a queue using an array helps understand pointer movement, memory management, and why sometimes a circular queue is needed when fixed arrays cause unused space. 💭 Learning: Today strengthened my understanding of how queues work under the hood and how core operations actually use pointer updates — a great foundation before moving to circular queues and deque structures. #100DaysOfCode #DSA #StriversSheet #Java #Queue #Arrays #ProblemSolving #CodingJourney #LogicBuilding #Consistency

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories