5 B tree
5 B tree
5 B tree
1 10/27/2023
Paper Code(s): CIC‐209 L P C
Paper: Data Structures 4 ‐ 4
Marking Scheme:
1. Teachers Continuous Evaluation: 25 marks
2. Term end Theory Examinations: 75 marks
Instructions for paper setter:
1. There should be 9 questions in the term end examinations question paper.
2. The first (1st) question should be compulsory and cover the entire syllabus. This question should be objective, single line answers or short
answer type question of total 15 marks.
3. Apart from question 1 which is compulsory, rest of the paper shall consist of 4 units as per the syllabus. Every unit shall have two questions
covering the corresponding unit of the syllabus. However, the student shall be asked to attempt only one of the two questions in the unit.
Individual questions may contain upto 5 sub‐parts / sub‐questions. Each Unit shall have a marks weightage of 15.
4. The questions are to be framed keeping in view the learning outcomes of the course / paper. The standard / level of the questions to be asked
should be at the level of the prescribed textbook.
5. The requirement of (scientific) calculators / log‐tables / data – tables may be specified if required.
Course Objectives :
1. To introduce basics of Data structures (Arrays, strings, linked list etc.)
2. To understand the concepts of Stacks, Queues and Trees, related operations and their implementation
3. To understand sets, heaps and graphs
4. To introduce various Sorting and searching Algorithms
Course Outcomes (CO)
CO 1 To be able to understand difference between structured data and data structure
CO 2 To be able to create common basic data structures and trees
CO 3 To have a knowledge of sets, heaps and graphs
CO 4 To have basic knowledge of sorting and searching algorithms
Course Outcomes (CO) to Programme Outcomes (PO) mapping (scale 1: low, 2: Medium, 3: High)
PO01 PO02 PO03 PO04 PO05 PO06 PO07 PO08 PO09 PO10 PO11 PO12
CO 1 3 2 2 2 3 ‐ ‐ ‐ 2 2 2 3
CO 2 3 2 2 2 3 ‐ ‐ ‐ 2 2 2 3
CO 3 3 2 2 2 3 ‐ ‐ ‐ 2 2 2 3
CO 4 3 2 2 2 3 ‐ ‐ ‐ 2 2 2 3
UNIT – I
Overview of data structure, Basics of Algorithm Analysis including Running Time Calculations, Abstract Data Types, Arrays, Arrays and Pointers,
Multidimensional Array, String processing, General Lists and List ADT, List manipulations, Single, double and circular lists. Stacks and Stack ADT,
Stack Manipulation, Prefix, infix and postfix expressions, recursion. Queues and Queue ADT, Queue manipulation.
UNIT – II
Sparse Matrix Representation (Array and Link List representation) and arithmetic (addition, subtraction and multiplication), polynomials and
polynomial arithmetic.
Trees, Properties of Trees, Binary trees, Binary Tree traversal, Tree manipulation algorithms, Expression trees and their usage, binary search trees,
AVL Trees, Heaps and their implementation, Priority Queues, B‐Trees, B* Tree, B+ Tree
UNIT – III
Sorting concept, order, stability, Selection sorts (straight, heap), insertion sort (Straight Insertion, Shell sort), Exchange Sort (Bubble, quicksort),
Merge sort (External Sorting) (Natural merge, balanced merge and polyphase merge). Searching – List search, sequential search, binary search,
hashing methods, collision resolution in hashing.
UNIT – IV
Disjoint sets representation, union find algorithm, Graphs, Graph representation, Graph Traversals and their implementations (BFS and DFS).
Minimum Spanning Tree algorithms, Shortest Path Algorithms
Textbook(s):
1. Richard Gilberg , Behrouz A. Forouzan, “Data Structures: A Pseudocode Approach with C, 2nd Edition, Cengage Learning, Oct 2004
2. E. Horowitz, S. Sahni, S. Anderson‐Freed, "Fundamentals of Data Structures in C", 2nd Edition, Silicon Press (US), 2007.
References:
1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in C”, 2nd Edition, Pearson, September, 1996
2. Robert Kruse, “Data Structures and Program Design in C”, 2nd Edition, Pearson, November, 1990
3. Seymour Lipschutz, “Data Structures with C (Schaum's Outline Series)”, McGrawhill, 2017
4. A. M. Tenenbaum, “Data structures using C”. Pearson Education, India, 1st Edition 2003.
5. Weiss M.A., “Data structures and algorithm analysis in C++”, Pearson Education, 2014.
Data Structure
4 10/27/2023
Multi‐way Trees
5 10/27/2023
M‐way Tree
P0 K0 P1 K1 P2 K2 … Pn‐1 Kn‐1 Pn
All the key values are stored in ascending order K0< K1< K2 …
7 10/27/2023
M‐way search tree
8 10/27/2023
M‐way Search tree
15 50
5 12 20 30 55 80
25 28 85 90
M=3
Every sub‐tree is also an M‐way search tree and
follows the same rule
9 10/27/2023
B‐Tree
10 10/27/2023
B‐tree properties
Similar to BST
11 10/27/2023
Insert: B‐tree
12 10/27/2023
B‐tree of order 5
Insert 8, 9, 39, 4
18 45 72
7 11 21 27 36 42 54 63 81 89 90
36
8 18 45 72
4 7 21 27 39 42 54 63 81 89 90
9 11
13 10/27/2023
B‐tree of order 5
Insert 8, 9, 39, 4
18 45 72
7 11 21 27 36 42 54 63 81 89 90
36
8 18 45 72
4 7 21 27 39 42 54 63 81 89 90
9 11
14 10/27/2023
Delete: B‐tree
15 10/27/2023
Deleting a Leaf node
1. Locate the leaf node which is to be deleted
2. If the leaf node contains more than minimum number of key values
(m/2 key values),
then delete the value
3. Else If the leaf node does not contain even m/2 elements, then
fill the node by taking either from the left or from the right sibling
If the left sibling has more than the minimum number of key values
push its largest key into its parent’s node and
Pull down the intervening element from the parent node to the leaf node
where the key is deleted
Else if the right sibling has more than minimum number of key values
push its smallest key into its parent’s node and
Pull down the intervening element from the parent node to the leaf node
where the key is deleted
16 10/27/2023
Deleting an internal node
17 10/27/2023
B‐tree of order 5
Delete 93, 201, 180, 72
108
63 81 117 201
18 10/27/2023
90 101 111 114
Example: B‐tree
B‐tree of order 5
3, 14, 7, 1, 8, 5, 11, 17, 13, 6, 23, 12, 20, 26, 4, 16, 18, 24, 25, 19
19 10/27/2023
Example: B‐tree
B‐tree of order 5
3, 14, 7, 1, 8, 5, 11, 17, 13, 6, 23, 12, 20, 26, 4, 16, 18, 24, 25, 19
20 10/27/2023
Example: B‐tree
B‐tree of order 4
3, 14, 7, 1, 8, 5, 11, 17, 13, 6, 23, 12, 20, 26, 4, 16, 18, 24, 25, 19
21 10/27/2023
2‐3 tree
B‐tree of order 3
Each non‐root node has either two or three sub‐trees
Root may have zero, two or three sub‐trees
Complete tree
[|33|72|]
22 10/27/2023
2‐3 tree
23 10/27/2023
2‐3‐4 tree
B‐tree or order 4
Each node can have either two or three or four sub‐trees
[|42|]
24 10/27/2023
B* tree
25 10/27/2023
B* tree
[|21|78|]
26 10/27/2023
REVISE: B‐tree
27 10/27/2023
B + ‐ Tree
28 10/27/2023
Example: B‐tree
B‐tree of order 5
3, 14, 7, 1, 8, 5, 11, 17, 13, 6, 23, 12, 20, 26, 4, 16, 18, 24, 25, 19
29 10/27/2023
B + ‐ Tree
Every node has one more references than it has keys (children)
All leaves are at the same distance from the root
The root has at least two children
Every non‐leaf, non‐root node has at least ceil(m / 2) children
Each leaf contains at least floor(m / 2) keys
Every key from the table appears in a leaf & in left‐to‐right sorted
order
For every non‐leaf node N with k being the number of keys in N:
all keys in the first child's subtree are less than N's first key;
all keys in the ith child's subtree (2 ≤ i ≤ k) are
between the (i − 1)th key of n and
31
the i th key of n
10/27/2023
B + tree
M= 4
Each leaf have at least two keys, and
Each internal node to have
at least two children (and thus at least one key)
32 10/27/2023
B + tree: Insertion algorithm
33 10/27/2023
B + tree: Insertion algorithm
IF the next level index page is full, continue splitting the index pages
B + tree (m = 4)
36 10/27/2023
B + tree
38 10/27/2023
B + tree
42 10/27/2023
+
B Example: insertion
order: m=4
Insert: 1, 4, 16, 25, 9, 20, 13, 15, 10, 11, 12
43 10/27/2023
Example
44 10/27/2023
B + tree: Deletion
45 10/27/2023
B + tree
46 10/27/2023
B + tree
47 10/27/2023
Deletion
[|45|]
[|5|29|] [|51|59|165|]
[|5|29|] [|51|59|65|]
[|45|]
[|5|29|] [|51|59|65|]
[|5|29|] [|51|59|65|]
50 10/27/2023
B + tree
[|47|]
[|5|29|] [|51|59|65|]
[|5|29|] [|51|59|65|]
[|5|29|] [|51|59|65|]
[|29|] [|51|59|65|]
[|29|] [|51|59|65|]
[|29|] [|51|59|65|]
[|29|] [|51|59|65|]
[|29|] [|51|59|65|]
[|29|] [|51|59|65|]
[|9|] [|51|59|65|]
[|9|] [|51|59|65|]
[|9|] [|51|59|]
[|9|] [|51|59|]
[|9|] [|51|61|]
[|43|]
[|9|] [|51|61|]
[|9|] [61|]
[|43|]
[|9|] [61|]
59 10/27/2023
Example: deletion
Order: 4
60 10/27/2023
B + trees vs. B tree
61 10/27/2023