Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 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

3 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 !

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 00ORANDNOTXOROUT

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

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

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

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

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

21 DFS Example 1 2 4 5 3 Stack

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

23 DFS 1 2 1 2 4 5 3 Stack

24 DFS 1 2 3 1 2 4 5 3 Stack

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

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.

30


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

Similar presentations


Ads by Google