SlideShare a Scribd company logo
1 of 20
SEARCHING
AND
SORTING
SEARCHING
Searching is a method of finding
a element position from group of
elements in data structure, such as
array, linked list, tree or graph.
LINEAR SEARCH :
 Linear search is also called as sequential search.
 It is a basic and simple search algorithm.
 Linear search starts at the beginning of the list and
checks every element in the list.
 Linear search compares the element with all the other
elements given in the list. If the element is matched it
returns the valve index, else it returns -1.
HOW LINEAR SEARCH WORKS ?
Now, let's see the working of the linear search Algorithm.
let's take an unsorted array. It will be easy to understand the working of
linear search with an example.
Let the elements of array are -
Let the element to be searched is K = 41
Now, start from the first element and compare K with each element of the array.
The value of K, i.e., 41, is not matched with the first element of the
array. So, move to the next element. And follow the same process until
the respective element is found.
Now, the element to be searched is found. So algorithm will return
the index of the element matched.
BINARY SEARCH :
 Binary search is used for searching an element
in a sorted array.
 It is useful when there are large number of
element in an array.
 These searching technique looks for a
particular element by comparing the middle
most element of the collection.
How does Binary search work ?
Now, let’s see the working of the Binary search algorithm.
Let the elements of array are-
Let the element to be searched is, K=56
Now, the element to search is found. So algorithm will return
the index of the element matched.
SORTING :
Sorting is a method of
elements of array in a particular
format either ascending or
descending.
Insertion
sort
Selection
sort
Bubble
sort
Sorting
INSERTION SORTING :
 Insertion sort algorithm arranges a list of
elements.
 In Insertion sort algorithm every iteration
moves an element from unsorted to sorted
portion.
 Until all the elements are sorted in the list.
 This algorithm is not suitable for the large data
set.
How does Insertion sort work ?
SELECTION SORTING :
 In Selection sorting algorithm the first element
in the list is selected and it is compared with all
the remaining elements in the list.
 If any element is smaller than the selected
element then the both are swapped.
 So, the first position is filled with smallest
element.
 This procedure is repeated until the entire list
is sorted.
How does Selection sort work ?
Now, let's see the working of the Selection sort Algorithm.
To understand the working of the Selection sort algorithm, let's take an unsorted array.
Let the elements of array are –
Now, the array is completely sorted.
BUBBLE SORTING :
 Bubble sort is the simplest sorting algorithm . It
always arrange the data in descending order.
 Bubble sort algorithm is not suitable for the
huge data set.
 Bubble sort algorithm compares two items at a
time and swapping them if they are in the
wrong order.
 The iteration is repeated until no swaps are
needed, which means list is sorted.
How does Bubble sort work ?
Now, let’s see the working of the Bubble sort
Algorithm. Suppose we have a list of array of 5 elements
A[5]={40,50,30,20,10}
Iteration-I:
A[0]=40 40 40 40 40 40
A[1]=50 50 50 30 30 30
A[2]=30 30 30 50 20 20
A[3]=20 20 20 20 50 10
A[4]=10 10 10 10 10 50
Iteration-II:
40 30 30 30
30 40 20 20
20 20 40 10
10 10 10 40
50 50 50 50
Iteration-III:
30 20 20
20 30 10
10 10 30
40 40 40
50 50 50
Iteration-IV:
20 10 10
10 20 20
30 30 30
40 40 40
50 50 50
Presented by:
Ch.Sreeja
Ch.Sandeep
K.Bhavani
S.Anil
R.Mounika

More Related Content

What's hot

Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm03446940736
 
Searching in c language
Searching in c languageSearching in c language
Searching in c languageCHANDAN KUMAR
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
Queue data structure
Queue data structureQueue data structure
Queue data structureanooppjoseph
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESSowmya Jyothi
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxShreyasLawand
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)Elavarasi K
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
Array data structure
Array data structureArray data structure
Array data structuremaamir farooq
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data StructureTalha Shaikh
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - NotesOmprakash Chauhan
 

What's hot (20)

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
 
Queues
QueuesQueues
Queues
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptx
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Array data structure
Array data structureArray data structure
Array data structure
 
Linked lists
Linked listsLinked lists
Linked lists
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 
Circular queue
Circular queueCircular queue
Circular queue
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 

Similar to Searching and sorting

MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingnikshaikh786
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sortingguest2cb109
 
What is a Sorting Algorithm Ishank mini project.pptx
What is a Sorting Algorithm Ishank mini project.pptxWhat is a Sorting Algorithm Ishank mini project.pptx
What is a Sorting Algorithm Ishank mini project.pptxSneakyGoblin1
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.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 JYOTHISowmya Jyothi
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxprakashvs7
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingThenmozhiK5
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sortingLavanyaJ28
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdfharamaya university
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structuresunilchute1
 
Sorting types and Algorithms
Sorting types and AlgorithmsSorting types and Algorithms
Sorting types and AlgorithmsAli Khan
 
Selection Sort and Insertion Sort
Selection Sort and Insertion SortSelection Sort and Insertion Sort
Selection Sort and Insertion Sorttamayaoraquel
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sortMay Ann Mendoza
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal searchKrish_ver2
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)Neil Soliven
 

Similar to Searching and sorting (20)

Unit v data structure-converted
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
 
What is a Sorting Algorithm Ishank mini project.pptx
What is a Sorting Algorithm Ishank mini project.pptxWhat is a Sorting Algorithm Ishank mini project.pptx
What is a Sorting Algorithm Ishank mini project.pptx
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.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
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
Ch05 Black Jack
Ch05  Black  JackCh05  Black  Jack
Ch05 Black Jack
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structure
 
Sorting types and Algorithms
Sorting types and AlgorithmsSorting types and Algorithms
Sorting types and Algorithms
 
Chap10
Chap10Chap10
Chap10
 
Selection Sort and Insertion Sort
Selection Sort and Insertion SortSelection Sort and Insertion Sort
Selection Sort and Insertion Sort
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sort
 
searching
searchingsearching
searching
 
arrays in c
arrays in carrays in c
arrays in c
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)
 

Recently uploaded

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Searching and sorting

  • 2. SEARCHING Searching is a method of finding a element position from group of elements in data structure, such as array, linked list, tree or graph.
  • 3.
  • 4. LINEAR SEARCH :  Linear search is also called as sequential search.  It is a basic and simple search algorithm.  Linear search starts at the beginning of the list and checks every element in the list.  Linear search compares the element with all the other elements given in the list. If the element is matched it returns the valve index, else it returns -1.
  • 5. HOW LINEAR SEARCH WORKS ? Now, let's see the working of the linear search Algorithm. let's take an unsorted array. It will be easy to understand the working of linear search with an example. Let the elements of array are - Let the element to be searched is K = 41 Now, start from the first element and compare K with each element of the array. The value of K, i.e., 41, is not matched with the first element of the array. So, move to the next element. And follow the same process until the respective element is found.
  • 6. Now, the element to be searched is found. So algorithm will return the index of the element matched.
  • 7. BINARY SEARCH :  Binary search is used for searching an element in a sorted array.  It is useful when there are large number of element in an array.  These searching technique looks for a particular element by comparing the middle most element of the collection.
  • 8. How does Binary search work ? Now, let’s see the working of the Binary search algorithm. Let the elements of array are- Let the element to be searched is, K=56
  • 9. Now, the element to search is found. So algorithm will return the index of the element matched.
  • 10. SORTING : Sorting is a method of elements of array in a particular format either ascending or descending.
  • 12. INSERTION SORTING :  Insertion sort algorithm arranges a list of elements.  In Insertion sort algorithm every iteration moves an element from unsorted to sorted portion.  Until all the elements are sorted in the list.  This algorithm is not suitable for the large data set.
  • 13. How does Insertion sort work ?
  • 14. SELECTION SORTING :  In Selection sorting algorithm the first element in the list is selected and it is compared with all the remaining elements in the list.  If any element is smaller than the selected element then the both are swapped.  So, the first position is filled with smallest element.  This procedure is repeated until the entire list is sorted.
  • 15. How does Selection sort work ? Now, let's see the working of the Selection sort Algorithm. To understand the working of the Selection sort algorithm, let's take an unsorted array. Let the elements of array are –
  • 16. Now, the array is completely sorted.
  • 17. BUBBLE SORTING :  Bubble sort is the simplest sorting algorithm . It always arrange the data in descending order.  Bubble sort algorithm is not suitable for the huge data set.  Bubble sort algorithm compares two items at a time and swapping them if they are in the wrong order.  The iteration is repeated until no swaps are needed, which means list is sorted.
  • 18. How does Bubble sort work ? Now, let’s see the working of the Bubble sort Algorithm. Suppose we have a list of array of 5 elements A[5]={40,50,30,20,10} Iteration-I: A[0]=40 40 40 40 40 40 A[1]=50 50 50 30 30 30 A[2]=30 30 30 50 20 20 A[3]=20 20 20 20 50 10 A[4]=10 10 10 10 10 50
  • 19. Iteration-II: 40 30 30 30 30 40 20 20 20 20 40 10 10 10 10 40 50 50 50 50 Iteration-III: 30 20 20 20 30 10 10 10 30 40 40 40 50 50 50
  • 20. Iteration-IV: 20 10 10 10 20 20 30 30 30 40 40 40 50 50 50 Presented by: Ch.Sreeja Ch.Sandeep K.Bhavani S.Anil R.Mounika