28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
Data Structure Questions and Answers – Queue
using Array
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Queue using
Array”.
1. Which of the following properties is associated with a queue?
a) First In Last Out
b) First In First Out
c) Last In First Out
d) Last In Last Out
View Answer
2. In a circular queue, how do you increment the rear end of the queue?
a) rear++
b) (rear+1) % CAPACITY
c) (rear % CAPACITY)+1
d) rear–
View Answer
3. What is the term for inserting into a full queue known as?
a) overflow
b) underflow
c) null pointer exception
d) program won’t be compiled
View Answer
advertisement
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 1/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
4. What is the time complexity of enqueue operation?
a) O(logn)
b) O(nlogn)
c) O(n)
d) O(1)
View Answer
5. What does the following Java code do?
Subscribe Now: Data Structure Newsletter | Important Subjects Newsletters
public Object function()
{
if(isEmpty())
return -999;
else
{
Object high;
high = q[front];
return high;
}
}
a) Dequeue
b) Enqueue
c) Return the front element
d) Return the last element
View Answer
advertisement
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 2/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
6. What is the need for a circular queue?
a) effective usage of memory
b) easier computations
c) to delete elements based on priority
d) implement LIFO principle in queues
View Answer
7. Which of the following represents a dequeue operation? (count is the number of elements in the
queue)
a)
advertisement
public Object dequeue()
{
if(count == 0)
{
System.out.println("Queue underflow");
return 0;
}
else
{
Object ele = q[front];
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 3/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
q[front] = null;
front = (front+1)%CAPACITY;
count--;
return ele;
}
}
b)
public Object dequeue()
{
if(count == 0)
{
System.out.println("Queue underflow");
return 0;
}
else
{
Object ele = q[front];
front = (front+1)%CAPACITY;
q[front] = null;
count--;
return ele;
}
}
c)
public Object dequeue()
{
if(count == 0)
{
System.out.println("Queue underflow");
return 0;
}
else
{
front = (front+1)%CAPACITY;
Object ele = q[front];
q[front] = null;
count--;
return ele;
}
}
d)
public Object dequeue()
{
if(count == 0)
{
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 4/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
System.out.println("Queue underflow");
return 0;
}
else
{
Object ele = q[front];
q[front] = null;
front = (front+1)%CAPACITY;
return ele;
count--;
}
}
View Answer
8. Which of the following best describes the growth of a linear queue at runtime? (Q is the original
queue, size() returns the number of elements in the queue)
a)
private void expand()
{
int length = size();
int[] newQ = new int[length<<1];
for(int i=front; i<=rear; i++)
{
newQ[i-front] = Q[i%CAPACITY];
}
Q = newQ;
front = 0;
rear = size()-1;
}
b)
private void expand()
{
int length = size();
int[] newQ = new int[length<<1];
for(int i=front; i<=rear; i++)
{
newQ[i-front] = Q[i%CAPACITY];
}
Q = newQ;
}
c)
private void expand()
{
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 5/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
int length = size();
int[] newQ = new int[length<<1];
for(int i=front; i<=rear; i++)
{
newQ[i-front] = Q[i];
}
Q = newQ;
front = 0;
rear = size()-1;
}
d)
private void expand()
{
int length = size();
int[] newQ = new int[length*2];
for(int i=front; i<=rear; i++)
{
newQ[i-front] = Q[i%CAPACITY];
}
Q = newQ;
}
View Answer
9. What is the space complexity of a linear queue having n elements?
a) O(n)
b) O(nlogn)
c) O(logn)
d) O(1)
View Answer
10. What is the output of the following Java code?
public class CircularQueue
{
protected static final int CAPACITY = 100;
protected int size,front,rear;
protected Object q[];
int count = 0;
public CircularQueue()
{
this(CAPACITY);
}
public CircularQueue (int n)
{
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 6/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
size = n;
front = 0;
rear = 0;
q = new Object[size];
}
public void enqueue(Object item)
{
if(count == size)
{
System.out.println("Queue overflow");
return;
}
else
{
q[rear] = item;
rear = (rear+1)%size;
count++;
}
}
public Object dequeue()
{
if(count == 0)
{
System.out.println("Queue underflow");
return 0;
}
else
{
Object ele = q[front];
q[front] = null;
front = (front+1)%size;
count--;
return ele;
}
}
public Object frontElement()
{
if(count == 0)
return -999;
else
{
Object high;
high = q[front];
return high;
}
}
public Object rearElement()
{
if(count == 0)
return -999;
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 7/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
else
{
Object low;
rear = (rear-1)%size;
low = q[rear];
rear = (rear+1)%size;
return low;
}
}
}
public class CircularQueueDemo
{
public static void main(String args[])
{
Object var;
CircularQueue myQ = new CircularQueue();
myQ.enqueue(10);
myQ.enqueue(3);
var = myQ.rearElement();
myQ.dequeue();
myQ.enqueue(6);
var = mQ.frontElement();
System.out.println(var+" "+var);
}
}
a) 3 3
b) 3 6
c) 6 6
d) 10 6
View Answer
Sanfoundry Global Education & Learning Series – Data Structure.
To practice all areas of Data Structure, here is complete set of 1000+ Multiple Choice Questions and
Answers.
« Prev - Data Structure Questions and Answers » Next - Data Structure Questions and Answers –
– Stack using Linked List Queue using Linked List
Related Posts:
Practice Programming MCQs
Practice Design & Analysis of Algorithms MCQ
Practice Computer Science MCQs
Apply for Data Structure Internship
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 8/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
Apply for Information Technology Internship
Data Structure MCQ, DS MCQ - Abstract Datatype
advertisement
Recommended Articles:
1. Data Structure Questions and Answers – Queue using Linked List
2. Data Structure Questions and Answers – Queue Operations
3. Data Structure Questions and Answers – Stack using Array
4. Data Structure Questions and Answers – Queue using Stacks
5. C Program to Implement Queue using Array
6. Java Questions & Answers – Data Structures-Queue
7. Data Structure Questions and Answers – Double Ended Queue (Dequeue)
8. Java Program to Implement Queue
9. Data Structure Questions and Answers – Array and Array Operations
10. C++ Program to Implement Queue using Linked List
advertisement
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 9/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
Additional Resources:
Data Structure MCQ Questions
Data Structures in C
Data Structures in Java
Data Structures in C++
Java Array Programs
Popular Pages:
C# Array Programs
Data Science MCQ Questions
C++ STL
Java Programs on Collections
C++ Algorithm Library
Subscribe: Data Structure Newsletter
Name
Email
Subscribe
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to
get free Certificate of Merit. Join our social networks below and stay updated with latest contests,
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 10/11
28/11/2023, 09:27 Queue using Array Questions and Answers - Sanfoundry
videos, internships and jobs!
Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is
Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on
development of Linux Kernel, SAN Technologies, Advanced C, Data
Structures & Alogrithms. Stay connected with him at LinkedIn.
Subscribe to his free Masterclasses at Youtube & discussions at Telegram
SanfoundryClasses.
About | Certifications | Internships | Jobs | Privacy Policy | Terms | Copyright | Contact
© 2011-2023 Sanfoundry. All Rights Reserved.
https://www.sanfoundry.com/data-structure-questions-answers-queue-array/ 11/11