wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Code Uncode 2.0

Total questions: 40

Worksheet time: 40mins

Name
Class
Date
1.

In order traversal of binary search tree will produce −

a)

unsorted list

b)

sorted list

c)

reverse of input

d)

none of the above

2.

What data structure is used for breadth first traversal of a graph?

a)

queue

b)

stack

c)

list

d)

none of the above

3.

left_subtree (keys) ≤ node (key) ≤ right_subtree (keys)

a)

Complete Binary Tree

b)

Binary Tree

c)

Binary Search Tree

d)

All of the above

4.

If the array is already sorted, which of these algorithms will exhibit the best performance

a)

Merge Sort

b)

Insertion Sort

c)

Quick Sort

d)

Heap Sort

5.

An algorithm is

a)

a piece of code to be executed.

b)

a loosely written code to make final code.

c)

a step by step procedure to solve problem.

d)

all of the above.

6.

In binary heap, whenever the root is removed then the rightmost element of last level is replaced by the root. Why?

a)

It is the easiest possible way.

b)

To make sure that it is still complete binary tree.

c)

Because left and right subtree might be missing.

d)

None of the above!

7.

If queue is implemented using arrays, what would be the worst run time complexity of queue and dequeue operations?

a)

Ο(n), Ο(n)

b)

Ο(n), Ο(1)

c)

Ο(1), Ο(n)

d)

Ο(1), Ο(1)

8.

Program with highest run-time complexity is

a)

Tower of Hanoi

b)

Fibonacci Series

c)

Prime Number Series

d)

None of the above

9.

If we choose Prim's Algorithm for uniquely weighted spanning tree instead of Kruskal's Algorithm, then

a)

we'll get a different spanning tree.

b)

we'll get the same spanning tree.

c)

spanning will have less edges.

d)

spanning will not cover all vertices.

10.

Which of the following algorithm does not divide the list −

a)

linear search

b)

binary search

c)

merge sort

d)

quick sort

11.

Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?

a)

Insertion sort

b)

Quick sort

c)

Heap sort

d)

Merge sort

12.

Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are

a)

Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT

b)

Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR

c)

Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT

d)

Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT

13.

A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

a)

An array of 50 numbers

b)

An array of 100 numbers

c)

An array of 500 numbers

d)

A dynamically allocated array of 550 numbers

14.

In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is

a)

log(2*n)

b)

n/2

c)

log(2*n) -1

d)

n

15.

What is the worst case possible height of AVL tree?

a)

2Logn, Assume base of log is 2

b)

1.44log n, Assume base of log is 2

c)

Depends upon implementation

d)

Theta(n)

16.

Which of the following is AVL Tree?

a)

Only A

b)

A and C

c)

A, B and C

d)

Only B

17.

B+ Trees are considered BALANCED because

a)

the lengths of the paths from the root to all leaf nodes are all equal.

b)

the lengths of the paths from the root to all leaf nodes differ from each other by at most 1.

c)


the number of children of any two non-leaf sibling nodes differ by at most 1.

d)


the number of records in any two leaf nodes differ by at most 1.

18.

The minimum number of stacks needed to implement a queue is

a)

3

b)

1

c)

2

d)

4

19.

The average depth of a binary search tree is:

a)

O(n0.5)

b)


O(n)

c)


O(log n)

d)

O(n log n)

20.

The five items: A, B, C, D, and E are pushed in a stack, one after other starting from A. The stack is popped four items and each element is inserted in a queue. The two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack. The popped item is

a)

A

b)

B

c)

C

d)

D

21.

Which of the following correctly declares an array?

a)

int geeks[20];

b)

int geeks;

c)

geeks{20};

d)

array geeks[20];

22.

What is the time complexity of binary search algorithm?

a)

O(n)

b)

O(log n)

c)

O(n^2)

d)

O(1)

23.

What is the worst case time complexity of quicksort algorithm?

a)

O(n)

b)

O(log n)

c)

O(n^2)

d)

O(1)

24.

Which of the following is not a stable sorting algorithm?

a)

Insertion sort

b)

Selection sort

c)

Bubble sort

d)

Quick sort

25.

What is the main advantage of using a hash table data structure?

a)

Constant time for all operations

b)

Efficient sorting

c)

Efficient searching in a sorted array

d)

Dynamic resizing

26.

Which sorting algorithm has the worst-case time complexity of O(n^2) but is widely used for small datasets or as a subroutine in other algorithms?

a)

Quick Sort

b)

Bubble Sort

c)

Merge Sort

d)

Insertion Sort

27.

In a binary search tree, which traversal visits the nodes in ascending order?

a)

Preorder

b)

Inorder

c)

Postorder

d)

Level Order

28.

Which data structure is used to implement priority queues?

a)

Stack

b)

Queue

c)

Heap

d)

Linked List

29.

Which of the following is NOT a type of algorithm design paradigm?

a)

Divide and Conquer

b)

Dynamic Programming

c)

Sequential

d)

Greedy

30.

Which of the following is NOT a fundamental operation in a binary search tree?

a)

Insertion

b)

Deletion

c)

Searching

d)

Sorting

31.

In dynamic programming, what does "optimal substructure" mean?

a)

A problem can be divided into smaller subproblems

b)

A solution can be built from solutions to subproblems

c)

A problem can be solved by a greedy algorithm

d)

A solution is derived by choosing the best option at each step

32.

Which sorting algorithm has a time complexity of O(n log n) in the best, average, and worst cases?

a)

Bubble Sort

b)

Selection Sort

c)

Merge Sort

d)

Insertion Sort

33.

Which algorithm is used for finding the shortest path in a weighted graph when there are negative weight edges?

a)

Dijkstra's Algorithm

b)

Bellman-Ford Algorithm

c)

Prim's Algorithm

d)

Kruskal's Algorithm

34.

What is the primary advantage of using an AVL tree over a regular binary search tree?

a)

Faster insertion

b)

Faster deletion

c)

Guaranteed balanced height

d)

Lower memory usage

35.

Given an algorithm with a time complexity of O(2^n), how will the running time be affected if the input size is doubled?

a)

It will remain the same

b)

It will be halved

c)

It will double

d)

It will quadruple

36.

Suppose you have an algorithm with a time complexity of O(log n) and another with a time complexity of O(sqrt(n)). As n increases, which algorithm will have a slower growth rate in terms of time?

a)

O(log n)

b)

O(sqrt(n))

c)

Both will have the same growth rate

d)

It depends on the specific values of n

37.

You have an algorithm with a time complexity of O(n^2) and another with a time complexity of O(n log n). For what range of input sizes, will the algorithm with O(n log n) be faster?

a)

n < 10

b)

10 < n < 100

c)

100 < n < 1000

d)

n > 1000

38.

Consider a weighted directed graph with n vertices and m edges. What is the maximum possible time complexity to find the shortest path between two vertices using Dijkstra's algorithm?

a)

O(n log n)

b)

O(n^2)

c)

O(m + n log n)

d)

O(n^3)

39.

You are given a weighted, connected, undirected graph. You want to find a spanning tree with the minimum possible weight. Which algorithm should you use?

a)

Prim's Algorithm

b)

Bellman-Ford Algorithm

c)

Kruskal's Algorithm

d)

Floyd-Warshall Algorithm

40.

In algorithm design, what is the primary purpose of the "Master Theorem"?

a)

To analyze the average-case time complexity of algorithms

b)

To analyze the worst-case time complexity of algorithms

c)

To provide a general framework for solving recurrence relations

d)

To optimize algorithms for specific use cases