• Keine Ergebnisse gefunden

Algorithms and Data Structures Summer Term 2021 Exercise Sheet 10

N/A
N/A
Protected

Academic year: 2022

Aktie "Algorithms and Data Structures Summer Term 2021 Exercise Sheet 10"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

University of Freiburg Dept. of Computer Science Prof. Dr. F. Kuhn

Algorithms and Data Structures Summer Term 2021

Exercise Sheet 10

Exercise 1: Dijkstras’ Algorithm

Execute Dijkstras’ Algorithm on the following weighted, directed graph, starting at nodes. Into the table further below, write the distances from each node tosthat the algorithm stores in the priority queue after each iteration.

s a

b c

d

e f

g 2

4 8

1 3

4 3

2

5 2

6 1 1

Initialization s a b c d e f g

δ(s,·) = 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞

1. Step(u=s) s a b c d e f g

δ(s,·) =

2. Step (u = ) s a b c d e f g

δ(s,·) =

3. Step (u = ) s a b c d e f g

δ(s,·) =

4. Step (u = ) s a b c d e f g

δ(s,·) =

5. Step (u = ) s a b c d e f g

δ(s,·) =

6. Step (u = ) s a b c d e f g

δ(s,·) =

7. Step (u = ) s a b c d e f g

δ(s,·) =

8. Step (u = ) s a b c d e f g

δ(s,·) =

Exercise 2: Currency Exchange

Considerncurrenciesw1, . . . , wn. The exchange rates are given in ann×n-matrix Awith entriesaij

(i, j ∈ {1, . . . , n}). Entry aij is the exchange rate from wi to wj, i.e., for one unit of wi one getsaij units of wj.

(2)

Given a currencywi0, we want to find out whether there is a sequencei0, i1, . . . , ik such that we make profit if we exchange one unit of wi0 towi1, then to wi2 etc. untilwik and then back towi0.

(a) Translate this problem to a graph problem. That is, define a graph and a property which the graph fulfills if and only if there is a sequence of currencies as described above.

(b) Give an algorithm that decides in O(n3) time steps whether there is a sequence of currencies as described above. Explain the correctness and runtime.

Hint: log(a·b) = loga+ logb.

Referenzen

ÄHNLICHE DOKUMENTE

For queries with scope node or path and radius local or path, we chose a batch size of one object, whereas all other queries had the batch size that was maximally possible with

The runtime corresponds to the runtime of the traversal of the whole tree which is O(n) as we have just one recursive call for each node and each recursive call costs O(1) (c.f.,

University of Freiburg Dept.. of Computer

(b) Argue why your algorithm is correct and has the desired

Execute Dijkstras’ Algorithm on the following weighted, directed graph, starting at node s.. That is, define a graph and a property which the graph fulfills if and only if there is

Claim DijkKor: Running Dijksta‘s Algorithm on a weighted directed graph with non- negativ weight function w and startnode s results in u ∈ S: dist[u] = δ(s,u) for all nodes, when

•  BFS computes the distance δ(s,v) of each node v from the start node s. The distance is defined as the minimal number of edges of all paths from s to v. •  The BFS

Li and Simha [6] introduced this N P-hard problem which was motivated by the wavelength routing and assignment in an optical network. In this context several approaches have