Data structure and algorithms

Data Structure And
Algorithms
UNIT-5
Searching, hashing and sorting
25/4/2020
1
Submitted by
Bhanupratap Singh Hirwani
Searching
• The process of locating target data is known as searching.
• Searching is the process of finding the location of the target
among a list of object.
• The two basic search techniques are the followings:
-sequential search
-binary search
25/4/2020
2
Linear Search
• The linear search is a sequential search which uses a loop to step
through an array, starting with the first element.
• It compares each element with the value being searched for, and
stops when either the value is found or the end of the array is
encountered.
• A search will be unsuccessful if all the elements are read and
desired element is not found
25/4/2020
3
Linear Search Algorithm
• Linear Search( Array A, Values X)
• Step 1: set i to 1
• Step 2: if i > n then go to step 7
• Step 3: if A[i] = X then go to step 6
• Step 4: set i to i+1
• Step 5: go to step 2
• Step 6: print element x found at index i and go to step 8
• Step 7: print element not found
• Step 8: exit
25/4/2020
4
Advantages and Disadvantages
• The linear search is a simple- it is very easy to understand and
implement
• It does not require the data in the array to be stored in any
particular order
• DISADVANTAGES
• It has very poor efficiency because it takes lots of comparisons to
find a particular record in big files
• Linear search is slower than other searching algorithms
25/4/2020
5
Binary Search
What is Binary Search?
• Binary search is an extremely
efficient algorithm when it is
compared to linear search.
• It searches data in minimum possible
comparisons.
• Binary search use sorted array by
repeatedly dividing the search
interval in half.
Algorithm
• Step 1: compare x with the middle
element.
• Step 2:If x matches with middle
element, we return the mid index.
• Step 3: Else if x is greater than the
mid element, search on right half.
• Step 4: Else if x is smaller than the
mid element, search on left half
25/4/2020
6
Example
• Assume the following array
• Search for 40
• Compare X=40
25/4/2020
7
Hashing
• Hashing is a technique where we can compute the location of the
desired record in order to retrieve it in a single access (or
comparison) .
• Hashing involves less key comparison and searching can
performed in constant time.
• The goal of hashed search is to find the target data in only one
test i.e. O(1)(best complexity).
• Hashing is an efficient method to store and retrieve elements.
• In hashing function the keys are stored in array which is called
hash table.
25/4/2020
8
Hashing function
• The basic idea of hash function Is the transformation of the key into the
corresponding location in the hash table.
• A Hash function H can be defined as a function as a function that takes key as
input and transforms it into a hash table index.
• The values returned by hash function are called hash values , hash codes, hash
sums, or simply hashes.
• Hash function are two types: 1) distribution –independent function ,2)
distribution-dependent function.
• The distribution independent hash functions are : a) division method, b) mid
square method, c) digit folding method.
25/4/2020
9
Hash Collision
• When an element is inserted, if it hashes to the same value as an
already inserted element, then we have a collision.
• A situation in which the hash function returns the same hash key
for more then one record , it is called as collision.
25/4/2020
10
Collision resolution technique
• If there is a problem of collision occurs then it can be handled by apply
some technique.these techniques are called as collision resolution
techniques.
• If the element to be inserted is mapped to the same location, where an
element is already inserted then we have a collision and it must be
resolved.
• There are several strategies for collision resolution. The most commonly
used are:
1) separate chaining- it used with open hashing.
2) open addressing- it used with closed hashing.
25/4/2020
11
Separate Chaining(open hashing)
• Separate chaining based on collision avoidance.
• The idea is to keep a list of all elements that hash to the same value.
-the array elements are pointers to the first nodes of the lists.
-A new item is inserted to the front of the list.
• Advantages:
- batter space utilization for large items.
-simple collision handling : searching link list.
-deletion is quick and easy : deletion from the linked list.
25/4/2020
12
Examples:
25/4/2020
13
Sorting
• Sorting is the operation of arranging the records of a table according to the key
value of each record, or it can be defined as the process of converting an
unordered set of elements to an ordered set of elements.
• Sorting is a process of organizing data in a certain order to help retrieve it more
efficiently.
• Sorting techniques can be divided into two categories. These are:
1) Internal sorting , 2) external sorting.
• Any sort algorithm that uses main memory exclusively during the sorting is
called as internal sort algorithm
• Any sort algorithm that uses external memory, such as tape or disk, during the
sorting is called as external sorting.
• Internal sorting is faster then external sorting. 25/4/2020
14
Internal Sorting |External Sorting
• The various internal sorting techniques are
the following:
1. Bubble sort
2. Selection sort
3. Insertion sort
4. Quick sort
5. Shell sort
6. Heap sort
7. Radix sort
8. Bucket sort
• Merge sort is used in external
sorting
25/4/2020
15
Bubble Sort
What is bubble sort?
• Bubble sort is simple algorithm
which is used to sort a given set of n
elements provided in form of an
array with n number of elements.
• Bubble sort compares all the
element one by one and sort them
based on their values.
• The bubble sort derives its name
from the fact that the smallest data
item bubbles up to the top of the
sorted array.
Algorithm for bubble sort
1. Starting with the first element(index=0),
compare the current element with the
next element of the array.
2. If the current element is greater than the
next element of the array, swap them.
3. If the current element is less than the
next element, move to the next element.
Repeat step 1
25/4/2020
16
Selection Sort
What is selection sort?
• Selection sort is a simple sorting algorithm.
• In this technique, the smallest element is
interchanged with the first element of the array.
• Then the next smallest element is interchanged with
the second element of the array.
• This process of searching the next smallest element
and placing it in its proper position continues until
all records have been sorted in ascending order.
Algorithm
For i<-1 to n-1 do
min<-i
for j<-i+1 to n do
if A[j]<A[i] then
min<-j
if min!=i then
temp<-A[i]
A[i]<-A[min]
A[min]<-temp
25/4/2020
17
Radix sort
• Radix sort algorithm different than other sorting algorithms .
• It does not use key comparisons to sort an array.
• The radix sort treats each data items as a character string.
• First it groups data items according to their rightmost character and put
these groups into order with respect to this right most character.
• Then combine these groups.
• We repeat these groupings and combining operation for all other
character positions in the data items from the right most to the left
most character position.
• At the end, the sort operation will be completed
25/4/2020
18
Heap Sort
• Heap is a special tree based data structure, that satisfies the
following special heap properties: 1)shape property , 2)heap
property
• Heap sort is the one of the fastest sorting algorithm, which
achieves the speed as that of quick sort and merge sort.
• The advantages of heap sort are as follows:
• It dose not use recursion, and it is efficient for any data order.
• It achieves the worst-case bounds better than those of quick sort.
• And for the list, it is better than merge sort since it needs only a
small and constant of space apart from the list being sorted
25/4/2020
19
Merge Sort(external sort)
• The most common algorithm used in external sorting is the merge sort.
• Merging is the process of combining two or more sorted files into the third
sorted file.
• The merge sort algorithm is base on the classical divide-and-conquer paradigm.
• Divide-and-conquer algorithm works in three steps:
1. Divide the problem into multiple small problems.
2. Conquer the subproblems by solving them. The idea is to break down the
problem into atomic subproblems, where they are actually solved.
3. Combine the solutions of the subproblems to find the solution of the actual
problem.
25/4/2020
20
1 de 20

Recomendados

Searching por
SearchingSearching
SearchingAshim Lamichhane
18.3K vistas35 diapositivas
Search methods por
Search methodsSearch methods
Search methodszahraa F.Muhsen
743 vistas10 diapositivas
Searching and Sorting Techniques in Data Structure por
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
13.3K vistas59 diapositivas
Data operatons & searching and sorting algorithms por
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsAnushdika Jeganathan
111 vistas24 diapositivas
Searching algorithms por
Searching algorithmsSearching algorithms
Searching algorithmsTrupti Agrawal
4.1K vistas28 diapositivas
Linear search-and-binary-search por
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-searchInternational Islamic University
14.8K vistas19 diapositivas

Más contenido relacionado

La actualidad más candente

Hashing por
HashingHashing
Hashinginvertis university
316 vistas15 diapositivas
Searching techniques in Data Structure And Algorithm por
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm03446940736
10K vistas12 diapositivas
Dsa – data structure and algorithms sorting por
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sortingsajinis3
135 vistas37 diapositivas
linear search and binary search por
linear search and binary searchlinear search and binary search
linear search and binary searchZia Ush Shamszaman
3.9K vistas24 diapositivas
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI por
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHISowmya Jyothi
239 vistas23 diapositivas
Data Structures 7 por
Data Structures 7Data Structures 7
Data Structures 7Dr.Umadevi V
87 vistas22 diapositivas

La actualidad más candente(20)

Searching techniques in Data Structure And Algorithm por 03446940736
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
0344694073610K vistas
Dsa – data structure and algorithms sorting por sajinis3
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
sajinis3135 vistas
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI por Sowmya Jyothi
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi239 vistas
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI por Sowmya Jyothi
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi320 vistas
DATA STRUCTURES USING C -ENGGDIGEST por Swapnil Mishra
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra86 vistas
Lecture 07 Data Structures - Basic Sorting por Haitham El-Ghareeb
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
Haitham El-Ghareeb12.9K vistas
11. Hashing - Data Structures using C++ by Varsha Patil por widespreadpromotion
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil
widespreadpromotion4.2K vistas
IRJET- A Survey on Different Searching Algorithms por IRJET Journal
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
IRJET Journal22 vistas
Sequential & binary, linear search por montazur420
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
montazur4201.5K vistas
9. Searching & Sorting - Data Structures using C++ by Varsha Patil por widespreadpromotion
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil

Similar a Data structure and algorithms

SORTING techniques.pptx por
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptxDr.Shweta
3 vistas104 diapositivas
Searching, Sorting and Hashing Techniques por
Searching, Sorting and Hashing TechniquesSearching, Sorting and Hashing Techniques
Searching, Sorting and Hashing TechniquesSelvaraj Seerangan
991 vistas148 diapositivas
searching techniques.pptx por
searching techniques.pptxsearching techniques.pptx
searching techniques.pptxDr.Shweta
8 vistas36 diapositivas
programming in C por
programming in Cprogramming in C
programming in CADITHYAM19
7 vistas9 diapositivas
Sorting por
SortingSorting
SortingFahadSaeed39
53 vistas15 diapositivas
Rahat &amp; juhith por
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhithRj Juhith
560 vistas31 diapositivas

Similar a Data structure and algorithms(20)

SORTING techniques.pptx por Dr.Shweta
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta3 vistas
searching techniques.pptx por Dr.Shweta
searching techniques.pptxsearching techniques.pptx
searching techniques.pptx
Dr.Shweta8 vistas
Rahat &amp; juhith por Rj Juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
Rj Juhith560 vistas
DS - Unit 2 FINAL (2).pptx por prakashvs7
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs718 vistas
Data Structures_ Sorting & Searching por ThenmozhiK5
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
ThenmozhiK567 vistas
Chapter 4.pptx por Tekle12
Chapter 4.pptxChapter 4.pptx
Chapter 4.pptx
Tekle1215 vistas
Searching,sorting por LavanyaJ28
Searching,sortingSearching,sorting
Searching,sorting
LavanyaJ2832 vistas

Último

ELECTRON TRANSPORT CHAIN por
ELECTRON TRANSPORT CHAINELECTRON TRANSPORT CHAIN
ELECTRON TRANSPORT CHAINDEEKSHA RANI
10 vistas16 diapositivas
Factors affecting fluorescence and phosphorescence.pptx por
Factors affecting fluorescence and phosphorescence.pptxFactors affecting fluorescence and phosphorescence.pptx
Factors affecting fluorescence and phosphorescence.pptxSamarthGiri1
7 vistas11 diapositivas
scopus cited journals.pdf por
scopus cited journals.pdfscopus cited journals.pdf
scopus cited journals.pdfKSAravindSrivastava
10 vistas15 diapositivas
BLOTTING TECHNIQUES SPECIAL por
BLOTTING TECHNIQUES SPECIALBLOTTING TECHNIQUES SPECIAL
BLOTTING TECHNIQUES SPECIALMuhammadImranMirza2
5 vistas56 diapositivas
Evaluation and Standardization of the Marketed Polyherbal drug Patanjali Divy... por
Evaluation and Standardization of the Marketed Polyherbal drug Patanjali Divy...Evaluation and Standardization of the Marketed Polyherbal drug Patanjali Divy...
Evaluation and Standardization of the Marketed Polyherbal drug Patanjali Divy...Anmol Vishnu Gupta
7 vistas10 diapositivas
How to be(come) a successful PhD student por
How to be(come) a successful PhD studentHow to be(come) a successful PhD student
How to be(come) a successful PhD studentTom Mens
524 vistas62 diapositivas

Último(20)

ELECTRON TRANSPORT CHAIN por DEEKSHA RANI
ELECTRON TRANSPORT CHAINELECTRON TRANSPORT CHAIN
ELECTRON TRANSPORT CHAIN
DEEKSHA RANI10 vistas
Factors affecting fluorescence and phosphorescence.pptx por SamarthGiri1
Factors affecting fluorescence and phosphorescence.pptxFactors affecting fluorescence and phosphorescence.pptx
Factors affecting fluorescence and phosphorescence.pptx
SamarthGiri17 vistas
Evaluation and Standardization of the Marketed Polyherbal drug Patanjali Divy... por Anmol Vishnu Gupta
Evaluation and Standardization of the Marketed Polyherbal drug Patanjali Divy...Evaluation and Standardization of the Marketed Polyherbal drug Patanjali Divy...
Evaluation and Standardization of the Marketed Polyherbal drug Patanjali Divy...
How to be(come) a successful PhD student por Tom Mens
How to be(come) a successful PhD studentHow to be(come) a successful PhD student
How to be(come) a successful PhD student
Tom Mens524 vistas
Open Access Publishing in Astrophysics por Peter Coles
Open Access Publishing in AstrophysicsOpen Access Publishing in Astrophysics
Open Access Publishing in Astrophysics
Peter Coles1.2K vistas
Light Pollution for LVIS students por CWBarthlmew
Light Pollution for LVIS studentsLight Pollution for LVIS students
Light Pollution for LVIS students
CWBarthlmew9 vistas
A giant thin stellar stream in the Coma Galaxy Cluster por Sérgio Sacani
A giant thin stellar stream in the Coma Galaxy ClusterA giant thin stellar stream in the Coma Galaxy Cluster
A giant thin stellar stream in the Coma Galaxy Cluster
Sérgio Sacani17 vistas
Nitrosamine & NDSRI.pptx por NileshBonde4
Nitrosamine & NDSRI.pptxNitrosamine & NDSRI.pptx
Nitrosamine & NDSRI.pptx
NileshBonde418 vistas
Ellagic Acid and Its Metabolites as Potent and Selective Allosteric Inhibitor... por Trustlife
Ellagic Acid and Its Metabolites as Potent and Selective Allosteric Inhibitor...Ellagic Acid and Its Metabolites as Potent and Selective Allosteric Inhibitor...
Ellagic Acid and Its Metabolites as Potent and Selective Allosteric Inhibitor...
Trustlife100 vistas
Structure of purines and pyrimidines - Jahnvi arora (11228108), mmdu ,mullana... por jahnviarora989
Structure of purines and pyrimidines - Jahnvi arora (11228108), mmdu ,mullana...Structure of purines and pyrimidines - Jahnvi arora (11228108), mmdu ,mullana...
Structure of purines and pyrimidines - Jahnvi arora (11228108), mmdu ,mullana...
jahnviarora9896 vistas
application of genetic engineering 2.pptx por SankSurezz
application of genetic engineering 2.pptxapplication of genetic engineering 2.pptx
application of genetic engineering 2.pptx
SankSurezz14 vistas
Discovery of therapeutic agents targeting PKLR for NAFLD using drug repositio... por Trustlife
Discovery of therapeutic agents targeting PKLR for NAFLD using drug repositio...Discovery of therapeutic agents targeting PKLR for NAFLD using drug repositio...
Discovery of therapeutic agents targeting PKLR for NAFLD using drug repositio...
Trustlife127 vistas
Study on Drug Drug Interaction Through Prescription Analysis of Type II Diabe... por Anmol Vishnu Gupta
Study on Drug Drug Interaction Through Prescription Analysis of Type II Diabe...Study on Drug Drug Interaction Through Prescription Analysis of Type II Diabe...
Study on Drug Drug Interaction Through Prescription Analysis of Type II Diabe...
Anmol Vishnu Gupta26 vistas

Data structure and algorithms

  • 1. Data Structure And Algorithms UNIT-5 Searching, hashing and sorting 25/4/2020 1 Submitted by Bhanupratap Singh Hirwani
  • 2. Searching • The process of locating target data is known as searching. • Searching is the process of finding the location of the target among a list of object. • The two basic search techniques are the followings: -sequential search -binary search 25/4/2020 2
  • 3. Linear Search • The linear search is a sequential search which uses a loop to step through an array, starting with the first element. • It compares each element with the value being searched for, and stops when either the value is found or the end of the array is encountered. • A search will be unsuccessful if all the elements are read and desired element is not found 25/4/2020 3
  • 4. Linear Search Algorithm • Linear Search( Array A, Values X) • Step 1: set i to 1 • Step 2: if i > n then go to step 7 • Step 3: if A[i] = X then go to step 6 • Step 4: set i to i+1 • Step 5: go to step 2 • Step 6: print element x found at index i and go to step 8 • Step 7: print element not found • Step 8: exit 25/4/2020 4
  • 5. Advantages and Disadvantages • The linear search is a simple- it is very easy to understand and implement • It does not require the data in the array to be stored in any particular order • DISADVANTAGES • It has very poor efficiency because it takes lots of comparisons to find a particular record in big files • Linear search is slower than other searching algorithms 25/4/2020 5
  • 6. Binary Search What is Binary Search? • Binary search is an extremely efficient algorithm when it is compared to linear search. • It searches data in minimum possible comparisons. • Binary search use sorted array by repeatedly dividing the search interval in half. Algorithm • Step 1: compare x with the middle element. • Step 2:If x matches with middle element, we return the mid index. • Step 3: Else if x is greater than the mid element, search on right half. • Step 4: Else if x is smaller than the mid element, search on left half 25/4/2020 6
  • 7. Example • Assume the following array • Search for 40 • Compare X=40 25/4/2020 7
  • 8. Hashing • Hashing is a technique where we can compute the location of the desired record in order to retrieve it in a single access (or comparison) . • Hashing involves less key comparison and searching can performed in constant time. • The goal of hashed search is to find the target data in only one test i.e. O(1)(best complexity). • Hashing is an efficient method to store and retrieve elements. • In hashing function the keys are stored in array which is called hash table. 25/4/2020 8
  • 9. Hashing function • The basic idea of hash function Is the transformation of the key into the corresponding location in the hash table. • A Hash function H can be defined as a function as a function that takes key as input and transforms it into a hash table index. • The values returned by hash function are called hash values , hash codes, hash sums, or simply hashes. • Hash function are two types: 1) distribution –independent function ,2) distribution-dependent function. • The distribution independent hash functions are : a) division method, b) mid square method, c) digit folding method. 25/4/2020 9
  • 10. Hash Collision • When an element is inserted, if it hashes to the same value as an already inserted element, then we have a collision. • A situation in which the hash function returns the same hash key for more then one record , it is called as collision. 25/4/2020 10
  • 11. Collision resolution technique • If there is a problem of collision occurs then it can be handled by apply some technique.these techniques are called as collision resolution techniques. • If the element to be inserted is mapped to the same location, where an element is already inserted then we have a collision and it must be resolved. • There are several strategies for collision resolution. The most commonly used are: 1) separate chaining- it used with open hashing. 2) open addressing- it used with closed hashing. 25/4/2020 11
  • 12. Separate Chaining(open hashing) • Separate chaining based on collision avoidance. • The idea is to keep a list of all elements that hash to the same value. -the array elements are pointers to the first nodes of the lists. -A new item is inserted to the front of the list. • Advantages: - batter space utilization for large items. -simple collision handling : searching link list. -deletion is quick and easy : deletion from the linked list. 25/4/2020 12
  • 14. Sorting • Sorting is the operation of arranging the records of a table according to the key value of each record, or it can be defined as the process of converting an unordered set of elements to an ordered set of elements. • Sorting is a process of organizing data in a certain order to help retrieve it more efficiently. • Sorting techniques can be divided into two categories. These are: 1) Internal sorting , 2) external sorting. • Any sort algorithm that uses main memory exclusively during the sorting is called as internal sort algorithm • Any sort algorithm that uses external memory, such as tape or disk, during the sorting is called as external sorting. • Internal sorting is faster then external sorting. 25/4/2020 14
  • 15. Internal Sorting |External Sorting • The various internal sorting techniques are the following: 1. Bubble sort 2. Selection sort 3. Insertion sort 4. Quick sort 5. Shell sort 6. Heap sort 7. Radix sort 8. Bucket sort • Merge sort is used in external sorting 25/4/2020 15
  • 16. Bubble Sort What is bubble sort? • Bubble sort is simple algorithm which is used to sort a given set of n elements provided in form of an array with n number of elements. • Bubble sort compares all the element one by one and sort them based on their values. • The bubble sort derives its name from the fact that the smallest data item bubbles up to the top of the sorted array. Algorithm for bubble sort 1. Starting with the first element(index=0), compare the current element with the next element of the array. 2. If the current element is greater than the next element of the array, swap them. 3. If the current element is less than the next element, move to the next element. Repeat step 1 25/4/2020 16
  • 17. Selection Sort What is selection sort? • Selection sort is a simple sorting algorithm. • In this technique, the smallest element is interchanged with the first element of the array. • Then the next smallest element is interchanged with the second element of the array. • This process of searching the next smallest element and placing it in its proper position continues until all records have been sorted in ascending order. Algorithm For i<-1 to n-1 do min<-i for j<-i+1 to n do if A[j]<A[i] then min<-j if min!=i then temp<-A[i] A[i]<-A[min] A[min]<-temp 25/4/2020 17
  • 18. Radix sort • Radix sort algorithm different than other sorting algorithms . • It does not use key comparisons to sort an array. • The radix sort treats each data items as a character string. • First it groups data items according to their rightmost character and put these groups into order with respect to this right most character. • Then combine these groups. • We repeat these groupings and combining operation for all other character positions in the data items from the right most to the left most character position. • At the end, the sort operation will be completed 25/4/2020 18
  • 19. Heap Sort • Heap is a special tree based data structure, that satisfies the following special heap properties: 1)shape property , 2)heap property • Heap sort is the one of the fastest sorting algorithm, which achieves the speed as that of quick sort and merge sort. • The advantages of heap sort are as follows: • It dose not use recursion, and it is efficient for any data order. • It achieves the worst-case bounds better than those of quick sort. • And for the list, it is better than merge sort since it needs only a small and constant of space apart from the list being sorted 25/4/2020 19
  • 20. Merge Sort(external sort) • The most common algorithm used in external sorting is the merge sort. • Merging is the process of combining two or more sorted files into the third sorted file. • The merge sort algorithm is base on the classical divide-and-conquer paradigm. • Divide-and-conquer algorithm works in three steps: 1. Divide the problem into multiple small problems. 2. Conquer the subproblems by solving them. The idea is to break down the problem into atomic subproblems, where they are actually solved. 3. Combine the solutions of the subproblems to find the solution of the actual problem. 25/4/2020 20