Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
188 views

Algorithms - Exam 2021-2022 Model Answer

This document contains a 50 question final exam for a CS algorithms course. The exam covers topics like data structures, algorithm analysis, sorting, searching, graphs, and optimization problems. It includes multiple choice questions testing knowledge of recursion, sorting algorithms, complexity analysis, and graph algorithms like Dijkstra's algorithm and the traveling salesman problem. The exam has a duration of 2 hours and is worth a total of 60 marks.

Uploaded by

Ahmed Mabrok
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
188 views

Algorithms - Exam 2021-2022 Model Answer

This document contains a 50 question final exam for a CS algorithms course. The exam covers topics like data structures, algorithm analysis, sorting, searching, graphs, and optimization problems. It includes multiple choice questions testing knowledge of recursion, sorting algorithms, complexity analysis, and graph algorithms like Dijkstra's algorithm and the traveling salesman problem. The exam has a duration of 2 hours and is worth a total of 60 marks.

Uploaded by

Ahmed Mabrok
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Cairo University

Faculty of Computers and Artificial Intelligence


Final Exam
Department: CS
Course Name: Algorithms Date: 29-1-2022
Course Code: CS316 Duration: 2 hours
Instructor(s): Basheer Youssef Total Marks: 60

Q. 1. Which Data Structure is used to perform Recursion?


A : Array B : queue C : stack D : linked list
Q. 2. What is the objective of the knapsack problem?
A : To Get Maximum Total Value In The Knapsack B : To Get Minimum Total Value In The
Knapsack
C : To Get Maximum Weight In The Knapsack D : To Get Minimum Weight In The Knapsack
Q. 3. What is the worst case time complexity of merge sort?
A : O(N Log N) B : O(n*n) C : O(Log N) D : O(Log Log N)
Q. 4. Time required to merge two sorted lists of size m and n, is
A - Ο(m | n) B - Ο(m + n) C - Ο(m log n) D - Ο(n log m)
Q. 5. What is best case complexity of selection sort
A:n B : n^2 C : nlogn D :logn
Q. 6. In computer science, algorithm refers to a special method usable by a computer for the
solution to a problem.
A : true B : false
Q. 7. Algorithm can be represented as
A : Pseudocode B : Flowchart C : None of the above D : both 1and 2
Q. 8. What is the average case time complexity of merge sort?
A : O(N Log N) B : O(n*n) C : O(Log N) D : O(Log Log N)
Q. 9. Alorithm should have finite number of steps
A : true B : false
Q. 10. Two main measures for the efficiency of an algorithm are 1)time 2) space 3) lines of code
A : 1 and 2 B : 2 and 3 C : 1 and 3 D: none
Q. 11. Hamiltonian path problem is _________
A : NP problem B : N class problem C : P class problem D : NP complete problem
Q. 12. Which algorithm strategy builds up a solution by choosing the option that looks the best at
every step.
A : greedy method B : branch and bound C : dynamic programming D : divide and conquer
Q. 13. 0/1 knapsack is based on which method to get better solution?
A : greedy method B : branch and bound C : dynamic programming D : divide and conquer
Q. 14. Dynamic programming is used to find:
A : All Optimal Solution Is Generated B : One Solution Is Generated
C : No Optimal Solution Is Generated D : Partial Solution Is Generated
Q. 15. What is the purpose of using randomized quick sort over standard quick sort?
A : To reduce worst case space complexity B : To reduce worst case time complexity
C : To improve average case time complexity D : To improve accuracy
Q. 16. Time taken in decreasing the node value in a heap is
A : O(n) B : O(1) C : O(log n) D : O(n log n)
Q. 17. Match the following pairs

A I-P, II-M, III-N, IV-O B I-O, II-P, III-M, IV-N


C I-O, II-N, III-M, IV-P D I-O, II-N, III-P, IV-M
1
Q. 18. Given items as {value,weight} pairs {{60,20},{50,25},{20,5}}. The capacity of knapsack=40.
Find the maximum value output assuming items to be divisible and nondivisible respectively.
‫مرة البد من اخذ العنصر كامل ومرة ممكن تاخد جزء من العنصر‬
A : 100-80 B : 110-70 C : 130-110 D : 110-80
Q. 19. Time complexity of LCS S:
A : O(M!) B : O(MN) C : O(N!) D : O(N)
Q. 20. What is time complexity of fun()? int fun(int n)
{ int count = 0;
for (int i = n; i > 0; i /= 2)
for (int j = 0; j < i; j++) count += 1;
return count; }
A : O(nlog n) B : O(n^2 ) C : O( n) D : O(log n)

21. Quick sort algorithm is an example of


A - Greedy approach B - Improved binary search C - Dynamic Programming D - Divide and conquer
22. The minimum number of edges required to create a cyclid graph of n vertices is
A– n B- n-1 C- n+1 D- 2n
23. Which of the following is example of not in-place algorithm?
A - Bubble Sort B - Merge Sort C - Insertion Sort D - All of the above
24. Which of the following uses memorization?
A - Greedy approach B - Divide and conquer approach C- Dynamic programming approach D - None
25. Heap is an example of
A - complete binary tree B - spanning tree C - sparse tree D - binary search tree
26. Access time of a binary search tree may go worse in terms of time complexity upto
A - Ο(n2) B - Ο(n log n) C - Ο(n) D - Ο(1)
27. What will be the Huffman code for the letters a,b,c,d,e? if The probability are ½,1/4,
1/8,1/16,,1/32
(a) 0,10,110,1110,1111 (b)10,011,11,001,010 (c)10,01,0001,100,1010
(d)100,110,001,000,010
28. From the following sorting algorithms which algorithm needs the minimum number of swaps
A. Bubble Sort B. Quick Sort C. Merge Sort D. Selection Sort
29. What shall be value of x in the following pseudocode?
x = 0; For (t = 1; t< N; t++) For( p = 1; p<= t; p++)
x = x+1; Endfor Endfor
A- x=N+1 B- x=N(N-1)/2 C- x=N(N+1)/2 D- x=N^2
30. Time complexity of merging three sorted lists of sizes m, n and p is
A Θ(m+n+p) B Θ(min(m,n,p)) C Θ(max(m,n,p)) D Θ (m.n.p)
31. Which of the algorithm design approach is used by Mergesort
A-Branch and bound approach B-Dynamic approach
C-Divide and Conquer approach D-Greedy approach
32. Which of the following shortest path algorithm cannot detect -presence of negative weight cycle
graph?
A-Bellman Ford Algorithm B-Floyd-Warshall Algorithm
C-Dijsktra’s Algorithm D-None of the above

33. If G is an directed graph with 20 vertices, how many boolean values will be needed to represent
G using an adjacency matrix?
A-20 B-40 C- 200 D-400
34. What is the special property of red-black trees and what root should always be?
a) a color which is either red or black and root should always be black color only
b) height of the tree c) pointer to next node d) a color which is either green or black

2
35. Why do we impose restrictions like . root property is black . every leaf is black . children of
red node are black . all leaves have same black
a) to get logarithm time complexity b) to get linear time complexity
c) to get exponential time complexity d) to get constant time complexity
36. What are the operations that could be performed in O(logn) time complexity by red-black
tree?
a) insertion, deletion, finding predecessor, successor
b) only insertion c) only finding predecessor, successor d) for sorting
37. Why Red-black trees are preferred over hash tables though hash tables have constant time
complexity?
a) no they are not preferred
b) because of resizing issues of hash table and better ordering in redblack trees
c) because they can be implemented using trees d) because they are balanced
38. What is the below pseudo code trying to do, where pt is a node pointer and root pointer?
redblack(Node root, Node pt) :
if (root == NULL) return pt
if (pt.data < root.data)
{
root.left = redblack(root.left, pt);
root.left.parent = root
}
else if (pt.data > root.data)
{
root.right = redblackt(root.right, pt)
root.right.parent = root
} return root
A) insert a new node B ) delete a node C) search a node D) count the number of nodes
39. Dijkstra’s Algorithm is used to solve _____________ problems.
a) All pair shortest path b) Single source shortest path c) Network flow d) Sorting
40. What is the time complexity of Dijikstra’s algorithm?
a) O(N) b) O(N3) c) O(N2) d) O(logN)
41. Dijkstra’s Algorithm cannot be applied on ______________
a) Directed and weighted graphs b) Graphs having negative weight function
c) Unweighted graphs d) Undirected and unweighted graphs
42. How many times the insert and extract min operations are invoked per vertex?
a) 1 b) 2 c) 3 d) 0
43. The maximum number of times the decrease key operation performed in Dijkstra’s
algorithm will be equal to ___________
a) Total number of vertices b) Total number of edges c) Number of vertices – 1
d) Number of edges – 1

44. What is running time of Dijkstra’s algorithm using Binary min- heap method?
a) O(V) b) O(VlogV) c) O(E) d) O(ElogV)

3
45. Consider the following graph

If b is the source vertex, what is the minimum cost to


reach f vertex?
a) 8 b) 9 c) 4 d) 6
46. Dijkstra’s Algorithm is the prime example for
___________
a) Greedy algorithm b) Branch and bound c)
Back tracking d) Dynamic programming
47. TSP Input: undirected graph with non-negative edge costs
Output: a min-cost tour [i.e., a cycle that visits every vertex exactly once
a) true b) false

48. Thr min-cost tour for the following graph is a) 10 b)13 c) 14 d) 12

49. If number of cities = 6 then TSP search space will be a) 120 b)720 c) 120 d) 24
50. In the following graph there exist a clique of size = 5 a) true b) false

Good Luck
Dr Basheer Youssef.

You might also like