Topics: 1. Finding a cycle in a graph 2. Propagation delay - example 3. Trees - properties מבנה המחשב - אביב 2004 תרגול 3#

Slides:



Advertisements
Similar presentations
Graph Algorithms Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 11Feb 07, 2014Carnegie Mellon University.
Advertisements

What is a graph ? G=(V,E) V = a set of vertices E = a set of edges edge = unordered pair of vertices
CS 336 March 19, 2012 Tandy Warnow.
Graphs - II Algorithms G. Miller V. Adamchik CS Spring 2014 Carnegie Mellon University.
Lecture 7 March 1, 11 discuss HW 2, Problem 3
Graphs III (Trees, MSTs) (Chp 11.5, 11.6)
Graphs – Depth First Search ORD DFW SFO LAX
Tirgul 8 Graph algorithms: Strongly connected components.
Tirgul 11 DFS Properties of DFS Topological sort.
Applications of graph traversals
CS 473Lecture 151 CS473-Algorithms I Lecture 15 Graph Searching: Depth-First Search and Topological Sort.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 11.
R. Bar-Yehuda © 1 קומבינטוריקה למדעי - המחשב – הרצאה #17 Chapter 2: TREES מבוסס על הספר : S. Even, "Graph Algorithms",
Boolean Algebra cont’ The digital abstraction Graphs and Topological Sort מבנה המחשב + מבוא למחשבים ספרתיים תרגול 2#
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Topics: 1. Trees - properties 2. The master theorem 3. Decoders מבנה המחשב - אביב 2004 תרגול 4#
Connected Components, Directed Graphs, Topological Sort COMP171.
An Euler Circuit is a cycle of an undirected graph, that traverses every edge of the graph exactly once, and ends at the same node from which it began.
Connected Components, Directed Graphs, Topological Sort Lecture 25 COMP171 Fall 2006.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
מבנה המחשב + מבוא למחשבים ספרתיים תרגול 5# Topics: 1.Encoders and decoders 2.Shifters.
מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3.
Connected Components, Directed graphs, Topological sort COMP171 Fall 2005.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Elementary graph algorithms Chapter 22
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
Depth-First Search Idea: Keep going forward as long as there are unseen nodes to be visited. Backtrack when stuck. v G G G G is completely traversed.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 10.
Foundations of Discrete Mathematics
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Discussion #32 1/13 Discussion #32 Properties and Applications of Depth-First Search Trees.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Graphs.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
Introduction to Graph Theory
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
 2004 SDU Lectrue4-Properties of DFS Properties of DFS Classification of edges Topological sort.
CS 61B Data Structures and Programming Methodology Aug 5, 2008 David Sun.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Topological Sort: Definition
DIRECTED ACYCLIC GRAPHS AND TOPOLOGICAL SORT CS16: Introduction to Data Structures & Algorithms Tuesday, March 10,
Properties and Applications of Depth-First Search Trees and Forests
SSSP in DAGs (directed acyclic graphs). DFS (depth first search) DFS(vertex v) { v.visited = TRUE; for each w adjacent to v do if(!w.visited) then dfs(w);
5. Biconnected Components of A Graph If one city’s airport is closed by bad weather, can you still fly between any other pair of cities? If one computer.
11 Graph Search Algorithms. 2 What parts of the graph are reachable from a given vertex ?
Week 11 - Wednesday.  What did we talk about last time?  Exam 2  And before that:  Graph representations  Depth first search.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Discrete Structures Li Tak Sing( 李德成 ) Lectures
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Trees.
Breadth-First Search (BFS)
Chapter 5 : Trees.
Depth-First Search.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Graph Algorithms Using Depth First Search
More Graph Algorithms.
Elementary graph algorithms Chapter 22
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
COMPS263F Unit 2 Discrete Structures Li Tak Sing( 李德成 ) Room A
Lecture 13 Algorithm Analysis
Elementary graph algorithms Chapter 22
Presentation transcript:

Topics: 1. Finding a cycle in a graph 2. Propagation delay - example 3. Trees - properties מבנה המחשב - אביב 2004 תרגול 3#

Checking if a Circuit is combinational Mapping the circuit into a directed graph DG(V,E).  Each gate is a vertex.  Each net defines a star of edges emanating out of an output terminal. OR AND NOT XOROUT IN Single net

Checking a Circuit (cont.) If an input terminal has two incoming edges, then it is fed by two nets, which is illegal. In that case we stop and return FALSE. OR AND NOT XOROUT IN Two inputs to one terminal !

Checking a Circuit (cont.) Is this condition enough for a circuit to be valid? No, we still need to check that the graph of the circuit contains no cycles.

Testing for Cycles Two classical algorithms: Topological sort based: –While “peeling off” sources, if there are no sources but the set of non-sorted vertices is not empty, then return FALSE (proof: next slide). DFS based: –If a backwards edge is encountered, return FALSE (proof: auxiliary slides at the end).

Existence of cycles Claim: If a directed (sub-)graph G has no sources, then it contains a cycle. Proof (algorithmic): –Note: No sources  For all u, in(u) > 0  |E| > |V|-1. –Delete repeatedly all sinks (this does not create sources) –Pick any vertex u and mark it. –Pick an edge (u,v) If v is marked: a cycle was found!!! Else: pick an edge emanating from v…repeat –Observation: The process must encounter a marked vertex (can’t have an infinite sequence of unmarked vertices). Hence, we close a cycle!

Propagation Delay There is always at least one “critical path”. What is the propagation delay of a circuit that is not acyclic?

Finding the Propagation Delay acyclic graph  topological order. Each time updating the “inputs stable” time of the next vertex. This update is often called relaxation. The total propagation delay is the maximal “inputs stable” time (assuming that we used output nodes). This is also the delay of a critical path in DG(V,E).

Finding the Maximum Delay 00ORANDNOTXOROUT

A circuit with 2 n/2 paths 2 options Note: n/2 stages with 2 options each, resulting in 2 n/2 paths.  There is no need to check all the paths, only the longest. This takes a linear time.

A circuit with 2 n paths …cannot be built! Why? A combinational circuit is a DAG, therefore we cannot reorder the gates to create different paths. Our only option is to include or exclude gates to create different paths. But, having n gates, we only have 2 n such paths. Each gate can be included or excluded, therefore 2 n. We cannot build this circuit since we will require an unbounded in-degree of the gates.

XOR is Associative Define mod(a,q) to be the remainder of a/q. Claim: – mod(a+b,q) = mod( mod(a,q) + mod(b,q),q) – mod(a · b,q) = mod( mod(a,q) · mod(b,q),q) Proof: – Let a = kq+j and b = sq+t.  a+b = q(k+s) + j+t  mod(a+b,q) = mod(j+t,q) = mod(mod(a,q)+mod(b,q),q) –The same proof for multiplication.

XOR is Associative (cont.) Note that xor(x,y) = mod(x+y,2)  xor(xor(x,y),z) = mod(mod(x+y,2)+mod(z,2),2)  = mod((x+y)+z,2)  = mod(x+(y+z),2)  = mod(mod(x,2)+mod(y+z,2),2)  = xor(x,xor(y,z)) Hence we may denote it by xor(x,y,z).

Tree: Basic properties An undirected graph is a tree if it is: Connected, i.e., there is a path between every two vertices. Contains no cycles. One of these properties can be replaced with the following: |E| = |V|-1

Directed Tree: Basic properties An directed graph is a directed tree if it is: In-degree = 1 for all v, besides the root. In degree of the root is 0. There is a directed path from the root to every node. Tree  directed tree: Pick one of its vertices to be a root Direct all the edges out from the root Repeat it with the vertices as the roots.

Directed Tree (cont.) A leaf is a node with out-degree zero. We define on the vertices of a directed tree: The parent of a node v. Note there is only one such vertices. A child of a node v (there may be many). Ancestor and Descendent of v.  The root (source): Ancestor for all x, but has no parent.  Internal node: has a parent, may have children.  A leaf (sink): has no children.

A claim on Trees In a directed tree, any non-leaf is called an internal node. For a tree: a leaf is a node whose degree is 1. Claim: If the degree of any vertex in the tree  3, then the number of internal nodes  the number of the leaves –2. Note: the underlying graph of a directed binary tree is such a tree, but since the root does not count as a leaf, we have in directed trees: #internal nodes  #internal leaves -1

A claim on Trees (cont.) Proof (Induction on the number of nodes): Basis: trivial for n=1,2, check for all trees with 3 nodes (there is only one such tree). Assumption: correct for all trees of size  n. Step: prove for any tree of size n+1. Given such a tree, it must contain an internal node v. There exists two trees T 1,T 2 such that connecting them yields T. Define |T i |=n i = m i +k i, (m is #leaf, k is # internal.

A claim on Trees (cont.)  n = n 1 + n 2.  k i  m i - 2 (From the induction hypothesis).  Note that the connection may reduce the number of leaves by at most two, the claim follows.

The next slides are for the curious students (home reading)

DFS Example Stack

DFS Stack = Currently in the stack

DFS Stack

DFS Stack

DFS Stack Backwards Edge This graph has a cycle!

Elements of the Proof The algorithm terminates regardless of the structure of the input graph. If there is a cycle in the graph, the algorithm will find it (return FALSE). If there is no cycle in the graph, the algorithm will return TRUE.

The Algorithm Terminates The algorithm passes through every vertex only once, therefore it will always terminate after visiting all of the vertices regardless of the edges.

The Proof Assume there is a cycle in the graph. At some point a first vertex that belongs to the cycle will be reached. All other vertices of the cycle have not been reached yet. Before that first vertex is popped out of the stack, the DFS procedure guarantees that an edge closing the cycle and entering that vertex will be tested. It is a backwards edge.

The Proof Immediate, but nevertheless: Assume there are no cycles in the graph. Backwards edges cannot exist since they require a path from a successor to a predecessor, which means there is a cycle.