Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Hashing and File Structure, Lecture notes of Data Structures and Algorithms

An overview of hashing and file structure concepts. It explains the use of hash tables as a data structure for storing key-value pairs, and how hashing can be used to efficiently access data. The document also discusses different collision resolution techniques, such as separate chaining and open addressing, and their trade-offs. Additionally, it covers the concepts of records, files, and file organization, including sequential access, direct access, and indexed sequential access file structures. The document delves into the advantages and disadvantages of each file organization approach, highlighting their suitability for different use cases. Overall, this document serves as a comprehensive introduction to the fundamental principles of hashing and file management, which are crucial topics in computer science and data structures.

Typology: Lecture notes

2022/2023

Uploaded on 04/25/2024

ajinkya-jagtap
ajinkya-jagtap 🇮🇳

7 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
UNIT 4: Hashing and File Structure
A hash table is a data structure that is used to store keys/value pairs.It uses a hash
function to compute an index into an array in which an element will be inserted or
searched. By using a good hash function, hashing can work well.
Hash Table is a data structure which stores data in an associative manner. In a
hash table, data is stored in an array format, where each data value has its own
unique index value. Access of data becomes very fast if we know the index of the
desired data.
Thus, it becomes a data structure in which insertion and search operations are very
fast irrespective of the size of the data. Hash Table uses an array as a storage
medium and uses hash technique to generate an index where an element is to be
inserted or is to be located from.
Hashing
Hashing is a technique to convert a range of key values into a range of indexes of
an array. We're going to use modulo operator to get a range of key values.
Consider an example of hash table of size 20, and the following items are to be
stored. Item are in the (key,value) format.
(1,20)
(2,70)
(42,80)
(4,25)
(12,44)
pf3
pf4
pf5

Partial preview of the text

Download Hashing and File Structure and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

UNIT 4: Hashing and File Structure A hash table is a data structure that is used to store keys/value pairs. It uses a hash function to compute an index into an array in which an element will be inserted or searched. By using a good hash function, hashing can work well. Hash Table is a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value. Access of data becomes very fast if we know the index of the desired data. Thus, it becomes a data structure in which insertion and search operations are very fast irrespective of the size of the data. Hash Table uses an array as a storage medium and uses hash technique to generate an index where an element is to be inserted or is to be located from. Hashing Hashing is a technique to convert a range of key values into a range of indexes of an array. We're going to use modulo operator to get a range of key values. Consider an example of hash table of size 20, and the following items are to be stored. Item are in the (key,value) format.  (1,20)  (2,70)  (42,80)  (4,25)  (12,44)

Collision in Hashing In this, the hash function is used to find the index of the array. The hash value is used to create an index for the key in the hash table. The hash function may return the same hash value for two or more keys. When two or more keys have the same hash value, a collision happens. To handle this collision, we use collision resolution techniques.

Collision Resolution Techniques:

There are two types of collision resolution techniques.  Separate chaining (open hashing)  Open addressing (closed hashing) Separate chaining: This method involves making a linked list out of the slot where the collision happened, then adding the new key to the list. Separate chaining is the term used to describe how this connected list of slots resembles a chain. It is more frequently utilized when we are unsure of the number of keys to add or remove. Time complexity  Its worst-case complexity for searching is o(n).  Its worst-case complexity for deletion is o(n).

Concept of Field, Record and Files:

Record - a record represents a collection of attributes that describe a real-world entity. A record consists of fields , with each field describing an attribute of the entity. File - a group of related records. Files are frequently classified by the application for which they are primarily used (employee file). File Structure: A file structure is the way files are organized on a computer. It's important because it helps you find the files you need. Adopting a file structure makes getting to the files you need as easy as possible. What is File? File is a collection of records related to each other. The file size is limited by the size of memory and storage medium. File Organization File organization ensures that records are available for processing. It is used to determine an efficient file organization for each base relation. For example, if we want to retrieve employee records in alphabetical order of name. Sorting the file by employee name is a good file organization. However, if we want to retrieve all employees whose marks are in a certain range, a file is ordered by employee name would not be a good file organization. Types of File Organization There are three types of organizing the file:

  1. Sequential access file organization
  2. Direct access files organization
  1. Indexed sequential accesses file organization 1. Sequential access file organization  Storing and sorting in contiguous block within files on tape or disk is called as sequential access file organization.  In sequential access file organization, all records are stored in a sequential order. The records are arranged in the ascending or descending order of a key field.  Sequential file search starts from the beginning of the file and the records can be added at the end of the file.  In sequential file, it is not possible to add a record in the middle of the file without rewriting the file. For example, on a magnetic drum, records are stored sequential on the tracks. However, each record is assigned an index that can be used to access it directly. Advantages of sequential file  It is simple to program and easy to design.  Sequential file is best use for storage space. Disadvantages of sequential file  Sequential file is time consuming process.  It has high data redundancy.  Random searching is not possible. 2. Direct access file organization  Direct access file is also known as random access or relative file organization.  In direct access file, all records are stored in direct access storage device (DASD), such as hard disk. The records are randomly placed throughout the file.  The record does not need to be in sequence because they are updated directly and rewritten back in the same location.  This file organization is useful for immediate access to large amount of information. It is used in accessing large databases.  It is also called as hashing.

 It provides quick access for sequential and direct processing.  It reduces the degree of the sequential search. Disadvantages of Indexed sequential access file organization  Indexed sequential access file requires unique keys and periodic reorganization.  Indexed sequential access file takes longer time to search the index for the data access or retrieval.  It requires more storage space.  It is expensive because it requires special software.  It is less efficient in the use of storage space as compared to other file organizations.