Download presentation
Published byAlaina Fisher Modified over 9 years ago
1
Runtime O(VE), for +/- edges, Detects existence of neg. loops
1. Using Bellman-Ford, find the shortest path tree from the node 3 (20points) - the shortest-path tree consists of edges ________________________ the number of iterations of BF is ___________ 3 1 4 6 2 5 -1 -7 -9 Runtime O(VE), for +/- edges, Detects existence of neg. loops After |V| iterations. Midterm preparation
2
2.Write the content of the queue Q/ the set S/ keys d(v) after 5 iterations of the Dijkstra algorithm for the graph G below and source s (weights are on edges): Q = __________ S = _______________ d(s) = _____ d(v1)=____ d(v2)= ____ d(v3)= ____ d(v4)= ____ d(v5)= ____ d(v6)= ___ d(v7)= ___ d(v8)= 2 8 3 v6 v3 v1 8 5 1 9 v4 7 v8 s 10 12 11 7 5 v2 13 v7 v5 15 14 (20points) Runtime O(E+VlgV), for + edges, Does not detect neg. loops. Similar to Prim’s for MST. Midterm preparation
3
Mistake from the previous class
Adjacency-matrix 2 5 -1 3 4 7 -4 2 5 -1 3 ∞ 4 7 -4 A = = correct wrong Midterm preparation
4
D(0) = A = All–Pairs Shortest paths Matrix Multiplication ∞ 2 5 -1 3 ∞
∞ 2 5 -1 3 ∞ 4 7 -4 D(0) = A = Midterm preparation
5
D(1) = D(0)×A = × All–Pairs Shortest paths Matrix Multiplication ∞ 2 5
∞ 2 5 -1 3 ∞ 4 7 -4 D(1) = D(0)×A = × D(0) – Identity Matrix for new operations D(1) = D(0)×A = I×A = A D(k) = A(k) Midterm preparation
6
M = D(0) × A = A , D(0) – initial dist. Matrix, A- adj. matrix
3. Find all shortest path weights with the matrix multiplication method for the graph on the right side.(15pts) - give all matrices that are obtained on the way, - are there any negative cycles in the graph 10 1 2 7 5 -5 -7 3 3 4 M = D(0) × A = A , D(0) – initial dist. Matrix, A- adj. matrix 1 M= M2= M4= M8= M16= M32= Midterm preparation
7
Sorting Algorithms,(Radix Sort, Quick Sort, Merge Sort, Heapsort, Insertion sort).
Binary Search Trees. Graph representation. DFS. BFS. Topological Sort. Strongly connected components. Algorithms for finding MST (Prim's, Kruskal), their applicability, limitations and running time. Algorithms for finding Single source shortest paths (Dijkstra,Bellman-Ford), their applicability, limitations and running time. Matrix Multiplication Algorithm for finding All-pairs shortest paths, applicability, limitations and running time. Midterm preparation
8
2. For Quicksort (from slides) for the sequence 35,17, 32, 10
the last swap is ___________, the first swap is _________ the number of swaps is ______, the number of comparisons is_______ (15pts) Midterm preparation
9
3. Show first 5 swaps of heapsort (deletions of max) with the input heap below (10pts)
67 15 35 19 27 23 16 53 60 8 39 30 45 90 61 62 15 35 19 27 23 16 67 60 8 39 30 45 90 61 62 15 35 19 27 23 16 67 60 8 39 30 45 90 61 62 15 35 19 27 23 16 67 60 8 39 30 45 90 61 62 15 35 19 27 23 16 67 60 8 39 30 45 90 61 62 15 35 19 27 23 16 67 60 8 39 30 45 90 61 Midterm preparation
10
Given a set of numbers, show first 3 iterations of Radix sort after alignment (5pts)
353466 345 4365 236547 4364 3467 67 Midterm preparation
11
Give adjacency list representation: (5 pts)
4 4.Given a graph G: 8 2 5 10 1 12 9 3 6 11 1 2 3 4 5 6 7 10 11 12 7 Give adjacency list representation: (5 pts) Midterm preparation
12
4.Given a graph G in matrix representation (5pts):
a) Give adjacency list representation: 1 2 3 4 5 6 7 10 11 12 b) Give edge list representation representation: Midterm preparation
13
Give the order in which nodes are traversed with BFS
1.Given a graph G: 8 4 2 10 5 9 12 1 3 6 11 7 Give the order in which nodes are traversed with BFS from source 5: ____________________________ (10 Pts) Midterm preparation
14
Give the order in which nodes are traversed with DFS
4 2.Given a graph G: 8 2 5 10 9 12 1 3 6 11 7 Give the order in which nodes are traversed with DFS _______________________________________ Give the nodes of the second cycle found by DFS ____________________________ (10 Pts) Midterm preparation
15
Provide Topological Sort of the following dependency graph:
4 8 2 5 10 9 12 1 3 6 11 7 _______________________________________ (10 Pts) Midterm preparation
16
4. Given a graph below(15 pts)
What are the neighbors in the minimum spanning tree (MST) of the node C___________ and the node Y__________ By how much the weight of edge (I,G) should be decreased to make this edge added to MST? At least by_______ Out of MST will go the edge _______ By how much the weight of edge (Y,E) should be increased to push this edges out of MST? At least by_______ Inside MST will go the edge _______ P 22 3 X H 35 10 21 16 15 J B 2 4 Y 29 5 E 16 A 8 L 6 6 I 7 7 13 14 1 F 9 8 C G K 1 2 2 D Midterm preparation
17
a A B C D E F k c 6 b j e x 2 r m 4 d 5 p y i v f z
3. Given Binary Search Trees (10pts) a A B C D E F k c 6 b j e x 2 r m 4 d 5 p y i v f z What are the children of k after deletion of b ? Give both possible variants or What is the successor of d What is the successor of E What is the predecessor of B What is the successor of C What is the predecessor of D Midterm preparation
18
Binary Search Tree Enumerate all operations Runtime for:
Finding Min or Max Finding any element Insertion Deletion (5pts) Midterm preparation
19
Sorting Algorithms,(Radix Sort, Quick Sort, Merge Sort, Heapsort, Insertion sort).
Binary Search Trees. Graph representation. DFS. BFS. Topological Sort. Strongly connected components. Algorithms for finding MST (Prim's, Kruskal), their applicability, limitations and running time. Algorithms for finding Single source shortest paths (Dijkstra,Bellman-Ford), their applicability, limitations and running time. Matrix Multiplication Algorithm for finding All-pairs shortest paths, applicability, limitations and running time. Midterm preparation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.