Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Standard view
Full view
of .
×
0 of .
Results for:
P. 1
Bridge - Algorithm

# Bridge - Algorithm

Ratings: 0|Views: 1,844|Likes:
BRIDGE
In graph theory, a bridge (also known as a cut-edge or cut arc or an isthmus) is an edge whose deletion increases the number of connected components. Equivalently, an edge is a bridge if and only if it is not contained in any cycle. A graph is said to be bridgeless if it contains no bridges. It is easy to see that this is equivalent to 2-edge-connectivity of each nontrivial component.

A graph with 6 bridges (highlighted in red)

Bridge-Finding Algorithm
An O( | V | + | E | ) algorithm f
BRIDGE
In graph theory, a bridge (also known as a cut-edge or cut arc or an isthmus) is an edge whose deletion increases the number of connected components. Equivalently, an edge is a bridge if and only if it is not contained in any cycle. A graph is said to be bridgeless if it contains no bridges. It is easy to see that this is equivalent to 2-edge-connectivity of each nontrivial component.

A graph with 6 bridges (highlighted in red)

Bridge-Finding Algorithm
An O( | V | + | E | ) algorithm f

### Availability:

See More
See less

10/13/2012

pdf

text

original

BRIDGE
In graph theory, a
bridge
(also known as a cut-edge or cut arc or an isthmus) is an edge whosedeletion increases the number of connected components. Equivalently, an edge is a bridge if andonly if it is not contained in any cycle.A graph is said to be
bridgeless
if it contains no bridges. It is easy to see that this is equivalent to2-edge-connectivity of each nontrivial component.A graph with 6 bridges (highlighted in red)

B
ridge-Finding Algorithm
An
O
( |
| + |
E
| ) algorithm for finding bridges in a connected graph was found by Tarjan in1974. A distributed version of the algorithm also existsAlgorithm:1.

F
ind a spanning tree of
G
2.

C
reate a rooted tree
from the spanning tree3.

Traverse the tree
in preorder and number the nodes. Parent nodes in the tree now havelower numbers than child nodes.4.

F
or each node from
v
1
(the leaf nodes of the tree) to 1 (the root node of the tree) do:1.

C
ompute the number of descendants
ND
(
v
) for this node.2.

C
ompute
L
(
v
) and
H
(
v
)3.

F
or each
w
such that : if and
H
(
w
) <
w
+
ND
(
w
) then (
v
,
w
) isa bridge.Definitions: A non-tree edge between
v
and
w
is denoted by
v
í í
w
. An in-tree edge with
v
asthe parent is denoted by .where
v
is the parent node of
w
.
ND
(
v
) is the number of descendants of v (including itself) in the rooted spanning tree.
L
(
v
) and
H
(
v
) are the labels of the nodes with lowest and highest preorder label respectivelyreachable from v by travelling in the subtree rooted at v, along with at most one non-tree edge.This algorithm works because
L
D
(
v
),
H
(
v
) and
L
(
v
) can all be computed for a node v providedwe know their values on all in-tree descendants of v. Also, if and only if the edge is a bridge, then it is clear that in the subtree rooted at
w
, it must be impossible to reach any node thatis not a descendant of w. This is easy to check because the subtree rooted at w (that is, alldescendants of w) consists of the nodes so we cansimply check if
L
(
w
),
H
(
w
) are in this set or not to check whether an edge is a bridge.

Bridge design pattern demo
The motivation is to decouple the Time interface from the Time implementation, while still allowing theabstraction and the realization to each be modelled with their own inheritance hierarchy. Theimplementation classes below are straight-forward. The interface classes are a little more subtle.Routinely, a Bridge pattern interface hierarchy hasa implementation class. Here the interface baseclass hasa a pointer to the implementation base class, and each class in the interface hierarchy isresponsible for populating the base class pointer with the correct concrete implementation class. Thenall requests from the client are simply delegated by the interface class to the encapsulatedimplementation class.
Code:

#include <iostream.h>#include <iomanip.h>#include <string.h>classTimeImp {public:TimeImp(inthr, int min) {hr_ = hr;min_ = min;}virtual void tell() {cout<< "time is " <<setw(2) <<setfill(48) <<hr_ << min_ <<endl;}protected:inthr_, min_;};classCivilianTimeImp: public TimeImp {public:CivilianTimeImp(inthr, int min, int pm): TimeImp(hr, min) {if (pm)strcpy(whichM_, " PM");elsestrcpy(whichM_, " AM");}/* virtual */void tell() {cout<< "time is " <<hr_ << ":" << min_ <<whichM_ <<endl;}protected:charwhichM_[4];};classZuluTimeImp: public TimeImp {public:ZuluTimeImp(inthr, int min, int zone): TimeImp(hr, min) {if (zone == 5)strcpy(zone_, " Eastern Standard Time");

## Activity (3)

### Showing

AllMost RecentReviewsAll NotesLikes