Searching,sorting

UNIT 5
SEARCHING & SORTING
SEARCHING
 Searching is the process of determining whether or
not a given value exists in a data structure or a
storage media.
 linear search and binary search.
LINEAR SEARCH
 The linear (or sequential) search algorithm on an
array is:
 Sequentially scan the array, comparing each array item with the searched
value.
 If a match is found; return the index of the matched element; otherwise
return –1.
 Note: linear search can be applied to both sorted and
unsorted arrays.
FEATURES OF LINEAR SEARCH
 It is used for unsorted and unordered small list of
elements.
 It has a time complexity of O(n), which means the
time is linearly dependent on the number of
elements, which is not bad, but not that good too.
 It has a very simple implementation.
Searching,sorting
APPLICATIONS OF LINEAR SEARCH
 Used to find the desired element from the collection
of data when the dataset is small
 The searching operations is less than 100 items
BINARY SEARCH
 An algorithm to solve this task looks at the
middle of the array or array segment first
 If the value looked for is smaller than the
value in the middle of the array
 Then the second half of the array or array
segment can be ignored
 This strategy is then applied to the first half of the
array or array segment
BINARY SEARCH (CONT.,)
 If the value looked for is larger than the value in the
middle of the array or array segment
 Then the first half of the array or array segment can be
ignored
 This strategy is then applied to the second half of the array
or array segment
 If the value looked for is at the middle of the array
or array segment, then it has been found
 If the entire array (or array segment) has been
searched in this way without finding the value, then
it is not in the array
EFFICIENCY OF BINARY SEARCH
 The binary search algorithm is extremely fast
compared to an algorithm that tries all array
elements in order
 About half the array is eliminated from consideration
right at the start
 Then a quarter of the array, then an eighth of the array,
and so forth
Searching,sorting
APPLICATIONS OF BINARY SEARCH
 The binary search algorithm is used in the libraries
of Java, C++, etc
 It is used in another additional program like finding
the smallest element or largest element in the array
 It is used to implement a dictionary
SORTING METHODS
 Sorting Algorithms are methods of reorganizing a
large number of items into some specific order such
as highest to lowest, or vice-versa, or even in some
alphabetical order.
 These algorithms take an input list, processes it
(i.e, performs some operations on it) and produce
the sorted list.
 The most common example we experience every
day is sorting clothes or other items on an e-
commerce website either by lowest-price to highest,
or list by popularity, or some other order.
TYPES OF SORTING ALGORITHMS
 Shell sort
 Heap sort
 Radix sort
 Bucket sort
 Quick sort
 Bubble sort
 Merge sort
 Insertion sort
 Selection sort
BUBBLE SORT
 Bubble sort, also referred to as comparison sort
 It is a simple sorting algorithm that repeatedly goes
through the list, compares adjacent elements and
swaps them if they are in the wrong order.
 This is the most simplest algorithm and inefficient at
the same time.
 https://www.interviewbit.com/tutorial/bubble-sort/
SELECTION SORT
 Selection sort is a simple comparison-based sorting
algorithm
 Steps to be followed
 Pick the minimum element from the unsorted
subarray.
 Swap it with the leftmost element of the unsorted
subarray.
 Now the leftmost element of unsorted subarray
becomes a part (rightmost) of sorted subarray and
will not be a part of unsorted subarray.
https://www.interviewbit.com/tutorial/selection-sort/
INSERTION SORT
 Insertion sort is the sorting mechanism where the
sorted array is built having one item at a time.
 The array elements are compared with each other
sequentially and then arranged simultaneously in
some particular order.
 This sort works on the principle of inserting an
element at a particular position, hence the name
Insertion Sort.
 https://www.interviewbit.com/tutorial/insertion-sort-
algorithm/
SHELL SORT
 Shell sort is a highly efficient sorting algorithm and is
based on insertion sort algorithm.
 This algorithm avoids large shifts as in case of insertion
sort, if the smaller value is to the far right and has to be
moved to the far left.
 Steps to be followed
 Step 1 − Initialize the value of h.
 Step 2 − Divide the list into smaller sub-list of equal
interval h.
 Step 3 − Sort these sub-lists using insertion sort.
 Step 3 − Repeat until complete list is sorted.
 https://www.tutorialspoint.com/data_structures_algorith
ms/shell_sort_algorithm.htm
RADIX SORT
 Radix sort is one of the sorting algorithms used
to sort a list of integer numbers in order.
 In radix sort algorithm, a list of integer numbers will
be sorted based on the digits of individual numbers.
 Sorting is performed from least significant digit to
the most significant digit.
Searching,sorting
QUICK SORT
 It is one of the most efficient sorting algorithms and
is based on the splitting of an array (partition) into
smaller ones and swapping (exchange) based on
the comparison with 'pivot' element selected.
 Due to this, quick sort is also called as "Partition
Exchange" sort.
 Steps to be followed:
 Step 1 − Make any element as pivot
Step 2 − Partition the array on the basis of pivot
Step 3 − Apply quick sort on left partition
recursively
Step 4 − Apply quick sort on right partition
recursively
Searching,sorting
HEAP SORT
 Heap sort is a comparison-based sorting
technique based on Binary Heap data structure
 https://www.youtube.com/watch?v=MtQL_ll5KhQ
 There are two kinds of heaps: min-heap and max-
heap.
 In min-heap parents nodes are smaller than
children nodes (the root node is smallest), while in
max-heap it is opposite (the root node is largest).
MERGE SORT
 Merge sort is one of the most efficient sorting
algorithms. It works on the principle of Divide and
Conquer.
 Merge sort repeatedly breaks down a list into
several sublists until each sublist consists of a
single element and merging those sublists in a
manner that results into a sorted list.
 https://www.interviewbit.com/tutorial/merge-sort-
algorithm/
COMPARISON OF SORTING ALOGORITHMS
 In a comparison based sorting algorithms, we
compare elements of an array with each other to
determines which of two elements should occur first
in the final sorted list.
 All comparison-based sorting algorithms have a
complexity lower bound of nlogn.
Searching,sorting
1 de 25

Más contenido relacionado

La actualidad más candente

Binary searchBinary search
Binary searchsana younas
291 vistas16 diapositivas
Binary search algorithmBinary search algorithm
Binary search algorithmmaamir farooq
1.3K vistas2 diapositivas
Searching in c languageSearching in c language
Searching in c languageCHANDAN KUMAR
284 vistas22 diapositivas
SortingSorting
SortingFahadSaeed39
53 vistas15 diapositivas
Rahat & juhithRahat & juhith
Rahat & juhithRj Juhith
555 vistas31 diapositivas

La actualidad más candente(20)

Binary searchBinary search
Binary search
sana younas291 vistas
Binary search algorithmBinary search algorithm
Binary search algorithm
maamir farooq1.3K vistas
Searching in c languageSearching in c language
Searching in c language
CHANDAN KUMAR284 vistas
SortingSorting
Sorting
FahadSaeed3953 vistas
Rahat & juhithRahat & juhith
Rahat & juhith
Rj Juhith555 vistas
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
vital vital251 vistas
Intro++ to C#Intro++ to C#
Intro++ to C#
Pixelles / Rebecca Cohen-Palacios734 vistas
ArraysArrays
Arrays
uos79 vistas
Binary search pythonBinary search python
Binary search python
MaryamAnwar10271 vistas
Searching linear & binary searchSearching linear & binary search
Searching linear & binary search
nikunjandy1.4K vistas
Sorting types and AlgorithmsSorting types and Algorithms
Sorting types and Algorithms
Ali Khan237 vistas
SearchingSearching
Searching
A. S. M. Shafi75 vistas
7 searching injava-binary7 searching injava-binary
7 searching injava-binary
irdginfo930 vistas
poornima.coseqpoornima.coseq
poornima.coseq
ramyaraigupta62 vistas
Linear and binary searchLinear and binary search
Linear and binary search
Arjunsinh Jadeja857 vistas
SEARCHINGSEARCHING
SEARCHING
SWATHIR7250 vistas

Similar a Searching,sorting(20)

DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs718 vistas
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta3 vistas
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
Shri Shankaracharya College, Bhilai,Junwani50 vistas
Sorting.pptxSorting.pptx
Sorting.pptx
LuciaMakwasha18 vistas
arrays in carrays in c
arrays in c
vidhi mehta680 vistas
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university113 vistas
Analysis of Algorithm - Binary Search.pptxAnalysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology164 vistas
Sorting algorithms in Data StructureSorting algorithms in Data Structure
Sorting algorithms in Data Structure
Balamurugan M29 vistas
cs702 ppt.pptcs702 ppt.ppt
cs702 ppt.ppt
JavedIqbal39817114 vistas
SortingSorting
Sorting
Varendra University Rajshahi-bangladesh720 vistas
Searching  and sortingSearching  and sorting
Searching and sorting
PoojithaBollikonda63 vistas
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
vital vital149 vistas
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic University14.7K vistas
Quick sortQuick sort
Quick sort
Fabia Nayeem129 vistas

Más de LavanyaJ28

Cs1301  syllabusCs1301  syllabus
Cs1301 syllabusLavanyaJ28
12 vistas2 diapositivas
Ds important questionsDs important questions
Ds important questionsLavanyaJ28
59 vistas14 diapositivas
2 marks- DS using python2 marks- DS using python
2 marks- DS using pythonLavanyaJ28
55 vistas20 diapositivas
HashingHashing
HashingLavanyaJ28
80 vistas34 diapositivas
GraphsGraphs
GraphsLavanyaJ28
24 vistas39 diapositivas
Unit 3   treesUnit 3   trees
Unit 3 treesLavanyaJ28
28 vistas35 diapositivas

Más de LavanyaJ28(16)

Cs1301  syllabusCs1301  syllabus
Cs1301 syllabus
LavanyaJ2812 vistas
Ds important questionsDs important questions
Ds important questions
LavanyaJ2859 vistas
2 marks- DS using python2 marks- DS using python
2 marks- DS using python
LavanyaJ2855 vistas
HashingHashing
Hashing
LavanyaJ2880 vistas
GraphsGraphs
Graphs
LavanyaJ2824 vistas
Unit 3   treesUnit 3   trees
Unit 3 trees
LavanyaJ2828 vistas
Heap types & TreesHeap types & Trees
Heap types & Trees
LavanyaJ286 vistas
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
LavanyaJ289 vistas
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
LavanyaJ2817 vistas
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
LavanyaJ2873 vistas
Stack and queueStack and queue
Stack and queue
LavanyaJ2817 vistas
Unit 1 linked listUnit 1 linked list
Unit 1 linked list
LavanyaJ2831 vistas
Unit 1 Basic concepts to DSUnit 1 Basic concepts to DS
Unit 1 Basic concepts to DS
LavanyaJ287 vistas
Unit 1  array based implementationUnit 1  array based implementation
Unit 1 array based implementation
LavanyaJ2875 vistas
Unit 1   polynomial manipulationUnit 1   polynomial manipulation
Unit 1 polynomial manipulation
LavanyaJ28709 vistas
Unit 1 abstract data typesUnit 1 abstract data types
Unit 1 abstract data types
LavanyaJ28116 vistas

Último(20)

9_DVD_Dynamic_logic_circuits.pdf9_DVD_Dynamic_logic_circuits.pdf
9_DVD_Dynamic_logic_circuits.pdf
Usha Mehta19 vistas
What is Whirling Hygrometer.pdfWhat is Whirling Hygrometer.pdf
What is Whirling Hygrometer.pdf
IIT KHARAGPUR 10 vistas
IEC 61850 Technical Overview.pdfIEC 61850 Technical Overview.pdf
IEC 61850 Technical Overview.pdf
ssusereeea975 vistas
Wire Cutting & StrippingWire Cutting & Stripping
Wire Cutting & Stripping
Iwiss Tools Co.,Ltd6 vistas
SWM L15-L28_drhasan (Part 2).pdfSWM L15-L28_drhasan (Part 2).pdf
SWM L15-L28_drhasan (Part 2).pdf
MahmudHasan74787028 vistas
CHI-SQUARE ( χ2) TESTS.pptxCHI-SQUARE ( χ2) TESTS.pptx
CHI-SQUARE ( χ2) TESTS.pptx
ssusera597c514 vistas
Codes and Conventions.pptxCodes and Conventions.pptx
Codes and Conventions.pptx
IsabellaGraceAnkers6 vistas
IWISS Catalog 2022IWISS Catalog 2022
IWISS Catalog 2022
Iwiss Tools Co.,Ltd23 vistas
Paper 3.pdfPaper 3.pdf
Paper 3.pdf
Javad Kadkhodapour6 vistas
cloud computing-virtualization.pptxcloud computing-virtualization.pptx
cloud computing-virtualization.pptx
RajaulKarim2078 vistas
Investor PresentationInvestor Presentation
Investor Presentation
eser sevinç15 vistas
Sanitary Landfill- SWM.pptxSanitary Landfill- SWM.pptx
Sanitary Landfill- SWM.pptx
Vinod Nejkar5 vistas
SICTECH CORPORATE PRESENTATIONSICTECH CORPORATE PRESENTATION
SICTECH CORPORATE PRESENTATION
SiCtechInduction16 vistas
Dynamics of Hard-Magnetic Soft MaterialsDynamics of Hard-Magnetic Soft Materials
Dynamics of Hard-Magnetic Soft Materials
Shivendra Nandan13 vistas

Searching,sorting

  • 2. SEARCHING  Searching is the process of determining whether or not a given value exists in a data structure or a storage media.  linear search and binary search.
  • 3. LINEAR SEARCH  The linear (or sequential) search algorithm on an array is:  Sequentially scan the array, comparing each array item with the searched value.  If a match is found; return the index of the matched element; otherwise return –1.  Note: linear search can be applied to both sorted and unsorted arrays.
  • 4. FEATURES OF LINEAR SEARCH  It is used for unsorted and unordered small list of elements.  It has a time complexity of O(n), which means the time is linearly dependent on the number of elements, which is not bad, but not that good too.  It has a very simple implementation.
  • 6. APPLICATIONS OF LINEAR SEARCH  Used to find the desired element from the collection of data when the dataset is small  The searching operations is less than 100 items
  • 7. BINARY SEARCH  An algorithm to solve this task looks at the middle of the array or array segment first  If the value looked for is smaller than the value in the middle of the array  Then the second half of the array or array segment can be ignored  This strategy is then applied to the first half of the array or array segment
  • 8. BINARY SEARCH (CONT.,)  If the value looked for is larger than the value in the middle of the array or array segment  Then the first half of the array or array segment can be ignored  This strategy is then applied to the second half of the array or array segment  If the value looked for is at the middle of the array or array segment, then it has been found  If the entire array (or array segment) has been searched in this way without finding the value, then it is not in the array
  • 9. EFFICIENCY OF BINARY SEARCH  The binary search algorithm is extremely fast compared to an algorithm that tries all array elements in order  About half the array is eliminated from consideration right at the start  Then a quarter of the array, then an eighth of the array, and so forth
  • 11. APPLICATIONS OF BINARY SEARCH  The binary search algorithm is used in the libraries of Java, C++, etc  It is used in another additional program like finding the smallest element or largest element in the array  It is used to implement a dictionary
  • 12. SORTING METHODS  Sorting Algorithms are methods of reorganizing a large number of items into some specific order such as highest to lowest, or vice-versa, or even in some alphabetical order.  These algorithms take an input list, processes it (i.e, performs some operations on it) and produce the sorted list.  The most common example we experience every day is sorting clothes or other items on an e- commerce website either by lowest-price to highest, or list by popularity, or some other order.
  • 13. TYPES OF SORTING ALGORITHMS  Shell sort  Heap sort  Radix sort  Bucket sort  Quick sort  Bubble sort  Merge sort  Insertion sort  Selection sort
  • 14. BUBBLE SORT  Bubble sort, also referred to as comparison sort  It is a simple sorting algorithm that repeatedly goes through the list, compares adjacent elements and swaps them if they are in the wrong order.  This is the most simplest algorithm and inefficient at the same time.  https://www.interviewbit.com/tutorial/bubble-sort/
  • 15. SELECTION SORT  Selection sort is a simple comparison-based sorting algorithm  Steps to be followed  Pick the minimum element from the unsorted subarray.  Swap it with the leftmost element of the unsorted subarray.  Now the leftmost element of unsorted subarray becomes a part (rightmost) of sorted subarray and will not be a part of unsorted subarray. https://www.interviewbit.com/tutorial/selection-sort/
  • 16. INSERTION SORT  Insertion sort is the sorting mechanism where the sorted array is built having one item at a time.  The array elements are compared with each other sequentially and then arranged simultaneously in some particular order.  This sort works on the principle of inserting an element at a particular position, hence the name Insertion Sort.  https://www.interviewbit.com/tutorial/insertion-sort- algorithm/
  • 17. SHELL SORT  Shell sort is a highly efficient sorting algorithm and is based on insertion sort algorithm.  This algorithm avoids large shifts as in case of insertion sort, if the smaller value is to the far right and has to be moved to the far left.  Steps to be followed  Step 1 − Initialize the value of h.  Step 2 − Divide the list into smaller sub-list of equal interval h.  Step 3 − Sort these sub-lists using insertion sort.  Step 3 − Repeat until complete list is sorted.  https://www.tutorialspoint.com/data_structures_algorith ms/shell_sort_algorithm.htm
  • 18. RADIX SORT  Radix sort is one of the sorting algorithms used to sort a list of integer numbers in order.  In radix sort algorithm, a list of integer numbers will be sorted based on the digits of individual numbers.  Sorting is performed from least significant digit to the most significant digit.
  • 20. QUICK SORT  It is one of the most efficient sorting algorithms and is based on the splitting of an array (partition) into smaller ones and swapping (exchange) based on the comparison with 'pivot' element selected.  Due to this, quick sort is also called as "Partition Exchange" sort.  Steps to be followed:  Step 1 − Make any element as pivot Step 2 − Partition the array on the basis of pivot Step 3 − Apply quick sort on left partition recursively Step 4 − Apply quick sort on right partition recursively
  • 22. HEAP SORT  Heap sort is a comparison-based sorting technique based on Binary Heap data structure  https://www.youtube.com/watch?v=MtQL_ll5KhQ  There are two kinds of heaps: min-heap and max- heap.  In min-heap parents nodes are smaller than children nodes (the root node is smallest), while in max-heap it is opposite (the root node is largest).
  • 23. MERGE SORT  Merge sort is one of the most efficient sorting algorithms. It works on the principle of Divide and Conquer.  Merge sort repeatedly breaks down a list into several sublists until each sublist consists of a single element and merging those sublists in a manner that results into a sorted list.  https://www.interviewbit.com/tutorial/merge-sort- algorithm/
  • 24. COMPARISON OF SORTING ALOGORITHMS  In a comparison based sorting algorithms, we compare elements of an array with each other to determines which of two elements should occur first in the final sorted list.  All comparison-based sorting algorithms have a complexity lower bound of nlogn.