Font size
WorksheetsData Structure - Final Assessment (18-7-2023)
Total questions: 100
Worksheet time: 2hrs 40mins
Which sorting algorithm makes one swap per pass (possibly swapping an element with itself)?
Selection Sort
Bubble Sort
Insertion Sort
4 8 6 2 5 7
4 8 6 2 5 7
4 6 8 2 5 7
1 4 2 9 3 8 5
What does the list look like after one pass of the bubble sort algorithm.
Time complexity of bubble sort in best case is
a) θ (n)
b) θ (nlogn)
c) θ (n2)
d) θ (n(logn) 2)
Which of these algorithms sorts items by first splitting the list of items down into smaller and smaller groups?
Bubble sort
Merge sort
Linear search
Binary search
What algorithm does this image represent?
Bubble sort
Merge sort
Linear search
Binary search
Partition a list A[] into two non-empty parts.
in left part the values should be:
A [ ] <= pivot
A [ ] > pivot
A[] >= pivot
A [ ] < pivot
Partition a list A[] into two non-empty parts.
in right part the values should be:
A [ ] > pivot
A [ ] >= pivot
A [ ] < pivot
A [ ] <= pivot
Which algorithm matches this description: "a sorting algorithm that repeatedly partitions the input into low and high parts (each part unsorted), and then recursively sorts each of those parts."
Selection Sort
Insertion Sort
Shell Sort
Quicksort
Which of the following is a max-heap?
Consider a binary max-heap implemented using an array. Which one of the following array represents a binary max-heap?
25,12,16,13,10,8,14
25,12,16,10,13,8,14
25,14,16,13,10,8,12
25,14,12,13,10,8,16
The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap is.
Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4. Now consider that a value 35 is inserted into this heap. After insertion, the new heap is
40, 30, 20, 10, 15, 16, 17, 8, 4, 35
40, 35, 20, 10, 30, 16, 17, 8, 4, 15
40, 30, 20, 10, 35, 16, 17, 8, 4, 15
40, 35, 20, 10, 15, 16, 17, 8, 4, 30
Given a binary-max heap. The elements are stored in an arrays as 25, 14, 16, 13, 10, 8, 12. What is the content of the array after two delete operations?
14,13,8,12,10
14,12,13,10,8
14,13,12,8,10
14,13,12,10,8
The 2 properties of a min heap are _____.
Tree must be full.
Tree must be complete.
Node values are always smaller than their children's values.
Node values are always greater than their children's values.
How many swaps are made in the min heap when inserting the value 18?
0
1
2
3
When removing the root from a min heap, what is the first step?
Replace the root with the next smallest value from the tree
Replace the root with the leaf furthest to the left on the bottom level of the tree
Replace the root with the leaf furthest to the right on the bottom level of the tree
Replace the root with the smallest of its children
When adding a value to a min heap, the first step is to ______.
Add the new node at the next open leaf.
Replace the root's value with the new value.
Replace the roots smallest child with the new value.
Add the new node as far right as possible on the bottom level of the tree.
Select the best description to explain what a binary search algorithm is.
Put the elements in order, check each item in turn.
Put the elements in order, compare with the middle value, split the list in order and repeat.
Elements do not need to be in order, check each item in turn.
Elements do not need to be in order, compare to the middle value, split the list in order and repeat
12 6 8 1 3
How many comparisons would it take to find number 1?
3 5 9 10 23
How many comparisons would it take to find number 9?
1 5 10 13 48 68 100 101
How many comparisons would it take to find number 101?
int nums[ ] =
{2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums
nums[8]
nums[3]
nums(4)
nums(3)
A FIFO structure implemented as a ring where the front and rear pointers can wrap around the end of the start of the array.
Linear Queue
Circular Queue
Priority Queue
LIFO stands for
List of Outputs
Last in First Out
First in Last Out
None of them
Act of adding values into a stack is called
Popping
Polling
Pushing
None
If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one at a time, in what order will they be removed?
ABCD
DCBA
DCAB
ABDC
In some languages, arrays are also called ___
groups or arrows
roots or leaves
lists or vectors
lines or strings
A data type that can be used to group items of possibly different types into a single type is called ___
a root
a struct
a tree
a pointer
A flexible data structure that can store many nodes is called ___
a tree
a linked list
a pointer
a queue
When linked lists are used as stacks, what kind of behaviour is implemented?
First-In First-Out, or FIFO
First-In Last-Out, or FILO
Last-In Last-Out, or LILO
Last-In First-Out, or LIFO
In a tree data structure, the top most node is called ___
the peak
the apex
the crown
the root
In a tree data structure, any nodes that hang from other nodes are called ___
branched nodes
leaf nodes
children nodes
daughter nodes
In a tree data structure, any nodes that have no children (where the tree ends) are called ___
boundary nodes
leaf nodes
orphan nodes
terminal nodes
What is the value of the ROOT node in this Tree?
35
24
42
20
Root
data structure similar to a graph, with no loops.
an object in a graph also known as a vertex
a join of relationship between nodes - also know as an arc
the starting node in a rooted tree structure from which all other nodes branch off./
Tree
data structure similar to a graph, with no loops.
an object in a graph also known as a vertex
a join of relationship between nodes - also know as an arc
the starting node in a rooted tree structure from which all other nodes branch off./
How many leaf are there in the tree?
1
3
4
7
Which Time and Space Complexity uses the O(n2) notation?
Quadratic
Linear
Exponential
Logarithmic
What is the time complexity of this code
int a = 0, i = N;
while (i > 0)
{
a += i;
i /= 2;
}
O(N)
O(Sqrt(N))
O(N / 2)
O(log N)
The complexity of Binary search algorithm is
O(n)
O(log n)
O(n2)
O(n log n)
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;
}
}
O(N)
O(N*log(N))
O(N * Sqrt(N))
O(N*N)
What is the time complexity of following code:
int i, j, k = 0;
for (i = n / 2; i <= n; i++) {
for (j = 2; j <= n; j = j * 2) {
k = k + n / 2;
}
}
O(n)
O(nLogn)
O(n^2)
O(n^2Logn)
A linear function takes the form
f(n) = an + b
f(n) = an2 +bn + c
f(n) = alog2n
f(n) = a + b
Find the slowest algorithm:
O (n)
O (n^2)
O (n!)
O (2^n)
The number of executions grows extremely quickly as the size of the input increases
Exponential Time
Linear Time
Polynomial Time
Constant Time
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
X will be a better choice for all inputs
X will be a better choice for all inputs except possibly small inputs
X will be a better choice for all inputs except possibly large inputs
Y will be a better choice for small inputs
What is the worst case running time of the above pseudo code?
O(n)
O(n log n)
O(n2)
O(n3)
asymptotic notations represents
space complexity of algo
time complexity of algo
both a and b
none of the above
Big
Ω defineslower bound
upper bound
middle bound
none of the above
What is the worst case complexity of selection sort?
O(n log n)
O(log n)
O(n)
O(n2)
The stack is also known as?
Last in first out
First in last out
First in first out
.none of these
define the name of the process in which items are added at one end and removed from another side?
stack
Queue
List
Tree
Define the value of r in a circular queue?
r=r+1
r=(r+1)%[QUEUE_SIZE=1]
r=(r+1)% QUEUE_SIZE
r=(r-1)% QUEUE_SIZE
What is the worst case complexity of bubble sort?
O(nlogn)
O(logn)
O(n)
O(n2)
The measure of the longest amount of time possibly taken to complete an algorithm is expressed as __.
Little-O
Little-Omega
Big-Omega
Big-O
___ of an algorithm is the amount of time required for it to execute.
Time complexity
Space complexity
Compiling time
Best case
___ is the maximum amount of time an algorithm takes to execute a specific set of inputs.
Running time
Average case time complexity
Worst case time complexity
Best case time complexity
Which one of the following helps in calculating the longest amount of time taken for the completion of the algorithm?
Theta notation
Big-Oh notation
Omega notation
Time complexity
Which method is practical to perform a single search in an unsorted list of elements?
Sequential search
Bubble sort
Horspool’s method of string matching
Brute force method of string matching
Which of the following best describes the useful criterion for comparing the efficiency of algorithms?
Time
Memory
Both of the above
None of the above
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
X will always be a better choice for small inputs
X will always be a better choice for large inputs
Y will always be a better choice for small inputs
X will always be a better choice for all inputs
If for an algorithm time complexity is given by O(1) then complexityof it is:
constant
polynomial
exponential
none of the mentioned
If for an algorithm time complexity is given by O(n) then complexityof it is:
constant
linear
exponential
none of the mentioned
What is the time complexity of following code:
int a = 0, i = N;
while (i > 0)
{
a += i;
i /= 2;
}
O(N)
O(Sqrt(N))
O(N / 2)
O(log N)
The asymptotic upper-bound of f(n)=20n2+100n+2 is O(n2)
True
False
The asymptotic upper-bound of f(n)=2n+2n is O(n2)
True
False
If for an algorithm time complexity is given by O(1) then complexity of it is
constant
polynomial
exponential
none of the mentioned
If for an algorithm time complexity is given by O(n) then complexity of it is
constant
linear
exponential
none of the mentioned
What is the time complexity of following code
int a = 0, i = N;
while (i > 0) {
a + = i;
i / = 2;
}
O(N)
O(Sqrt(N))
O(N / 2)
O(log N)
The linear/sequential search method to search an element in an array has the complexity of BigO(?)
n
n-1
n^2
n logn
Indicate exponential time complexity in terms of big-O notation
O (n)
O (n^2)
O (2^n)
O (log n)
Find the slowest time complexity
O (n)
O (n^2)
O (n!)
O (2^n)
Which notation is consistent for every execution?
O (n)
O (n^2)
O (1)
O (2^n)
Which notation grows in proportion to the size of the input
O (n)
O (n^2)
O (1)
O (2^n)
Which notation would you usually use for a nested loop?
O (n)
O (n^2)
O (1)
O (2^n)
The number of executions grows extremely quickly as the size of the input increases
Exponential Time
Linear Time
Polynomial Time
Constant Time
The number of executions remains the same regardless of the input size
Exponential Time
Linear Time
Polynomial Time
Constant Time
The number of executions grows quickly by the input being multiplied by the input
Exponential Time
Linear Time
Polynomial Time
Constant Time
For every element, you are doing a constant number of operations, such as comparing each element to a known value.
Quadratic
Linear
Logarithmic
Constant
Exponential
What is the correct Big O notation for an algorithm where the number of operations (steps) can be expressed as:
4n3 +3n log2n + 273 n is the size of the input.
O(n2)
O(3n)
O(log2n)
O(273)
O(n3)
What is the big-Oh runtime of A()?
O(nlogn)
O(n2)
O(n)
O(10⋅n)
What is true for f(n)=logn and g(n)=n ?
f(n)=O(g(n))
f(n)=θ(g(n))
f(n)=Ω(g(n))
What is the maximum number of comparisons that a binary search will apply for an array of length 30.
30
15
5
3
2
What is the big-Oh runtime of B()?
O(n2)
O(n3)
O(30⋅n)
O(n)
Which of these is true for f(n)=5n3+7n+13 and g(n) = n5 ?
f(n)=θ(g(n))
f(n)=Ω(g(n))
f(n)=O(g(n))
What is the big-Oh runtime of C(n)?
O(10)
O(n)
O(2n)
O(logn)
Which of the following is the time complexity of insertion sort?
O(n2)
O(logn)
O(n)
O(nlogn)
Which is true for f(n)=2n and g(n)=n! ?
f(n)=O(g(n))
f(n)=θ(g(n))
f(n)=Ω(g(n))
What is the big-Oh runtime of D(n)?
O(n⋅logn)
O(n2)
O(logn)
O(2n)
