1 / 30

Topics: 1. Finding a cycle in a graph 2. Propagation delay - example 3. Trees - properties

מבנה המחשב - אביב 2004 תרגול 3 #. Topics: 1. Finding a cycle in a graph 2. Propagation delay - example 3. Trees - properties. IN. Single net. AND. OR. XOR. OUT. NOT. IN. Checking if a Circuit is combinational. Mapping the circuit into a directed graph DG(V,E).

joepope
Télécharger la présentation

Topics: 1. Finding a cycle in a graph 2. Propagation delay - example 3. Trees - properties

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. IN Single net AND OR XOR OUT NOT IN 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.

  3. Two inputs to one terminal ! IN AND OR XOR OUT NOT IN 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.

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

  5. 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).

  6. 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!

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

  8. 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).

  9. Finding the Maximum Delay 0 0 OR AND NOT XOR OUT

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

  11. A circuit with 2n 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 2n such paths. Each gate can be included or excluded, therefore 2n. • We cannot build this circuit since we will require an unbounded in-degree of the gates.

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

  13. 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).

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

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

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

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

  18. A claim on Trees (cont.) • Proof (Induction on the number of nodes): • Basis: trivial for n=1,2 , check forall 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 T1,T2 such that connecting them yields T. • Define |Ti|=ni = mi+ki, (m is #leaf, k is # internal.

  19. A claim on Trees (cont.) • n = n1 + n2. • ki  mi - 2 (From the induction hypothesis). • Note that the connection may reduce the number of leaves by at most two, the claim follows.

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

  21. DFS Example Stack 1 2 5 3 4

  22. DFS Stack 1 2 5 3 1 4 = Currently in the stack

  23. DFS Stack 1 2 5 3 2 1 4

  24. DFS Stack 1 2 5 3 3 2 1 4

  25. DFS Stack 1 2 5 4 3 3 2 Backwards Edge This graph has a cycle! 1 4

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

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

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

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

More Related