my file structure btrees project report

11
Project by : Usman Sait A.K.

Upload: usman-sait

Post on 18-Nov-2014

3.423 views

Category:

Education


4 download

DESCRIPTION

This presentation gives the brief description of B-Tree implementation using File Structures concept.

TRANSCRIPT

Page 1: My File Structure Btrees Project Report

Project by : Usman Sait A.K.

Page 2: My File Structure Btrees Project Report

File structure is a combination of representation for data in files & of operations for accessing the data.

A B-Tree is a balanced search tree. A B-Tree is a method of placing & locating files (called records or keys) in a database. It is a multi-way tree in which all insertions are made at the leaf level. It uses bottom up approach.

Why B-Trees are used: When working with large sets of data, its often not possible

or desirable to maintain the entire structure in primary storage (RAM).

Instead, a relatively small portion of the data structure is maintained in primary storage, and additional data is read from secondary storage as needed.

Unfortunately, a magnetic disk, the most common form of secondary storage, is significantly slower than random access memory (RAM).

B-Trees are balanced trees that are optimized for situations when part or all of the tree must be maintained in secondary storage such as a magnetic disk.

Page 3: My File Structure Btrees Project Report

The Project consists of:Part-1 : The objective of this part of the project is to create a

class STUDENT with variable length fields and fixed length records

The implementation of this part of the project will help us maintain a student database which can help us store and retrieve the details of students.

Operations in Part-1 Insert records onto the file. Delete a record from the file. Write from object file to buffer- Pack. Write from buffer to object file- Unpack. Modify the contents of the record- Update. Display contents of the file. To search for a particular record.

Part-2 : The objective of this part is to add B-Tree indexes to the

data files created in part one. Operations in Part-2 Display the records using B-Trees. Display the average space utilization.

Page 4: My File Structure Btrees Project Report

Consider the sequence: C D S T A M P I B W N G U R K E H O L J Y Q Z F X V

Maximum of four key-reference pairs can be inserted per node. This is order four B-Tree.

Insertion of C S D T into initial node

When 5th key, A is added, the original node is split & the tree grows by one level as a new root is created- Split Operation. The keys in the root are the largest key in the left leaf D & the largest key in the right leaf T.

After inserting M P I B W N G U, the B-Tree looks as shown below. The root is now full.

C D S T

TD

DCA TS

WPMD

DCBA MIG PN WUTS

Page 5: My File Structure Btrees Project Report

Insertion of R causes the rightmost leaf node to split , insertion into the root to split and the tree grows to the level 3- Recursive Split.

Insertion of K E H O L J Y Q Z F X V results in the B-Tree as shown below.

WP

PMD WT

DCBA PN WU

MIG TSR

ZPI

IGD PM ZXT

DCBA MLKJ TSRQ ZY

GFE IH PON XWVU

Page 6: My File Structure Btrees Project Report

Insertion Operation: To perform an insertion on a B-Tree, the appropriate node

for the key must be located. Next, the key must be inserted into the node. If the node is not full prior to the insertion, no special

action is required. However, if the node is full, the node must be split to make room for the new key. This splitting takes place such that the left node will have three keys & the right node will have two keys . The parent node will have the largest key of both the nodes. The parent node must not be full or another split operation is required. This process may repeat all the way up to the root and may require splitting the root node.

Search operation: The correct child is chosen by performing a linear search

of the values in the node. After finding the value greater than or equal to the

desired value, the child pointer to the immediate left of that value is followed.

If all values are less than the desired value, the rightmost child pointer is followed.

The search can be terminated as soon as the desired node is found.

Page 7: My File Structure Btrees Project Report

Linear Search technique is used for the search operation.Searching for S results in the traversal of the B-Tree up to the right leaf node. Searching for the key which is not present results in the traversal of the B-Tree with respect to the parent node.

WP

PMD WT

DCBA PN WU

MIG TSR

Page 8: My File Structure Btrees Project Report

Rules for deleting a key k from a node n: If n has more than the number of keys and the k is not

the largest in n, simply delete k from n. If n has more than the minimum number of keys and

the k is the largest in n, delete k and modify the higher level indexes to reflect the new largest key in n.

If n has exactly the minimum number of keys and one of the siblings of n has few enough keys, merge n with its sibling and delete a key from the parent node.

If n has exactly the minimum number of keys and one of the siblings of n has extra keys, redistribute by moving some keys from a sibling to n, and modify the higher level indexes to reflect the new largest keys in the affected nodes.

Redistribution: Redistribution is a new idea which can restore the B-

Tree properties by moving one key from a sibling into the node that has underflowed , even if the distribution of the keys between the pages is very uneven.

Redistribution during insertion is a way to avoid, or at least postpone, the creation of new nodes.

Page 9: My File Structure Btrees Project Report

No change occurs when there is a removal of a key from the leaf node.

Deleting P- P changes to O in the 2nd level & the root.

Removal of H causes an underflow. This results in the merging of two leaf nodes.

ZOI

IGD OM ZXT

DCBA MLKJ TSRQ ZY

GFE IH ON XWVU

ZOI

ID OM ZXT

DCBA MLKJ TSRQ ZY

IGFE ON XWVU

Page 10: My File Structure Btrees Project Report

A database is a collection of data organized in a fashion that facilitates updating, retrieving, and managing the data. The data can consist of anything, including, but not limited to names, addresses, pictures, and numbers. Databases are commonplace and are used everyday.

For example, an airline reservation system might maintain a database of available flights, customers, and tickets issued. A teacher might maintain a database of student names and grades.

In order for a database to be useful and usable, it must support the desired operations, such as retrieval and storage, quickly. Because databases cannot typically be maintained entirely in memory, b-trees are often used to index the data and to provide fast access.

For example, searching an unindexed and unsorted database containing n key values will have a worst case running time of O(n); if the same data is indexed with a B-Tree, the same search operation will run in O(log n).

Page 11: My File Structure Btrees Project Report