Institute of Operating Systems and Computer Networks Algorithms Group Network Algorithms Tutorial 1: Flashback and Fast Forward Christian Rieck
Staff Lecture: Dr. Christian Scheffer scheffer@ibr.cs.tu-bs.de Room: IZ 331 Tutorial: Christian Rieck rieck@ibr.cs.tu-bs.de Room: IZ 314 Small tutorial: Jakob Keller jakob.keller@tu-braunschweig.de 2
Structure Lecture: theoretical content on graph algorithms Tutorial: application of graph algorithms and many more cool stuff on graphs and problems on graphs Small tutorial: discussion of homework sheets 3
Homework and exam There will be five homework assignment sheets. You have to get at least 50% of the points in total. (Probably 150 out of 300.) You have to pass a written exam at the end of the lecture August, 6th. (Probably at 12am.) 4
Extra points You can earn extra points for your homework! find a (crucial) mistake in the slides improve the tutorial by a better example improve the tutorial by ideas on new interesting stuff Please send an email or talk to me and I will think about it. Usually the amount of extra points is in some way related to the improvement and is a fraction of my room number π. 5
Mailing list There is a mailing list for this lecture. https://mail.ibr.cs.tu-bs.de/mailman/listinfo/na We will distribute several announcements via this list. So, please subscribe. 6
Webpage There is a webpage for this lecture. https://www.ibr.cs.tu-bs.de/courses/ss18/na/index.html There is all the stuff like the slides of the tutorials, the homework assignment sheets, the schedule of the lecture, informations regarding the exam, 7
(preliminary) Schedule 8
(preliminary) Schedule There is also a calendar on the webpage which will be up-to-date! 8
Questions? 9
Previously in * 10
Graphs A graph is an ordered pair G=(V,E) comprising a set V of vertices together with a set E of edges, which are 2-element subsets of V. We normally consider simple graphs, i.e., there is at most one edge between two specific vertices and there are no edges connecting a vertex with itself. 11
Digraphs A digraph is an ordered pair D=(V,A) comprising a set V of vertices together with a set A of arcs (edges), which are ordered pairs of vertices. 12
Data structures for graphs There are several ways to represent graphs, e.g., adjacency list adjacency matrix incidence matrix Please make yourself familiar with these data structures. A good reference is the lecture on algorithms and data structures. https://www.ibr.cs.tu-bs.de/courses/ws1718/aud/webpages/skript/vl7_new.pdf https://www.ibr.cs.tu-bs.de/courses/ws1718/aud/webpages/skript/vl8_new.pdf 13
Other data structures Stack last in, first out (LIFO) push pop Queue first in, first out (FIFO) enqueue dequeue 14
Breadth-First-Search procedure BFS(G,v) let Q be a queue Q.enqueue(v) while Q is not empty v = Q.dequeue() for each edge e incident to v let w be the other endpoint of e if w is not marked mark w Q.enqueue(w) v 0 v 0 v 1 v 2 v 3 v 4 v 1 v 2 v 3 v 5 v 6 v 7 v 8 v 5 v 6 v 7 v 10 v 9 v 10 v 9 v 11 v 12 v 11 v 4 v 8 v 12 15
Depth-First-Search procedure DFS(G,v) let S be a stack S.push(v) while S is not empty v = S.pop() if v is not labeled as discovered label v as discovered for all edges from v to w S.push(w) v 0 v 0 v 1 v 2 v 3 v 4 v 1 v 2 v 3 v 5 v 6 v 7 v 8 v 5 v 10 v 9 v 10 v 11 v 12 v 11 v 6 v 7 v 9 v 4 v 8 v 12 16
Walk, path, trail, Kantenfolge: Weg: Pfad: Tour: Kreis: Alternating sequence of vertices and edges. Kantenfolge + no repeating edges Kantenfolge + no repeating vertices Weg + same start and end vertex Pfad + same start and end vertex 17
Big O-Notation describes the limiting behavior of a function when the argument tends towards infinity is used to classify algorithms according to their running time (and other stuff ) O( f )={g : N! R + 9c 2 R >0 9n 0 2 N 8n 2 N n0 : g(n) apple c f (n)} g(n) 2 O( f (n)) f (n) g(n) n 0 18
Other Landau symbols There are some other notations for analyzing the running time and space requirements of algorithms, e.g., big-omega, Theta, Please make yourself familiar with these notations. Lecture on algorithms and data structures: Theta Lecture on algorithms and data structures: Big-O and Big-Omega 19
Proofs Well Sometimes it is very challenging to prove something. There are different methods, e.g., induction, or contraposition. Not only in this class you have to prove mathematical statements. Therefore you should be familiar with these methods and techniques https://www.ibr.cs.tu-bs.de/courses/ws1718/aud/uebungen/u2.pdf https://www.ibr.cs.tu-bs.de/courses/ws1718/aud/uebungen/merkzettel-beweise.pdf 20
Proofs Well Sometimes it is very challenging to prove something. There are different methods, e.g., induction, or contraposition. Not only in this class you have to prove mathematical statements. Therefore you should be familiar with these methods and techniques https://www.ibr.cs.tu-bs.de/courses/ws1718/aud/uebungen/u2.pdf https://www.ibr.cs.tu-bs.de/courses/ws1718/aud/uebungen/merkzettel-beweise.pdf 20
Different issues Eulerian Tour this is a problem! Given: A graph G Wanted: A tour that visits every edge exactly once Fleury s algorithm! Given: this is a specific instance! Wanted: A tour that visits every edge exactly once specific solution! 21
Different issues Hamiltonian Circle Given: A graph G Wanted: A circle that visits every vertex exactly once Traveling Salesman Tour Given: A weighted graph G Wanted: A circle of minimum total weight that visits every vertex exactly once Decision problem Given: A graph ( ) Wanted: A specific structure or an argument that such a structure do not exist in that graph Optimization problem Given: A graph ( ) and edge weights Wanted: From all feasible specific structures the best or an argument that such a structure do not exist in that graph 22
Soon in network algorithms 23
Minimum-cost problems Minimum Spanning Tree Given: A graph G=(V,E) with edge weights Wanted: A tree T of minimum cost that spans the graph 5 1 5 9 3 7 8 3 4 2 1 2 7 6 11 5 6 5 1 3 7 3 4 2 1 2 7 6 5 G T 24
Minimum-cost problems Minimum Spanning Tree Given: A graph G=(V,E) with edge weights A geometric generalization is the Minimum Steiner Tree Problem. Wanted: A tree T of minimum cost that spans the graph One can also ask for a spanning tree where the longest edge is as short as possible the Minimum Bottleneck Spanning Tree! 7 5 1 5 8 7 6 7 Or we want a minimum spanning tree where each vertex degree 7 6 is bounded by some value (Bounded Degree 5 Spanning Tree), 11 1 3 or satisfies some other constraints. 3 9 2 6 2 4 4 Some 3 of them 3 2 1 are really hard, e.g., most Steiner problems. 5 2 1 5 G T 24
Shortest-path problems Single source shortest paths Given: A graph G=(V,E) with edge weights, and a vertex s Wanted: A shortest path tree T rooted in s 5 1 5 9 3 7 8 3 4 2 1 2 7 6 11 5 6 s 5 1 9 3 7 3 2 1 2 7 5 6 G T 25
Shortest-path problems Single source shortest paths Given: A graph G=(V,E) with edge weights, and a vertex s Wanted: A shortest path tree T rooted in s There are many 7 related problems, 7 7 5 1 5 8 7 6 e.g., Longest Path, Hamiltonian Path, several tour problems like the Traveling Salesman Problem, 5 11 1 3 Almost all of them are NP-hard! 3 9 2 6 s 9 2 6 4 3 3 2 1 2 1 5 5 G T 25
Flows Maximum Flow Given: A digraph D=(V,A) with edge weights, and vertices s and t Wanted: A maximum flow F starting from s to t 7 5 5 1 9 3 2 8 3 4 1 2 7 6 11 5 6 s 5 7 5 5 5 1 9 9 3 2 26 8 5 7 2 33 11 11 22 1 4 1 1 1 5 t 6 1 D F 26
Flows Maximum Flow Given: A digraph D=(V,A) with edge weights, and vertices s and t Wanted: A maximum flow F starting from s to t A fundamental theorem is the MaxFlow-MinCut-Theorem of Ford and Fulkerson that shows that a maximum flow is equal to 7 a minimum 6 cut of a flow network. 5 7 26 5 5 8 7 1 5 5 8 5 7 2 t 5 There are polynomial-time 1 3 11algorithms for solving such flow 9 2 6 33 11 problems. 11 But there are many related problems, and s 9some 9 of them are 2 6 2 NP-hard. 1 3 4 3 1 4 2 1 1 5 2 1 1 5 D F 26
Matchings Maximum Matching Given: A graph G=(V,E) Wanted: A maximum set M of pairwise non-adjacent edges G M 27
Matchings Maximum Matching Given: A graph G=(V,E) Wanted: A maximum set M of pairwise non-adjacent edges There are many different variants of the matching problem, e.g., Perfect Matching, Minimum Cost Perfect Matching, Maximal Matching, Matching in bipartite Graphs, G M 27
Questions? 28