2. Motivation For B tree
● So far we have assume that we can store an entire data structure in
main memory
● What if we have so much data that it won’t fit?
● We will have to use disk storage but when this happens our time
complexity fails
● The problem is that Big-Oh analysis assumes that all operations take
roughly equal time
● This is not the case when disk access is involved
3. Motivation Cont..
● Assume that a disk spins at 3600 RPM
● In 1 minute it makes 3600 revolutions, hence one revolution occurs in 1/60 of
a second
● Assume that we use an AVL tree to store all the covid’19 patient details in
india (about 20 lakh records)
● We know we can’t improve on the log n for a binary tree
● But, the solution is to use more branches and thus less height, as branching
increases, depth decreases
4. What is B - Tree and Properties?
● A B -tree of order m is an m-way tree where each node may have up to m
children
● Root :
- It can have 2 children or ‘m’ children, where ‘m’ is called order of the tree
● Internal nodes :
- Internal node can store upto ‘m-1’ keys
- They can have between ⎡m / 2⎤ and ‘m’ children
<Ptr < K1, Pr1 > Ptr<K2, Pr2>- - - - - - -<Kq-1, Pr-1>Pq>
5. Properties:
● Leaf:
- A leaf may store between ⎡(m -1)/ 2⎤ and m-1 keys
- All leaves are at the same depth
9. Insertion Algorithm
● Insertion: when a node becomes too full, split it into two nodes and promote
the middle key into a parent key. Repeat recursively on the parent key
● Num of node after adding the key:
Fewer than ‘m’ - 1
Equal to ‘m’ Overflow
10. Deletion
If P is Tp then (p-1)KE
For min ceil[p/2-1] KE
Underflow : Tp = KE
11. Time complexity
● Search (logn)
● Insert (logn)
● Delete (logn)
Why we use B -tree
● When searching tables held on disc, the cost of each disc transfer is high but
doesn't depend much on the amount of data transferred, especially if
consecutive items are transferred
-If we use a B-tree of order 101, say, we can transfer each node in one disc
read operation
12. Cont...
● If we take m = 3, we get a 2-3 tree, in which non-leaf nodes have two or
three children (i.e., one or two keys)
– B-Trees are always balanced (since the leaves are all at the same
level), so 2-3 trees make a good type of balanced tree
13. Hamiltonian Cycle
In the mathematical field of graph theory, a Hamiltonian cycle (or traceable path) is
a path in which an undirected or directed graph that visits each vertex exactly
once.
A Hamiltonian cycle in a
dodecahedron
14. The figure has 20 red dots. Can you draw a path that visits each vertex (Dots)
exactly once?
Solution:
Icosian game developed by William Rowan Hamilton
15. Hamiltonian path problem
Knight Tours Revisited
● Let us form a graph G = (V, E) as follows:
● V = the squares of a chessboard
● E = the set of edges (v, w) where v and w are squares
on the chessboard and a knight can jump from v to w in
a single move.
● Hence, a knight tour is just a Hamiltonian Cycle in this graph
16. Theorem and Application of Hamiltonian cycle
Theorem: The Hamiltonian Cycle Problem is NP-Complete
● This result explains why knight tours were so difficult to find, there is no
known quick method to find them
Application of Hamiltonian cycle:
● Computer graphics
● Mapping genomes
● Operation research
17. Eulerian Path
● An Euler path is a path in a graph that uses every edge of a graph exactly
once
● An Euler path starts and ends at different vertices
18. How to find given graph is eulerian or not?
● Given a drawing on a piece of paper, try to cross all the lines with a pen such
that the pen doesn’t leave the paper and you mustn’t cross a line more than
once.
● An undirected graph has Eulerian Path if following two conditions are true:
-All vertices with non-zero degree are connected. We don’t care about
vertices with zero degree because they don’t belong to Eulerian Path
-If a graph has Eulerian path then no. of odd degree vertices is either ‘0’ or
‘2’(start !=end)
19. Fleury’s algorithm for printing eulerian path or circuit
Step 1: Make Sure the graph has either ‘0’ or ‘2’ odd vertices
Step 2: If there are ‘0’ odd vertices start anywhere. If there are ‘2’ odd vertices
start at one of them
Step 3: fallow edges one at a time. If you have bridge and a non bridge always
choose non bridge
Step 4: Stop when run out of the edges
20. Example:
1. We pick ‘2-0’. We remove this
edge and move to vertex ‘0’
2. Euler tour ‘2-0’
3. Euler tour ‘2-0 0-1’
4. Euler tour ‘2-0 0-1 1-2’
5. Euler tour ‘2-0 0-1 1-2 2-3’
21. Application of Eulerian graph
● 1735, Seven bridge of Königsber
Here eulerian rule is violets so problem in impossible to solve
● DNA fragment assembly
Hybrid approach on the basis of overlap-layout-consensus technique implicitly
solves the Hamiltonian path problem and has a high rate of misassembly