Você está na página 1de 3

Binomial heap is implemented as a collection of binomial trees where a binomial tree:

1. With order 0 ,this will have only one node.


2. With order k, it will be root with each of it's child will be the root of K-1,k-2,...2,1 ,0 elements.
So as was the case with binary heap , it should follow two property:
1. Binomial tree property.
2. Heap property
For a set with N nodes the number of Binomial trees will (Log N +1). Furthermore, If you
represent the same under binary digit such 2^3 +2^2 ,that means it will contain binomial tree of
order 3 and order 2
Height <= [Log N] base of 2
Merge will take 0(Log N)
No of Trees in merge root list is <= 2(Log N +1)
Level is node level ,i.e source node is at level 1. While order define the depth
-The extract Min will take O(log N), since it will go through all the binomial trees which are Log
N for N nodes
Insert Operation will also take O(Log N). where every new node addition will bring a new
configuration of binomial tree.
Amortized Analysis :- Instead of looking cost per individual operation, We will look cost over
sequence of operation
Fibonacci heaps are loosely based on binomial heaps and don't follow strict condition on binding
the various trees together to maintain the binomial heap property (2)
Inserting the element into Fibonacci heap : O(1).
Delete operation :Extract Min :Merge Operation :- Constant time such connecting the links
Operation

Binary Heap

binomial heap

Fibonacci
heap

Find Min

O(1)

Log N

0(1)

Insert

O( Log N)

Log N

0(1)

Extract Min

O( Log N)

Log N

0(1)

Delete

0 (Log N)

Log N

O( Log N)
-Amortized

Decrease Key

O(Log N)

Log N

O( Log N)

-Amortized
Merge

O(n)

Log N

0(1)

Construct

O(n)

O(n)

O(n)

Amortized Cost is not average cost ,It is still the worst case.
Shortest Path: G = (V,E)

Running time O() for a path A to B or from Point A to every other point will be same (in
BFS) it will be O(|V| + |E|)

@ Is there will be any edge which if I take will be of less cost than current one ?
A No, this the given edge S-> Y is the shortest from Source S and any other edge will increase
the distance as all the distances are positive
High Level Solution :
1. A set S -> A set of shortest vertices's and u -> V-S to find the shortest distance from source
s(Think Greedy)
Define first nodes at distance of infinity and check to see if lower distance is found is called
relaxation step.
Problem Solving Principle :1. Define the problem in most abstract way
2. Define the algorithm for given problem
3. Provide proof of correctness
4. Implementation
5.Analyze the time/Space complexity
Proof of Correctness for Shortest Path Algorithm(Dijkstra's) :Proof: At each step Dijkstra's find a smallest path to the new nodes in the graph
Procedure : Mathematical Induction
Base Case :- |S| =1 and picks the source node.d(s) =0, shortest distance.
Inductive hypothesis :- lets say the above proof claim hold for |S| =k for some k >=1
If there is another path ,but that will also cross the boundary of set S and in that case Dijkstra's
will pick the node with shortest distance .
implementation :Initially S = {s} and d(s) = 0 for all the nodes d(u) = infinity .
while S != V
select a node V not in S with at least one edge from s for which d(v) = min(d(u) + le)
e(u,v) where u belong to S

Add to S
end While
Data Structure :- Priority Queue
Initialize the Priority Queue : - O(n)
Cost on n Extract Min :
Cost of m decrease key operation :
Connected : As many edges as Nodes
Operation

Binary heap

Binomial heap

Fib heap

n Extract Min

O(n log N)

O(n log N)

0(n log N)

m Decrease key

0(m log N)

0(m log N)

O(m)

If Graph is sparse ,i.e edges are in linear term of number of nodes than all are (n Log N)
if Graph is dense ,(Could have as many of n^2)
Any tree that covers all the nodes of a graph is called spanning tree
A spanning tree with minimum total edge cost is a Minimum spanning tree, or MST.
Kruskal Algorithm :Sort all the edges in the increasing order of cost.Add edge to T such that not cycle.
Connected Component :- A connected component for a graph is a subgraph with nodes that are
connected and no additional vertex is joined in that subgraph

Difference Between Kruskal and Prims Algorithm :Prims algorithm is mostly similar with Dijkstra's with node set S (initially the root node ) on
which MST has been constructed and each step we grow S by one and at each step adding a step
V that minimizes the attachment cost, => Prims Algorithms
Another way,We will remove the Edges with highest cost , unless it will remove/ disconnect the
graph (Backward Kruskal ) and if it disconnect the graph then keep those edges. => Reverse
Delete Algorithms