wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DSA-Quiz-1

Total questions: 40

Worksheet time: 23mins

Name
Class
Date
1.

Explain the difference between O(n) and O(log n) complexity.

a)

O(n) is linear complexity, while O(log n) is logarithmic complexity.

b)

O(n) is faster than O(log n) for large inputs.

c)

O(n) is logarithmic complexity, while O(log n) is quadratic complexity.

d)

O(n) is constant complexity, while O(log n) is exponential complexity.

2.

What are the main operations of a stack?

a)

Insert, Delete, View, Check

b)

Enqueue, Dequeue, Top, Size

c)

Push, Pop, Peek, IsEmpty

d)

Add, Remove, Display, Clear

3.

How can a stack be used to reverse a string?

a)

Use a stack to push characters of the string and then pop them to form the reversed string.

b)

Replace each character in the string with its ASCII value to reverse it.

c)

Use a queue to enqueue characters and then dequeue them to reverse the string.

d)

Reverse the string by sorting its characters alphabetically.

4.

Describe a real-world application of a queue.

a)

A list of items in a shopping cart.

b)

A stack used for managing browser history.

c)

Customer service systems, such as banks or call centers, where customers are served in the order they arrive.

d)

A database for storing customer information.

5.

List the different methods for traversing a binary tree.

a)

Binary search

b)

Depth-first search

c)

Pre-order, In-order, Post-order

d)

Breadth-first search

6.

What is the role of the stack in the infix to postfix conversion?

a)

The stack is used to evaluate the postfix expression immediately.

b)

The stack holds operators and parentheses to ensure correct order of operations in postfix notation.

c)

The stack stores the final postfix expression directly.

d)

The stack manages memory allocation for the conversion process.

7.

What is the result of the postfix expression: 3 4 + 2 * 7 / ?

a)

1

b)

3

c)

2

d)

4

8.

How do you find the height of a binary tree?

a)

The height of a binary tree is the number of edges on the longest path from the root to a leaf.

b)

The height is the depth of the deepest node from the root.

c)

The height is the number of leaves in the tree.

d)

The height is the total number of nodes in the tree.

9.

What is the significance of the post-order traversal in a binary tree?

a)

It is used to delete the tree.

b)

It retrieves nodes in ascending order.

c)

It visits all nodes in a left-right-root order.

d)

It processes the root node before its children.

10.

What is the result of the postfix expression: 8 2 5 * 7 + - ?

a)

4

b)

6

c)

1

d)

3

11.

What is the primary difference between a stack and a queue?

a)

Both follow the same order of operations.

b)

A stack follows LIFO order, while a queue follows FIFO order.

c)

A stack can only store numbers, while a queue can store any data type.

d)

A stack follows FIFO order, while a queue follows LIFO order.

12.

What is the main characteristic of a priority queue?

a)

It is implemented using a linked list.

b)

It only allows unique elements.

c)

Elements are processed based on their priority.

d)

Elements are processed in the order they are added.

13.

It is a method of solving problems that involves breaking a problem down into smaller and smaller sub problems until you get to a small enough problem that it can be solved trivially.

a)

Recursion

b)

Iteration

c)

Looping

14.

What is a data structure?

a)

A method of arranging data

b)

A way of keeping data without an order?

c)

A "stack" only

d)

There is no formal definition for "Data Structure"

15.

Which of these data structures is FIFO?

a)

Stack

b)

Queue

c)

Binary Tree

d)

Linked List

16.

Stack is also called as

a)

Last in first out

b)

First in last out

c)

Last in last out

d)

First in first out

17.

Which of the following data structure is non linear type?

a)

Stack

b)

Queue

c)

Tree

d)

Liked list

18.

In linked list each node is divided into ___________parts?

a)

one

b)

two

c)

three

d)

four

19.

In stack insertion and deletion can take place only at one end call the ____________________ of the stack.

a)

Path

b)

Function

c)

Top

d)

Bottom

20.

Algorithm is a __________________ procedure.

a)

shortcut

b)

function

c)

reverse

d)

step by step

21.

In which algorithm takes less time or space is called

a)

Best case

b)

Worst case

c)

Average case

d)

None of the above

22.

The number of edges from the node to the deepest leaf is called ___ of the tree.

a)

Height

b)

Depth

c)

Length

d)

Width

23.

What is a full binary tree?

a)

Each node has exactly zero or two children

b)

Each node has exactly two children

c)

All the leaves are at the same level

d)

Each node has exactly one or two children

24.

What is a complete binary tree?

a)

 Each node has exactly zero or two children

b)

A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from right to left

c)

A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right

d)

A tree In which all nodes have degree 2

25.

How many number of fields in each node of a doubly linked list is ____

a)

A. 2

b)

B. 3

c)

C. 4

d)

D. 5

26.

Identify the data structure which allows deletions at both ends of the list but insertion at only one end.

a)

A. Input restricted dequeue

b)

B. Output restricted dequeue

c)

C. Circular queue

d)

D. Priority queue

27.

The operation of visiting each element in the list is known as ……

a)

A. Sorting

b)

B. Traversing

c)

C. Merging

d)

D. Inserting

28.

What is the time complexity of following code:

int a = 0;

for (i = 0; i < N; i++) {

for (j = N; j > i; j--) {

a = a + i + j;

}

}

a)

O(N)

b)

O(N*log(N))

c)

O(N * Sqrt(N))

d)

O(N*N)

29.
What two pieces of information allow you to analyse an algorithm?
a)
Time Complexity
b)
Space Complexity
c)
Size Complexity
d)
Complex Complexity
e)
Simplicity Complex
30.

What is the time complexity of this algorithm?

a)

O(n)

b)

O(2n)

c)

O(log n)

d)

O(n2)

e)

O(1)

31.

Define time complexity and space complexity.

a)

Time complexity is the time taken by an algorithm, while space complexity is the memory used by an algorithm.

b)

Time complexity is the amount of data processed by an algorithm.

c)

Space complexity refers to the number of lines in an algorithm.

d)

Time complexity measures the speed of a computer.

32.

What is infix notation?

a)

Operators are placed before the operands.

b)

Operators are placed after the operands.

c)

Operators are placed randomly.

d)

Operators are placed between the operands.

33.

What happens when a closing parenthesis is encountered during conversion?

a)

Pop operators until an opening parenthesis is found.

b)

Add the closing parenthesis to the postfix expression.

c)

Push the closing parenthesis onto the stack.

d)

Ignore the closing parenthesis.

34.

Which of the following is an example for a postfix expression?

a)

a*b(c+d)

b)

abc*+de-+

c)

+ab

d)

a+b-c

35.

The prefix form of an infix expression (p + q) – (r * t) is?

a)

a) + pq – *rt

b)

b) – +pqr * t

c)

c) – +pq * rt

d)

d) – + * pqrt

36.

Find the postfix expression for: A+B+C+D+E

a)

AB+C+D+E+

b)

AB+C+D++E

c)

ABC++D+E+

d)

AB+C+D+E++

37.

The type of expression in which operator succeeds its operands is?

a)

a) Infix Expression

b)

b) Prefix Expression

c)

c) Postfix Expression

d)

d) Both Prefix and Postfix Expressions

38.

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

39.

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

40.

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