Algorithm Design (8) Graph Algorithms 1/2
|
|
- Irene Cannon
- 5 years ago
- Views:
Transcription
1 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 Engineering The University of Tokyo Things Best Represented as Graphs Concrete existences and what connect them Stations connected via railroad lines Liquid or gas tanks connected with pipes Computers and/or switches connected by cables Relations between: Things: on, under, above, below, adjacent-to, Events: precedence, causality Notions: subsumption, equivalence, Multiple and Simple Edges Edges are multiple if there is another edge connecting the same two vertices Otherwise, an edge is simple A graph is simple if all the edges are simple An edge of a simple graph is a vertex pair,
2 Subgraphs Subgraph: A graph both of its vertices and edges are subsets of the original graph Spanning subgraph: A connected subgraph containing all the vertices of the original graph Directed Graphs and Weighted Graphs When edges of a graph have No direction: undirected graph Directions: directed graph or digraph Graphs with values associated with their edges are called weighted graphs Weighted digraphs are sometime called networks 6 Walks, Trails and Paths Loops and Cycles Walk: An alternating sequence of adjacent vertices and edges connecting them For a digraph, the order of the vertices must agree with the edge direction Trail: A walk without duplicated edges Path: A walk without duplicated vertices Loop: An edge with that links to itself Cycle: A trail that starts and ends at the same vertex Acyclic Graph: A graph without cycles 8
3 Connectivity A graph is connected if all nodes are directly or indirectly linked Otherwise the graph is disconnected Complete graph: a graph in which all pairs of vertices have a connecting edge Connectivity in Digraphs A directed graphs is weakly connected if an undirected graph obtained by removing directions of its edges is connected It is strongly connected if there exists a directed path from all of its nodes to all of its nodes. A strong component of a graph is a maximal strongly connected subgraph of the graph. 9 0 Degree or Valence Degree (or valence) of a vertex: the number of edges connected to a vertex In-degree and out-degree are distinguished in digraphs in-degree = degree = out-degree = Connectivity of a Graph Given a graph, if at least k vertices have to be removed to make the graph disconnected, the graph is called k-vertex-connected If at least k edges have to be removed to make a graph it disconnected, the graph is called to be k-edge-connected Cut Set: A set of edges removing which will make the graph disconnected When one single edge forms a cut set, that edge is called a bridge
4 Tree Tree: A connected acyclic simple graph All the edges in a tree are bridges A vertex of a tree is a leaf if it has only one edge connected to it Note that most of the trees that are used in algorithms are rooted trees, that are simple acyclic digraphs with certain restriction on edge directions Representation of Graphs A variety of representations are possible Chosen considering the characteristics of the graph and the kind of processing required Points are: Memory amount required Costs to obtain information such as: Whether given two vertices are directly linked Which vertices connect to which Enumerate all the vertices or all the edges Adjacency Matrix A square matrix that has the same number of rows and columns as the number of vertices Element (i, j) being /0 tells whether an edge from vertex i to vertex j exists or not For weighted graphs, the edge weights are stored The matrix is symmetric for an undirected graph Merits and Demerits of Adjacency Matrix Dense graphs (with many edges) can be compactly represented Efficient to tell whether two vertices are directly connected For sparse graphs, redundant with many zeros For graphs with n vertices, the size is O(n ), irrespective of the number of edges For sparse graphs, enumerating vertices directly connected a given vertex is inefficient: O(n) Only simple graphs can be represented; No way to represent mulitple edges 6
5 Incidence Matrix A matrix in which rows correspond to vertices and columns correspond to edges Element (i, j) being /0 tells whether the vertex i is one end of the edge j or not For digraphs, different values for starts and ends can be used; yet another value for loops A B C D E F G D E B C A G F Merits and Demerits Any graphs can be represented Sparse graphs can be represented compactly With vertices and edges, the size is Edge weights can be stored separately ( ) Inefficient to tell whether two vertices have a direct edge connecting them For sparse graphs, enumerating vertices adjacent to a given vertex is inefficient Not as efficient as adjacency matrix for dense graphs 8 Adjacency List For each vertex, a list of adjacent vertices is kept A list representation of the information in an adjacency matrix Merits and Demerits of Adjacency List Compact for sparse graphs For vertices and edges Enumeration of adjacent vertices is efficient for sparse graphs Inefficient for dense graphs One pointer instead of one bit per edge If edges are to be registered for both ends, the representation is redundant (doubles the memory) 9 0
6 Sparse Adjacency Matrix Non-zero elements of an adjacency matrix are linked with pointers, both row-wise and column-wise ,,,,,,, Merits and Demerits of Sparse Adjacency Matrix Compact for sparse graphs For vertices and edges Inefficient for dense graphs For each non-zero elements, its row number, column number, and two pointers are required Only one bit in an adjacency matrix Cost of telling whether two vertices are adjacent is proportional to the number of edges from (or to) the same vertex Hash Table Hash table of edges indexed with its two ends h(i, j) Efficient to tell whether two vertices are adjacent or not Compact for sparse graphs; for edges Enumerating edges from a given vertex is quite inefficient Hash collisions may degrade the performance Hash Index in Addition to Sparse Adjacency Matrix A hash table can be added to a sparse adjacency matrix to allow efficient accesses h(, ),,,,,,, 6
7 Graph Traversal Graph Traversal Starting from a given vertex, find all the vertices connected to it by tracing edges Depth-first traversal Visit a vertex adjacent to the most recently visited vertex next Breadth-first traversal Visit a vertex adjacent to the least recently visited vertex next Data structures: A flag to tell whether a vertex is already visited To decide the vertex to visit next A LIFO stack for depth-first traversal Depth-first Stack Breadth-first Queue A FIFO queue for breadth-first traversal 6 Edge Weights Priority Queues Weights given to edges can represent information such as distance, time, costs, capacities, etc Locations as vertices and distances as weights System states as vertices and time of transition as weights Tanks as vertices, maximum flow of connecting pipes as weights Computers or switches as vertices, bandwidths as weights If weights depend on directions, digraphs are appropriate Many of the algorithms for weighted graphs require the following Keeping a subset of edges and/or vertices each associated some value Inspecting edges in the order of their values Efficiency in finding the edge/vertex with the largest (or the smallest) value is often the key Priority queues fit this purpose 8
8 Heap Property Heap is a structure with the following properties A heap is a tree A parent node has its associated value less than or equal to those of their children nodes This is for min-heaps; for max-heaps the order relation is reversed As a consequence, the item at the root is with the minimum value Priority Queue Represented as a Binary Heap Binary heap (or sometime simply heap) A balanced binary tree with key values at nodes No child node has a value less than parent Note that the value may be the same The heap is not unique for the same set of keys Representing a Binary Heap as an Array A binary heap can be represented as an array compactly with the same number of elements Two children of A[ k ] are A[ k+ ] and A[ k+ ] Condition of being a heap is A[ k ] A[ k+ ] and A[ k ] A[ k+ ] 0 0 Heap Operation: Extracting the Least Item. The least item is at the root, so take it off. The last item in the heap is moved to the root. If the lesser of the values of its children is less than that of the moved item, swap them. Repeat the step until a leaf is reached Repeated at most as many times as the tree depth O(log n) 0 8
9 Heap Operation: Adding a New Item. Insert the new item as the last item. If it has a key less than its parent, swap them. Repeat the step until the key is greater than or equal to the parent, or the root has been reached Repeated at most as many times as the tree depth O(log n) Heap Operation: Removing an Item. Remove the item and place the last item there. If its key is less than the parent, or greater than the lesser of the children, swap them. Repeat until reaching the root or a leaf Repeated at most as many times as the tree depth O(log n) 0 0 Binomial Tree Binomial Heap Binomial tree is a tree structure used for heaps A binomial tree of order 0 is a single node A binomial tree of order k has a root node that has k binomial trees of orders k, k,...,,, 0 (in this order) as its children A binomial tree of order k has k nodes A collection of binomial trees satisfying: All binomial trees that have heap property, and No two binomial trees have the same order From the above, the following can be said The smallest item is at one of the roots of trees At most log n trees for n-elements k=0 k= k= k= k=0 6 9 k= k= 6 9
10 Binomial Heap: Merging Two Heaps Merging two binomial heaps can be done in the same way as adding two binary numbers Merge trees of the same order of both heaps When one has a tree of order k and the other doesn t, the resultant heap will have that tree When both have a tree of order k, they are merged to a tree of order k+, which should be considered in merging trees of order k+ (carry ) Merging three trees of order k, from both heaps and a carry tree, one will be in the result and the rest are merged into a carry tree of order k+ Binomial Heap: A Merger Example k=0 k= k= k= + 0 = 00 k= 8 Binomial Heap: Complexity of Merger The worst case complexity of merging two binomial heaps is proportional to the number of trees in the heap, that is O(log n) Adding a new item to a binomial heap can be done by: Making a heap consisting only of the added item Merging it with the original heap The worst case complexity of adding an element is O(log n) The worst case is caused by carry propagation 9 Binomial Heap: Retrieving the Minimum Item The minimum item is at one of the roots of at most log n trees; linear search costs O(log n) When the minimum is at the root of order k tree, removing it leaves trees with orders 0 thru k The binomial heap is reconstructed by merging: The original heap without the order k tree, and A heap of trees with orders 0 thru k 0000 = = = 00 + The total cost is O(log n) 0 0
11 Skew Binary Numbers Common binary representation of an integer is: n = { k A[k]} Weights of digits are,,, 8, 6,, 6, e.g. 9 = is, starting from LSB, 000 An alternative representation: n = { ( k+ ) A[k]} Weights of digits are,,,,, 6,, The first non-zero digit is allowed to be e.g. 9 = ++6 is represented as 000 Natural numbers can be uniquely represented in this system Skew Binary Numbers: Examples Decimal Skew binary Decimal Skew binary Decimal Skew binary Weights of digits are,,,,, 6,, Skew Binary Numbers: Incrementing/Decrementing When the first non-zero digit is not, simply incrementing the very first digit will do e.g. 8+ = = When the first non-zero digit is, observing that ( k+ ) + = ( k+ ) incrementing can be by setting that digit to 0 and incrementing the next digit e.g. 9+ = ( ++6)+ = ( +)++6 = ++6 = Note that no more than two digits are changed Skew Binary Numbers: Examples Skew Decimal binary Decimal Skew binary Decimal Skew binary
12 Skew Binary Numbers: Sparse Representation A skew binary number represented as a list consisting only of non-zero elements 9: On incrementing it, the first non-zero digit is at the top and no more than two items are changed 9: 000 9: The worst case complexity is O() The same applies to decrementing Skew Binomial Heap A collection of binomial heap trees, just like normal binomial heaps There can be two smallest trees, instead of one Operations are almost the same as for binomial heaps, but when a new element is added, at most one place of carry propagation is needed 6 Minimum Spanning Trees Minimum spanning tree (MST) For a connected weighted graph with positive weights, MST is the spanning subgraph with the least sum of edge weights MST is a tree If it is not, there must be a cycle Removing one edge from the cycle will not lose connectivity while decreasing the weight sum Applications: Minimizing cost for connecting all the items with roads, railroads, computer networks, etc. Kruskal s Algorithm Joseph Kruskal, 96 Adding edges in increasing order of weights. Sort the list of edges in the increasing order of their weights. Initiate the graph as an empty graph. Add edges to the graph one by one from the list, making multiple trees grow up gradually If adding an edge would make a cycle, ignore it. Finish when the graph is connected With m edges, sorting cost of O(m log m) is dominant 8
13 Kruskal s Algorithm: An Example Prim s Algorithm (aka Jarnik s, Jarnik-Prim, or DJP) Jarnik 90, Prim 9, Dijkstra 99 Adding nodes one by one to a connected graph. An arbitrary vertex is selected as the initial tree. Initialize the set of edges outgoing from the tree. Select the edge from the set that will not form a cycle with the least weight and add to the tree. Add new outgoing edges, if any, to the set. Repeat and until the tree spans all the nodes The set of outgoing edges is maintained as a heap Heap operations in and are dominant The total cost is log 0 Prim s Algorithm: An Example Finding the Shortest Paths Among paths from one vertex to another in a weighted graph, the shortest path has the minimum weight sum of its edges (distance) Variations: Either directed or undirected graph Variations on start and end vertices Single pair/all pairs Single source or single destination (inverting edge meanings, these are the same) Whether negative or zero weights are allowed
14 Dijkstra s Algorithm: Policy Edsger W. Dijkstra, 96 An algorithm based on dynamic programming for single-source positive weight problems Vertices are associate them with information of their distances from the source The information is either tentative or final Tentative distances are initially set to infinity and gradually decreased as computation proceeds When no further decrease is possible, the distance information becomes final, which gives the minimum distance from the source Dijkstra s Algorithm: Procedure. Make all vertices give distances of infinity and make them tentative, except for the starting vertex, which is set to zero and made final. For tentative vertices adjacent to one just made final, add it to the frontier set, update their distances. Choose the vertex with the least distance among frontier vertices and make it final. If that made all the vertices final, stop. Otherwise, go back to and repeat until all the vertices become final Dijkstra s Algorithm: Computational Complexity With n vertices and m edges All the vertices except for finalized one can be kept in a heap in the order of tentative distances All the following have complexities of log Taking out the vertex with least distance Removing a vertex Registering a new vertex These heap operations are repeated O(n) times Initialization cost is Thus, the total complexity is log Other Representative Shortest Path Algorithms Bellman-Ford Algorithm Richard Bellman and Lester Ford, Jr., 98 Allows negative weights of worst case complexity Dijkstra s is better if weights are positive Warshall-Floyd Algorithm Robert Floyd, 96 (Bernard Roy, 99 and Stephen Warshall, 96) Shortest paths between all the vertex pairs are computed simultaneously of worst case complexity 6
15 Finding Connected Subgraphs Finding connected subgraphs and labeling vertices with IDs of the subgraph it belongs to Essentially, finding an equivalence class Edges represent equivalence between directly connected vertices Aka union-find problem A Naïve Algorithm: Using List Structures Vertices of each connected subgraphs are maintained in lists. Initially, make distinct lists for all vertices. When two vertices have a common edge, merge two lists, labeling vertices. Repeat the step for all edges Appending another list to a list of length k has cost of O(k), as the end of the list has to be found The total cost is O(n+m ) 8 An Improvement Using Tree Structures Appending a short list to the end of a long list causes inefficiency Keeping the list length information, the longer list can always be appended to the end of the shorter one The cost of appending is, at worst, proportional to half the length of the resultant list The total cost becomes log Each group is represented as a tree Children nodes have a pointer to its parent For a new edge, make a pointer from the root of one tree to an element of the other Labeling can be done after all edges are processed 9 60
16 Computational Complexity of Union Find Using Trees With no control of the tree depths, the worst case is the same as when using lists Controlling the tree sizes and making the root of smaller tree to the root of the larger, amortized complexity of a single merger becomes O(log n) While finding the root, each nodes on the way can be made to point to its grandparent Using this, the amortized complexity of O( (n)) is obtained, where α(n) is the inverse Ackermann function; as the Ackermann function grows very rapidly, this can be regarded as a constant Making Paths Shorter While Finding the Root 6 6 Summary Next Week Graphs can model a variety of problems Graphs can be represented in several ways in memory, each with different characteristics Priority queues can be represented in heap data structures Several representative graph algorithms Minimum spanning tree Shortest path Union find More graph algorithms Topological Sort Maximum Clique Hamiltonian Path and Cycle Graph Coloring Maximum Flow/Minimum Cut Matching 6 6 6
Chapter 9 Graph Algorithms
Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures Chapter 9 Graph s 2 Definitions Definitions an undirected graph is a finite set
More informationChapter 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 informationChapter 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 information11/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 informationCS521 \ Notes for the Final Exam
CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )
More informationMinimum-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 informationGraphs 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 informationGraph and Digraph Glossary
1 of 15 31.1.2004 14:45 Graph and Digraph Glossary A B C D E F G H I-J K L M N O P-Q R S T U V W-Z Acyclic Graph A graph is acyclic if it contains no cycles. Adjacency Matrix A 0-1 square matrix whose
More informationDijkstra 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 informationAlgorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee
Algorithm Analysis Graph algorithm Chung-Ang University, Jaesung Lee Basic definitions Graph = (, ) where is a set of vertices and is a set of edges Directed graph = where consists of ordered pairs
More informationCSE 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 informationLecture Summary CSC 263H. August 5, 2016
Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.
More informationCOMP 251 Winter 2017 Online quizzes with answers
COMP 251 Winter 2017 Online quizzes with answers Open Addressing (2) Which of the following assertions are true about open address tables? A. You cannot store more records than the total number of slots
More informationGraphs & Digraphs Tuesday, November 06, 2007
Graphs & Digraphs Tuesday, November 06, 2007 10:34 PM 16.1 Directed Graphs (digraphs) like a tree but w/ no root node & no guarantee of paths between nodes consists of: nodes/vertices - a set of elements
More informationCourse Review for Finals. Cpt S 223 Fall 2008
Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,
More informationCSE 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 informationIndex. stack-based, 400 A* algorithm, 325
Index Abstract transitive closure, 174-175, 217-221 Active vertex, 411 Acyclic graph. See Digraph; Directed acyclic graph (DAG) Acyclic network, 313-321, 334-335 maxflow, 427-429 Adjacency-lists representation,
More informationOutline. Graphs. Divide and Conquer.
GRAPHS COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges books. Outline Graphs.
More informationCSE 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 informationDirect Addressing Hash table: Collision resolution how handle collisions Hash Functions:
Direct Addressing - key is index into array => O(1) lookup Hash table: -hash function maps key to index in table -if universe of keys > # table entries then hash functions collision are guaranteed => need
More informationDecreasing 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 information22 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 informationDHANALAKSHMI 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 informationGraph Theory. ICT Theory Excerpt from various sources by Robert Pergl
Graph Theory ICT Theory Excerpt from various sources by Robert Pergl What can graphs model? Cost of wiring electronic components together. Shortest route between two cities. Finding the shortest distance
More informationEnd-Term Examination Second Semester [MCA] MAY-JUNE 2006
(Please write your Roll No. immediately) Roll No. Paper Code: MCA-102 End-Term Examination Second Semester [MCA] MAY-JUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 1.
More informationLecture 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 informationGRAPHICAL ALGORITHMS. UNIT _II Lecture-12 Slides No. 3-7 Lecture Slides No Lecture Slides No
GRAPHICAL ALGORITHMS UNIT _II Lecture-12 Slides No. 3-7 Lecture-13-16 Slides No. 8-26 Lecture-17-19 Slides No. 27-42 Topics Covered Graphs & Trees ( Some Basic Terminologies) Spanning Trees (BFS & DFS)
More informationSELF-BALANCING SEARCH TREES. Chapter 11
SELF-BALANCING SEARCH TREES Chapter 11 Tree Balance and Rotation Section 11.1 Algorithm for Rotation BTNode root = left right = data = 10 BTNode = left right = data = 20 BTNode NULL = left right = NULL
More informationThomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms
Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Introduction to Algorithms Preface xiii 1 Introduction 1 1.1 Algorithms 1 1.2 Analyzing algorithms 6 1.3 Designing algorithms 1 1 1.4 Summary 1 6
More informationCS6301 Programming and Data Structures II Unit -5 REPRESENTATION OF GRAPHS Graph and its representations Graph is a data structure that consists of following two components: 1. A finite set of vertices
More information& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n
CSE Name Test Summer Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n " n matrices is: A. " n C. "% n B. " max( m,n, p). The
More informationLecture 6 Basic Graph Algorithms
CS 491 CAP Intro to Competitive Algorithmic Programming Lecture 6 Basic Graph Algorithms Uttam Thakore University of Illinois at Urbana-Champaign September 30, 2015 Updates ICPC Regionals teams will be
More information22 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 informationDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Module 1 OBJECTIVE: Algorithms play the central role in both the science and the practice of computing. There are compelling reasons to study algorithms.
More informationE.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.
17CA 104DATA STRUCTURES Academic Year : 018-019 Programme : MCA Year / Semester : I / I Question Bank Course Coordinator: Mrs. C.Mallika Course Objectives The student should be able to 1. To understand
More informationModule 5 Graph Algorithms
Module 5 Graph lgorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 97 E-mail: natarajan.meghanathan@jsums.edu 5. Graph Traversal lgorithms Depth First
More informationDijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the
Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the Floyd-Warshall algorithm in O(n 3 ) time. Neither of
More informationlooking 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 informationWeek 12: Minimum Spanning trees and Shortest Paths
Agenda: Week 12: Minimum Spanning trees and Shortest Paths Kruskal s Algorithm Single-source shortest paths Dijkstra s algorithm for non-negatively weighted case Reading: Textbook : 61-7, 80-87, 9-601
More informationFINAL EXAM REVIEW CS 200 RECITATIOIN 14
FINAL EXAM REVIEW CS 200 RECITATIOIN 14 I don t *think* the final is cumulative. Sangmi will say for sure during her review sessions. Either way, keep in mind that this course s material is naturally cumulative
More informationKonigsberg Bridge Problem
Graphs Konigsberg Bridge Problem c C d g A Kneiphof e D a B b f c A C d e g D a b f B Euler s Graph Degree of a vertex: the number of edges incident to it Euler showed that there is a walk starting at
More informationIntroduction to Algorithms Third Edition
Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Introduction to Algorithms Third Edition The MIT Press Cambridge, Massachusetts London, England Preface xiü I Foundations Introduction
More informationR10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May
www.jwjobs.net R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 *******-****** 1. a) Which of the given options provides the
More informationElementary 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 informationUnweighted Graphs & Algorithms
Unweighted Graphs & Algorithms Zachary Friggstad Programming Club Meeting References Chapter 4: Graph (Section 4.2) Chapter 22: Elementary Graph Algorithms Graphs Features: vertices/nodes/dots and edges/links/lines
More information( D. Θ n. ( ) f n ( ) D. Ο%
CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j
More information) $ f ( n) " %( g( n)
CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.
More informationCSE 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 informationUndirected Graphs. Hwansoo Han
Undirected Graphs Hwansoo Han Definitions Undirected graph (simply graph) G = (V, E) V : set of vertexes (vertices, nodes, points) E : set of edges (lines) An edge is an unordered pair Edge (v, w) = (w,
More informationGraph Algorithms (part 3 of CSC 282),
Graph Algorithms (part of CSC 8), http://www.cs.rochester.edu/~stefanko/teaching/11cs8 Homework problem sessions are in CSB 601, 6:1-7:1pm on Oct. (Wednesday), Oct. 1 (Wednesday), and on Oct. 19 (Wednesday);
More informationGraph Algorithms (part 3 of CSC 282),
Graph Algorithms (part of CSC 8), http://www.cs.rochester.edu/~stefanko/teaching/10cs8 1 Schedule Homework is due Thursday, Oct 1. The QUIZ will be on Tuesday, Oct. 6. List of algorithms covered in the
More informationChapter 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 informationMinimum 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 informationUNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:
UNIT 5 CSE 103 - Unit V- Graph GRAPH Graph is another important non-linear data structure. In tree Structure, there is a hierarchical relationship between, parent and children that is one-to-many relationship.
More informationIntroductory Remarks
Chapter 8: Graphs Introductory Remarks Although trees are quite flexible, they have an inherent limitation in that they can only express hierarchical structures Fortunately, we can generalize a tree to
More informationUNIT 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 informationDepth First Search A B C D E F G A B C 5 D E F 3 2 G 2 3
Depth First Search A B C D E F G A 4 3 2 B 4 5 4 3 C 5 D 3 4 2 E 2 2 3 F 3 2 G 2 3 Minimum (Weight) Spanning Trees Let G be a graph with weights on the edges. We define the weight of any subgraph of G
More informationCS 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( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&
CSE 0 Name Test Summer 008 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time for the following code is in which set? for (i=0; i
More informationUndirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1
Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching
More information9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap?
1 1 Name Test 1 - Closed Book Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each 1. During which operation on a leftist heap may subtree swaps be needed? A. DECREASE-KEY
More informationUNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list
UNIT-4 Graph: Terminology, Representation, Traversals Applications - spanning trees, shortest path and Transitive closure, Topological sort. Sets: Representation - Operations on sets Applications. 1. Name
More information2.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 informationWeighted Graph Algorithms Presented by Jason Yuan
Weighted Graph Algorithms Presented by Jason Yuan Slides: Zachary Friggstad Programming Club Meeting Weighted Graphs struct Edge { int u, v ; int w e i g h t ; // can be a double } ; Edge ( int uu = 0,
More informationMultiple Choice. Write your answer to the LEFT of each problem. 3 points each
CSE 0-00 Test Spring 0 Name Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose f ( x) is a monotonically increasing function. Which of the
More informationmanaging 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 informationFundamental Algorithms
Fundamental Algorithms Chapter 8: Graphs Jan Křetínský Winter 2017/18 Chapter 8: Graphs, Winter 2017/18 1 Graphs Definition (Graph) A graph G = (V, E) consists of a set V of vertices (nodes) and a set
More informationChapter 9. Priority Queue
Chapter 9 Priority Queues, Heaps, Graphs Spring 2015 1 Priority Queue Priority Queue An ADT in which only the item with the highest priority can be accessed 2Spring 2015 Priority Depends on the Application
More informationTutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].
Tutorial Question 1 A depth-first forest classifies the edges of a graph into tree, back, forward, and cross edges. A breadth-first tree can also be used to classify the edges reachable from the source
More informationMinimum Spanning Trees
Minimum Spanning Trees 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 a repair cost w(u, v). Goal: Repair enough (and no
More informationCS350: Data Structures Dijkstra s Shortest Path Alg.
Dijkstra s Shortest Path Alg. James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Shortest Path Algorithms Several different shortest path algorithms exist
More informationWeek 9 Student Responsibilities. Mat Example: Minimal Spanning Tree. 3.3 Spanning Trees. Prim s Minimal Spanning Tree.
Week 9 Student Responsibilities Reading: hapter 3.3 3. (Tucker),..5 (Rosen) Mat 3770 Spring 01 Homework Due date Tucker Rosen 3/1 3..3 3/1 DS & S Worksheets 3/6 3.3.,.5 3/8 Heapify worksheet ttendance
More informationAlgorithms and Data Structures
Algorithms and Data Structures Graphs: Introduction Ulf Leser This Course Introduction 2 Abstract Data Types 1 Complexity analysis 1 Styles of algorithms 1 Lists, stacks, queues 2 Sorting (lists) 3 Searching
More informationAlgorithms and Data Structures
Algorithms and Data Structures Graphs: Introduction and First Algorithms Ulf Leser This Course Introduction 2 Abstract Data Types 1 Complexity analysis 1 Styles of algorithms 1 Lists, stacks, queues 2
More informationEND-TERM EXAMINATION
(Please Write your Exam Roll No. immediately) Exam. Roll No... END-TERM EXAMINATION Paper Code : MCA-205 DECEMBER 2006 Subject: Design and analysis of algorithm Time: 3 Hours Maximum Marks: 60 Note: Attempt
More informationName: 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 informationAdvanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012
topological ordering, minimum spanning tree, Union-Find problem Jiří Vyskočil, Radek Mařík 2012 Subgraph subgraph A graph H is a subgraph of a graph G, if the following two inclusions are satisfied: 2
More informationWeighted Graphs and Greedy Algorithms
COMP 182 Algorithmic Thinking Weighted Graphs and Greedy Algorithms Luay Nakhleh Computer Science Rice University Reading Material Chapter 10, Section 6 Chapter 11, Sections 4, 5 Weighted Graphs In many
More informationLecture 4: Graph Algorithms
Lecture 4: Graph Algorithms Definitions Undirected graph: G =(V, E) V finite set of vertices, E finite set of edges any edge e = (u,v) is an unordered pair Directed graph: edges are ordered pairs If e
More informationThe ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value
The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value 1 Possible implementations Sorted linear implementations o Appropriate if
More informationCS 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 informationUnit #9: Graphs. CPSC 221: Algorithms and Data Structures. Will Evans 2012W1
Unit #9: Graphs CPSC 1: Algorithms and Data Structures Will Evans 01W1 Unit Outline Topological Sort: Getting to Know Graphs with a Sort Graph ADT and Graph Representations Graph Terminology More Graph
More informationCS 6783 (Applied Algorithms) Lecture 5
CS 6783 (Applied Algorithms) Lecture 5 Antonina Kolokolova January 19, 2012 1 Minimum Spanning Trees An undirected graph G is a pair (V, E); V is a set (of vertices or nodes); E is a set of (undirected)
More informationThus, it is reasonable to compare binary search trees and binary heaps as is shown in Table 1.
7.2 Binary Min-Heaps A heap is a tree-based structure, but it doesn t use the binary-search differentiation between the left and right sub-trees to create a linear ordering. Instead, a binary heap only
More informationCSci 231 Final Review
CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.
More informationRouting. Information Networks p.1/35
Routing Routing is done by the network layer protocol to guide packets through the communication subnet to their destinations The time when routing decisions are made depends on whether we are using virtual
More informationGreedy 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 informationUNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.
UNIT III TREES A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items. Tree: A tree is a finite set of one or more nodes such that, there
More informationMAT 7003 : Mathematical Foundations. (for Software Engineering) J Paul Gibson, A207.
MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson, A207 paul.gibson@it-sudparis.eu http://www-public.it-sudparis.eu/~gibson/teaching/mat7003/ Graphs and Trees http://www-public.it-sudparis.eu/~gibson/teaching/mat7003/l2-graphsandtrees.pdf
More informationData Structures Question Bank Multiple Choice
Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationChapter 3 Trees. Theorem A graph T is a tree if, and only if, every two distinct vertices of T are joined by a unique path.
Chapter 3 Trees Section 3. Fundamental Properties of Trees Suppose your city is planning to construct a rapid rail system. They want to construct the most economical system possible that will meet the
More informationLecture 10: Analysis of Algorithms (CS ) 1
Lecture 10: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 05, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 Topological Sort Strongly Connected Components 2
More informationTIE Graph algorithms
TIE-20106 1 1 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common
More informationCS420/520 Algorithm Analysis Spring 2009 Lecture 14
CS420/520 Algorithm Analysis Spring 2009 Lecture 14 "A Computational Analysis of Alternative Algorithms for Labeling Techniques for Finding Shortest Path Trees", Dial, Glover, Karney, and Klingman, Networks
More informationSelection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix
Spring 2010 Review Topics Big O Notation Heaps Sorting Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix Hashtables Tree Balancing: AVL trees and DSW algorithm Graphs: Basic terminology and
More informationn 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)
CSE 0 Name Test Fall 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to find the maximum of the n elements of an integer array is in: A.
More informationECE250: Algorithms and Data Structures Final Review Course
ECE250: Algorithms and Data Structures Final Review Course Ladan Tahvildari, PEng, SMIEEE Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo
More informationFinal Examination CSE 100 UCSD (Practice)
Final Examination UCSD (Practice) RULES: 1. Don t start the exam until the instructor says to. 2. This is a closed-book, closed-notes, no-calculator exam. Don t refer to any materials other than the exam
More informationDesign and Analysis of Algorithms - - Assessment
X Courses» Design and Analysis of Algorithms Week 1 Quiz 1) In the code fragment below, start and end are integer values and prime(x) is a function that returns true if x is a prime number and false otherwise.
More information