wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Algorithm questions

Total questions: 20

Worksheet time: 15mins

Name
Class
Date
1.
Consider this list of numbers: 9 3 6 8 4 7. An algorithm compares 9 and 3 followed by 9 and 6 followed by 9 and 8. Which algorithm is being described?
a)
Bubble sort
b)
Insertion sort
c)
Merge sort
d)
Binary search
2.
Comparing a bubble sort to the insertion sort, which is the better algorithm in terms of time complexity on average?
a)
They are both similar
b)
Bubble sort
c)
Insertion sort
d)
It is not possible to determine
3.
Consider this list of numbers: 3 4 6 7 8 9. If the number 9 was to be found using a linear search, how many comparisons need to be made?
a)
6
b)
3
c)
8
d)
4
4.
What is the main disadvantage of a binary search compared to a linear search?
a)
It requires the data to be in order
b)
It requires more memory
c)
It does not execute as quickly with larger data sets
d)
Not all CPUs are capable of executing the algorithm
5.
An advantage of pseudocode is that:
a)
It is a convenient way of designing algorithms to aid thinking logically
b)
Algorithms are represented graphically
c)
There are standards for representing syntax
d)
It is easier to see where there are logic errors in a program
6.
The recursive algorithm to perform a post-order traversal of a binary tree can be described simply as:
a)
Left pointer, right pointer, node
b)
Node, left pointer, right pointer
c)
Left pointer, node, right pointer
d)
Right pointer, left pointer, node
7.
The recursive algorithm to perform a pre-order traversal of a binary tree can be described simply as:
a)
Node, left pointer, right pointer
b)
Left pointer, node, right pointer
c)
Left pointer, right pointer, node
d)
Right pointer, left pointer, node
8.
Consider this list of numbers L: 3 4 5 6 7 8 9. Which number would be checked first in a binary search?
a)
6
b)
3
c)
9
d)
4
9.
Consider this list of numbers: 9 3 6 8 4 7. A bubble sort algorithm starts from the first item in the list (9) and orders the list from lowest to highest number. What is the order of the numbers after one pass through all the numbers of the bubble sort algorithm on this list?
a)
3 6 8 4 7 9
b)
9 3 6 8 4 7
c)
3 4 6 7 8 9
d)
3 6 8 9 4 7
10.
O(1) describes which type of algorithm complexity?
a)
Constant
b)
Logarithmic
c)
Linear
d)
Polynomial
11.
What is the time complexity of a binary search in best case?
a)
O(1)
b)
O(n)
c)
O(n^2)
d)
O(log n)
12.
What is the time complexity of finding an item using a breadth first search in best case?
a)
O(1)
b)
O(n)
c)
O(n^2)
d)
O(log n)
13.
Comparing a merge sort to a quicksort, which is the better algorithm in terms of time complexity on average?
a)
They are both similar
b)
Quicksort
c)
Merge sort
d)
It is not possible to determine
14.
What is the time complexity of finding an item in a hashing table on average?
a)
O(1)
b)
O(log n)
c)
O(n)
d)
O(n^2)
15.
One difference between Dijkstra's shortest path and the A* algorithm is that:
a)
A* uses a heuristic
b)
Dijkstra's shortest path uses a heuristic
c)
A* finds a path between the start node and all others
d)
Dijkstra's shortest path uses divide and conquer
16.
What is the time complexity of an insertion sort on average and worst case?
a)
O(n^2)
b)
O(1)
c)
O(n)
d)
O(log n)
17.
How can a search on a binary tree result in linear time complexity O(n) when it makes use of divide and conquer?
a)
The binary tree is unbalanced with all items stored on a left or right pointer
b)
The binary tree is balanced with an equal height for all leaf nodes
c)
The binary tree is a graph with some nodes having more than two children
d)
The binary tree only has one item, a single root node
18.
On average, which searching algorithm would give the worst performance?
a)
Linear search
b)
Binary search tree
c)
Hashing function
d)
Binary search array
19.
What is the time complexity of a binary search on average?
a)
O(log n)
b)
O(n)
c)
O(n2)
d)
O(1)
20.
What is the time complexity of a quicksort on average?
a)
O(n log n)
b)
O(n2)
c)
O(n)
d)
O(log n)