Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Regulation 2019 Academic Year 2022 - 23

IFET College of Engineering


(An Autonomous Institution)
Department of CSE & IT
Subject code: 19UITPC301 Year: 2nd Year
Name of the Subject: DATA STRUCTURE Sem: III Sem
UNIT–V SORTING, SEARCHING AND HASH TECHNIQUES
FUNDAMENTALS
Searching: Linear Search, Binary Search. Sorting: Bubble sort, Selection sort, Insertion sort, Shell sort,
Radix sort, Quick Sort, Merge Sort. Hashing: Hash Functions, Separate Chaining, Open Addressing,
Rehashing and Extendible Hashing.

SEARCHING
• Searching is an algorithm, to check whether a particular element is present in the list.
• Two types:
o Linear Search
o Binary Search
Linear search
Linear search or sequential search is a method for finding a target value within a list. It sequentially
checks each element of the list for the target value until a match is found or until all the elements have
been searched.
Binary Search
Binary search is used to search an item in a sorted list. In this method, initialize the lower limit and
upper limit.
SORTING
Sorting is a technique for arranging data in a particular order. Order means the arrangement of data.
The sorting order can be ascending or descending.
Types of Sorting
• Internal Sorting - Internal Sorting is a type of sorting technique in which data resides on main memory
of computer. It is applicable when the number of elements in the list is small.
• External Sorting - External Sorting is a type of sorting technique in which there is a huge amount of
data and it resides on secondary device
SORTING ALGORITHMS:
*Insertion sort *Selection sort *Shell sort
*Bubble sort *Quick sort *Merge sort
*Radix sort
BUBBLE SORT
• Bubble sort is one of the simplest internal sorting algorithms.
• Bubble sort works by comparing two consecutive elements and the largest element among
these two bubbles towards right at the end of the first pass the largest element gets sorted and
placed at the end of the sorted list.
SELECTION SORT
• Selection sort selects the smallest element in the list and place it in the first position then
selects the second smallest element and place it in the second position and it proceeds in the
similar way until the entire listm is sorted.
• For “n” elements, (n-1) passes are required. At the end of the ith iteration, the ith smallest
element will be placed in its correct position.
SHELL SORT
• In shell sort the whole array is first fragmented into K segments, where K is preferably a prime
Regulation 2019 Academic Year 2022 - 23
number.
• After the first pass the whole array is partially sorted.
• In the next pass, the value of K is reduced which increases the size of each segment and
reduces the number of segments.
• The next value of K is chosen so that it is relatively prime to its previous value.
• The process is repeated until K=1 at which the array is sorted.
• The insertion sort is applied to each segment so each successive segment is partially sorted.
RADIX SORT
• Radix sort is one of the linear sorting algorithms. It is generalized form of bucket sort. It
can be performed using buckets from 0 to 9.
• It is also called binsort, card sort.
• It works by sorting the input based on each digit. In first pass all the elements are stored
according to the last significant digit.
QUICK SORT
• The basic idea is to find a “pivot” item in the array and compare all other items with pivot
element.
• Shift items such that all of the items before the pivot are less than the pivot value and all the
items after the pivot are greater than the pivot value.
• After that, recursively perform the same operation on the items before and after the pivot.
Find a “pivot” item in the array. This item is the basis for comparison for a single round. Start
a pointer (the left pointer) at the first item in the array.
MERGE SORT
• Merge sort is a sorting algorithm that uses the divide, conquer, and combine algorithmic
paradigm.
• Divide means partitioning the n-element array to be sorted into two sub-arrays of n/2 elements.
• If there are more elements in the array, divide A into two sub-arrays, A1 and A2, each
containing about half of the elements of A.
• Conquer means sorting the two sub-arrays recursively using merge sort.
• Combine means merging the two sorted sub-arrays of size n/2 to produce the sorted array of n
elements.
HASHING
• Hashing is a technique that is used to store, retrieve and find data in the data structure called Hash
Table.
• Hashing is a technique that is used to store, retrieve and find data in the data structure called
Hash Table. Hash function distributes the keys evenly among the cells in the Hash Table.
Types of Hash Functions
1. Division Method
2. Mid Square Method
3. Multiplicative Hash Function
4. Digit Folding
Collision
• If two more keys hashes to the same index, the corresponding records cannot be stored in the
same location. This condition is known as collision.
• Collision Resolution strategies
Separate chaining (Open Hashing)
Open addressing. (Closed Hashing)
➢ Linear Probing
➢ Quadratic Probing
➢ Double Hashing

You might also like