wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Final Exam - Algorithms and Complexity 1

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.

What is the first step of Merge Sort?

a)

Merging pairs immediately

b)

Splitting the list into two halves

c)

Sorting each element individually

d)

Removing duplicates

2.

Using Merge sort, After the first split, the list [38,12,27,3,9,82,10,5] becomes:

a)

[38,12,27] | [3,9,82,10,5]

b)

[38,12,27,3] | [9,82,10,5]

c)

[38,12] | [27,3] | [9,82] | [10,5]

d)

[3,5,9,10] | [12,27,38,82]

3.

Unsorted [38,12,27,3,9,82,10,5] using Merge Sort,
What is the result of merging [38] and [12]?

a)

[38, 12]

b)

[12, 38]

c)

[50]

d)

[38]

4.

Unsorted [38,12,27,3,9,82,10,5] use the Merge Sort,
Which pair results in [3, 27] after merging?

a)

[12] and [38]

b)

[27] and [3]

c)

[5] and [10]

d)

[9] and [82]

5.

Unsorted [38,12,27,3,9,82,10,5] using the Merge Sort,
What is the result of merging [12, 38] and [3, 27]?

a)

[3, 12, 27, 38]

b)

[12, 27, 3, 38]

c)

[38, 12, 3, 27]

d)

[3, 27, 12, 38]

6.

Unsorted [38,12,27,3,9,82,10,5] using the Merge Sort,
What is the result of merging [10] and [5]?

a)

[10, 5]

b)

[5, 10]

c)

[15]

d)

[5]

7.

Unsorted [38,12,27,3,9,82,10,5] using the Merge Sort,
What is the result of merging [9, 82] and [5, 10]?

a)

[82, 9, 10, 5]

b)

[9, 5, 10, 82]

c)

[5, 9, 10, 82]

d)

[5, 10, 9, 82]

8.

Merge Sort is an example of which algorithmic technique?

a)

Greedy Algorithm

b)

Dynamic Programming

c)

Divide and Conquer

d)

Backtracking

9.

Unsorted [38,12,27,3,9,82,10,5] using the Merge Sort, What is the correct final sorted output?

a)

[3, 5, 9, 10, 12, 27, 38, 82]

b)

[82, 38, 27, 12, 10, 9, 5, 3]

c)

[12, 27, 38, 3, 5, 9, 10, 82]

d)

[3, 9, 5, 10, 12, 27, 38, 82]

10.

Unsorted [38,12,27,3,9,82,10,5] using the Merge Sort, Why does Merge Sort guarantee a correct sorted result?

a)

Because it guesses the correct order

b)

Because it sorts using random swaps

c)

Because merging always produces sorted lists

d)

Because it sorts only the largest elements

11.

What is the main idea of Quick Sort?

a)

Repeatedly merging sorted lists

b)

Repeatedly splitting into equal halves

c)

Partitioning the array around a pivot

d)

Using frequency counts

12.

Unsorted List: [38, 12, 27, 3, 9, 82, 10, 5] using Quick Sort,
which element was chosen as the first pivot?

a)

38

b)

3

c)

5

d)

27

13.

Unsorted List: [38, 12, 27, 3, 9, 82, 10, 5] using Quick Sort,
After the first partition using pivot 5, which number ends up immediately to the left of the pivot?

a)

9

b)

3

c)

12

d)

27

14.

Unsorted List: [38, 12, 27, 3, 9, 82, 10, 5] using Quick Sort,
After placing pivot 5 in its correct position, what does the array look like?

a)

[5, 3, 27, 38, 9, 82, 10, 12]

b)

[3, 27, 5, 38, 9, 82, 10, 12]

c)

[3, 5, 27, 38, 9, 82, 10, 12]

d)

[3, 27, 38, 5, 9, 10, 82, 12]

15.

Unsorted List: [38, 12, 27, 3, 9, 82, 10, 5] using Quick Sort,
Which element served as the pivot for the sub-array [27, 38, 9, 82, 10, 12]?

a)

10

b)

12

c)

27

d)

82

16.

Unsorted List: [38, 12, 27, 3, 9, 82, 10, 5] using Quick Sort,
What is the result after partitioning with pivot 12?

a)

[9, 10, 12, 82, 38, 27]

b)

[10, 9, 12, 38, 82, 27]

c)

[12, 9, 10, 27, 38, 82]

d)

[3, 5, 12, 10, 9, 27]

17.

Unsorted List: [38, 12, 27, 3, 9, 82, 10, 5] using Quick Sort,
Which sub-array is already sorted after processing pivot 10?

a)

[38, 27]

b)

[9, 10]

c)

[82, 38, 27]

d)

[3]

18.

Unsorted List: [38, 12, 27, 3, 9, 82, 10, 5] using Quick Sort,
For the sub-array [82, 38, 27], which element is used as the pivot?

a)

27

b)

82

c)

38

d)

5

19.

Unsorted List: [38, 12, 27, 3, 9, 82, 10, 5] using Quick Sort,
The final sorted array after applying Quick Sort is:

a)

[3, 5, 9, 10, 12, 27, 38, 82]

b)

[82, 38, 27, 12, 10, 9, 5, 3]

c)

[3, 9, 5, 12, 10, 27, 38, 82]

d)

[3, 5, 9, 10, 12, 27, 82, 38]

20.

What causes Quick Sort to fail worst-case performance?

a)

Choosing a pivot that is always the smallest or largest

b)

Using too many loops

c)

Sorting only half the array

d)

Removing duplicates

21.

Before using Binary Search, what must be done to the array?

a)

Remove duplicates

b)

Sort it in ascending order

c)

Reverse the array

d)

Replace all values with indexes

22.

Using Binary Search, What is the sorted version of the array [38,12,27,3,9,82,10,5]?

a)

[3, 5, 9, 10, 12, 27, 38, 82]

b)

[82, 38, 27, 12, 10, 9, 5, 3]

c)

[3, 9, 5, 12, 10, 27, 38, 82]

d)

[10, 9, 12, 27, 38, 82, 3, 5]

23.

What is the formula for finding the mid index?

a)

mid = (low + high)

b)

mid = low - high / 2

c)

mid = low + (high - low) // 2

d)

mid = (low - high) // 3

24.

in Binary Search - unsorted [38,12,27,3,9,82,10,5], When searching for 10, what value is found at mid on the first step?

a)

5

b)

3

c)

10

d)

12

25.

What is returned when the target is found during Binary Search?

a)

The array length

b)

The index of the target

c)

The mid value multiplied by 2

d)

The sorted array

26.

In Binary Search, When searching for 7, what happens when mid points to value 10?

a)

Set low = mid + 1

b)

Set high = mid − 1

c)

Return the index

d)

Swap low and high

27.

In which condition does Binary Search stop and declare “not found”?

a)

When low == mid

b)

When mid == high

c)

When low > high

d)

When high > low

28.

What is the time complexity of Binary Search?

a)

O(n²)

b)

O(n)

c)

O(log n)

d)

O(1)

29.

In Binary Search unsorted [38, 12, 27, 3, 9, 82, 10, 5], When searching for 7, what value does mid point to in the second step?

a)

3

b)

5

c)

9

d)

10

30.

Binary Search is best described as:

a)

A linear scanning algorithm

b)

A divide-and-conquer search algorithm

c)

A greedy algorithm

d)

A recursive-only algorithm

31.

A greedy algorithm always chooses the option that is:

a)

Globally optimal

b)

Locally optimal

c)

Randomly chosen

d)

Computed through recursion

32.

Greedy algorithms work only when the problem has:

a)

NP-hard structure

b)

Optimal substructure and greedy-choice property

c)

Dynamic programming property

d)

Backtracking behavior

33.

Most greedy algorithms run in:

a)

O(n²)

b)

O(n³)

c)

O(n log n) or better

d)

O(1)

34.

Which of the following is NOT a greedy algorithm.

a)

Activity Selection

b)

Huffman Coding

c)

Minimum Spanning Tree

d)

QuickSort

35.

The greedy-choice property means:

a)

All choices must be evaluated

b)

The local choice leads to global optimality

c)

The solution must always use recursion

d)

Choices must be random

36.

Greedy algorithms fail when:

a)

Local choices do not guarantee global optimality

b)

The input size is small

c)

Only one solution exists

d)

Recursion is removed

37.

The goal of the Activity Selection problem is to:

a)

Minimize total duration

b)

Select maximum non-overlapping activities

c)

Maximize total finish time

d)

Minimize number of selected activities

38.

The greedy rule for Activity Selection is to pick the activity:

a)

With shortest start time

b)

With longest duration

c)

That finishes earliest

d)

That starts latest

39.

which activity is selected first?

a)

B

b)

C

c)

A

d)

D

40.

Which activity is rejected because it starts before activity A finishes?

a)

B

b)

C

c)

A

d)

D

41.

In the final answer, the selected activities are:

a)

A, B, F

b)

A, D, E

c)

B, C, D

d)

A, C, F

42.

The maximum number of activities selected is:

a)

2

b)

3

c)

4

d)

5

43.

Huffman coding assigns shorter codes to characters that are:

a)

Used rarely

b)

Most frequent

c)

Alphabetically earlier

d)

Randomly generated

44.

The Huffman algorithm repeatedly combines the two:

a)

Longest codes

b)

Most frequent nodes

c)

Least frequent nodes

d)

Random nodes

45.

the two smallest frequencies combined first were:

a)

C and D

b)

E and F

c)

A and B

d)

B and C

46.

In HUFFMAN CODING, After combining A (5) and B (9), the new node has frequency:

a)

12

b)

13

c)

14

d)

15

47.

In HUFFMAN CODING, Which frequency pair was combined next?

a)

12 + 13

b)

16 + 45

c)

14 + 16

d)

25 + 30

48.

Huffman trees assign:

a)

1 to left and 0 to right

b)

0 to left and 1 to right

c)

Both 1

d)

Both 0

49.

The final root of the Huffman tree in the example has value:

a)

45

b)

30

c)

55

d)

100

50.

Huffman codes are:

a)

Prefix-free

b)

Always the same length

c)

Randomly assigned

d)

Linear search trees

51.

A Minimum Spanning Tree contains:

a)

All vertices with maximum weight

b)

All vertices with no cycles

c)

Some vertices only

d)

Duplicate edges

52.

Kruskal's algorithm sorts edges by:

a)

Alphabetical order

b)

Start vertex

c)

Weight (ascending)

d)

Vertex degree

53.

Kruskal builds the MST by:

a)

Adding edges that form cycles

b)

Selecting largest edges

c)

Adding smallest edges without forming cycles

d)

Removing edges randomly

54.

the smallest edge is:

a)

A–B (4)

b)

A–C (2)

c)

B–C (1)

d)

D–E (2)

55.

The total MST weight using Kruskal is:

a)

8

b)

12

c)

10

d)

15

56.

Prim’s Algorithm begins with:

a)

The largest vertex

b)

Any chosen vertex

c)

All vertices at once

d)

A sorted edge list

57.

Prim adds the edge that:

a)

Creates a cycle

b)

Has the maximum weight

c)

Is the smallest connecting to the tree

d)

Connects two visited nodes

58.

Starting at A, the first edge chosen

a)

A–B (4)

b)

A–C (2)

c)

C–B (1)

d)

B–D (5)

59.

The final MST edges for Prim are the same as:

a)

QuickSort results

b)

Bellman-Ford

c)

Kruskal’s MST

d)

Dijkstra’s output

60.

Prim works best for:

a)

Sparse graphs

b)

Dense graphs

c)

Linear arrays

d)

Directed acyclic graphs