SlideShare a Scribd company logo
Table of contents
1
Searching
Sequential / Linear Search 2
Binary Search 3
Sorting
Selection Sort 4
Radix Sort 5 – 8
Quick Sort 9 – 12
Insertion Sort 13 – 14
Bubble Sort 15 - 17
1. i = 0
2. Read value of key to be searched.
3. if k( i ) == key
Display "Recode found at position"
go to step 7
4. increment k
5. if i < n
go to step 3
6. Display "No match found!"
7. Stop
Algorithm of Sequential / Linear Search
2
Binary Search
1. Accept Key
2. Top = 0, Bottom = n-1
3. m=(Top + Bottom) / 2
4. if (key==k(mid))
Display Record found at position mid.
go to step 8
5. if key< k(mid)
else
top=m+1
6. if (top<=bottom)
go to step 3
7. Display Record Found
8. Stop
3
Algorithm of Selection Sort
1. Start
2. Pass = 1
3. i = 0
4. j = i+1
5. if x[i] > x[j]
interchange x[i] and x[i+1]
6. j = j+1
7. if j < = n-1
Go to step 5
8. Pass = Pass + 1
9. if pass < = n-1
then i = i+1 and go to step 4
10. Stop
4
Algorithm of Radix Sort
This method is based on the value of actual digits in each position of the numbers being sorted.
Example: 132 has 2 in the unit's position , 3 in the ten's position and 1 in the hundred's position.
Start comparing from the most significant digits and move towards the last digit as long as the
digits are equal. if there is no match, the number with digit is the greater number.
This method used the above techniques.
1. The number are partitioned into ten groups based on their unit's digit.
2. Elements within individual groups are sorted on ten's digit.
3. The process is repeated till each sub group has been subdivided an most significant digit.
in the above method, a lot of partitions have to be created which complexity.
Comparing two numbers of equal length
5
Inputs Packets
0 1 2 3 4 5 6 7 8 9
612 612
912 912
796 796
412 412
432 432
100 100
206 206
First Pass
Example of Radix Sort
Example: 612, 912, 796, 412, 432, 100, 206
6
Inputs Packets
0 1 2 3 4 5 6 7 8 9
100 100
612 612
912 912
412 412
432 432
796 796
206 206
Second Pass
7
Inputs Packets
0 1 2 3 4 5 6 7 8 9
100 100
206 206
612 612
912 912
412 412
432 432
796 796
Third Pass
Sorted list : 100, 206, 412, 432, 612, 796, 912
8
1. Start
2. A is an array of 'n' elements.
3. lb=0, ub = n-1 ( ub → upper bound, lb → lower bound)
4. if ( lb < ub ) i.e. if the array can be partitioned.
j = partition (A, lb, j-1) // j is the pivot position
Quicksort (A, lb, j-1) // sort the first partition
Quicksort (A, j+1, ub ) // sort the second partition
5. Stop
Algorithm of Quick Sort
9
Pivot position = up
First sub array = 23 7 48 32 18
Second partition = 82 62
[55] 7 48 32 18 23 82 62
Partition I Partition II
Pivot = A [lb] = 55
Move dn (82 is greater than pivot so stop
incrementing dn)
Move up (23 is less than pivot so stop
decrementing up)
Interchange A[dn] and A[up]
updn
Example of Quick Sort
[55] 7 48 32 18 23 82 62
[55] 7 48 32 18 23 82 62
23 7 48 32 18 [55] 82 62
Example : 55, 7, 48, 32, 18, 23, 82, 62
dn
dn
dn
up
up
up
10
1. down = lb
2. up = ub
3. pivot = A[lb]
4. While (A[down] < = pivot && down < ub)
down ++
5. while (A[up] > pivot && up > lb)
up --
6. if (down < up)
interchange A [down] and A [up]
go to step 4
7. interchange A[up] and pivot
8. return up
9. Stop
Algorithm of Quick Sort (Partitions)
11
[23] 7 48 32 18
[23] 7 48 32 18
[23] 7 48 32 18
[23] 7 18 32 48
[23] 7 18 32 48
18 7 [23] 32 48
[23] 7 18 32 48
Partition I Partition II
Pivot = A [lb] = 23
Move dn (48 is greater than pivot - 23
so stop incrementing dn)
Move up (18 is less than pivot - 23
so stop decrementing up)
Interchange A[dn] and A[up]
Move dn
Move up
Interchange A[up] and pivot
updn
dn
dn
dn
dn
dn
up
up
up
up
dn up
up
Example of Quick Sort (Partitions)
Example: 55, 7, 48, 32, 18, 23, 82, 62
12
Algorithm of Insertions Sort
• In the first pass the 1st element 7 is compared with 0th element 15, 7 is inserted
at 0th place, since 7 is smaller than 15. The 0th element. i.e. 15 is moved one
position to the right.
• In the second pass, the 2nd element 22 is compared with 0th element 7. hence 7
is smaller than 22 then no change. Then 2nd element 22 is compared with 1st
element 15 and again no change.
• In the third pass 3rd element is compared with 0th element. As 3 is smaller than
7, 3 is inserted at 0th place and all the elements from 0th till 2nd position are
moved to right by one position.
• This procedure is repeated for all the element of array. In the last pass array gets
sorted.
13
Example of Insertions Sort
15 7 22 3 14 2
7 15 22 3 14 2
7 15 22 3 14 2
7 15 22 3 14 2
3 7 15 22 14 2
3 7 15 22 14 2
3 7 15 22 14 2
3 7 15 22 14 2
3 7 15 22 14 2
3 7 14 15 22 2
3 7 14 15 22 2
2 3 7 14 15 22
First pass
Second pass
Third pass
Fifth pass
Sorted array
Fourth pass
14
Algorithm of Bubble Sort
1. Start
2. Pass = 1
3. i = 0
4. If x[i] > x(i + 1)
interchange x[i] and x[I + 1]
5. i = i + 1
6. If i<=n-1- Pass
go to Step 4
7. Pass =Pass + 1
8. If Pass < = n-1
go to Step 3
9. Stop
15
Example of Bubble Sort
Example: 25, 37, 12, 48, 57, 33
25 25 25 25 25 25
37 37 12 12 12 12
12 12 37 37 37 37
48 48 48 48 48 48
57 57 57 57 57 33
33 33 33 33 33 57
12 12 12 12 12
25 25 25 25 25
37 37 37 37 37
48 48 48 48 33
33 33 33 33 48
57 57 57 57 57
Pass 1 Pass 2
16
Example of Bubble Sort
Example: 25, 37, 12, 48, 57, 33
12 12 12 12
25 25 25 25
37 37 37 33
33 33 33 37
48 48 48 48
57 57 57 57
12 12 12
25 25 25
33 33 33
37 37 37
48 48 48
57 57 57
Pass 3 Pass 4
12 12
25 25
33 33
37 37
48 48
57 57
Pass 5
17
Ad

More Related Content

What's hot (19)

Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 
Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)
Adam Mukharil Bachtiar
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
Fajar Baskoro
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
Lovely Professional University
 
Queue
QueueQueue
Queue
Muhammad Farhan
 
Circular queue
Circular queueCircular queue
Circular queue
Lovely Professional University
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
Kumar
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Shakila Mahjabin
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
greatqadirgee4u
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
Stack
StackStack
Stack
Ghaffar Khan
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
Toseef Hasan
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
Dipayan Sarkar
 
Stack application
Stack applicationStack application
Stack application
Student
 

Similar to Sorting and Searching - Data Structure - Notes (20)

Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
kalyanineve
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
Krish_ver2
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for print
Abdii Rashid
 
Data Structure and algorithms for software
Data Structure and algorithms for softwareData Structure and algorithms for software
Data Structure and algorithms for software
ManishShukla712917
 
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
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
RenalthaPujaBagaskar
 
14-sorting (3).ppt
14-sorting (3).ppt14-sorting (3).ppt
14-sorting (3).ppt
yasser3omr
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
SushantRaj25
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
KamalAlbashiri
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
ssuserd602fd
 
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
denveramoson
 
Weak 11-12 Sorting update.pptxbhjiiuuuuu
Weak 11-12 Sorting update.pptxbhjiiuuuuuWeak 11-12 Sorting update.pptxbhjiiuuuuu
Weak 11-12 Sorting update.pptxbhjiiuuuuu
baloch4551701
 
Sorting
SortingSorting
Sorting
Zaid Shabbir
 
Sorting
SortingSorting
Sorting
Zaid Shabbir
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
pppepito86
 
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
Tosin Amuda
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
Krish_ver2
 
sorting.pptx
sorting.pptxsorting.pptx
sorting.pptx
DrRanjeetKumar51721
 
All Searching and Sorting Techniques in Data Structures
All Searching and Sorting Techniques in Data StructuresAll Searching and Sorting Techniques in Data Structures
All Searching and Sorting Techniques in Data Structures
sonalishinge2015
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Radhika Talaviya
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
Krish_ver2
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for print
Abdii Rashid
 
Data Structure and algorithms for software
Data Structure and algorithms for softwareData Structure and algorithms for software
Data Structure and algorithms for software
ManishShukla712917
 
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
 
14-sorting (3).ppt
14-sorting (3).ppt14-sorting (3).ppt
14-sorting (3).ppt
yasser3omr
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
ssuserd602fd
 
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
denveramoson
 
Weak 11-12 Sorting update.pptxbhjiiuuuuu
Weak 11-12 Sorting update.pptxbhjiiuuuuuWeak 11-12 Sorting update.pptxbhjiiuuuuu
Weak 11-12 Sorting update.pptxbhjiiuuuuu
baloch4551701
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
pppepito86
 
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
Tosin Amuda
 
All Searching and Sorting Techniques in Data Structures
All Searching and Sorting Techniques in Data StructuresAll Searching and Sorting Techniques in Data Structures
All Searching and Sorting Techniques in Data Structures
sonalishinge2015
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Radhika Talaviya
 
Ad

More from Omprakash Chauhan (17)

Introduction to curve
Introduction to curveIntroduction to curve
Introduction to curve
Omprakash Chauhan
 
Basic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - NotesBasic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - Notes
Omprakash Chauhan
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - Notes
Omprakash Chauhan
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
Omprakash Chauhan
 
Basic of computer graphic - Computer Graphic - Notes
Basic of computer graphic - Computer Graphic - NotesBasic of computer graphic - Computer Graphic - Notes
Basic of computer graphic - Computer Graphic - Notes
Omprakash Chauhan
 
E-R Diagram of College Management Systems
E-R Diagram of College Management SystemsE-R Diagram of College Management Systems
E-R Diagram of College Management Systems
Omprakash Chauhan
 
Burglar Alarm Micro Project
Burglar Alarm Micro ProjectBurglar Alarm Micro Project
Burglar Alarm Micro Project
Omprakash Chauhan
 
Simple Calculator Flowchart
Simple Calculator FlowchartSimple Calculator Flowchart
Simple Calculator Flowchart
Omprakash Chauhan
 
Full Wave Rectifier (FWR) Microproject
Full Wave Rectifier (FWR) MicroprojectFull Wave Rectifier (FWR) Microproject
Full Wave Rectifier (FWR) Microproject
Omprakash Chauhan
 
A detailed study of guidelines required for presentation skills
A detailed study of guidelines required for presentation skillsA detailed study of guidelines required for presentation skills
A detailed study of guidelines required for presentation skills
Omprakash Chauhan
 
Fractional-horsepower Motor Report
Fractional-horsepower Motor ReportFractional-horsepower Motor Report
Fractional-horsepower Motor Report
Omprakash Chauhan
 
motherboard electronic components and their functions
motherboard electronic components and their functionsmotherboard electronic components and their functions
motherboard electronic components and their functions
Omprakash Chauhan
 
How To Area of irregular shape Using Integration Method.
How To Area of irregular shape Using Integration Method.How To Area of irregular shape Using Integration Method.
How To Area of irregular shape Using Integration Method.
Omprakash Chauhan
 
Process of ionization
Process of ionizationProcess of ionization
Process of ionization
Omprakash Chauhan
 
Welcome to the world of ionization
Welcome to the world of ionization Welcome to the world of ionization
Welcome to the world of ionization
Omprakash Chauhan
 
Printer
PrinterPrinter
Printer
Omprakash Chauhan
 
System of units
System of unitsSystem of units
System of units
Omprakash Chauhan
 
Basic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - NotesBasic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - Notes
Omprakash Chauhan
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - Notes
Omprakash Chauhan
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
Omprakash Chauhan
 
Basic of computer graphic - Computer Graphic - Notes
Basic of computer graphic - Computer Graphic - NotesBasic of computer graphic - Computer Graphic - Notes
Basic of computer graphic - Computer Graphic - Notes
Omprakash Chauhan
 
E-R Diagram of College Management Systems
E-R Diagram of College Management SystemsE-R Diagram of College Management Systems
E-R Diagram of College Management Systems
Omprakash Chauhan
 
Full Wave Rectifier (FWR) Microproject
Full Wave Rectifier (FWR) MicroprojectFull Wave Rectifier (FWR) Microproject
Full Wave Rectifier (FWR) Microproject
Omprakash Chauhan
 
A detailed study of guidelines required for presentation skills
A detailed study of guidelines required for presentation skillsA detailed study of guidelines required for presentation skills
A detailed study of guidelines required for presentation skills
Omprakash Chauhan
 
Fractional-horsepower Motor Report
Fractional-horsepower Motor ReportFractional-horsepower Motor Report
Fractional-horsepower Motor Report
Omprakash Chauhan
 
motherboard electronic components and their functions
motherboard electronic components and their functionsmotherboard electronic components and their functions
motherboard electronic components and their functions
Omprakash Chauhan
 
How To Area of irregular shape Using Integration Method.
How To Area of irregular shape Using Integration Method.How To Area of irregular shape Using Integration Method.
How To Area of irregular shape Using Integration Method.
Omprakash Chauhan
 
Welcome to the world of ionization
Welcome to the world of ionization Welcome to the world of ionization
Welcome to the world of ionization
Omprakash Chauhan
 
Ad

Recently uploaded (20)

introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 

Sorting and Searching - Data Structure - Notes

  • 1. Table of contents 1 Searching Sequential / Linear Search 2 Binary Search 3 Sorting Selection Sort 4 Radix Sort 5 – 8 Quick Sort 9 – 12 Insertion Sort 13 – 14 Bubble Sort 15 - 17
  • 2. 1. i = 0 2. Read value of key to be searched. 3. if k( i ) == key Display "Recode found at position" go to step 7 4. increment k 5. if i < n go to step 3 6. Display "No match found!" 7. Stop Algorithm of Sequential / Linear Search 2
  • 3. Binary Search 1. Accept Key 2. Top = 0, Bottom = n-1 3. m=(Top + Bottom) / 2 4. if (key==k(mid)) Display Record found at position mid. go to step 8 5. if key< k(mid) else top=m+1 6. if (top<=bottom) go to step 3 7. Display Record Found 8. Stop 3
  • 4. Algorithm of Selection Sort 1. Start 2. Pass = 1 3. i = 0 4. j = i+1 5. if x[i] > x[j] interchange x[i] and x[i+1] 6. j = j+1 7. if j < = n-1 Go to step 5 8. Pass = Pass + 1 9. if pass < = n-1 then i = i+1 and go to step 4 10. Stop 4
  • 5. Algorithm of Radix Sort This method is based on the value of actual digits in each position of the numbers being sorted. Example: 132 has 2 in the unit's position , 3 in the ten's position and 1 in the hundred's position. Start comparing from the most significant digits and move towards the last digit as long as the digits are equal. if there is no match, the number with digit is the greater number. This method used the above techniques. 1. The number are partitioned into ten groups based on their unit's digit. 2. Elements within individual groups are sorted on ten's digit. 3. The process is repeated till each sub group has been subdivided an most significant digit. in the above method, a lot of partitions have to be created which complexity. Comparing two numbers of equal length 5
  • 6. Inputs Packets 0 1 2 3 4 5 6 7 8 9 612 612 912 912 796 796 412 412 432 432 100 100 206 206 First Pass Example of Radix Sort Example: 612, 912, 796, 412, 432, 100, 206 6
  • 7. Inputs Packets 0 1 2 3 4 5 6 7 8 9 100 100 612 612 912 912 412 412 432 432 796 796 206 206 Second Pass 7
  • 8. Inputs Packets 0 1 2 3 4 5 6 7 8 9 100 100 206 206 612 612 912 912 412 412 432 432 796 796 Third Pass Sorted list : 100, 206, 412, 432, 612, 796, 912 8
  • 9. 1. Start 2. A is an array of 'n' elements. 3. lb=0, ub = n-1 ( ub → upper bound, lb → lower bound) 4. if ( lb < ub ) i.e. if the array can be partitioned. j = partition (A, lb, j-1) // j is the pivot position Quicksort (A, lb, j-1) // sort the first partition Quicksort (A, j+1, ub ) // sort the second partition 5. Stop Algorithm of Quick Sort 9
  • 10. Pivot position = up First sub array = 23 7 48 32 18 Second partition = 82 62 [55] 7 48 32 18 23 82 62 Partition I Partition II Pivot = A [lb] = 55 Move dn (82 is greater than pivot so stop incrementing dn) Move up (23 is less than pivot so stop decrementing up) Interchange A[dn] and A[up] updn Example of Quick Sort [55] 7 48 32 18 23 82 62 [55] 7 48 32 18 23 82 62 23 7 48 32 18 [55] 82 62 Example : 55, 7, 48, 32, 18, 23, 82, 62 dn dn dn up up up 10
  • 11. 1. down = lb 2. up = ub 3. pivot = A[lb] 4. While (A[down] < = pivot && down < ub) down ++ 5. while (A[up] > pivot && up > lb) up -- 6. if (down < up) interchange A [down] and A [up] go to step 4 7. interchange A[up] and pivot 8. return up 9. Stop Algorithm of Quick Sort (Partitions) 11
  • 12. [23] 7 48 32 18 [23] 7 48 32 18 [23] 7 48 32 18 [23] 7 18 32 48 [23] 7 18 32 48 18 7 [23] 32 48 [23] 7 18 32 48 Partition I Partition II Pivot = A [lb] = 23 Move dn (48 is greater than pivot - 23 so stop incrementing dn) Move up (18 is less than pivot - 23 so stop decrementing up) Interchange A[dn] and A[up] Move dn Move up Interchange A[up] and pivot updn dn dn dn dn dn up up up up dn up up Example of Quick Sort (Partitions) Example: 55, 7, 48, 32, 18, 23, 82, 62 12
  • 13. Algorithm of Insertions Sort • In the first pass the 1st element 7 is compared with 0th element 15, 7 is inserted at 0th place, since 7 is smaller than 15. The 0th element. i.e. 15 is moved one position to the right. • In the second pass, the 2nd element 22 is compared with 0th element 7. hence 7 is smaller than 22 then no change. Then 2nd element 22 is compared with 1st element 15 and again no change. • In the third pass 3rd element is compared with 0th element. As 3 is smaller than 7, 3 is inserted at 0th place and all the elements from 0th till 2nd position are moved to right by one position. • This procedure is repeated for all the element of array. In the last pass array gets sorted. 13
  • 14. Example of Insertions Sort 15 7 22 3 14 2 7 15 22 3 14 2 7 15 22 3 14 2 7 15 22 3 14 2 3 7 15 22 14 2 3 7 15 22 14 2 3 7 15 22 14 2 3 7 15 22 14 2 3 7 15 22 14 2 3 7 14 15 22 2 3 7 14 15 22 2 2 3 7 14 15 22 First pass Second pass Third pass Fifth pass Sorted array Fourth pass 14
  • 15. Algorithm of Bubble Sort 1. Start 2. Pass = 1 3. i = 0 4. If x[i] > x(i + 1) interchange x[i] and x[I + 1] 5. i = i + 1 6. If i<=n-1- Pass go to Step 4 7. Pass =Pass + 1 8. If Pass < = n-1 go to Step 3 9. Stop 15
  • 16. Example of Bubble Sort Example: 25, 37, 12, 48, 57, 33 25 25 25 25 25 25 37 37 12 12 12 12 12 12 37 37 37 37 48 48 48 48 48 48 57 57 57 57 57 33 33 33 33 33 33 57 12 12 12 12 12 25 25 25 25 25 37 37 37 37 37 48 48 48 48 33 33 33 33 33 48 57 57 57 57 57 Pass 1 Pass 2 16
  • 17. Example of Bubble Sort Example: 25, 37, 12, 48, 57, 33 12 12 12 12 25 25 25 25 37 37 37 33 33 33 33 37 48 48 48 48 57 57 57 57 12 12 12 25 25 25 33 33 33 37 37 37 48 48 48 57 57 57 Pass 3 Pass 4 12 12 25 25 33 33 37 37 48 48 57 57 Pass 5 17