SlideShare a Scribd company logo
SEARCHING & SORTING
TECHNIQUES
By
Kaushal Shah
LINEAR/SEQUENTIAL
SEARCH
 The simplest technique for searching an
unordered array for a particular element is to
scan each entry in the array in a sequential
manner until the desired element is found.
ALGORITHM:
SEQSEARCH (K, N, X) – Given an unordered array K of N
elements, this algorithm searches the array for a particular
element having value X. The given algorithm returns the index
(position) of the required element if the search is successful,
and returns 0 otherwise.
 
1. [Initialize search]
I  1
2. [Search the array]
Repeat while K[I] ≠ X
I  I + 1
3. [Is the search successful?]
if I > N
then Write (‘UNSUCCESSFUL SEARCH’)
Return (0)
else Write (‘SUCCESSFUL SEARCH’)
Return (I)
BINARY SEARCH
 In this method, the main requirement is
that the array should be arranged in
ascending order.
 Here, the approximate middle element of
the array is located, and its value is
examined.
If its value is too high, then the value of the
middle element of the first half of the array is
examined and the procedure is repeated to the
first half until the required item is found.
If the value is too low, then the value of the
middle element of the second half of the
array is checked and the procedure is repeated.
BINARYSEARCH (K, N, X) – Given an array K of size N arranged in
ascending order, this algorithm searches the array for a given
element whose value is given by X. The variables LOW, MIDDLE and
HIGH denote the lower, middle and upper limits of the search
interval, respectively.
 1. [Initialize]
LOW  1
HIGH  N
2. [Perform search]
Repeat thru step 4 while LOW <= HIGH
3. [Obtain index of midpoint of interval]
MIDDLE  (LOW + HIGH) / 2
4. [Compare]
If X < K [MIDDLE]
then HIGH  MIDDLE – 1
else if X > K[MIDDLE]
then LOW  MIDDLE + 1
else Write (‘SUCCESSFUL SEARCH’)
Return (MIDDLE)
5. [Unsuccessful Search]
Write (‘UNSUCCESSFUL SEARCH’)
Return (0)
BINARY SEARCH: TRACING
A trace of binary search algorithm for the sample array: 
75, 151, 203, 275, 318, 489, 524, 591, 647, and 727
 is given below for X = 275 and X = 727…
Search for X = 275
Iteration LOW HIGH MIDDLE
1 1 10 5
2 1 4 2
3 3 4 3
4 4 4 4
Search for X = 727
Iteration LOW HIGH MIDDLE
1 1 10 5
2 6 10 8
3 9 10 9
4 10 10 10
SELECTION SORT
 One of the easiest ways to sort an array is by
selection.
 In this technique, the smallest element is
interchanged with the first element of the
array.
 Then the second 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.
TRACIN
G
 Here a pass is defined as the search for the next smallest
element. To perform the sort operation, this technique will
require n-1 passes.
 In the above figure, each “encircled” entry denotes the
record with the smallest element selected in a particular
pass. The elements above the “double underline” for a
given pass are those elements that have been placed in order.
SELECTIONSORT (K, N) – Given an array K of size N, this procedure
rearranges the elements of array in ascending order. The variable
PASS represents the pass index and the position of the first element in
the array which is to be examined during a particular pass. The
variable MIN_INDEX shows the position of the smallest element
encountered till now in a particular pass. The variable I is used to
index elements from PASS to N in a given pass.
 1. [Create a loop for n-1 passes]
Repeat thru step 4 for PASS = 1, 2, …, N - 1
2. [Initialize MIN_INDEX to first element of each pass]
MIN_INDEX  PASS
3. [Make a pass and obtain element with smallest value]
Repeat for I = PASS + 1, PASS + 2, …, N
If K[I[ < K[MIN_INDEX]
Then MIN_INDEX  I
4. [Exchange smallest element with first element of each pass]
If MIN_INDEX ≠ PASS
Then K[PASS] ↔ K[MIN_INDEX] (Interchange)
5. [Finished]
Return
BUBBLE SORT
 In this technique, two elements of an array are
interchanged immediately upon discovering
that they are out of order.
 During the first pass, the first and second
elements are compared, say R1 and R2, and if they
are out of order (i.e. R1>R2), then they are
interchanged; this process is repeated for second
and third elements (R2 and R3), then for third and
fourth element (R3 and R4), and so on.
 After first pass, the largest element will be in the
last position.
 This process of comparing consecutive elements
continues until the whole array is sorted.
 Note: The whole process requires at the most n-1
passes. After each pass through the array, a check can
be made to determine whether any interchange
was made during that pass. If no interchange
occurred in a particular pass, then the array must be
sorted and no further passes are required.
TRACIN
G
BUBBLESORT (K, N) – Given an array K of size N, this procedure rearranges the
elements of array in ascending order. PASS and LAST variables are used for the
pass counter and position of the last unsorted element, respectively. The variable I
is used to index the elements of array. The variable EXCHS is used to count the
number of interchanges made on any pass.
1. [Initialize]
LAST  N
2. [Create a loop for the passes]
Repeat thru step 5 for PASS = 1, 2, …, N - 1
3. [Initialize counter for no of interchanges for this pass]
EXCHS  0
4. [Perform pair-wise comparisons on unsorted consecutive elements]
Repeat for I = 1, 2, … LAST-1
If K[I[ > K[I+1]
Then K[I] ↔ K[I+1] (Interchange elements)
EXCHS  EXCHS + 1
5. [Check if any interchange was made on this pass]
If EXCHS = 0
Then Return (Array Sorted; Return early)
Else
LAST  LAST – 1 (Reduce size of unsorted list)
6. [Finished]
Return
INSERTION SORT
 Insertion sort is a simple sorting algorithm: a
comparison sort in which the sorted array (or list)
is built one entry at a time. It is much less efficient
on large lists than more advanced algorithms such
as quicksort, or merge sort.
 Every repetition of insertion sort removes an
element from the input data, inserting it into the
correct position in the already-sorted list, until no
input elements remain.
 Sorting is typically done in-place. The resulting
array after k iterations has the property where the
first k + 1 entries are sorted. In each iteration the
first remaining entry of the input is removed,
inserted into the result at the correct position, thus
extending the result:
BEFORE
AFTER
InsSort(A[1…N]) –
For i = 2 to N
{
temp = A[i]
j = i-1
while(j>0 and temp<A[j])
{
A[j+1] = A[j]
j = j-1
}
A[j+1] = temp
}
ALGORITHM:
Unsorted Array: 3, 7, 4, 9, 5, 2, 6, 1
i temp j
1 7 0 3 7 4 9 5 2 6 1
2 4 1 3 7 7 9 5 2 6 1
3 4 7 9 5 2 6 10
3 9 2 3 4 7 9 5 2 6 1
4 5 3 3 4 7 9 9 2 6 1
3 4 7 7 9 2 6 1
3 4 5 7 9 2 6 1
2
1
5 2 4 3 4 5 7 9 9 6 1
3 4 5 7 7 9 6 1
3 4 5 5 7 9 6 1
3 4 4 5 7 9 6 1
3 3 4 5 7 9 6 1
2 3 4 5 7 9 6 1
3
2
1
0
-1
6 6 5 2 3 4 5 7 9 9 1
2 3 4 5 7 7 9 1
2 3 4 5 6 7 9 1
4
3
7 1 6 2 3 4 5 6 7 9 9
2 3 4 5 6 7 7 9
2 3 4 5 6 6 7 9
2 3 4 5 5 6 7 9
2 3 4 4 5 6 7 9
2 3 3 4 5 6 7 9
2 2 3 4 5 6 7 9
5
4
3
2
1
0
-1

More Related Content

What's hot

Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
District Administration
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
Trupti Agrawal
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
KristinaBorooah
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
Nisha Soms
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Quick Sort
Quick SortQuick Sort
Quick Sort
Shweta Sahu
 
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
03446940736
 
Array data structure
Array data structureArray data structure
Array data structure
maamir farooq
 
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
Afzal Badshah
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
Dr. Sindhia Lingaswamy
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
Huba Akhtar
 
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
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
almaqboli
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
Expression trees
Expression treesExpression trees
Expression trees
Salman Vadsarya
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 

What's hot (20)

Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Sorting
SortingSorting
Sorting
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
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
 
Array data structure
Array data structureArray data structure
Array data structure
 
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 list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
 
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...
 
Linked lists
Linked listsLinked lists
Linked lists
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
 
Expression trees
Expression treesExpression trees
Expression trees
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 

Viewers also liked

Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
Sorting algorithms v01
Sorting algorithms v01Sorting algorithms v01
Sorting algorithms v01
Dusan Vuckovic
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Vicente García Díaz
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Trupti Agrawal
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
Muhammad Hammad Waseem
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Mohammed Hussein
 

Viewers also liked (6)

Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 
Sorting algorithms v01
Sorting algorithms v01Sorting algorithms v01
Sorting algorithms v01
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 

Similar to Data Structures - Searching & sorting

sorting1.pptx
sorting1.pptxsorting1.pptx
sorting1.pptx
AJAYVISHALRP
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
maamir farooq
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
kalyanineve
 
358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14
sumitbardhan
 
DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024
RUHULAMINHAZARIKA
 
Sorting
SortingSorting
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptx
ParagAhir1
 
Sorting
SortingSorting
Sorting
Zaid Shabbir
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
maamir farooq
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
chouguleamruta24
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)eShikshak
 
Searching and Sorting Algorithms in Data Structures
Searching and Sorting Algorithms  in Data StructuresSearching and Sorting Algorithms  in Data Structures
Searching and Sorting Algorithms in Data Structures
poongothai11
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sortingFadhil Ismail
 
Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
Tribhuvan University
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsAakash deep Singhal
 
Lec 03 - Sorting.pptx
Lec 03 - Sorting.pptxLec 03 - Sorting.pptx
Lec 03 - Sorting.pptx
Dr. Shaukat Wasi
 
Searching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresSearching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structures
PRIANKA R
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
Hossain Md Shakhawat
 

Similar to Data Structures - Searching & sorting (20)

sorting1.pptx
sorting1.pptxsorting1.pptx
sorting1.pptx
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
Unit6 C
Unit6 C Unit6 C
Unit6 C
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
 
358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14
 
DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024
 
Sorting
SortingSorting
Sorting
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptx
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
Searching and Sorting Algorithms in Data Structures
Searching and Sorting Algorithms  in Data StructuresSearching and Sorting Algorithms  in Data Structures
Searching and Sorting Algorithms in Data Structures
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
 
Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
 
Lec 03 - Sorting.pptx
Lec 03 - Sorting.pptxLec 03 - Sorting.pptx
Lec 03 - Sorting.pptx
 
Searching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresSearching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structures
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
 

Recently uploaded

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

Data Structures - Searching & sorting

  • 2. LINEAR/SEQUENTIAL SEARCH  The simplest technique for searching an unordered array for a particular element is to scan each entry in the array in a sequential manner until the desired element is found.
  • 3. ALGORITHM: SEQSEARCH (K, N, X) – Given an unordered array K of N elements, this algorithm searches the array for a particular element having value X. The given algorithm returns the index (position) of the required element if the search is successful, and returns 0 otherwise.   1. [Initialize search] I  1 2. [Search the array] Repeat while K[I] ≠ X I  I + 1 3. [Is the search successful?] if I > N then Write (‘UNSUCCESSFUL SEARCH’) Return (0) else Write (‘SUCCESSFUL SEARCH’) Return (I)
  • 4. BINARY SEARCH  In this method, the main requirement is that the array should be arranged in ascending order.  Here, the approximate middle element of the array is located, and its value is examined. If its value is too high, then the value of the middle element of the first half of the array is examined and the procedure is repeated to the first half until the required item is found. If the value is too low, then the value of the middle element of the second half of the array is checked and the procedure is repeated.
  • 5. BINARYSEARCH (K, N, X) – Given an array K of size N arranged in ascending order, this algorithm searches the array for a given element whose value is given by X. The variables LOW, MIDDLE and HIGH denote the lower, middle and upper limits of the search interval, respectively.  1. [Initialize] LOW  1 HIGH  N 2. [Perform search] Repeat thru step 4 while LOW <= HIGH 3. [Obtain index of midpoint of interval] MIDDLE  (LOW + HIGH) / 2 4. [Compare] If X < K [MIDDLE] then HIGH  MIDDLE – 1 else if X > K[MIDDLE] then LOW  MIDDLE + 1 else Write (‘SUCCESSFUL SEARCH’) Return (MIDDLE) 5. [Unsuccessful Search] Write (‘UNSUCCESSFUL SEARCH’) Return (0)
  • 6. BINARY SEARCH: TRACING A trace of binary search algorithm for the sample array:  75, 151, 203, 275, 318, 489, 524, 591, 647, and 727  is given below for X = 275 and X = 727… Search for X = 275 Iteration LOW HIGH MIDDLE 1 1 10 5 2 1 4 2 3 3 4 3 4 4 4 4 Search for X = 727 Iteration LOW HIGH MIDDLE 1 1 10 5 2 6 10 8 3 9 10 9 4 10 10 10
  • 7. SELECTION SORT  One of the easiest ways to sort an array is by selection.  In this technique, the smallest element is interchanged with the first element of the array.  Then the second 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.
  • 8. TRACIN G  Here a pass is defined as the search for the next smallest element. To perform the sort operation, this technique will require n-1 passes.  In the above figure, each “encircled” entry denotes the record with the smallest element selected in a particular pass. The elements above the “double underline” for a given pass are those elements that have been placed in order.
  • 9. SELECTIONSORT (K, N) – Given an array K of size N, this procedure rearranges the elements of array in ascending order. The variable PASS represents the pass index and the position of the first element in the array which is to be examined during a particular pass. The variable MIN_INDEX shows the position of the smallest element encountered till now in a particular pass. The variable I is used to index elements from PASS to N in a given pass.  1. [Create a loop for n-1 passes] Repeat thru step 4 for PASS = 1, 2, …, N - 1 2. [Initialize MIN_INDEX to first element of each pass] MIN_INDEX  PASS 3. [Make a pass and obtain element with smallest value] Repeat for I = PASS + 1, PASS + 2, …, N If K[I[ < K[MIN_INDEX] Then MIN_INDEX  I 4. [Exchange smallest element with first element of each pass] If MIN_INDEX ≠ PASS Then K[PASS] ↔ K[MIN_INDEX] (Interchange) 5. [Finished] Return
  • 10. BUBBLE SORT  In this technique, two elements of an array are interchanged immediately upon discovering that they are out of order.  During the first pass, the first and second elements are compared, say R1 and R2, and if they are out of order (i.e. R1>R2), then they are interchanged; this process is repeated for second and third elements (R2 and R3), then for third and fourth element (R3 and R4), and so on.  After first pass, the largest element will be in the last position.  This process of comparing consecutive elements continues until the whole array is sorted.
  • 11.  Note: The whole process requires at the most n-1 passes. After each pass through the array, a check can be made to determine whether any interchange was made during that pass. If no interchange occurred in a particular pass, then the array must be sorted and no further passes are required. TRACIN G
  • 12. BUBBLESORT (K, N) – Given an array K of size N, this procedure rearranges the elements of array in ascending order. PASS and LAST variables are used for the pass counter and position of the last unsorted element, respectively. The variable I is used to index the elements of array. The variable EXCHS is used to count the number of interchanges made on any pass. 1. [Initialize] LAST  N 2. [Create a loop for the passes] Repeat thru step 5 for PASS = 1, 2, …, N - 1 3. [Initialize counter for no of interchanges for this pass] EXCHS  0 4. [Perform pair-wise comparisons on unsorted consecutive elements] Repeat for I = 1, 2, … LAST-1 If K[I[ > K[I+1] Then K[I] ↔ K[I+1] (Interchange elements) EXCHS  EXCHS + 1 5. [Check if any interchange was made on this pass] If EXCHS = 0 Then Return (Array Sorted; Return early) Else LAST  LAST – 1 (Reduce size of unsorted list) 6. [Finished] Return
  • 13. INSERTION SORT  Insertion sort is a simple sorting algorithm: a comparison sort in which the sorted array (or list) is built one entry at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, or merge sort.  Every repetition of insertion sort removes an element from the input data, inserting it into the correct position in the already-sorted list, until no input elements remain.
  • 14.  Sorting is typically done in-place. The resulting array after k iterations has the property where the first k + 1 entries are sorted. In each iteration the first remaining entry of the input is removed, inserted into the result at the correct position, thus extending the result: BEFORE AFTER
  • 15.
  • 16. InsSort(A[1…N]) – For i = 2 to N { temp = A[i] j = i-1 while(j>0 and temp<A[j]) { A[j+1] = A[j] j = j-1 } A[j+1] = temp } ALGORITHM:
  • 17. Unsorted Array: 3, 7, 4, 9, 5, 2, 6, 1 i temp j 1 7 0 3 7 4 9 5 2 6 1 2 4 1 3 7 7 9 5 2 6 1 3 4 7 9 5 2 6 10 3 9 2 3 4 7 9 5 2 6 1 4 5 3 3 4 7 9 9 2 6 1 3 4 7 7 9 2 6 1 3 4 5 7 9 2 6 1 2 1 5 2 4 3 4 5 7 9 9 6 1 3 4 5 7 7 9 6 1 3 4 5 5 7 9 6 1 3 4 4 5 7 9 6 1 3 3 4 5 7 9 6 1 2 3 4 5 7 9 6 1 3 2 1 0 -1 6 6 5 2 3 4 5 7 9 9 1 2 3 4 5 7 7 9 1 2 3 4 5 6 7 9 1 4 3 7 1 6 2 3 4 5 6 7 9 9 2 3 4 5 6 7 7 9 2 3 4 5 6 6 7 9 2 3 4 5 5 6 7 9 2 3 4 4 5 6 7 9 2 3 3 4 5 6 7 9 2 2 3 4 5 6 7 9 5 4 3 2 1 0 -1