WorksheetsUnderstanding The Algorithms
Total questions: 65
Worksheet time: 3hrs 15mins
What is the time complexity of Bubble Sort in the worst case?
O(2^n)
O(n)
O(n^2)
O(n log n)
How does Insertion Sort work on a nearly sorted array?
Insertion Sort requires a complete array to function properly.
Insertion Sort is efficient on nearly sorted arrays due to fewer necessary swaps and comparisons.
Insertion Sort is only effective on completely unsorted arrays.
Insertion Sort is slow on nearly sorted arrays due to many swaps.
What is the main advantage of Selection Sort over other sorting algorithms?
Its simplicity and in-place sorting capability.
It requires additional memory for sorting.
It is the fastest sorting algorithm available.
It can sort linked lists more efficiently than other algorithms.
What is the best-case time complexity of Insertion Sort?
O(n^2)
O(1)
O(n log n)
O(n)
How many swaps does Bubble Sort perform in the worst case?
O(n)
O(n^2)
O(log n)
O(n^3)
What is the average time complexity of Bubble Sort?
O(n^2)
O(n)
O(n log n)
O(log n)
In which scenario is Insertion Sort most efficient?
When the array is very large and complex.
When the array is completely unsorted.
When the array is nearly sorted or small in size.
When the array contains duplicate elements only.
How does the performance of Selection Sort compare to Insertion Sort?
Selection Sort is faster than Insertion Sort.
Insertion Sort is slower than Selection Sort.
Insertion Sort is generally faster than Selection Sort.
Both algorithms have the same performance.
What is the primary disadvantage of Bubble Sort?
Stable sorting algorithm
In-place sorting with minimal memory usage
Inefficiency for large datasets due to O(n^2) time complexity.
Fast execution for small datasets
What is the key operation performed in Insertion Sort?
The key operation is inserting an element into its correct position in the sorted portion of the array.
Removing duplicates from the array
Finding the maximum element in the array
Sorting the entire array at once
How does the number of comparisons in Selection Sort relate to the size of the array?
Selection Sort requires no comparisons regardless of array size.
The number of comparisons in Selection Sort is O(n^2), where n is the size of the array.
The number of comparisons in Selection Sort is O(n) for large arrays.
The number of comparisons in Selection Sort is O(n log n).
What sorting algorithm is this?
Insertion Sort
Sort of lame
Selection Sort
Bubble Sort
What sorting algorithm is this?
Insertion Sort
Selection Sort
Quicksort
Bubble Sort
What sorting algorithm is this?
Bubble Sort
Insertion Sort
Selection Sort
None of the above
1 4 2 9 3 8 5
What does the list look like after one pass of the bubble sort algorithm.
1 4 2 9 3 8 5
What does the list look like after one pass of the insertion sort algorithm.
Which of the following case does not exist in complexity theory?
Best case
•Worst case
•Average case
Null case
int fun(int n)
•{
•int count = 0;
•for (int i = 0; i < n; i++)
•for (int j = i; j > 0; j--)
count = count + 1;
•return count;
•}
Theta (n)
Theta (n^2)
•Theta (n*Logn)
•Theta (nLognLogn)
•If for an algorithm time complexity is given by O(1) then complexity of it is:
•constant
•polynomial
•exponential
•none of the mentioned
space complexity of algorithm means
space it requires
time it requires
hardware it requires
all of the above
This picture represents
big theta noataion
big oh notation
big omega notation
none of the above
big O represents
best case scenario
worst case scenario
average case scenario
none of the above
•What is the time complexity of following code:
•int a = 0, b = 0;
•for (i = 0; i < N; i++) {
•a = a + rand();
•}
•for (j = 0; j < M; j++) {
•b = b + rand();
•}
•O(N * M) time,
•O(N + M) time,
None of these
Big
Ω defineslower bound
upper bound
middle bound
none of the above
Which of the following case does not exist in complexity theory?
Best case
•Worst case
•Average case
Null case
Which of the following functions has the largest growth rate? *
n^(1/2)
n^100
2^(n/2)
2^(n!)
Which of the following shows the correct relationship among some of the more common computing times on algorithms
. O(log n) < O(n) < O( n* log n) < O(2n ) < O(n2)
O(log n) < O(n) < O( n* log n) < O(n2) < O(2n )
O(n) < O(log n) < O( n* log n) < O(n2) < O(2n )
O(n) < O(log n) < O( n* log n) < O(2n ) < O(n2)
•The worst case complexity for insertion sort is _________
•
O(n)
•
O(log n)
•O(n2)
•O(n log n)
•If for an algorithm time complexity is given by O(1) then complexity of it is:
•constant
•polynomial
•exponential
•none of the mentioned
Find the slowest time complexity
O (n)
O (n^2)
O (n!)
O (2^n)
Which Asymptotic notation is used to represent the Best time complexity
Big Oh
Omega
Theta
Small Omega
Which Asymptotic notation is used to represent the average time complexity
Big Oh
Omega
Theta
Small Onega
asymptotic notations represents
space complexity of algo
time complexity of algo
both a and b
none of the above
...................................are the characteristics of an algorithm
Input
infiniteness
Effectiveness
output
finiteness
____, if there are positive constants n0 and c such that at and to the right of n0, the value of f(n) always lies on or below cg(n).
f(n) = Ω(g(n))
f(n) = O(g(n))
f(n) = Θ(g(n))
What is the time complexity of this algorithm?
O(n)
O(2n)
O(log n)
O(n2)
O(1)
What is the time complexity of this algorithm?
O(n)
O(2n)
O(log n)
O(n2)
O(1)
Which of the following is the time complexity of insertion sort?
O(n2)
O(logn)
O(n)
O(nlogn)
The mechanism of finding an element /key in a given set of elements is known as ________________
sorting
searching
both
none
Which greedy algorithm is used to solve the Huffman coding problem?
Kruskal's algorithm
Huffman algorithm
Dijkstra's algorithm
Prim's algorithm
In Prim’s algorithm, how do we decide which edge to add next to the growing Minimum Spanning Tree (MST)?
The edge with the minimum weight that connects a new vertex to the MST
The edge with the maximum weight that connects a new vertex to the MST
Any random edge from the graph
The edge that forms a cycle in the MST
Prim’s algorithm starts with:
The edge with the lowest weight
The highest weighted edge
Any arbitrary vertex
A randomly chosen edge
Which is optimal value in the case of job sequence problem Item : 1 2 3 4 5..
Profit : 20 15 10 5 1
Deadline : 2 2 3 3 3
1,3,4
1,2,4
4,2,3
1,5,2
The correct encoding of the letter C in this tree is...
11
10
01
00
How do you move through a Huffman tree?
0 = right 1= left
1 = left 2 = right
0 = left 1 = right
0 = middle 1 = back
The output of Kruskal and Prims algorithm is ________________
Maximum spanning tree
Spanning tree
Minimum spanning tree
None
Given items as {value,weight} pairs {{40,20},{30,10},{20,5}}. The capacity of knapsack=20. Find the maximum value output assuming items to be divisible.
60
80
100
40
Consider a job scheduling problem with 4 jobs J1, J2, J3, J4 and with corresponding deadlines: ( d1, d2, d3, d4) = (4, 2, 4, 2). Which of the following is not a feasible schedule without violating any job schedule?
J2, J4, J1, J3
J4, J1, J2, J3
J4, J2, J1, J3
J4, J2, J3, J1
From the following given tree, what is the code word for the character ‘a’?
011
010
100
101
Fractional knapsack solution maximizes:
Weight in knapsack
Number of items
Total value of knapsack
Number of distinct items
Dijkstra's algorithm is based on which paradigm?
Greedy paradigm
Backtracking paradigm
Dynamic Programming paradigm
Divide and Conquer paradigm
Suppose you have coins of denominations 1, 3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm NOT produce an optimal answer?
20
12
6
5
Consider the given graph. What is the weight of the minimum spanning tree using the Prim’s algorithm, starting from vertex a?
23
28
27
11
Consider the graph shown below. Which of the following edges form the MST of the given graph using Prim’a algorithm, starting from vertex 4.
(4-3)(5-3)(2-3)(1-2)
(4-3)(3-5)(5-1)(1-2)
(4-3)(3-5)(5-2)(1-5)
(4-3)(3-2)(2-1)(1-5)
Big
Ω defineslower bound
upper bound
middle bound
none of the above
Using Kruskal’s algorithm, which edge should you choose fourth?
AB
BC
BD
DE
Using Kruskal’s algorithm, which edge should you choose second?
AE
BD
DE
AB
Create a minimal spanning tree, then find the minimum total cost.
30
39
47
50
Which Algorithm is used for finding single-source shortest path
Kruskal's Algorithm
Dijkstra's Algorithm
Prims Algorithm
Huffman's Algorithm
