Professional Documents
Culture Documents
EECS2011 - Final - F20 Test No Solutions
EECS2011 - Final - F20 Test No Solutions
EECS2011 - Final - F20 Test No Solutions
Exam: Final
Instructor: Hamzeh Khazaei
Markers: Prof.
Instructions:
• Make sure you are logged into the Zoom throughout the exam. All live communications are via
chat box or voice announcement in the Zoom class.
• This is a 180-minute open-book exam. The time has been adjusted for those with accommodation
letters.
• There are two types of questions with a total of 30 points.
• In section 1, you have 9 multiple choice questions for each only one choice is correct.
• In section 2, you have 9 short essay questions. You will be asked to explain in plain English, write
Java code or pseudo code.
• Be concise in descriptive questions; the answers are short.
• Email your work by the deadline to hkh@eecs.yorku.ca
• Good luck.
Student Name: Student no:
1-9 /9
10 /2
11 /2
12 /2
13 /2
14 /2
15 /2
16 /3
17 /3
18 /3
Total /30
2
Student Name: Student no:
2. Consider a binary tree with n as the number of nodes, e as the number of external
nodes, i as the number of internal nodes and h as the height of the tree; which one
of the following is always true: (I need to see what to do about this question)
1. n = 2i+1
2. h <= (n-1)/2
3. e <= 2h
4. i >= h
5. none of them.
Note: Both of 3 and 4 are correct; choosing any of them will be correct.
3. How long would it take to remove the ⌈Log(n)⌉ smallest elements from a heap that contains
n entries, using the removeMin operation? R-9.2
1. O(Log(n))
2. O(Log2(n))
3. O(Log(n) + Log(n))
4. O(1)
4. Suppose you set the key for each position p of a binary tree T equal to its preorder rank.
Under what circumstances is T a heap?
1. T will never be a heap under any circumstances.
2. Only if T is also complete.
3. Only if T is a balanced tree.
4. T will always be a heap.
Hint: when doing a traversal algorithm, we visit nodes in a sequence; we rank the first visited
node as 0, the second visited node as 1, the third as 3 and so forth so on. For example in
preorder traversal, root will always get the rank of 0.
3
Student Name: Student no:
6. How many different binary search trees can store the keys {1,2,3}?
1. 1
2. 4
3. 5
4. 3
5. 6
8. Sara has a comparison-based sorting algorithm that sorts the first k elements of a
sequence of size n in O(n) time. What is the big-Oh characterization of the biggest that k
can be.
1. O(logn)
2. O(nlog(n))
3. O(logn/n)
4. O(n/logn)
5. O(n)
9. How many edges are in the transitive closure of a graph that consists of a
simple directed path of n vertices?
1. n(n-1)/2
2. n^2
3. n
4. n(n+1)/2
4
Student Name: Student no:
10. Following code iterates a collection, stores them one by one in variable and performs
something with each element in the loopBody. Assume that we are only interested in items
stored in even positions, (i.e., 2, 4, 6, …). How would you modify the following code to
achieve this. First element is stored at position 1. [2 points]
5
Student Name: Student no:
11. Show the binary tree T using array-based representation that satisfies simultaneously the
following conditions: [ 3 points]
1. Each internal node of T stores a single character.
2. An inorder traversal of T yields GEHCFIADZ
3. A postorder traversal of T yields GHEIFCZDA
12.
1. Briefly compare the separate chaining and linear probing collision handling
techniques. [2 points]
2. Insert 15, 23, 1, 25, 5, 13, 33, 12, 2 and 9 into a hash table with size 10 using linear
probing technique. (hint: use h(x) = x mod 10 as the hash function) [1 points]
6
Student Name: Student no:
13. What would be the postorder traversal of the following binary search tree after
deleting nodes 8, 88 and 80? [3 points]
14. Insert 19 into the following AVL tree. Is the resulted tree an AVL or not? if yes, explain
why you think the resulted tree is AVL. If your answer is no, describe the steps that you
took to make the tree AVL again. In the end, write down the inorder traversal of your final
AVL tree. [3 points]
7
Student Name: Student no:
15. Would you use the adjacency matrix structure or the adjacency list structure in each of the
following cases? Justify your choice. [3 points]
1. The graph has 10,000 vertices and 20,000 edges, and it is important to use as little
space as possible. [1.5 points]
2. You need to answer the query getEdge(u, v) as fast as possible, no matter how
much space you use. [1.5 points]
16. John claims to have an algorithm that takes an input sequence S and produces an output
sequence T that is a sorting of the n elements in S.
1. Give an algorithm (i.e., psudocode), isSorted, that tests in O(n) time if T is sorted.
[1 point]
2. Explain why the algorithm isSorted is not sufficient to prove a particular output T
of John’s algorithm is a sorting of S. [1 point]
8
Student Name: Student no:
17. Describe (i.e., write the pseudocode) and analyze (i.e., big-Oh analysis) an efficient
algorithm for removing all duplicates from a collection A of n elements. [2 points]
9
Student Name: Student no:
18. There are eight small islands in a lake, and the state wants to build seven bridges to
connect them so that each island can be reached from any other one via one
or more bridges. The cost of constructing a bridge is proportional to its length.
The distances between pairs of islands are given in the following table. [2 points]
1
0