Reference Sheet for CO142.2 Discrete Mathematics II

Size: px
Start display at page:

Transcription

1 Reference Sheet for CO14. Discrete Mathematics II Spring Graphs Defintions 1. Graph: set of N nodes and A arcs such that each a A is associated with an unordered pair of nodes.. Simple graph: no parallel arcs and no loops. 3. Degree: number of arcs incident on given node. (a) Sum of degrees of all nodes in a graph is even. (b) Number of nodes with odd degree is even. 4. Subgraph: G S is a subgraph of G iff nodes (G S ) nodes (G) and arcs (G S ) arcs (G). 5. Full (induced) subgraph: contains all arcs of G which join nodes present in G S. 6. Spanning subgraph: nodes (G S ) = nodes (G). Representation 1. Adjacency matrix: symmetric matrix with number of arcs between nodes, count each loop twice.. Adjacency list: array of linked lists, if multiple arcs then multiple entries, count loops once. 3. An adjacency matrix has size n, an adjacency list has size n + a (better for sparse graphs). Isomorphisms 1. Isomorphism: bijection f on nodes together with bijection g on arcs such that each arc a between nodes n 1 and n maps to the node g (a) between nodes f (n 1 ) and f (n ). Same adjacency matrix (possibly reordered).. Automorphism: isomorphism from a graph to itself. Testing for isomorphisms: 1. Check number of nodes, arcs and loops. Check degrees of nodes.. Attempt to find a bijection on nodes. Check using adjacency matrices. Finding the number of automorphisms: find number of possibilities for each node in turn. Then multiply together. Planar Graphs 1. Planar: can be drawn so that no arcs cross.. Kuratowski s thm: a graph is planar iff it does not contain a subgraph homeomorphic to K 5 or K 3,3. Homeomorphic: can be obtained from the graph by replacing the arc x y by x z y where required. 3. For a planar graph, F = A N +. Graph Colouring 1. k-colourable: nodes can be coloured using no more than k colours.. Four colour thm: every simple planar graph can be coloured with at most four colours. 3. Bipartite: nodes can be partitioned into two sets such that no two nodes from the same set are joined. Bipartite is equivalent to -colourable. 1

2 Paths and Connectedness 1. Path: sequence of adjacent arcs.. Connected: there is a path joining any two nodes. 3. x y iff there is a path from x to y. The equivalence classes of are the connected components. 4. Cycle: path which finishes where it starts, has at least one arc, does not use the same arc twice. 5. Acyclic: graph with no cycles. 6. Euler path: path which uses each arc exactly once. Exists iff number of odd nodes is 0 or. 7. Euler circuit: cycle which uses each arc exactly once. Exists iff every node is even. 8. Hamiltonian path: path which visits every node exactly once. 9. Hamiltonian circuit: HP which returns to start node. Trees 1. Tree: acyclic, connected, rooted (has distinguished / root node) graph. (a) Exists a unique non-repeating path between any two nodes. (b) A tree with n nodes has n 1 arcs.. Depth: distance of node (along unique path) from root. 3. Spanning tree: spanning subgraph which is a non-rooted tree (lowest-cost network which still connects the nodes). All connected graphs have spanning trees, not necessarily unique. 4. Minimum spanning tree: spanning tree, no other spanning tree has smaller weight. Weight of spanning tree is sum of weights of arcs. Directed Graphs 1. Graph: set of N nodes and A arcs such that each a A is associated with an ordered pair of nodes.. Indegree: number of arcs entering given node. 3. Outdegree: number of arcs leaving given node. 4. Sum of indegrees = sum of outdegrees = number of arcs. Weighted Graphs Weighted graph: simple graph G together with a weight function W : arcs (G) R +. Graph Algorithms.1 Traversing a Graph.1.1 Depth First Search # ### Depth First Search #### visited [ x] = true print x for y in adj [ x]: # Follow first available arc if not visited [ y]: parent [ y] = x dfs ( y) # Repeat from the discovered node # Once all arcs followed, backtrack.1. Breadth First Search # ### Breadth First Search #### visited [ x] = true print x enqueue (x, Q) while not isempty ( Q): y = front (Q) for z in adj [ y]: # Follow all available arcs if not visited [ z]: visited [ z] = true print z parent [ z] = y enqueue (z, Q) # Repeat for each discovered node dequeue (Q) For both methods, each node is processed once, each adjacency is list processed once, giving running time of O (n + a). Applications 1. Find if a graph is connected.. Find if a graph is cyclic: use DFS, if we find a node that we have already visited (except by backtracking) there is a cycle. 3. Find distance from start node: BFS with a counter.

4 tree [ f] = true # and add to tree for y in adj [ f]: # For adj nodes if not tree [ y]: # if in fringe, update distance if fringe [y]: if distance [ f] + W[f, y] < distance [ y]: distance [ y] = distance [ f] + W[f, y] parent [ y] = f else : # otherwise, add to fringe fringe [ y] = true distance [ y] = distance [ f] + W[f, y] parent [ y] = f return distance [ finish ] Requires O ( n ) steps (or O (m log n) with PQ). 1. k is not an intermediate node of p. Then B k 1 [i, j] = d already.. k is an intermediate node of p. Then B k 1 [i, j] = B k 1 [i, k] + B k 1 [k, j] since these give shortest paths to and from k. Both algorithms are examples of dynamic program- Dynamic Programming ming: 1. Break down the main problem into sub-problems.. Sub-problems are ordered and culminate in the main problem. Correctness Prove by the following invariant:.4 The Travelling Salesman Problem 1. If x is a tree or fringe node, then parent [x] is a tree node.. If x is a tree node, then distance [x] is the length of the shortest path and parent [x] is its predecessor along that path. 3. If f is a fringe node then distance [f] is the length of the shortest path where all nodes except f are tree nodes..3. Floyd s Algorithm # ### Floyd s Algorithm #### A # Input adj matrix B[i, j] if i = j : 0 if A[i, j] > 0: A[i, j] otherwise : INFINITY # Init shortest paths via no nodes for k = 1 to n: for i = 1 to n: for j = 1 to n: B[i, j] = min ( B[i, j], # New shortest path is direct B[i, k] + B[k, j]) # or concat shortest paths via k return B Warshall s algorithm is the same but uses Boolean values (determines whether a path exists). Both have complexity O ( n 3). Correctness We discuss the inductive step: Suppose there is a shortest path p from i to j using nodes with identifiers < k, of length d. Either: Problem Given a complete weighted graph, find a minimum weight tour of the graph visiting each node exactly once..4.1 Bellman-Held-Karp Algorithm # ### Bellman - Held - Karp Algorithm #### start =... # Choose some start node for x in Nodes \ { start }: # Set costs on empty set C[{}, x] = W[ start, x] # as direct weight from start for S in subsets ( Nodes \ { start }): # For sets S of increasing size for x in Nodes \ ( S union { start }): # for each node x out of set c[s, x] = INFINITY for y in S: C[S, x] # update the cost to minimum = min ( C[ S \ { y}, y] + W[y, x], # that visits all nodes in S C[S, x]) # and then x opt = INFINITY for x in Nodes \ { start }: # Then choose the min value opt = min ( C[ Nodes \ { start, x}, x] # for an S without x plus + W[x, start ], opt ) # weight of x from start return opt Dynamic programming approach that requires O ( n n) steps..4. Nearest Neighbour Algorithm Always choose the the shortest available arc. Not optimal but has O ( n ) complexity. 4

6 3.4.3 Quick Sort 1. Split around the first element.. Sort the two sides recursively. 3. Worst case: W (n) = n 1 + W (n 1) = n(n 1) (occurs when already sorted). 4. Average case: A (n) = n n n s=1 (A (s 1) + A (n s)) = n 1 + n 1 n i= A (i), asuming each position s is equally likely. A (n) is order Θ (n log n) Heap Sort 1. Add elements to a priority queue, implemented with binary heap. Read off the queue.. Is Θ(n log n) - also can be performed in place. (a) Θ (n) inserts each taking Θ (log n). (b) Θ (n) gets each taking Θ (1). (c) Θ (n) deletions each taking Θ (log n) Lower Bounds We express the sorting algorithm as a decision tree. Internal nodes are comparisons. Leaves are results. The worst case number of comparisons is given by depth. Minimising Depth (Worst Case) 1. There are n! permutations so we require n! leaves.. Proposition: if a binary tree had depth d then it has d leaves. 3. Proof : simple proof by induction. 4. Lower bound (worst case): d n! so d log (n!). 5. log (n!) = n 1 log (k) n log x dx = n log (n) n + 1. Minimising Total Path Length (Average Case) Parallel Sorting 1. Merge sort can be parallelised by executing recursive calls in parallel.. Work still same but time taken reduced. 3. Worst case (time taken): W (n) = n 1 + W ( n ) = n log n Odd / Even Merge 1. To merge L 1 and L : (a) Take odd positions and merge to get L 3 (O (log n)). (b) Take even positions and merge to get L 4 (O (log n)). (c) Do an interleaving merge on L 3 and L 4 (O (1)).. Merge is O (log n) instead of O (n) (sequential). 3. Exploits odd/even networks (made up of comparators). 4. Time taken is now (log n) (1 + log n) / which is Θ ( log n ). 1. Balanced tree: tree at which every leaf is at depth d or d 1.. Proposition: if a tree is unbalanced then we can find a balanced tree with the same number of leaves without increasing total path length. 3. Lower bound (average case): must peform at least log (n!) calculations (since total path length is minimum for balanced trees). 3.5 Master Theorem For T (n) = at ( ) n b + f (n), with the critical exponent E = log a log b : 1. If n E+ɛ = O (f (n)) for some ɛ > 0 then T (n) = Θ (f (n)).. If f (n) = Θ ( n E) then T (n) = Θ (f (n) log n). 3. If f (n) = O ( n E ɛ) for some ɛ > 0 then T (n) = Θ ( n E). 6

7 4 Complexity 4.1 Tractable Problems and P P: Class of decision problems that can be easily solved. 1. Tractable problem: efficiently computable, focusing on worst case.. Decision problem: Has a yes or no answer. 3. Cool-Karp Thesis: Problem is tractable if it can be computed within polynomially many steps in the worst case. 4. Polynomial Invariance Thesis: If a problem can be solved in p-time in some reasonable model of computation, then it can be solved in p-time in any other reasonable model. 5. P: A decision problem D (x) is in P if it can be decided within time p (n) in some reasonable model of computation, where n is the size of the input, x. Unreasonable Models 1. Superpolynomial Parallelism: I.e. take out more than polynomially many operations in parallel in a single step.. Unary numbers: Gives input size exponentially larger than binary. Polynomial Time Functions 1. Arithmetical operations are p-time.. If f is a p-time function, then its ouput size is polynomially bounded in the input size. I.e. f (x) p ( x ) - because we only have p-time to build the output. 3. Composition: If functions f and g are p-time, then g f is computable. Since f takes p (n) and g then takes q (p (n)) where p (n) is the output size of f. 4. NP NP: Class of decision problems that can be easily verified HamPath Problem Given a graph G and a list p, is p a Ham path of G? 1. Verification of HamPath is in P. HamPath (G) iff pver-hampath (G, p).. D (x) is in NP if there is a problem E (x, y) in P and a polynomial p (n) such that: (a) D (x) iff y.e (x, y). (b) If E (x, y) then y p ( x ) (E is poly bounded). 4.. Satisfiability Problem Given a propositional formula φ in CNF, is it satisfiable? 1. SAT is not decidable in p-time: we have to try all possible truth assignments - for m variables this is m assignments.. SAT is in NP: Guess an assignment v and verify in p-time that v satisfies φ P NP 1. Suppose that D is in P.. To verify D (x) holds, we don t need to guess a certificate y - we just decide D (x) directly. 3. Formally: Define E (x, y) iff D(x) and y is the empty string. Then clearly D (x) iff y.e (x, y) and y p ( x ) P=NP Unknown. 4.3 Problem Reduction 1. Many-one reduction: Consider two decision problems D and D. D manyone reduces to D (D D ) if there is a p-time function f s.t. D (x) iff D (f (x)).. Reduction is reflexive and transitive. 3. If both D D and D D, then D D. 7

8 4.3.1 P and Reduction 1. Suppose algorithm A decides D in time p (n). We define algorithm A to solve D by first computing f (x) and then running A (f (x)). (a) Step 1 takes p (n) steps. (b) Note that f (x) q (n) for some poly q. Step takes p (q (n)).. Hence: If D D and D P, then D P NP and Reduction Assumption 1. Assume D D and D NP. Intractability 1. Suppose P NP and D is NP-hard.. Suppose for a contradiction that D P. 3. Consider any other D NP. D D since D is NP-hard. Hence D P. 4. Hence NP P. But P NP. Hence P = NP, which is a contradiction. Proving NP-Completeness E.g. Prove TSP is NP-complete. 1. Prove TSP is NP (easy).. Reduce HamPath (a known NP-hard problem) to TSP.. Then D (x) iff D (f (x)). 3. Also there is E (x, y) P s.t. D (x) iff y.e (x, y). 4. Also if E (x, y) then y p ( x ). Proof Part A 1. D (x) iff y.e (f (x), y).. Define then E (x, y) iff E (f (x), y). We can now prove part (a). Proof Part B 1. Suppose E (x, y). Then E (f (x), y), hence y p ( x ).. f x < q (n) for some poly q. So y p (q ( x )), proving part (b). 4.4 NP-Completeness 1. D is NP-hard if for all problems D NP, D D.. D is NP-complete if for all problems D NP and D is NP-hard. Cook-Levin Theorem SAT is NP-complete. 8

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

CS521 \ 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: ( ) ( ) ( ) ( )

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

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)

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

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

Best known solution time is Ω(V!) Check every permutation of vertices to see if there is a graph edge between adjacent vertices

Hard Problems Euler-Tour Problem Undirected graph G=(V,E) An Euler Tour is a path where every edge appears exactly once. The Euler-Tour Problem: does graph G have an Euler Path? Answerable in O(E) time.

Undirected 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

CS 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

r=1 The Binomial Theorem. 4 MA095/98G Revision

Revision Read through the whole course once Make summary sheets of important definitions and results, you can use the following pages as a start and fill in more yourself Do all assignments again Do the

Elements of Graph Theory

Elements of Graph Theory Quick review of Chapters 9.1 9.5, 9.7 (studied in Mt1348/2008) = all basic concepts must be known New topics we will mostly skip shortest paths (Chapter 9.6), as that was covered

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

Discrete mathematics II. - Graphs

Emil Vatai April 25, 2018 Basic definitions Definition of an undirected graph Definition (Undirected graph) An undirected graph or (just) a graph is a triplet G = (ϕ, E, V ), where V is the set of vertices,

Thomas 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

Index. 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,

DESIGN 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.

UNIT 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

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

Graphs and Trees Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) who is connected to whom Web search views web pages as a graph Who points to whom Niche graphs (Ecology):

Solutions to relevant spring 2000 exam problems

Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Trees 1 Introduction Trees are very special kind of (undirected) graphs. Formally speaking, a tree is a connected graph that is acyclic. 1 This definition has some drawbacks: given a graph it is not trivial

Assignment 4 Solutions of graph problems

Assignment 4 Solutions of graph problems 1. Let us assume that G is not a cycle. Consider the maximal path in the graph. Let the end points of the path be denoted as v 1, v k respectively. If either of

Chapter 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

& ( 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

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

Unit 8: Coping with NP-Completeness. Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems. Y.-W.

: Coping with NP-Completeness Course contents: Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems Reading: Chapter 34 Chapter 35.1, 35.2 Y.-W. Chang 1 Complexity

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

Lecture 8: The Traveling Salesman Problem

Lecture 8: The Traveling Salesman Problem Let G = (V, E) be an undirected graph. A Hamiltonian cycle of G is a cycle that visits every vertex v V exactly once. Instead of Hamiltonian cycle, we sometimes

Notation Index. Probability notation. (there exists) (such that) Fn-4 B n (Bell numbers) CL-27 s t (equivalence relation) GT-5.

Notation Index (there exists) (for all) Fn-4 Fn-4 (such that) Fn-4 B n (Bell numbers) CL-27 s t (equivalence relation) GT-5 ( n ) k (binomial coefficient) CL-15 ( n m 1,m 2,...) (multinomial coefficient)

The Konigsberg Bridge Problem

The Konigsberg Bridge Problem This is a classic mathematical problem. There were seven bridges across the river Pregel at Königsberg. Is it possible to take a walk in which each bridge is crossed exactly

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

Graph 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

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

CSE 1 Greedy Alg: Union Find/Dijkstra s Alg Shayan Oveis Gharan 1 Dijkstra s Algorithm Dijkstra(G, c, s) { d s 0 foreach (v V) d[v] //This is the key of node v foreach (v V) insert v onto a priority queue

There are severe limits on our ability to compute near-optimal tours It is NP-complete to decide whether a given undirected =(,)has a Hamiltonian cycle An approximation algorithm for the TSP can be used

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

UNIT 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.

Introduction 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

implementing the breadth-first search algorithm implementing the depth-first search algorithm

Graph Traversals 1 Graph Traversals representing graphs adjacency matrices and adjacency lists 2 Implementing the Breadth-First and Depth-First Search Algorithms implementing the breadth-first search algorithm

1 The Traveling Salesperson Problem (TSP)

CS 598CSC: Approximation Algorithms Lecture date: January 23, 2009 Instructor: Chandra Chekuri Scribe: Sungjin Im In the previous lecture, we had a quick overview of several basic aspects of approximation

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:

v V Question: How many edges are there in a graph with 10 vertices each of degree 6?

ECS20 Handout Graphs and Trees March 4, 2015 (updated 3/9) Notion of a graph 1. A graph G = (V,E) consists of V, a nonempty set of vertices (or nodes) and E, a set of pairs of elements of V called edges.

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

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

Contents 1 Introduction... 1 1.1 What is Competitive Programming?... 1 1.1.1 Programming Contests.... 2 1.1.2 Tips for Practicing.... 3 1.2 About This Book... 3 1.3 CSES Problem Set... 5 1.4 Other Resources...

Graph Algorithms. Definition

Graph Algorithms Many problems in CS can be modeled as graph problems. Algorithms for solving graph problems are fundamental to the field of algorithm design. Definition A graph G = (V, E) consists of

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

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

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV

Sr.No. Question Option A Option B Option C Option D 1 2 3 4 5 6 Class : S.E.Comp Which one of the following is the example of non linear data structure Let A be an adjacency matrix of a graph G. The ij

Design 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.

COMP 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

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

CSE 0 Name Test Fall 00 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each t. What is the value of k? k=0 A. k B. t C. t+ D. t+ +. Suppose that you have

Travelling Salesman Problem. Algorithms and Networks 2015/2016 Hans L. Bodlaender Johan M. M. van Rooij

Travelling Salesman Problem Algorithms and Networks 2015/2016 Hans L. Bodlaender Johan M. M. van Rooij 1 Contents TSP and its applications Heuristics and approximation algorithms Construction heuristics,

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

8.1 Polynomial-Time Reductions

Algorithm Design Patterns and Anti-Patterns Analysis of Algorithms Algorithm design patterns. Ex. Greed. O(n 2 ) Dijkstra s SSSP (dense) Divide-and-conquer. O(n log n) FFT. Dynamic programming. O(n 2 )

n 2 ( ) ( ) + n is in Θ n logn

CSE Test Spring Name Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply an m n matrix and a n p matrix is in: A. Θ( n) B. Θ( max(

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS Analyzing find in B-trees Since the B-tree is perfectly height-balanced, the worst case time cost for find is O(logN) Best case: If every internal node is completely

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

Tree 1. Trees and their Properties. Spanning trees 3. Minimum Spanning Trees 4. Applications of Minimum Spanning Trees 5. Minimum Spanning Tree Algorithms 1.1 Properties of Trees: Definition: A graph G

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo

Foundations of Discrete Mathematics

Foundations of Discrete Mathematics Chapter 12 By Dr. Dalia M. Gil, Ph.D. Trees Tree are useful in computer science, where they are employed in a wide range of algorithms. They are used to construct efficient

CS 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)

Course 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.,

Introduction III. Graphs. Motivations I. Introduction IV

Introduction I Graphs Computer Science & Engineering 235: Discrete Mathematics Christopher M. Bourke cbourke@cse.unl.edu Graph theory was introduced in the 18th century by Leonhard Euler via the Königsberg

Konigsberg 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

Introduction to Graph Theory

Introduction to Graph Theory Tandy Warnow January 20, 2017 Graphs Tandy Warnow Graphs A graph G = (V, E) is an object that contains a vertex set V and an edge set E. We also write V (G) to denote the vertex

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

END-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

Notation Index 9 (there exists) Fn-4 8 (for all) Fn-4 3 (such that) Fn-4 B n (Bell numbers) CL-25 s ο t (equivalence relation) GT-4 n k (binomial coef

Notation 9 (there exists) Fn-4 8 (for all) Fn-4 3 (such that) Fn-4 B n (Bell numbers) CL-25 s ο t (equivalence relation) GT-4 n k (binomial coefficient) CL-14 (multinomial coefficient) CL-18 n m 1 ;m 2

( ) ( ) 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

8.1 Polynomial-Time Reductions

8.1 Polynomial-Time Reductions Classify Problems According to Computational Requirements Q. Which problems will we be able to solve in practice? A working definition. Those with polynomial-time algorithms.

Matching Theory. Figure 1: Is this graph bipartite?

Matching Theory 1 Introduction A matching M of a graph is a subset of E such that no two edges in M share a vertex; edges which have this property are called independent edges. A matching M is said to

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION 1. What is performance measurement? 2. What is an algorithm? 3. How the algorithm is good? 4. What are the

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

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,

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

CSE 0 Name Test Summer 006 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n x n matrices is: A. "( n) B. "( nlogn) # C.

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

FINAL EXAM SOLUTIONS

COMP/MATH 3804 Design and Analysis of Algorithms I Fall 2015 FINAL EXAM SOLUTIONS Question 1 (12%). Modify Euclid s algorithm as follows. function Newclid(a,b) if a

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

Basics of Graph Theory

Basics of Graph Theory 1 Basic notions A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Simple graphs have their

15CS43: DESIGN AND ANALYSIS OF ALGORITHMS

15CS43: DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK MODULE1 1. What is an algorithm? Write step by step procedure to write an algorithm. 2. What are the properties of an algorithm? Explain with an

These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions.

CSE 591 HW Sketch Sample Solutions These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions. Problem 1 (a) Any

Outline. 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.

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

Week 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

NP-Complete Reductions 2

x 1 x 1 x 2 x 2 x 3 x 3 x 4 x 4 12 22 32 CS 447 11 13 21 23 31 33 Algorithms NP-Complete Reductions 2 Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline NP-Complete

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

1. To reduce the probability of having any collisions to < 0.5 when hashing n keys, the table should have at least this number of elements.

CSE 5311 Test 1 - Closed Book Spring 004 Name Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 4 points each 1. To reduce the probability of having any collisions to < 0.5 when

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

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

CS 124 Quiz 2 Review 3/25/18 1 Format You will have 83 minutes to complete the exam. The exam may have true/false questions, multiple choice, example/counterexample problems, run-this-algorithm problems,

NP and computational intractability. Kleinberg and Tardos, chapter 8

NP and computational intractability Kleinberg and Tardos, chapter 8 1 Major Transition So far we have studied certain algorithmic patterns Greedy, Divide and conquer, Dynamic programming to develop efficient

CS 310 Advanced Data Structures and Algorithms

CS 31 Advanced Data Structures and Algorithms Graphs July 18, 17 Tong Wang UMass Boston CS 31 July 18, 17 1 / 4 Graph Definitions Graph a mathematical construction that describes objects and relations

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.

Lecture 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.

CS 4407 Algorithms Lecture 5: Graphs an Introduction

CS 4407 Algorithms Lecture 5: Graphs an Introduction Prof. Gregory Provan Department of Computer Science University College Cork 1 Outline Motivation Importance of graphs for algorithm design applications

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, 2013 Midterm 1 Solutions 1 True/False 1. The Mayan base 20 system produces representations of size that is asymptotically

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

Traveling Salesman Problem. Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij

Traveling Salesman Problem Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij 1 Contents TSP and its applications Heuristics and approximation algorithms Construction heuristics,

Treewidth and graph minors

Treewidth and graph minors Lectures 9 and 10, December 29, 2011, January 5, 2012 We shall touch upon the theory of Graph Minors by Robertson and Seymour. This theory gives a very general condition under

Review of course COMP-251B winter 2010

Review of course COMP-251B winter 2010 Lecture 1. Book Section 15.2 : Chained matrix product Matrix product is associative Computing all possible ways of parenthesizing Recursive solution Worst-case running-time

PSD1A. DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V

PSD1A DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V UNIT I -- Introduction -- Definition of Algorithm -- Pseudocode conventions -- Recursive algorithms -- Time and space complexity -- Big- o notation --