cse101_11_7_11

# cse101_11_7_11 - The conversion rate from Ci to Cj is fij...

This preview shows pages 1–2. Sign up to view the full content.

Shortest paths in graphs 1. Dijkstra’s algorithm a. Given graph = (V,E) Edge lengths l€ > 0 Starting node S in V For all u in V: Dist[u] = infinity Prev[u] = nil Dist[s] = 0 H = V While H is not empty: U = node in H with smallest dist[] Remove u from H For all (u, w) in H If dist[w] > dist[u] + l(u, w) Dist[w] = dist[u] + l(u,w) Prev[w] = u b. Example A B C D E F G 0/nil inf/nil inf/nil inf/nil inf/nil inf/nil inf/nil Done 1/A 5/A inf/nil inf/nil inf/nil 8/A Done done 4/B inf/nil 5/B 5/B 8/A Done done done 6/C 5/B 5/B 8/A Done done done done done done 7/F, then copy everything over Shortest path tree C -> D down A -> B -> E down G <-F c. Running time O(V + E) plus time taken for * Naïve implantation of ( O(V^2)) Total time(naïve) = O(V^2) d. A faster implementation puts H in a priority queue (aka HEAP) and takes time O((V+E) log (V)) binary heap 2. Currency trading a. You are a trader dealing in n currency C1, C2, C3, Cn

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The conversion rate from Ci to Cj is fij (one unit of ci becomes fij units of cj) what is the best way to convert C1 to Cn \$ yen pounds asdf \$ 1 0.51 0.77 121 Yen 1.96 1 1.51 237 Pounds 1.3 0.66 1 157 Asdf 0.008 0.004 0.006 1 b. Build a directed graph G = V, E) with nodes V = {c1, c2, cn} and edges E = {(c1, c2), I != j} we will find a path from Ci to Cn, each edge along the path is a currency conversion \$ -> pounds = -log(0.51) -> yen = -log(237). Put a negative sign to find the longest path Edge length l(ci, cj) = -log(r ij ) Length of a path \$->f->pounds->yen is log(r(all combinations) = -log(r(all combos from one to another, \$->ye, yen->pounds, pounds->asdf) and multiply 3. General shortest paths algorithm a. Basic principle of Dijkstra: the shortest path...
View Full Document

## This note was uploaded on 01/09/2012 for the course CSE 101 taught by Professor Staff during the Spring '08 term at UCSD.

### Page1 / 2

cse101_11_7_11 - The conversion rate from Ci to Cj is fij...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online