Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Stack & Queue

Total questions: 70

Worksheet time: 47mins

Name
Class
Date
1.

What is a stack in data structure?

a)

A stack is a data structure that allows random access to its elements.

b)

A stack is a non-linear data structure.

c)

A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle.

d)

A stack is a linear data structure that follows the First-In-First-Out (FIFO) principle.

2.

What are the two main operations performed on a stack?

a)

insert and remove

b)

add and remove

c)

enqueue and dequeue

d)

push and pop

3.

How is a stack implemented using an array in C?

a)

Using a linked list instead of an array.

b)

Using a queue instead of a stack.

c)

Using a binary tree instead of an array.

d)

Using a fixed-size array and a top variable to keep track of the top element.

4.

What is the time complexity of push and pop operations in a stack implemented using an array?

a)

O(log n)

b)

O(n^2)

c)

O(1)

d)

O(n)

5.

What is the time complexity of accessing the top element of a stack implemented using an array?

a)

O(log n)

b)

O(n)

c)

O(1)

d)

O(n^2)

6.

What is a stack overflow?

a)

A stack overflow is when a program's variables exceed their maximum size.

b)

A stack overflow is when a program's call stack exceeds its maximum size.

c)

A stack overflow is when a program encounters an infinite loop.

d)

A stack overflow is when a program runs out of memory.

7.

What is a stack underflow?

a)

An item is popped from a full stack.

b)

An item is popped from an empty stack.

c)

An item is pushed onto an empty stack.

d)

An item is pushed onto a full stack.

8.

How is a stack implemented using a linked list in C?

a)

By creating a linked list structure with a top pointer and using push and pop operations to add and remove elements from the top of the stack.

b)

By creating a linked list structure with a tail pointer and using push and pop operations to add and remove elements from the tail of the stack.

c)

By creating a linked list structure with a front pointer and using push and pop operations to add and remove elements from the front of the stack.

d)

By creating a linked list structure with a bottom pointer and using enqueue and dequeue operations to add and remove elements from the bottom of the stack.

9.

What is the time complexity of push and pop operations in a stack implemented using a linked list?

a)

O(1)

b)

O(log n)

c)

O(n^2)

d)

O(n)

10.

What is the difference between a stack implemented using an array and a stack implemented using a linked list?

a)

The array-based stack has a fixed maximum capacity, while the linked list-based stack can grow dynamically as needed.

b)

The main difference is the way elements are stored and accessed: array-based stack uses a fixed-size contiguous block of memory, while linked list-based stack uses dynamically allocated nodes that are linked together.

c)

The array-based stack allows for constant-time access to any element, while the linked list-based stack requires traversing the list to access an element.

d)

The array-based stack is more memory efficient than the linked list-based stack due to its contiguous memory allocation.

11.

In a stack, if a user tries to remove an element from an empty stack it is called _________

a)

Underflow

b)

Empty collection

c)

Overflow

d)

Garbage Collection

12.

What is the value of the postfix expression 6 3 2 4 + - *?

a)

1

b)

40

c)

74

d)

-18

13.

The following postfix expression with single digit operands is evaluated using a stack: 8 2 3 ^ / 2 3 * + 5 1 * - Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are:

a)

3,2

b)

1,5

c)

6,1

d)

5,7

14.

Assume that the operators +, -, × are left associative and ^ is right associative. The order of precedence (from highest to lowest) is ^, x , +, -. The postfix expression corresponding to the infix expression a + b × c - d ^ e ^ f is

a)

abc × + def ^ ^ -

b)

abc × + de ^ f ^ -

c)

ab + c × d - e ^ f ^

d)

+ a × bc ^ ^ def

15.

To evaluate an expression without any embedded function calls : As many stacks as the height of the expression tree are needed One stack is enough Two stacks are needed A Turing machine is needed in the general case

a)

As many stacks as the height of the expression tree are needed

b)

One stack is enough

c)

Two stacks are needed

d)

A Turing machine is needed in the general case

16.

The result evaluating the postfix expression 10 5 + 60 6 / * 8 - is

a)

284

b)

213

c)

142

d)

71

17.

A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?

a)

6

b)

4

c)

3

d)

2

18.

Suppose a stack is to be implemented with a linked list instead of an array. What would be the effect on the time complexity of the push and pop operations of the stack implemented using linked list (Assuming stack is implemented efficiently)?

a)

O(1) for insertion and O(n) for deletion

b)

O(1) for insertion and O(1) for deletion

c)

O(n) for insertion and O(1) for deletion

d)

O(n) for insertion and O(n) for deletion

19.

Consider n elements that are equally distributed in k stacks. In each stack, elements of it are arranged in ascending order (min is at the top in each of the stack and then increasing downwards). Given a queue of size n in which we have to put all n elements in increasing order. What will be the time complexity of the best known algorithm?

a)

O(n logk)

b)

O(nk)

c)

O(n2)

d)

O(k2)

20.

If the elements "A", "B", "C" and "D" are placed in a queue and are deleted one at a time, in what order will they be removed?

a)

ABCD

b)

DCBA

c)

DCAB

d)

ABDC

21.

A normal queue, if implemented using an array of size MAX_SIZE, gets full when?

a)

Rear = MAX_SIZE - 1

b)

Front = (rear + 1)mod MAX_SIZE

c)

Front = rear + 1

d)

Rear = front

22.

Which one of the following is an application of Queue Data Structure?

a)

When a resource is shared among multiple consumers.

b)

When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes

c)

Load Balancing

d)

All of the above

23.

How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you.

a)

1

b)

2

c)

3

d)

4

24.

Which of the following is NOT a common operation in a queue data structure?

a)

Enqueue

b)

Dequeue

c)

Peek

d)

Shuffle

25.

 Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. The maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression?

a)

1

b)

2

c)

3

d)

4

26.

Only top element can be accessed in stack

a)

TRUE

b)

FALSE

27.

Stacks have LIFO ordering

a)

TRUE

b)

FALSE

28.

The postfix form of the expression (A+ B)*(C*D- E)*F / G is?

a)

AB + CDE * - * F *G /

b)

AB+ CD*E - FG /**

c)

AB + CD* E - F **G /

d)

AB + CD* E - *F *G /

29.

Which of them is an abstract data structure (ADT)?

a)

Stacks

b)

Functions

c)

Queues

d)

Both A and C

30.

LIFO stands for

a)

List of Outputs

b)

Last in First Out

c)

First in Last Out

d)

None of them

31.

Act of adding values into a stack is called

a)

Popping

b)

Polling

c)

Pushing

d)

None

32.

The postfix form of A*B+C/D is?

a)

*AB/CD+

b)

AB*CD/+

c)

A*BC+/D

d)

ABCD+/*

33.

Convert the following Infix expression to Postfix form using a stack


x + y * z + (p * q + r) * s

a)

xyz*+pq*r+s*+

b)

xyz*+pq*r+s+*

c)

xyz+*pq*r+s*+

d)

none

34.

Which of the following statement(s) about stack data structure is/are NOT correct?

a)

Stack data structure can be implemented using linked list

b)

New node can only be added at the top of the stack

c)

Stack is the FIFO data structure

d)

The last node at the bottom of the stack has a NULL link

35.

Which of the following application generally use a stack?

a)

Parenthesis balancing program

b)

Syntax analyzer in compiler

c)

Keeping track of local variables at run time

d)

All of the above

36.

Consider the following operation performed on a stack of size 5.


Push(1);

Pop();

Push(2);

Push(3);

Pop();

Push(4);

Pop();

Pop();

Push(5);


After the completion of all operation, the no of element present on stack are

a)

1

b)

2

c)

3

d)

4

37.

If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order will they be removed?

a)

ABCD

b)

DCBA

c)

DCAB

d)

ABDC

38.

In linked list implementation of a queue, where does a new element be inserted?

a)

At the head of link list

b)

At the centre position in the link list

c)

At the tail of the link list

d)

None of the mentioned

39.

In linked list implementation of a queue, from where is the item deleted?

a)

At the head of link list

b)

At the centre position in the link list

c)

At the tail of the link list

d)

None of the mentioned

40.

In linked list implementation of a queue, the important condition for a queue to be empty is?

a)

FRONT is null

b)

REAR is null

c)

LINK is empty

d)

None of the mentioned

41.

What is the term for inserting into a full queue known as?

a)

overflow

b)

underflow

c)

null pointer exception

d)

all of the mentioned

42.

a QUEUE in a computer acts just like people queuing for a bus - the first person in queue is going to be the first to get on the bus.

a)

True

b)

False

43.

A Queue uses a front and rear pointer?

a)

True

b)

False

44.
Which of these data structures is FIFO? 
a)
Stack
b)
Queue
c)
Binary Tree
d)
Double linked list
45.
What is returned by values[5]?
a)
9
b)
12
c)
6
d)
8
46.

Choose correct output for the following sequence of operations.

push(5)

push(8)

pop

push(2)

push(5)

pop

pop

pop

push(1)

pop

a)

8 5 2 5 1

b)

8 5 5 2 1

c)

8 2 5 5 1

d)

8 1 2 5 5

47.

Stack can be implemented using _________ and ________ ?

a)

Array and Binary Tree

b)

Linked List and Graph

c)

Array and Linked List

d)

Queue and Linked List

48.

When the function calls another function then the details of the previous function are stored in Stack?

a)

Yes

b)

No

49.

Consider an empty stack of an integers. Let the numbers 4,5,6,7,8 to be pushed on to this stack only in the order they appeared from left to right. Let P indicates PUSH and Q indicates POP operation. What sequence of operations should be performed on stack in order to get the output as 548.

a)

PPPXPPXX

b)

PPXPPPXX

c)

PPXXPPPX

d)

PXXPPXPX

50.

What is the postfix expression for the corresponding infix expression?

a+b*c+(d*e)

a)

abc*+de*+

b)

abc+*de*+

c)

a+bc*de+*

d)

abc*+(de)*+

51.

What is the postfix expression for the infix expression?

a-b-c

a)

abc--

b)

ab – c –

c)

– -abc

d)

-ab-c

52.

Which of the following statement is incorrect with respect to infix to postfix conversion algorithm?

a)

operand is always placed in the output

b)

operator is placed in the stack when the stack operator has lower precedence

c)

parenthesis are included in the output

d)

higher and equal priority operators follow the same condition

53.

What is the corresponding postfix expression for the given infix expression?

a+(b*c(d/e^f)*g)*h)

a)

ab*cdef/^*g-h+

b)

abcdef^/*g*h*+

c)

abcd*^ed/g*-h*+

d)

abc*de^fg/*-*h+

54.

What is the correct postfix expression for the following expression?

a+b*(c^d-e)^(f+g*h)-i

a)

abc^de-fg+*^*+i-

b)

abcde^-fg*+*^h*+i-

c)

abcd^e-fgh*+^*+i-

d)

ab^-dc*+ef^gh*+i-

55.

In linked list implementation of a queue, where does a new element be inserted?

a)

At the head of link list

b)

At the tail of the link list

c)

At the centre position in the link list

d)

None

56.

If the MAX_SIZE is the size of the array used in the implementation of circular queue, array index start with 0, front point to the first element in the queue, and rear point to the last element in the queue. Which of the following condition specify that circular queue is FULL?

a)

Front=rear= -1

b)

Front=(rear+1)%MAX_SIZE

c)

Rear=front+1

d)

Rear=(front+1)%MAX_SIZE

57.

A circular queue is implemented using an array of size 10. The array index starts with 0, front is 6, and rear is 9. The insertion of next element takes place at the array index.

a)

0

b)

7

c)

9

d)

10

58.

Which one of the following is not the application of the stack data structure

a)

String reversal

b)

Recursion

c)

Backtracking

d)

Asynchronous data transfer

59.

What is the outcome of the prefix expression +, -, *, 3, 2, /, 8, 4, 1 ?

a)

12

b)

11

c)

5

d)

4

60.

If the elements '1', '2', '3' and '4' are inserted in a queue, what would be order for the removal?

If the elements '1', '2', '3' and '4' are inserted in a stack, what would be order for the removal?

a)

1234

4321

b)

4321

1234

c)

3241

4123

d)

None

61.

The time complexity of enqueue operation in Queue is __

a)

O(1)

b)

O(n)

c)

O(logn)

d)

O(nlogn)

62.

Consider the following code.

int fun() {  

    if(isEmpty())  

{  

       return -10;   

 }  

  else  

  {  

      int n;  

     n= q[front];  

     front++;  

      return n;   

  }  

    

}   

Which operation does the above code perform?

a)

Enqueue

b)

Dequeue

c)

Return the front element

d)

Both b and c

63.

What would be the output after performing the following operations in a Deque?

Insertfront(10);  

Insertfront(20);  

Insertrear(30);  

Insertrear(40);  

Deletefront();  

Insertfront(50);  

Deleterear();  

Display();  

a)

10, 20, 30

b)

50, 10, 30

c)

40, 20, 30

d)

None of the above

64.

Consider the implementation of the singly linked list having the head pointer only in the representation. Which of the following operations can be performed in O(1) time?

i) Deletion of the last node in the linked list

ii) Insertion at the front of the linked list

iii) Deletion of the first node in the linked list

iv) Insertion at the end of the linked list

a)

ii

b)

both ii and iii

c)

both i and iv

d)

both i and ii

65.

Find the output of the following prefix expression.

*+2-2 1/-4 2+-5 3 1

a)

2

b)

12

c)

10

d)

4

66.

If -*+abcd = 11, find a, b, c, d using evaluation of prefix algorithm.

a)

a=2, b=3, c=5, d=4

b)

a=1, b=2, c=5, d=4

c)

a=5, b=4, c=7,d=5

d)

a=1, b=2, c=3, d=4

67.

n the given C snippet, find the statement number that has error.

//C code to push an element into a stack

1. void push( struct stack *s, int x)

2. {

3. if(s->top==MAX-1)

4. {

5. printf(“stack overflow”);

6. }

7. else

8. {

9. s->items[++s->top]=x;

10. s++;

11. }

12. }

a)

1

b)

9

c)

10

d)

11

68.

The result of evaluating the postfix expression 5, 4, 6, +, , 4, 9, 3, /, +, is?

a)

600

b)

350

c)

650

d)

588

69.

Consider the following operation performed on a stack of size 5.

Push(1);

Pop();

Push(2);

Push(3);

Pop();

Push(4);

Pop();

Pop();

Push(5);

After the completion of all operation, the no of element present on stack are

a)

1

b)

2

c)

3

d)

4

70.

Consider the usual implementation of parentheses balancing program using stack. What is the maximum number of parentheses that will appear on stack at any instance of time during the analysis of ( ( ) ( ( ) ) ( ( ) ) )?

a)

1

b)

2

c)

3

d)

4