Data Structures Question:

Download Job Interview Questions and Answers PDF

What is the relationship between a queue and its underlying array?

Data Structures Interview Question
Data Structures Interview Question

Answer:

Data stored in a queue is actually stored in an array. Two indexes, front and end will be used to identify the start and end of the queue.

When an element is removed front will be incremented by 1. In case it reaches past the last index available it will be reset to 0. Then it will be checked with end. If it is greater than end queue is empty.

When an element is added end will be incremented by 1. In case it reaches past the last index available it will be reset to 0. After incrementing it will be checked with front. If they are equal queue is full.

Download Data Structures Interview Questions And Answers PDF

Previous QuestionNext Question
What is a queue in data structure?Which process places data at the back of the queue?