Loading...

PPT – 1. Using Bellman-Ford, find the shortest path tree from the node 3 (20points) PowerPoint presentation | free to view - id: 1d1251-ZDc1Z

The Adobe Flash plugin is needed to view this content

- 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 ___________

Runtime O(VE), for /- edges, Detects existence

of neg. loops After V iterations.

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

v6

3

v3

v1

8

5

9

1

v4

7

v8

s

12

10

11

5

7

v2

13

v7

15

v5

14

(20points)

Runtime O(EVlgV), for edges, Does not detect

neg. loops. Similar to Prims for MST.

Mistake from the previous class

Adjacency-matrix

0 2 5 -1

3 0 0 5

0 4 0 3

7 0 -4 0

0 2 5 -1

3 0 8 5

8 4 0 3

7 8 -4 0

A

correct

wrong

AllPairs Shortest paths Matrix Multiplication

0 8 8 8

8 0 8 8

8 8 0 8

8 8 8 0

0 2 5 -1

3 0 8 5

8 4 0 3

7 8 -4 0

A

D(0)

AllPairs Shortest paths Matrix Multiplication

0 8 8 8

8 0 8 8

8 8 0 8

8 8 8 0

0 2 5 -1

3 0 8 5

8 4 0 3

7 8 -4 0

D(1) D(0)A

D(0) Identity Matrix for new operations

D(1) D(0)A IA A

D(k) A(k)

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

2

1

7

5

-5

-7

3

4

3

M D(0) A A , D(0) initial dist. Matrix,

A- adj. matrix

1

M

M2

M4

M8

M16

M32

- 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.

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)

3. Show first 5 swaps of heapsort (deletions of

max) with the input heap below (10pts)

Given a set of numbers, show first 3 iterations

of Radix sort after alignment (5pts)

353466 345 4365 236547 4364 3467 67

4

4.Given a graph G

8

10

2

5

12

1

9

11

3

6

1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ?

10 ? 11 ? 12 ?

7

Give adjacency list representation (5 pts)

4.Given a graph G in matrix representation

(5pts) 1 2 3 4 5 6 7 8 9 10 11

12 1 0 0 1 1 0 1 0 0 0 1 0 0 2

0 0 0 1 1 0 1 1 1 0 0 0 3 1

0 0 0 0 1 0 0 0 1 1 0 4 0 1 1

0 0 0 0 0 0 0 1 0 5 1 0 1 1 0

1 0 0 1 0 0 1 6 0 0 0 0 0 0 0

0 0 0 0 0 7 0 0 0 0 0 1 0 0 0

0 0 0 8 1 0 0 0 0 0 0 0 1 0

0 0 9 1 1 1 0 0 0 1 1 0 0 1

1 10 0 1 0 1 1 0 0 0 1 0 0 0 11 0

0 0 0 0 0 0 0 0 0 0 1 12 0 0 0

0 1 0 0 1 0 1 0 0

a) Give adjacency list representation

1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ?

10 ? 11 ? 12 ?

b) Give edge list representation

representation

1.Given a graph G

8

4

10

2

5

12

9

1

11

3

6

7

Give the order in which nodes are traversed with

BFS from source 5 ____________________________

(10 Pts)

4

2.Given a graph G

8

10

2

5

12

9

1

11

3

6

7

Give the order in which nodes are traversed with

DFS _______________________________________ Give

the nodes of the second cycle found by

DFS ____________________________ (10 Pts)

Provide Topological Sort of the following

dependency graph

4

8

10

2

5

9

12

1

11

3

6

7

_______________________________________ (10 Pts)

- 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

H

X

35

10

21

16

J

15

B

2

4

29

Y

E

5

16

L

8

A

6

I

6

7

7

13

14

9

1

F

8

G

K

C

1

2

2

D

3. Given Binary Search Trees (10pts)

a

k

c

b

6

e

j

x

4

m

r

2

5

d

i

y

p

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 .

Binary Search Tree

- Enumerate all operations
- Runtime for
- Finding Min or Max
- Finding any element
- Insertion
- Deletion

(5pts)

- 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.