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

What's hot (20)

Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
3.3 shell sort
3.3 shell sort3.3 shell sort
3.3 shell sort
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
C++ Data Structure PPT.ppt
C++ Data Structure PPT.pptC++ Data Structure PPT.ppt
C++ Data Structure PPT.ppt
 
Heap sort
Heap sortHeap sort
Heap sort
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
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
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Stacks
StacksStacks
Stacks
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Rahat & juhith
Rahat & juhithRahat & juhith
Rahat & juhith
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
 
linked list
linked list linked list
linked list
 

Similar to Searching and sorting

Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
guest2cb109
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs7
 

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
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
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++
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 

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