Top Banner
28

CS215 - Lec 10 b trees and hashing

Jun 29, 2015

Download

Education

BTrees and Hashing:
Insert elements into a Btree
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS215 - Lec 10   b trees and hashing
Page 2: CS215 - Lec 10   b trees and hashing

� Multilevel Index in form of B trees.

� Hashing

Dr. Hussien M.

Sharaf2

Page 3: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf3

� When an Index gets very big, it can not be stored in RAM.� It should be stored on file, hence another level of index that can be loaded into memory is required.� Hence we need multilevel of indexing.

Page 4: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf4

B-tree

� Allows searches, insertions, and deletions in O(Log n) .

� The B-tree is a generalization of a binary search tree.

� A Btree of order m is where each node contains (m) keys and (m+1) pointers for children.

� It is a balanced tree.

� Each node is a sorted index of keys.

Page 5: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf5

B-tree Example

Page 6: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf6

Adding Records to a B Tree

� If global root still have empty slots then place the new record in sorted position in the appropriate root node.

Page 7: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf7

Adding Records to a B Tree� If current node is full then:

1. Split the leaf node.

2. Place median key in the parent node in sorted order.

3. Records with keys < middle key go to the left leaf node.

4. Records with keys >= middle key go to the right leaf node.

Page 8: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf8

Adding Records to a B Tree� If parent node is full then:

1. Split the parent node.

2. keys < middle key go to the left parent node.

3. key s >= middle key go to the right parent node.

4. The median key goes to the next (higher level) index.

5. IF the next level index node is full, continue splitting the index nodes.

Page 9: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf9

Example for order = 4

Page 10: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf10

Inserting X

Page 11: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf11

Inserting X

Page 12: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf12

Example of Insertions

Page 13: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf13

Example for order = 4

Page 14: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf14

Example for order = 4

Page 15: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf15

Example for order = 4

Page 16: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf16

Example for order = 4

Page 17: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf17

Example for order = 4

Page 18: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf18

Example for order = 4

Page 19: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf19

Example for order = 4

Page 20: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf20

Example for order = 4

Page 21: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf21

Example for order = 4

Page 22: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf22

Example for order = 4

Page 23: CS215 - Lec 10   b trees and hashing

Dr. Hussien M.

Sharaf23

Properties of B trees

Page 24: CS215 - Lec 10   b trees and hashing

Dr. Hussien M. Sharaf 24

Page 25: CS215 - Lec 10   b trees and hashing

� A hash table is an effective data structure for implementing dictionaries.

� A dictionary is an abstract data type composed of a collection of (key,value) pairs, such that each possible key appears at most once in the collection.

Dr. Hussien M. Sharaf 25

Page 26: CS215 - Lec 10   b trees and hashing

� A hash table uses a hash function as an algorithm to map identifying values, known as keys (e.g., a person's name), to their associated values (e.g., their telephone number).

Dr. Hussien M. Sharaf 26

Page 27: CS215 - Lec 10   b trees and hashing

1. Direct-Address tables.

2. Hash tables.

3. Hash functions.

4. Open addressing.

5. Perfect hashing.

Dr. Hussien M. Sharaf 27

Page 28: CS215 - Lec 10   b trees and hashing