CS : Data Structures

Size: px
Start display at page:

Download "CS : Data Structures"

Transcription

1 CS : Data Structures Michael Schatz Dec 7, 2016 Lecture 38: Union-Find

2 Assignment 10: Due Monday Dec 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently written!

3 Part 1: Dijkstra s Algorithm aka Shortest Path Revisited

4 Dijkstra s Correctness X Y S U V Assume that Dikjstra s algorithm has correctly found the shortest path to the first N items, including from S to X and U (but not yet Y or V) It now decides the next closest node to visit is v, using the edge from u Could there be some other shorter path to v? No: cost(s->x->v) must be greater than or equal to cost(s->u->v) or it would have already revised the cost of v to go through X No: cost(s->x->y) must be greater than or equal to cost(s->u->v) (and therefore cost(s->x->y->v) must be even greater) or it would be visiting node Y next

5 Dijkstra s Pseudocode dijkstra(graph, start): distance = {} for v in graph.vertices: distance[v] = infinity distance[start] = 0 unvisited = graph.vertices unvisited.remove(start) current = start while!unvisted.empty() for e in current.outgoing: v = e.tovertex if v in unvisited: d = distance[current] + e.weight if d < distance[v]: distance[v] = d unvisited.remove(current) current = unvisited.findsmallestdistance() if distance[current] == infinity: break Running time? Explore every edge once, Visit every node once At every node, scan the unvisited nodes to find next smallest distance O( E + V 2 ) Can you do better? Greedy choice In case >1 connected components

6 Dijkstra with Priority Queue dijkstra(graph, start): distance = {} for v in graph.vertices: if v == start distance[v] = 0 else distance[v] = infinity Q.add_with_priority(v, distance[v]) while!q.empty() cur = Q.extract_min() if distance[current] == infinity: break for e in current.outgoing: v = e.tovertex if v in Q: d = distance[current] + e.weight if d < distance[v]: distance[v] = d Q.decrease_priority(v,d) Normally it takes O(n) time to find an element in a heap, but use an integer index (or something) to directly reference its position A min-priority queue that supports extract_min(), add_with_priority(), and decrease_priority() Now Dikstra will run in O( E lg V ) Notice we have to do work on every edge

7 Min-priority queue public interface PriorityQueue<T extends Comparable<T>> { void insert(t t); void remove() throws EmptyQueueException; T top() throwsemptyqueueexception; boolean empty(); } public interface MinPriorityQueue<K, P extends Comparable<T>> { void addwithpriority(k key, P priority); void decreasepriority(k key, P newp) throws InvalidItem; T extractmin() throws EmptyQueueException; boolean empty(); }

8 Min-priority queue public interface MinPriorityQueue<K, P extends Comparable<T>> { void addwithpriority(k key, P priority); void decreasepriority(k key, P newp) throws InvalidItem; T extractmin() throws EmptyQueueException; boolean empty(); } MPQ heap Mike/0 / \ Peter/7 Kelly/1 / \ / Katherine/9 Sydney/7 James/2 keys James Katherine Kelly Mike Peter Sydney

9 Min-priority queue public interface MinPriorityQueue<K, P extends Comparable<T>> { void addwithpriority(k key, P priority); void decreasepriority(k key, P newp) throws InvalidItem; T extractmin() throws EmptyQueueException; boolean empty(); } How to implement? MPQ heap keys Mike/0 / \ Peter/7 Kelly/1 / \ / Katherine/9 Sydney/7 James/2 James Katherine Kelly Mike Peter Sydney (1) If keys are integers in the range 0 to n, make an array of references (2) Use a HashMap from keys to hash (3) Give client a reference, store in graph node

10 Fibonnaci Heap Special form of heaps specifically designed to allow fast updates to values Set of heap-ordered tree (value(n) < value(n.children)) Maintain pointer to overall minimum element Set of marked nodes used to track heights of certain trees Insert Findmin Deletemin Decreasekey Merge Binary Heap O(1) O(lg n) O(lg n) O(lg n) O(n) Fibonnaci Heap O(1) O(lg n) O(1) O(1) O(1) Reduces Dijkstra s run time to O( E + V lg V )

11 Part 2: Minimum Spanning Trees

12 Long Distance Calling Supposes it costs different amounts of money to send data between cities A through F. Find the least expensive set of connections so that anyone can send data to anyone else. Given an undirected graph with weights on the edges, find the subset of edges that (a) connects all of the vertices of the graph and (b) has minimum total costs This subset of edges is called the minimum spanning tree (MST) Removing an edge from MST disconnects the graph, adding one forms a cycle

13 Dijkstra s!= MST 100 X S Y Dijkstra s will build the tree S->X, S->Y (tree visits every node with shortest paths from S to every other node) but the MST is S->X, X->Y (tree visits every node and minimizes the sum of the edges)

14 Prim s Algorithm 1. Pick an arbitrary starting vertex and add it to set T. Add all of the other vertices to set R Every vertex will be included eventually, so doesn t matter where you start T={A} R={B,C,D,E,F}

15 Prim s Algorithm 1. Pick an arbitrary starting vertex and add it to set T. Add all of the other vertices to set R Every vertex will be included eventually, so doesn t matter where you start T={A} R={B,C,D,E,F} 2. While R is not empty, pick an edge from T to R with minimum cost A-B: 4 <- pick me A-C: 7 A-D: 8 A-F: 10

16 Prim s Algorithm 1. Pick an arbitrary starting vertex and add it to set T. Add all of the other vertices to set R Every vertex will be included eventually, so doesn t matter where you start T={A} R={B,C,D,E,F} 2. While R is not empty, pick an edge from T to R with minimum cost A-B: 4 <- pick me A-C: 7 A-D: 8 A-F: 10

17 Prim s Algorithm 3. Repeat! A-B

18 Prim s Algorithm 3. Repeat! A-B A-C

19 Prim s Algorithm 3. Repeat! A-B A-C C-D

20 Prim s Algorithm 3. Repeat! A-B A-C C-D C-F

21 Prim s Algorithm 3. Repeat! A-B A-C C-D C-F C-E By making a set of simple local choices, it finds the overall best solution The greedy algorithm is optimal J

22 Prim s Algorithm Prim s Algorithm Sketch 1. Initialize a tree with a single vertex, chosen arbitrarily from the graph. 2. Grow the tree by one edge: of the edges that connect the tree to vertices not yet in the tree, find the minimum-weight edge, and add it to the tree. 3. Repeat step 2 (until all vertices are in the tree).

23 Prim s Algorithm Prim s Pseudo-code 1. For each vertex v, Compute C[v] (the cheapest cost of a connection to v from the MST) and an edge E[v] (the edge providing that cheapest connection). Initialize C[v] to and E[v] to a special flag value indicating that there is no edge connecting v to the MST 2. Initialize an empty forest F (set of trees) and a set Q of vertices that have not yet been included in F (initially, all vertices). 3. Repeat the following steps until Q is empty: 1. Find and remove a vertex v from Q with the minimum value of C[v] 2. Add v to F and, if E[v] is not the special flag value, also add E[v] to F 3. Loop over the edges vw connecting v to other vertices w. For each such edge, if w still belongs to Q and vw has smaller weight than C[w], perform the following steps: 1. Set C[w] to the cost of edge vw 2. Set E[w] to point to edge vw. 4. Return F How fast is the naïve version? O( V 2 ) What data structures do we need to make it fast? HEAP

24 Prim s Algorithm Faster Prim s Pseudo-code 1. Add the cost of all of the edges to a heap (or sort the edge costs) 2. Repeatedly pick the next smallest edge (u,v) 1. If u or v is not already in the MST, add the edge uv to the MST How fast is this version O( E lg E ) Fastest Prim s Pseudo-code 1. Add all of the vertices to a min-priority-queue prioritized by the min edge cost to be added to the MST. Initialize (key=v, dist=, edge=<>) 2. Repeatedly pick the next closest vertex v from the MPQ 1. Add v to the MST using the recorded edge 2. For each edge (v, u) 1. If cost(v,u) < MPQ(u) 1. MPQ.decreasePriority(u, cost(v,u), (v,u)) How fast is this version Using Fibonacci Heap O( E lg V ) O( E + V lg V )

25 Teaser: Kruskal s Algorithm Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

26 Traveling Salesman Problem What if we wanted to compute the minimum weight path visiting every node once? ABDCA: = 14 ACDBA: = 14* ABCDA: = 11 ADCBA: = 11* ACBDA: = 7 ADBCA: = 7 * 3 A C B D 2

27 Greedy Search Greedy Search cur=graph.randnode() A 11 8 B while (!done) next=cur.getnextclosest() Greedy: ABDCA = = 73 Optimal: ACBDA = = 38 C 50 D Greedy finds the global optimum only when 1. Greedy Choice: Local is correct without reconsideration 2. Optimal Substructure: Problem can be split into subproblems Optimal Greedy: Dijkstra s, Prim s, Cookie Monster

28 TSP Complexity No fast solution Knowing optimal tour through n cities doesn't seem to help much for n+1 cities 3 A 1 4 B 2 1 [How many possible tours for n cities?] C 5 D Extensive searching is the only provably correct algorithm A 4 B Brute Force: O(n!) ~20 cities max 20! = 2.4 x C 5 D 2 E 30

29 Branch-and-Bound Abort on suboptimal solutions as soon as possible ADBECA = = 10 ABDE = > 10 ADE = 1+30 > 10 AED = 1+30 > 10 Performance Heuristic Always gives the optimal answer Doesn't always help performance, but often does Current TSP record holder: 85,900 cities 85900! = C A [When not?] 4 E B D

30 TSP and NP-complete TSP is one of many extremely hard problems of the class NP-complete Extensive searching is the only way to find an exact solution Often have to settle for approx. solution WARNING: Many natural problems are in this class Find a tour the visits every node once Find the smallest set of vertices covering the edges Find the largest clique in the graph Find the highest mutual information encoding scheme Find the best set of moves in tetris

31 Part 3: Kruskal s Algorithm and Union Find

32 Kruskal s Algorithm B C E 9 14 D A 10 F Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

33 Kruskal s Algorithm B C E 9 14 D A 10 F Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

34 Kruskal s Algorithm B C A E F 9 14 D Tinting is just to make it easier to look at Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

35 Kruskal s Algorithm B C E 9 14 D A 10 F Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

36 Kruskal s Algorithm B C E 9 14 D A 10 F Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

37 Kruskal s Algorithm B C E 9 14 D A 10 F Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

38 Kruskal s Algorithm B 4 C E A F 10 D Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

39 Kruskal s Algorithm B 4 C E A F 10 D Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

40 Kruskal s Algorithm 4 C E B A F 10 D Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

41 Kruskal s Algorithm C 4 E B D 4 A F Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree

42 Kruskal s Algorithm C 4 E B D 4 A F Running time: Kruskal s Algorithm Sketch 1. Create a forest F (a set of trees), where each vertex in the graph Easy: is a O( V ) separate tree 2. Create a set S containing all the edges in the graph 3. while S is nonempty and F is not yet spanning Easy: O( E lg E ) 1. remove an edge with minimum weight from S 2. if the removed edge connects two different trees then add it to the forest F, combining two trees into a single tree Hmm???

43 Disjoint Sets C E C E B D B D A F A F Disjoint Subset: every element is assigned to a single subset Problem: Determine which elements are part of the same subset as sets are dynamically joined together Two main methods: Find: Are elements x and y part of the same set? Union: Merge together sets containing elements x and y

44 Quick Find

45 Implementation Find is quick O(1), but each union is O(N) time Kruskal s ultimately merges all N items: O(N 2 ) Can we do any faster?

46 Implementation Find is quick O(1), but each union is O(N) time Kruskal s ultimately merges all N items: O(N 2 ) Can we do any faster?

47 Quick Find Forest

48 Quick Union

49 Quick Union Why not just change id[q]? Why set it to p s root instead of p?

50 Quick Union Implementation

51 Quick Union Example What is the worst case for Quick Union?

52 Quick-Union Analysis

53 Improved Quick-Union: Weighting

54 Improved Quick-Union: Weighting

55 Weighted Quick-Union Implementation

56 Weighted Quick-Union

57 Weighted Quick-Union Hooray! Tree stays pretty flat! How tall can the tree grow? Uniting a short tree and a tall tree doesn t increase the height of the tall tree Height of tree only grows when two trees of equal height are united, thereby doubling the number of elements How many rounds of doubling can we do until we include all N elements? lg N rounds => O(lg N) max height J

58 Weighted Quick-Union Analysis Should we stop trying here? Usually very happy with lg(n), but here we can do better!

59 Improvement 2: Path Compression

60 Path Compression Implementation

61 Weighted Path Compression Example

62 Weighted Path Compression Analysis Much bigger than #atoms in the universe

63 Kruskal s Algorithm C 4 E B D 4 A F Running time: Kruskal s Algorithm Sketch 1. Using Create Weighted-Path a forest F (a Compression set of trees), Quick where Union each vertex in the graph is a (aka separate Union-Find) tree each find or union in O(lg* V ) time. Easy: O( V ) 2. Total Create time a is set O( E lg E S containing + Elg* V ) all the => edges O( E lg E ) in the graph 3. while S is nonempty and F is not yet spanning Easy: O( E lg E ) If the 1. edges remove are an already edge with in sorted minimum order weight (or use from a S linear 2. time if the sorting removed algorithm edge connects such as counting two different sort), trees then add it to the reduce forest total time F, combining to O( E lg* V ) two trees into a single tree Hmm???

64 Other Applications: Connected Components

65 Other Applications: Connected Components How would you use Union-Find to solve this? Assign every dot to a set, then merge sets that have an edge between them

66 Other Applications: Connected Components 63 Connected Components

67 Never underestimate the power of the LOG STAR!!!!

68 Next Steps 1. Reflect on the magic and power of the logstar! 2. Final Exam: Sunday Dec 9am

69 Welcome to CS Questions?

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Greedy Algorithms. At each step in the algorithm, one of several choices can be made. Greedy Algorithms At each step in the algorithm, one of several choices can be made. Greedy Strategy: make the choice that is the best at the moment. After making a choice, we are left with one subproblem

More information

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29 Lecture 13 Connectedness in graphs Spanning trees in graphs Finding a minimal spanning tree Time costs of graph problems and NP-completeness Finding a minimal spanning tree: Prim s and Kruskal s algorithms

More information

CSE 100: GRAPH ALGORITHMS

CSE 100: GRAPH ALGORITHMS CSE 100: GRAPH ALGORITHMS Dijkstra s Algorithm: Questions Initialize the graph: Give all vertices a dist of INFINITY, set all done flags to false Start at s; give s dist = 0 and set prev field to -1 Enqueue

More information

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem Minimum Spanning Trees (Forests) Given an undirected graph G=(V,E) with each edge e having a weight w(e) : Find a subgraph T of G of minimum total weight s.t. every pair of vertices connected in G are

More information

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CSE 100 Minimum Spanning Trees Prim s and Kruskal CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:

More information

looking ahead to see the optimum

looking ahead to see the optimum ! Make choice based on immediate rewards rather than looking ahead to see the optimum! In many cases this is effective as the look ahead variation can require exponential time as the number of possible

More information

Minimum Spanning Trees My T. UF

Minimum Spanning Trees My T. UF Introduction to Algorithms Minimum Spanning Trees @ UF Problem Find a low cost network connecting a set of locations Any pair of locations are connected There is no cycle Some applications: Communication

More information

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees //8 About A, Prelim Spanning Trees, greedy algorithms Lecture CS Fall 8 Prelim : Thursday, November. Visit exams page of course website and read carefully to find out when you take it (: or 7:) and what

More information

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018 1 Spanning Trees, greedy algorithms Lecture 20 CS2110 Fall 2018 1 About A6, Prelim 2 Prelim 2: Thursday, 15 November. Visit exams page of course website and read carefully to find out when you take it

More information

Announcements Problem Set 5 is out (today)!

Announcements Problem Set 5 is out (today)! CSC263 Week 10 Announcements Problem Set is out (today)! Due Tuesday (Dec 1) Minimum Spanning Trees The Graph of interest today A connected undirected weighted graph G = (V, E) with weights w(e) for each

More information

Algorithms for Minimum Spanning Trees

Algorithms for Minimum Spanning Trees Algorithms & Models of Computation CS/ECE, Fall Algorithms for Minimum Spanning Trees Lecture Thursday, November, Part I Algorithms for Minimum Spanning Tree Sariel Har-Peled (UIUC) CS Fall / 6 Sariel

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees Overview Problem A town has a set of houses and a set of roads. A road connects and only houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and

More information

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Dijkstra s algorithm for shortest paths when no edges have negative weight. Lecture 14 Graph Algorithms II 14.1 Overview In this lecture we begin with one more algorithm for the shortest path problem, Dijkstra s algorithm. We then will see how the basic approach of this algorithm

More information

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 9 Greedy Technique Copyright 2007 Pearson Addison-Wesley. All rights reserved. Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that

More information

6.1 Minimum Spanning Trees

6.1 Minimum Spanning Trees CS124 Lecture 6 Fall 2018 6.1 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties

More information

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017 1 Spanning Trees, greedy algorithms Lecture 22 CS2110 Fall 2017 1 We demo A8 Your space ship is on earth, and you hear a distress signal from a distance Planet X. Your job: 1. Rescue stage: Fly your ship

More information

Minimum-Cost Spanning Tree. Example

Minimum-Cost Spanning Tree. Example Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Example 2 4 12 6 3 Network has 10 edges.

More information

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Example 2 4 12 6 3 Network has 10 edges.

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected

More information

CAD Algorithms. Categorizing Algorithms

CAD Algorithms. Categorizing Algorithms CAD Algorithms Categorizing Algorithms Mohammad Tehranipoor ECE Department 2 September 2008 1 Categorizing Algorithms Greedy Algorithms Prim s Algorithm (Minimum Spanning Tree) A subgraph that is a tree

More information

Priority Queues. 04/10/03 Lecture 22 1

Priority Queues. 04/10/03 Lecture 22 1 Priority Queues It is a variant of queues Each item has an associated priority value. When inserting an item in the queue, the priority value is also provided for it. The data structure provides a method

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees 1 Minimum- Spanning Trees 1. Concrete example: computer connection. Definition of a Minimum- Spanning Tree Concrete example Imagine: You wish to connect all the computers in an office

More information

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees /9/7 Prelim, assignments Prelim is Tuesday. See the course webpage for details. Scope: up to but not including today s lecture. See the review guide for details. Deadline for submitting conflicts has passed.

More information

Spanning Trees. Lecture 22 CS2110 Spring 2017

Spanning Trees. Lecture 22 CS2110 Spring 2017 1 Spanning Trees Lecture 22 CS2110 Spring 2017 1 Prelim 2, assignments Prelim 2 is Tuesday. See the course webpage for details. Scope: up to but not including today s lecture. See the review guide for

More information

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016 CS125 Lecture 2 Fall 2016 2.1 Greedy Algorithms We will start talking about methods high-level plans for constructing algorithms. One of the simplest is just to have your algorithm be greedy. Being greedy,

More information

Partha Sarathi Manal

Partha Sarathi Manal MA 515: Introduction to Algorithms & MA5 : Design and Analysis of Algorithms [-0-0-6] Lecture 20 & 21 http://www.iitg.ernet.in/psm/indexing_ma5/y09/index.html Partha Sarathi Manal psm@iitg.ernet.in Dept.

More information

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 9 Minimum Spanning Trees Thanks to the text authors who contributed to these slides Why Minimum Spanning Trees (MST)? Example 1 A

More information

SPANNING TREES. Lecture 21 CS2110 Spring 2016

SPANNING TREES. Lecture 21 CS2110 Spring 2016 1 SPANNING TREES Lecture 1 CS110 Spring 016 Spanning trees What we do today: Calculating the shortest path in Dijkstra s algorithm Look at time complexity of shortest path Definitions Minimum spanning

More information

Minimum Spanning Tree (5A) Young Won Lim 5/11/18

Minimum Spanning Tree (5A) Young Won Lim 5/11/18 Minimum Spanning Tree (5A) Copyright (c) 2015 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013 CSE373: Data Structures & Algorithms Lecture 7: Minimum Spanning Trees Dan Grossman Fall 03 Spanning Trees A simple problem: Given a connected undirected graph G=(V,E), find a minimal subset of edges such

More information

Minimum Spanning Trees

Minimum Spanning Trees CS124 Lecture 5 Spring 2011 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties

More information

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm Spanning Trees 1 Spanning Trees the minimum spanning tree problem three greedy algorithms analysis of the algorithms 2 The Union-Find Data Structure managing an evolving set of connected components implementing

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 018 D/Q Greed SP s DP LP, Flow B&B, Backtrack Metaheuristics P, NP Design and Analysis of Algorithms Lecture 8: Greed Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Optimization

More information

CS 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 0 Advanced Data Structures and Algorithms Weighted Graphs July 0, 07 Tong Wang UMass Boston CS 0 July 0, 07 / Weighted Graphs Each edge has a weight (cost) Edge-weighted graphs Mostly we consider only

More information

Week 11: Minimum Spanning trees

Week 11: Minimum Spanning trees Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,

More information

CS 561, Lecture 9. Jared Saia University of New Mexico

CS 561, Lecture 9. Jared Saia University of New Mexico CS 561, Lecture 9 Jared Saia University of New Mexico Today s Outline Minimum Spanning Trees Safe Edge Theorem Kruskal and Prim s algorithms Graph Representation 1 Graph Definition A graph is a pair of

More information

Union/Find Aka: Disjoint-set forest. Problem definition. Naïve attempts CS 445

Union/Find Aka: Disjoint-set forest. Problem definition. Naïve attempts CS 445 CS 5 Union/Find Aka: Disjoint-set forest Alon Efrat Problem definition Given: A set of atoms S={1, n E.g. each represents a commercial name of a drugs. This set consists of different disjoint subsets.

More information

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, ) Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 1. if >. 2. error new key is greater than current key 3.. 4.. 5. if NIL and.

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170 UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, 2003 Notes 8 for CS 170 1 Minimum Spanning Trees A tree is an undirected graph that is connected

More information

2 A Template for Minimum Spanning Tree Algorithms

2 A Template for Minimum Spanning Tree Algorithms CS, Lecture 5 Minimum Spanning Trees Scribe: Logan Short (05), William Chen (0), Mary Wootters (0) Date: May, 0 Introduction Today we will continue our discussion of greedy algorithms, specifically in

More information

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve

More information

Lecture 13: Minimum Spanning Trees Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Lecture 13: Minimum Spanning Trees Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY Lecture 13: Minimum Spanning Trees Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Problem of the Day Your job is to

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 10 Implementing MST Algorithms Adam Smith Minimum spanning tree (MST) Input: A connected undirected graph G = (V, E) with weight function w : E R. For now, assume

More information

Lecture Notes for Chapter 23: Minimum Spanning Trees

Lecture Notes for Chapter 23: Minimum Spanning Trees Lecture Notes for Chapter 23: Minimum Spanning Trees Chapter 23 overview Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has

More information

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD UNIT 3 Greedy Method GENERAL METHOD Greedy is the most straight forward design technique. Most of the problems have n inputs and require us to obtain a subset that satisfies some constraints. Any subset

More information

2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23)

2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23) 2pt 0em Computer Science & Engineering 423/823 Design and of s Lecture 04 Minimum-Weight Spanning Trees (Chapter 23) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 18 Given a connected, undirected

More information

Priority queue ADT part 1

Priority queue ADT part 1 http://www.mainjava.com/java/core-java/priorityqueue-class-in-java-with-programming-example/ Priority queue ADT part 1 CS 146 - Spring 2017 Today Dijkstra s algorithm The minimum spanning tree problem

More information

Chapter 6. The Traveling-Salesman Problem. Section 1. Hamilton circuits and Hamilton paths.

Chapter 6. The Traveling-Salesman Problem. Section 1. Hamilton circuits and Hamilton paths. Chapter 6. The Traveling-Salesman Problem Section 1. Hamilton circuits and Hamilton paths. Recall: an Euler path is a path that travels through every edge of a graph once and only once; an Euler circuit

More information

CS : Data Structures

CS : Data Structures CS 600.226: Data Structures Michael Schatz Nov 30, 2016 Lecture 35: Topological Sorting Assignment 10: Due Monday Dec 5 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 3 Definitions an undirected graph G = (V, E)

More information

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions Introduction Chapter 9 Graph Algorithms graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 2 Definitions an undirected graph G = (V, E) is

More information

Spanning Trees. Lecture 20 CS2110 Spring 2015

Spanning Trees. Lecture 20 CS2110 Spring 2015 1 Spanning Trees Lecture 0 CS110 Spring 01 1 Undirected trees An undirected graph is a tree if there is exactly one simple path between any pair of vertices Root of tree? It doesn t matter choose any vertex

More information

CSE332: Data Abstractions Lecture 25: Minimum Spanning Trees. Ruth Anderson via Conrad Nied Winter 2015

CSE332: Data Abstractions Lecture 25: Minimum Spanning Trees. Ruth Anderson via Conrad Nied Winter 2015 CSE33: Data Abstractions Lecture 5: Minimum Spanning Trees Ruth Anderson via Conrad Nied Winter 05 A quick note about Gradescope 3/06/05 Today s XKCD 3/06/05 3 You guys are awesome 3/06/05 4 Do you still

More information

Minimum Spanning Trees

Minimum Spanning Trees CSMPS 2200 Fall Minimum Spanning Trees Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 11/6/ CMPS 2200 Intro. to Algorithms 1 Minimum spanning trees Input: A

More information

CSE 332: Data Structures & Parallelism Lecture 22: Minimum Spanning Trees. Ruth Anderson Winter 2018

CSE 332: Data Structures & Parallelism Lecture 22: Minimum Spanning Trees. Ruth Anderson Winter 2018 SE 33: Data Structures & Parallelism Lecture : Minimum Spanning Trees Ruth nderson Winter 08 Minimum Spanning Trees iven an undirected graph =(V,E), find a graph =(V, E ) such that: E is a subset of E

More information

Lecture 13: Minimum Spanning Trees Steven Skiena

Lecture 13: Minimum Spanning Trees Steven Skiena Lecture 13: Minimum Spanning Trees Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Your job

More information

Lecture 18: Implementing Graphs

Lecture 18: Implementing Graphs Lecture 18: Implementing Graphs CS 373: Data Structures and Algorithms CS 373 19 WI - KASY CHAMPION 1 Administrivia HW 5 Part due Friday, last day to turn in Monday Optional: HW 3 regrade to be turned

More information

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck Theory of Computing Lecture 10 MAS 714 Hartmut Klauck Seven Bridges of Königsberg Can one take a walk that crosses each bridge exactly once? Seven Bridges of Königsberg Model as a graph Is there a path

More information

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP)

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP) Spanning Tree (015) Lecture1: Graph III ohyung Han S, POSTH bhhan@postech.ac.kr efinition and property Subgraph that contains all vertices of the original graph and is a tree Often, a graph has many different

More information

The Algorithms of Prim and Dijkstra. Class 19

The Algorithms of Prim and Dijkstra. Class 19 The Algorithms of Prim and Dijkstra Class 19 MST Introduction you live in a county that has terrible roads a new county commissioner was elected based on her campaign promise to repave the roads she promised

More information

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

CIS 121 Data Structures and Algorithms Minimum Spanning Trees CIS 121 Data Structures and Algorithms Minimum Spanning Trees March 19, 2019 Introduction and Background Consider a very natural problem: we are given a set of locations V = {v 1, v 2,..., v n }. We want

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 9: Minimum Spanning Trees Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Goal: MST cut and cycle properties Prim, Kruskal greedy algorithms

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 05 Minimum-Weight Spanning Trees (Chapter 23) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction

More information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

CS 440 Theory of Algorithms /

CS 440 Theory of Algorithms / CS 440 Theory of Algorithms / CS 468 Algorithms in Bioinformaticsi Brute Force. Design and Analysis of Algorithms - Chapter 3 3-0 Brute Force A straightforward approach usually based on problem statement

More information

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast

More information

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs Graphs and Network Flows ISE 411 Lecture 7 Dr. Ted Ralphs ISE 411 Lecture 7 1 References for Today s Lecture Required reading Chapter 20 References AMO Chapter 13 CLRS Chapter 23 ISE 411 Lecture 7 2 Minimum

More information

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree Algorithms and Theory of Computation Lecture 5: Minimum Spanning Tree Xiaohui Bei MAS 714 August 31, 2017 Nanyang Technological University MAS 714 August 31, 2017 1 / 30 Minimum Spanning Trees (MST) A

More information

CHAPTER 23. Minimum Spanning Trees

CHAPTER 23. Minimum Spanning Trees CHAPTER 23 Minimum Spanning Trees In the design of electronic circuitry, it is often necessary to make the pins of several components electrically equivalent by wiring them together. To interconnect a

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Minimum Spanning Tree Kostas Alexis The Minimum Spanning Tree Algorithm A telecommunication company wants to connect all the blocks in a new neighborhood. However,

More information

Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1

Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1 Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1 Minimum Spanning Tree Problem Given: Undirected connected weighted graph (G, W ) Output: An MST of G We have already

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures 3 Definitions an undirected graph G = (V, E) is a

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms, Lecture 1 /1/200 Introduction to Algorithms.04J/1.401J LECTURE 11 Graphs, MST, Greedy, Prim Graph representation Minimum spanning trees Greedy algorithms hallmarks. Greedy choice

More information

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees CSE1 Introduction to Algorithms Lecture 1 Minimum Spanning Trees Antoine Vigneron antoine@unist.ac.kr Ulsan National Institute of Science and Technology July 11, 201 Antoine Vigneron (UNIST) CSE1 Lecture

More information

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms Elementary Graph Algorithms: Summary CmSc250 Intro to Algorithms Definition: A graph is a collection (nonempty set) of vertices and edges A path from vertex x to vertex y : a list of vertices in which

More information

Greedy Approach: Intro

Greedy Approach: Intro Greedy Approach: Intro Applies to optimization problems only Problem solving consists of a series of actions/steps Each action must be 1. Feasible 2. Locally optimal 3. Irrevocable Motivation: If always

More information

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree Algorithms and Theory of Computation Lecture 5: Minimum Spanning Tree Xiaohui Bei MAS 714 August 31, 2017 Nanyang Technological University MAS 714 August 31, 2017 1 / 30 Minimum Spanning Trees (MST) A

More information

Algorithms. Algorithms. Algorithms 4.3 MINIMUM SPANNING TREES

Algorithms. Algorithms. Algorithms 4.3 MINIMUM SPANNING TREES Announcements Algorithms ROBERT SEDGEWICK KEVIN WAYNE Exam Regrades Due by Wednesday s lecture. Teaching Experiment: Dynamic Deadlines (WordNet) Right now, WordNet is due at PM on April 8th. Starting Tuesday

More information

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs Representations of Weighted Graphs (as Matrices) A B Algorithms and Data Structures: Minimum Spanning Trees 9.0 F 1.0 6.0 5.0 6.0 G 5.0 I H 3.0 1.0 C 5.0 E 1.0 D 28th Oct, 1st & 4th Nov, 2011 ADS: lects

More information

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G. 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G. A shortest s-t path is a path from vertex to vertex, whose sum of edge weights is minimized. (b) Give the pseudocode

More information

1 Minimum Spanning Trees: History

1 Minimum Spanning Trees: History -80: Advanced Algorithms CMU, Spring 07 Lecture #: Deterministic MSTs January, 07 Lecturer: Anupam Gupta Scribe: Anshu Bansal, C.J. Argue Minimum Spanning Trees: History The minimum spanning tree problem

More information

Introduction: (Edge-)Weighted Graph

Introduction: (Edge-)Weighted Graph Introduction: (Edge-)Weighted Graph c 8 7 a b 7 i d 9 e 8 h 6 f 0 g These are computers and costs of direct connections. What is a cheapest way to network them? / 8 (Edge-)Weighted Graph Many useful graphs

More information

In this chapter, we consider some of the interesting problems for which the greedy technique works, but we start with few simple examples.

In this chapter, we consider some of the interesting problems for which the greedy technique works, but we start with few simple examples. . Greedy Technique The greedy technique (also known as greedy strategy) is applicable to solving optimization problems; an optimization problem calls for finding a solution that achieves the optimal (minimum

More information

Notes on Minimum Spanning Trees. Red Rule: Given a cycle containing no red edges, select a maximum uncolored edge on the cycle, and color it red.

Notes on Minimum Spanning Trees. Red Rule: Given a cycle containing no red edges, select a maximum uncolored edge on the cycle, and color it red. COS 521 Fall 2009 Notes on Minimum Spanning Trees 1. The Generic Greedy Algorithm The generic greedy algorithm finds a minimum spanning tree (MST) by an edge-coloring process. Initially all edges are uncolored.

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II Anna University 2 & 16 Mark Questions & Answers Year / Semester: II / III

More information

Graphs. The ultimate data structure. graphs 1

Graphs. The ultimate data structure. graphs 1 Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely

More information

CSE 21: Mathematics for Algorithms and Systems Analysis

CSE 21: Mathematics for Algorithms and Systems Analysis CSE 21: Mathematics for Algorithms and Systems Analysis Week 10 Discussion David Lisuk June 4, 2014 David Lisuk CSE 21: Mathematics for Algorithms and Systems Analysis June 4, 2014 1 / 26 Agenda 1 Announcements

More information

Union Find and Greedy Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 8

Union Find and Greedy Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 8 Union Find and Greedy Algorithms CSE 101: Design and Analysis of Algorithms Lecture 8 CSE 101: Design and analysis of algorithms Union find Reading: Section 5.1 Greedy algorithms Reading: Kleinberg and

More information

CSE 417 Branch & Bound (pt 4) Branch & Bound

CSE 417 Branch & Bound (pt 4) Branch & Bound CSE 417 Branch & Bound (pt 4) Branch & Bound Reminders > HW8 due today > HW9 will be posted tomorrow start early program will be slow, so debugging will be slow... Review of previous lectures > Complexity

More information

What is a minimal spanning tree (MST) and how to find one

What is a minimal spanning tree (MST) and how to find one What is a minimal spanning tree (MST) and how to find one A tree contains a root, the top node. Each node has: One parent Any number of children A spanning tree of a graph is a subgraph that contains all

More information

We have already seen the transportation problem and the assignment problem. Let us take the transportation problem, first.

We have already seen the transportation problem and the assignment problem. Let us take the transportation problem, first. Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Lecture 19 Network Models In this lecture, we will discuss network models. (Refer

More information

Three Graph Algorithms

Three Graph Algorithms Three Graph Algorithms Shortest Distance Paths Distance/Cost of a path in weighted graph sum of weights of all edges on the path path A, B, E, cost is 2+3=5 path A, B, C, E, cost is 2+1+4=7 How to find

More information

Three Graph Algorithms

Three Graph Algorithms Three Graph Algorithms Shortest Distance Paths Distance/Cost of a path in weighted graph sum of weights of all edges on the path path A, B, E, cost is 2+3=5 path A, B, C, E, cost is 2+1+4=7 How to find

More information

Spanning Trees. CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Motivation. Observations. Spanning tree via DFS

Spanning Trees. CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Motivation. Observations. Spanning tree via DFS Spanning Trees S: ata Structures & lgorithms Lecture : Minimum Spanning Trees simple problem: iven a connected undirected graph =(V,), find a minimal subset of edges such that is still connected graph

More information

CSC 505, Fall 2000: Week 7. In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion.

CSC 505, Fall 2000: Week 7. In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion. CSC 505, Fall 2000: Week 7 In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion. Page 1 of 18 Prim s algorithm without data structures

More information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS 4 Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 8 Data Structures for Disjoint Sets Thanks to the text authors who contributed to these slides Data Structures for Disjoint Sets Also

More information

Algorithm Design (8) Graph Algorithms 1/2

Algorithm Design (8) Graph Algorithms 1/2 Graph Algorithm Design (8) Graph Algorithms / Graph:, : A finite set of vertices (or nodes) : A finite set of edges (or arcs or branches) each of which connect two vertices Takashi Chikayama School of

More information