Data Structures and Algorithms · Unit 7 · 6 hrs
Searching and Hashing
Exam-focused notes for Searching and Hashing (Data Structures and Algorithms, CSC211): what the TU syllabus asks and how it has actually been tested, with 10 solved past questions from this unit.
What this unit covers
- Introduction to Searching, Search Algorithms: Sequential Search, Binary Search
- Efficiency of Search Algorithms
- Hashing: Hash Function and Hash Tables, Collision Resolution Techniques
Hashing
What is hashing? how do you apply linear probing and rehashing explain with example. [5]
Hashing is a technique used to map data (keys) to specific locations (indices) in a hash table using a hash function. The hash function converts a key into an index within the range of the table size. General form: The main advantage of hashing is that it a...
Full solved answer →Define hash table and hash function. What is collision in hashing? Explain linear probing and quadratic probing with suitable example.[10]
--- A hash table is a data structure that stores data in an array format, where each data item is placed at a specific position (index) calculated based on the value of the key. The data is stored in an array called a hash table, and the mapping of keys to ...
Full solved answer →Assume you have to store the data {0,1,2,4,5,7} into a hash table of size 5, with hash function, $h(x) = x % 5$. Apply linear probing and double hashing as collision resolution techniques. [5]
- Data set (in insertion order): {0, 1, 2, 4, 5, 7} → 6 keys - Hash table size: m = 5 (slots 0 to 4) - Primary hash function: h(x) = x % 5 Observation: 6 keys into a table of size 5 means the table can hold at most 5 keys. The 6th key must overflow. --- Pro...
Full solved answer →What is hashing? Explain concept of hash table and hash function with example. [5]
Hashing is a technique used to calculate the position of a key in a table based on the value of the key itself. It is a useful method to implement dictionaries and is used to perform searching, insertion, and deletion at a faster rate compared to traditiona...
Full solved answer →What is hashing? Discuss rehashing with example. [5]
Hashing is an efficient searching technique in which a key is placed at a direct accessible address for rapid search. Hashing provides direct access of records from a file no matter where the record is in the file, which reduces unnecessary comparisons. Thi...
Full solved answer →Introduction to Searching, Search Algorithms
Explain binary search with an example. What is the time complexity of binary search? [5]
Binary search is a searching algorithm that works only on a sorted list of elements. It repeatedly divides the search space in half by comparing the target element with the middle element of the current sublist, eliminating half of the remaining elements at...
Full solved answer →Write a program to implement binary search. [5]
Binary search works on a sorted array by repeatedly dividing the search interval in half. It compares the target key with the middle element and narrows the search to the left or right sub-list accordingly. --- --- --- --- Step l r m a[m] Action -----------...
Full solved answer →Write a program to implement sequential search algorithm. [5]
Sequential search (also called linear search) is a method to search for an item in a data structure by checking each element one by one from the beginning until the target element is found or the list ends. --- --- --- Case Condition Time Complexity -------...
Full solved answer →How do you implement binary search algorithm? What is time complexity of this algorithm? [5]
Binary search is a searching algorithm that works only on sorted lists. It repeatedly divides the search space in half by comparing the target element with the middle element of the list. --- --- Consider sorted array: A = [10, 20, 30, 40, 50, 60, 70], Sear...
Full solved answer →Differentiate between sequential searching and binary searching. [5]
--- Sequential searching is a method of finding a particular element in a list by checking each element one by one from the beginning until the desired element is found or the list ends. - The list need not be sorted. - Searching starts from the first eleme...
Full solved answer →Make Unit 7 stick
Practice CSC211 with flashcards & quizzes