260 likes | 1.01k Views
Final Exam COEN 352. Partial solutions. A. E. C. M. F. G. H. I. A. E. C. M. Consider the following array and apply: buble sort Quicksort Merge sort What is the complexity of each sort?
E N D
Final Exam COEN 352 Partial solutions
A E C M F G H I A E C M
Consider the following array and apply: • buble sort • Quicksort • Merge sort • What is the complexity of each sort? • In you answer, explain each of the above sort algorithm and provide all the steps of it application. 15 A 15 21 23 24 24 11 47 49 52 19 29 46 30
What is an AVL tree? Is the tree given in figure xx verifies the proprieties of an AVL tree? Delete the item 10, provide the deletion algorithm and apply it step by step Insert in the original tree the item 75, provide the insertion algorithm and apply it step by step What is the complexity of the main operations of an AVL tree ADT? 30 50 15 70 40 10 35 42 80 v
Unbalanced Tree Cut/Link Restructure Algorithm a 1 30 4 b 50 2 15 6 c 70 40 3 5 35 42 80 T0 7 T2 T3 v T1
a 1 30 4 b 50 2 15 6 c 70 40 3 5 35 42 80 T0 7 T2 T3 v T1 Cut/Link Restructure Algorithm 50 Balanced Tree AVL Tree 30 70 15 40 80 35 42
30 50 15 70 40 10 35 42 80 30 75 v 50 15 75 40 10 80 35 42 70 v
Define a {binary tree, complete binary tree, full binary tree}. • What is the maximal number of nodes on a given level of a binary tree? • What is the maximal number of nodes in a binary tree of depth D?
Give the algorithm for a {DFS,BFS} of a graph. • List the nodes visited in the order of a {DFS,BFS} of this graph. Starting from A A BEF C, I DG, JMN H, KL B C D A BFS E F G H I J K L M N B C D A E F G H I J K L DFS B C D A M N Starting from A A,B,C,D,H,L,G,J,K,N,M,I,F,E ** Solution is not unique** E F G H I J K L M N
Shortest path 22 15 A B C 9 7 3 12 30 2 D E 12 7 13 F G 12 (C,E)-3 (C,D)-9 (C,B)-15 (C,G)-30 (E,G)-7 (C,E,G)-10 (3+7) (E,D)-12 (C,E,D)-15 (B,F)-2 (C,B,F)-17 (15 +2) (B,A)-22 (C,B,A)-37 (D,A)-7 (C,D,A)-16 (9+7) (G,F)-12 (C,G,F)-22 (A,F)-12 (C,D,A,F)-28 16 15 22 15 A B C 9 7 9 3 12 3 30 2 D E 12 7 13 10 17 F G 12
Bubble sort algorithm ( solution) 1st pass 2d pass
3d pass 4th pass 5th up to the last pass No swap • O(n2)
Quick Sort Algorithm (solution) L G E 30 29 46 52 11 49 24 23 Partition / Pivot Selection 15 The solution is not unique, it depends on the pivot selection
Join/ Combine 46 30 46 29 52 11 49 24 23 47 15 • O(n log n)
Partition 29 46 30 23 47 15 15 23 24 11 47 49 52 29 Merge • O(n log n)