wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Data Structures (linear DS)

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.

Given 6 items A,B,C,D,E & F are pushed in a stack S1, one after another starting from A. The stack is popped 3 items and each element is inserted in queue Q1. Again the stack S1 is popped 3 items and pushed to another stack S2. The two elements are deleted from the queue Q1 and pushed back to stack S1. Then three elements popped from stack S2 and each element is inserted in a queue Q1, then two elements from stack S1 are popped and inserted to queue Q1. What is the true statement Statement 1: both stacks S1 and S2 are equal Statement 2: All the elements (A,B,C,D,E,F) are present in queue Q1 Statement 3: both stacks S1 and S2 are empty Statement 4: Queue Q1 is empty

a)

Statement 1 and Statement 2 are false

b)

Statement 1 and Statement 2 are true

c)

Statement 3 is false

d)

Statement 3 and 4 are true

2.

A Double-ended queue supports operations such as adding and removing items from both the sides of the queue. They support four operations like addFront(adding item to top of the queue), addRear(adding item to the bottom of the queue), removeFront(removing item from the top of the queue) and removeRear(removing item from the bottom of the queue). You are given only stacks to implement this data structure. You can implement only push and pop operations. What are the total number of stacks required for this operation?(you can reuse the stack)

a)

1

b)

2

c)

3

d)

4

3.

You are given a queue of characters representing the instructions for a robot. The robot can move forward ('F') or turn around ('T'). The initial position of the robot is facing right and position with coordinates (0,0). Your task is to determine the final position and direction of the robot after executing all the instructions. Hint:Create variables to keep track of the current position (X, Y coordinates) and the current direction (right, left, up, down). Initialize these variables accordingly. If the instruction is 'F', update the position based on the current direction. If the instruction is 'T', update the direction based on the current position and the turning rules right -> down -> left -> up -> right(Eg:if the current direction is right, instruction T is given, it will turn down). For instruction 'T' the robot should only turn around in the same position, but it should not move. Instruction:['F', 'T', 'F', 'F', 'T', 'T', 'F', 'F', 'F']

a)

Position :(-1,3) direction:UP

b)

Position :(1,1) direction:UP

c)

Position :(-1,-1) direction:LEFT

d)

Position :(1,1) direction:DOWN

4.

The optimal data structure used to solve Tower of Hanoi is _________

a)

Tree

b)

Queue

c)

Stack

d)

Linkedlist

5.

In an event-driven system, events are inserted into a priority queue based on their urgency. During execution, some event priorities may change (increase or decrease).

What challenge does this create for a typical binary heap-based priority queue?


a)

The queue must be rebalanced manually

b)

Changed priorities are automatically updated

c)

The heap size changes

d)

Priority changes are handled in constant time

6.

What happens if two elements have the same priority in a priority queue?

a)

Only one is inserted

b)

They are sorted by name

c)

The queue may return either one first

d)

The queue throws an error

7.

Below snippet code deletes values from the front in an circular deque

What is the purpose of this line “front = (front + 1) % capacity;”?

a)

Moves the front pointer backward


b)

Moves the front pointer forward circularly

c)

Always resets front to 0

d)

Moves the rear pointer instead

8.

What is the number of moves required to solve Tower of Hanoi problem for k disks?

a)

2^k– 1

b)

2^k+1

c)

2*k-1

d)

2*k+1

9.

You are given the string: "((()[{]}]){}("

You are using a stack to check for balanced parentheses.What will be the final state of the stack after processing all characters in the string?

a)
  1. [ ( ( 

b)
  1. ( ( ]

c)
  1. [ } }

d)
  1. [ ( )

10.

Below code supposed to find minimum number of jumps to reach the end of an array, but there is some logical error in this code example: arr={2, 3, 1, 1, 4}

a)

farthest = max(farthest, i + nums[i]) should be inside an if condition


b)

The condition i == farthest is checked twice and causes a logic error

c)

The return type of the function should be bool instead of int

d)

There should be a nested loop to try all paths

11.

Consider a Linked list of values 1,2,3,4,5,6,7,8,9,10. what is the functionality of the following code


a)

Reverse alternate kth node in a singly linked list

b)

Finds kth node in given linked list

c)

Finds kth node from end of linked list

d)

Rotate linked list from Kth node

12.

Below code finds the loop in a linked list,A loop in a linked list occurs when any node points to a previously visited node 

for example: 1 2 3 4 3 (3->4->3 makes a loop).

Which of the following inputs will have no loop.


a)

  1. [1,2,3,4,5,7,8,3,5]

b)

[1,2,3,4,3,7,4,3,5]

c)

[10,18,17,16,15,19,16,18,15,16,19]

d)

[10,18,17,16,18,19,10]

13.

Given array elements [3, 2, 4, 5, 7, 8] What is the functionality of the below code

a)
  1. Checks given array is non-decreasing order

b)
  1. Checks given array is non-Increasing order

c)
  1. Checks given array is unsorted order

d)
  1. Checks given array is empty after performing stack operations

14.

Which of the following is a good real-world use case for a priority queue?

a)

Saving user data in a file

b)

Simulating call center task handling based on urgency

c)

Displaying images in a gallery

d)

Rotating banner ads

15.

Which use case is best suited for a min-heap?

a)

Finding the maximum score in real-time

b)

Scheduling tasks with earliest deadline

c)

Sorting data in descending order

d)

Implementing a LIFO stack