Вы находитесь на странице: 1из 4

1.

Asymptotic Analysis:
Big –O Notation:
T(n) is said to be in O(f(n)) when T(n) is bounded by a constant multiple of f(n). So we can say
T(n)<= c.f(n) where c is a constant.

This gives the upper bound on running times of an algorithm.

Big-Ὼ Notation:

This gives us the lower bound on the running times of an algorithm. We would want to prove for
this that T(n) is at least a constant multiple of some specific function f(n). T(n)>= € . f(n) is the
statement in order to show the lower bound on the algorithm.

Big-ϴ Notation:

This gives the asymptotically tight bound on the running times of an algorithm. If a function is
said to be in both O(f(n)) and Ὼ(f(n)) we can say that T(n) is ϴ(f(n)).
Asymptotically tight bounds on worst-case performances of an algorithm is desirable to
characterize it.

Graph :
A graph G may be defined as a collection of vertices and edges,G=(V,E). The edges in the graph
are used to connect the different vertices with one another. The edges may be directed or
undirected and based on that may be called as directed or undirected graph.
Breadth – First Search Algorithm :
The algorithm uses a queue data structure to store intermediate results as it traverses the graph,
as follows:

 Enqueue the root node first into the queue.


 Dequeue any node from the queue and examine it
 If the element being searched for is found in this node,then quit the search and return
a result for the search.
 Otherwise enqueue any successors that have not yet been traversed.
 If the queue is empty at the end of the search, and if every node on the graph has been
examined – then end the search and return saying no such node is found..
 If the queue is found not to be empty, repeat from Step 2.

The time complexity of this algorithm may be expressed as O|V|+O|E| since every vertex and
edge will be visited in the worst case scenario and space complexity may be O|V|.

Depth First Search: ( From Textbook )

DFS(s):

Initialize S to be a stack with one element s

While S is not empty

Take a node u from S

If Explored[u]=false then

Set explored[u]=true

For each edge (u,v) incident to u

Add v to the stack S

End for

End if

End while

In the worst case it uses O|V| space and O|E| time.

Topological Ordering:

Topological ordering of vertices in a directed graph is an ordering of vertices such that for every
directed edge uv from vertex u to vertex v, u comes before v in the ordering.
4. In any connected undirected graph, there is a vertex whose removal leaves the graph
connected.

Proof:

Consider any directed graph G=(V,E). Let us do depth first search on the graph G and construct a
tree form that named ‘T’. Let us denote the leaves of the tree as Leaves(T). If we choose any
vertex v ∈ Leaves(T), then removal of that particular vertex from the tree and the edges
associated with it will still keep the tree ‘T’ connected (by the definition of tree). Thus Tˆ = T -
{v} is connected which goes on to imply that the graph Gˆ=(V-{v},E-{(i, j) : i = v ∨ j = v}) is
still connected because Tˆ and Gˆ are isomorphic to each other.

5. DAG:

Algorithm:

We use the breadth first strategy in this algorithm

Let us say s and t are the nodes with indegree and outdegree as zero.

Let us consider we have nodes x,y and z between s and t.

Algorithm –

For(x = s to t)

For (y=s to a-1)

For (x+1 to c)

For (z+1 to t)

If(discovered[node]==true)

Then exit

Else

Go to Next Node
Return discovered[node]=true

Вам также может понравиться