Ques-1- Hashed indexing and binary tree indexing.
Ans - Hash Indexing
A Hash table is one of the simplest index structures which a database can implement. The major components of a hash index are the "hash function" and the "buckets". Effectively the DBMS constructs an index for every table you create that has a PRIMARY KEY attribute, like: CREATE TABLE test ( id INTEGER PRIMARY KEY , name varchar (100) ); The algorithm splits the places which the rows are to be stored into areas. These areas are called buckets. If a row's primary key matches the requirements to be stored in that bucket, then that is where it will be stored. The algorithm to decide which bucket to use is called the hash function. For our example we will have a nice simple hash function, where the bucket number equals the primary key. When the index is created we have to also decide how many buckets there are. In this example we have decided on 4.
Figure: Hash Table with no collisions Now we can find id 3 quickly and easily by visiting bucket 3 and looking into it.
finding id 6 means visiting bucket 2. And then finally 6.Figure: Hash Table with collisions We have had to put more than 1 row in some of the buckets. Then 10. The more collisions we have the longer the collision chain and the slower the system will get. And then finding id 2. This is called a hash collision. For instance.
It is easier as compared to a B-Tree. a copy of low-order key value from the rightmost node is promoted to be the separator key value in the parent node. The top most level of the index is called the root.B-Tree Indexing
The B-Tree Index is the default index for most relational database systems. If there is a key in the index that matches the sought key.. 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.It is done almost the same way as insertion of a new key into a B-tree. Inserting a new key. Deleting a key. Both the root and branch contain entries that point to the next level in the index. The key value still can direct searches to proper leaves. When a key value is deleted from a leaf. the preceding pointer is followed until the correct leaf is reached.
B. row ids) in which the corresponding records are stored. Leaf nodes consisting of the index key and pointers pointing to the physical location (i.It terminates in a node in the sequence set.Tree Indexing
. The new node also must be inserted in the linked list of the sequence set. When a leak node is split into two nodes. The lowest level is called the leaf node.e. there is no need to delete that key from the index of the tree. All other levels in between are called branches. Searching a B Tree.
then key (A) ≥ key (B). 4) Development Software Technique Modularization. 6) Binary Space Partition .. that each can be developed independently. So. we can search for a given key in moderate time (quicker than Linked List and slower than arrays). a heap is a specialized tree-based data structure that satisfies the heap property: if B is a child node of A. This implies that an element with the greatest key is always in the root node. (Alternatively.Grand Father / \ . the file system on a computer: Family Tree ———/ ----. Self-balancing search trees like AVL guarantee an upper bound of O (Logn) for search. For example. It aims at dividing complex software system into functionally independent modules. tree is hierarchical (or non-linear) data structure.Used in almost every high-bandwidth router for storing router-tables.g. 1) One reason to use trees might be because you want to store information that naturally forms a hierarchy. Self-balancing search trees like AVL guarantee an upper bound of O (Logn) for insertion/deletion. This reduces the time to develop software.
. And these modules can be further divided thus forming a Tree. 7) Binary Trees . and so such a heap is sometimes called a max-heap. which results in a min-heap.Ques-2.Used in almost every 3D video game to determine what objects need to be rendered.What is Application of Trees? Ans . which are linear data structures.. the smallest element is always in the root node.Applications of Trees
Unlike Array and Linked List. and Government Structure. 2) If we organize keys in form of a tree (with some ordering e. and in the sorting algorithm heap sort. 5) Heaps: In computer science. Father / \ st Child (1 Born) Child (2nd Born) Hence we can have many such hierarchical structures like Family Tree. although in practice each node has at most two Heaps are crucial in several efficient graph algorithms such as Dijkstra's algorithm. if the comparison is reversed. Business Corporate Structure.) There is no restriction as to how many children each node has in a heap. BST). 3) We can insert/delete keys in moderate time (quicker than Arrays and slower than Unordered Linked Lists).
2. • Reorganizations are expensive and done when system load is low. Disadvantages • Records can only be accessed in sequence • Does not support updating operation in place • Does not support interactive applications
. reorganize the file. • Pointer points to next record in order. Advantages • Easy to handle • Involves no overhead • Can be stored on tapes as well as disks • Well suited for batch-oriented applications. this will work well. • Records in a sequential file can be of varying lengths 5. • Adjust pointers accordingly. It is difficult to maintain physical sequential order as records are inserted and deleted. 4. else put new record in an overflow block.Write a short note on different types of file organisations? Ans . If insertions rarely occur. • Deletion can be managed with the pointer chains.(a). Sequential File Organization
1. A sequential file is designed for efficient processing of records in sorted order on some search key. • If order is lost. • If space. • If very few records in overflow blocks. the pointer fields are no longer required.Ques-3. • Insertion poses problems if no space where new record should go. use it. • This minimizes number of block accesses. 3. In this case. we could keep the file in physically sorted order and reorganize when insertion occurs. • Records are stored physically in search key order (or as close to this as possible). • Problem: we now have some records out of physical sequential order. • Records are chained together by pointers to permit fast retrieval in search key order.
• Speed of record processing is very fast. magnetic disc. Disadvantages • Can only be stored on disks • Involve more overhead in the form of maintenance of indexes • Handling bit complex as compared to sequential files • Records can only be of fixed length • Does not fully use memory locations • More security and backup problems
. but the keys may not be in logical sequence. Other types of access of a random file • Random file can be accessed sequentially. Basic Features • Records are read directly from or written on to the file.g. CD. randomly • Well suited for interactive (on-line) applications • Support updating operation in place • Concurrent processing is possible. • Serial access can also be made by a program while generating mailing labels for each customer 3. • Records do not necessarily appear physically in sorted order by their keys • A random file would have to be stored on a direct access backing storage medium e. • It can be accessed serially when input to a sort/merge utility. • The records are stored at known address. Advantages • Records can be accessed out-of-sequence.(b). 4. DVD 2. Random or Relative File Organisation
1. • There is a predictable relationship between the key and record's location in file • Address is calculated by applying a mathematical function to the key field.
Thus. and another one might be maintained for product types. • An indexed sequential file can only be stored on a random access device e. Data items in these systems are usually stored compressed which would normally slow the retrieval process. The benefits are apparent immediately because searching is fast. 2..
." Inverted list files use more space and the storage devices get full quickly with this type of organization. Disadvantages • Extra storage space required • Can only be stored on disks • Involve more overhead in the form of maintenance of indexes • Handling bit complex as compared to sequential files • Records can only be of fixed length
(d) Inverted File Organisation
In file organization. magnetic disc. • An indexed sequential file is a sequential file (i. updating is much slower. a file is indexed on many of the attributes of the data itself. in a company file..g.(c) Indexed or Linked File Organisation
1. 1. Randomly using the index. but indexes are updated for the record keys and location. • An index consists of keys and addresses. it is faster to search the indexes than every record.e. However. but the compression algorithm will be chosen to support this technique. • Indexed sequential files are important for applications where data needs to be accessed. Content-based queries in text retrieval systems use inverted indexes as their preferred mechanism. an index could be maintained for all products. CD. • A full index to a file is one in which there is an entry for every record. sequentially 2. Advantages • Records can be accessed sequentially or randomly • Supports interactive as well as batch-oriented applications • Support updating operation in place • Faster than sequential 3. Basic Features • Each record of a file has a key field which uniquely identifies that record. Here's an example. These types of file are also known as "inverted indexes. The inverted list method has a single index for each key type. The records are not necessarily stored in a sequence. They are placed in the data storage area... When querying a file there are certain circumstances when the query is designed to be modal which means that rules are set which require that different information be held in the index. sorted into order of a key field) which has an index.
A record can be viewed as the computer analogue of a mathematical tuple. The parameters of a function or procedure can often be viewed as the fields of a record variable. Indeed. a month field represented as a string. In the same vein. A record type is a data type that describes such values and variables.Ques-4. Records are among the simplest data structures. records are just special cases of objects. Most modern computer languages allow the programmer to define new record types. typically in fixed number and sequence and typically indexed by names. and object data types (often called object classes) are an elaboration of record types. including main memory and mass storage devices such as magnetic tapes or hard disks. especially linked data structures. A record is a value that contains other values. often grouped into larger physical records or blocks for efficiency.Write a short note on records? Ans .
. Records can exist in any storage medium. in most object-oriented languages. Many computer files are organized as arrays of logical records. The elements of records are usually called fields or members. or the implementation of an abstract product type in a specific language. The definition includes specifying the data type of each field and an identifier (name or label) by which it can be accessed. each field has a name. and that each field may have a different type. a record type can be viewed as the computer language analogue of the Cartesian product of two or more mathematical sets. Records are distinguished from arrays by the fact that their number of fields is typically fixed. and a numeric day-of-month field. and the arguments passed to that function can be viewed as a record value that gets assigned to that variable at the time of the call. containing the procedure parameters and local variables. a date may be stored as a record containing a numeric year field. In C it is the compound data in a structure. each entry is an activation record or call frame. Records are a fundamental component of most data structures. the return address. and other internal fields.Records:
A record is an instance of a product of primitive data types called a tuple. An object in object-oriented language is essentially a record that contains procedures specialized to handle that record. For example. in the call stack that is often used to implement procedure calls. Also.