Assignment (DS)
Assignment (DS)
Figure: Hash Table with no collisions Now we can find id 3 quickly and easily by visiting bucket 3 and looking into it.
Figure: Hash Table with collisions We have had to put more than 1 row in some of the buckets. This is called a hash collision. The more collisions we have the longer the collision chain and the slower the system will get. For instance, finding id 6 means visiting bucket 2, And then finding id 2, Then 10, And then finally 6.
B-Tree Indexing
The B-Tree Index is the default index for most relational database systems. The top most level of the index is called the root. The lowest level is called the leaf node. All other levels in between are called branches. Both the root and branch contain entries that point to the next level in the index. Leaf nodes consisting of the index key and pointers pointing to the physical location (i.e., row ids) in which the corresponding records are stored. Inserting a new key- It is done almost the same way as insertion of a new key into a B-tree. When a leak node is split into two nodes, a copy of low-order key value from the rightmost node is promoted to be the separator key value in the parent node. The new node also must be inserted in the linked list of the sequence set. Deleting a key- It is easier as compared to a B-Tree. When a key value is deleted from a leaf, there is no need to delete that key from the index of the tree. The key value still can direct searches to proper leaves. Searching a B Tree- It terminates in a node in the sequence set. If there is a key in the index that matches the sought key, the preceding pointer is followed until the correct leaf is reached. Also not every key in the index set need to appear in the sequence set, since the deleted keys are retained in the index set.
B- Tree Indexing
Ques-3- Write a short note on different types of file organisations? Ans - (a). Sequential File Organization
1. A sequential file is designed for efficient processing of records in sorted order on some search key. Records are chained together by pointers to permit fast retrieval in search key order. Pointer points to next record in order. Records are stored physically in search key order (or as close to this as possible). This minimizes number of block accesses. 2. It is difficult to maintain physical sequential order as records are inserted and deleted. Deletion can be managed with the pointer chains. Insertion poses problems if no space where new record should go. If space, use it, else put new record in an overflow block. Adjust pointers accordingly. Problem: we now have some records out of physical sequential order. If very few records in overflow blocks, this will work well. If order is lost, reorganize the file. Reorganizations are expensive and done when system load is low. 3. If insertions rarely occur, we could keep the file in physically sorted order and reorganize when insertion occurs. In this case, the pointer fields are no longer required. 4. Advantages Easy to handle Involves no overhead Can be stored on tapes as well as disks Well suited for batch-oriented applications. Records in a sequential file can be of varying lengths 5. Disadvantages Records can only be accessed in sequence Does not support updating operation in place Does not support interactive applications