Download presentation
1
Final Exam COEN 352 Partial solutions
2
A C E M A E C F G M H I
3
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
4
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 15 10 50 70 40 35 80 42 v
5
Cut/Link Restructure Algorithm
Unbalanced Tree Cut/Link Restructure Algorithm 30 15 50 70 40 35 80 42 v b a c T0 T1 T2 T3 1 2 3 4 5 6 7 1 2 3 4 5 6 7 T0 a T1 b T2 c T3
6
Cut/Link Restructure Algorithm
1 2 3 4 5 6 7 T0 a T1 b T2 c T3 30 15 50 70 40 35 80 42 v b a c T0 T1 T2 T3 1 2 3 4 5 6 7 Cut/Link Restructure Algorithm 50 30 15 40 35 42 70 80 Balanced Tree AVL Tree
7
30 15 10 50 70 40 35 80 42 v 75 30 15 50 75 10 40 35 42 80 70 v
8
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?
9
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 A B C D E F G H I J K L M N A B C D BFS E F G H I J K L M N DFS A B C D 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
10
Shortest path (C,E)-3 (C,D)-9 (C,B)-15 (C,G)-30
F E D G 15 22 30 3 7 12 9 2 13 (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 A B C F E D G 15 22 30 3 7 12 9 2 13 10 16 17
11
Bubble sort algorithm ( solution)
15 23 24 11 47 49 52 29 46 30 1st pass 2d pass
12
15 11 23 24 29 47 46 30 49 52 3d pass 4th pass 5th up to the last pass No swap O(n2)
13
Quick Sort Algorithm (solution)
15 23 24 11 47 49 52 29 46 30 L G E 15 23 24 11 29 47 49 52 46 30 15 23 24 11 29 46 47 49 52 47 49 52 11 15 23 24 47 49 15 23 24 23 15 Partition / Pivot Selection 15 15 The solution is not unique, it depends on the pivot selection
14
Join/ Combine 11 15 23 24 29 30 46 47 49 52 11 15 23 24 29 30 46 47 49 52 11 15 23 24 29 46 47 49 52 47 49 52 11 15 23 24 47 49 15 23 24 23 15 47 15 15 O(n log n) 15
15
15 23 24 11 47 49 52 29 46 30 Partition 15 23 24 11 47 49 52 29 46 30 15 23 24 11 47 49 52 29 46 30 49 52 29 46 30 15 23 24 11 47 30 46 15 15 23 24 11 47 49 52 29 49 52 15 11 24 Merge 29 49 52 15 23 11 24 47 11 15 23 24 47 29 30 46 49 52 11 15 23 24 29 30 46 47 49 52 O(n log n)
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.