## Similar to Data structure.pptx

Unit III Version I.pptx
Unit III Version I.pptx
ssuserd602fd

my docoment
my docoment
NeeshanYonzan

search_sort.ppt
search_sort.ppt
SwatiHans10

Sorting
Unit 7 sorting
Unit 7 sorting
Dabbal Singh Mahara

searching in data structure.pptx
searching in data structure.pptx
chouguleamruta24

Sorting algorithms
Sorting algorithms
CHANDAN KUMAR

Searching
Searching
A. S. M. Shafi

searching
searching
A. S. M. Shafi

Unit 6 dsa SEARCHING AND SORTING
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
nikshaikh786

haramaya university

Algo PPT.pdf
Algo PPT.pdf
sheraz7288

Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
Aakash deep Singhal

Sorting
16-sorting.ppt
16-sorting.ppt
18Gunaalanpg

Searching and Sorting Algorithms in Data Structures
Searching and Sorting Algorithms in Data Structures
poongothai11

Searching and sorting by B kirron Reddi
Searching and sorting by B kirron Reddi
B.Kirron Reddi

data structures and algorithms Unit 3
data structures and algorithms Unit 3
infanciaj

Sorting and Its Types
Sorting and Its Types
amberkhan59

### Similar to Data structure.pptx(20)

Unit III Version I.pptx
Unit III Version I.pptx

my docoment
my docoment

search_sort.ppt
search_sort.ppt

Sorting
Sorting

Unit 7 sorting
Unit 7 sorting

searching in data structure.pptx
searching in data structure.pptx

Sorting algorithms
Sorting algorithms

Searching
Searching

searching
searching

Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTING

MODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting

Algo PPT.pdf
Algo PPT.pdf

Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithms

Sorting
Sorting

16-sorting.ppt
16-sorting.ppt

Searching and Sorting Algorithms in Data Structures
Searching and Sorting Algorithms in Data Structures

Searching and sorting by B kirron Reddi
Searching and sorting by B kirron Reddi

data structures and algorithms Unit 3
data structures and algorithms Unit 3

Sorting and Its Types
Sorting and Its Types

## More from SajalFayyaz

Data structure.pptx
Data structure.pptx
SajalFayyaz

Data structure.ppt
Data structure.ppt
SajalFayyaz

data structure 9.pptx
data structure 9.pptx
SajalFayyaz

Data structure 8.pptx
Data structure 8.pptx
SajalFayyaz

Data structure 6.pptx
Data structure 6.pptx
SajalFayyaz

Data Structure.pptx
Data Structure.pptx
SajalFayyaz

Data structure.pptx
Data structure.pptx
SajalFayyaz

data structure3.pptx
data structure3.pptx
SajalFayyaz

Data structure.pptx
Data structure.pptx
SajalFayyaz

Data Structure.pptx
Data Structure.pptx
SajalFayyaz

### More from SajalFayyaz(10)

Data structure.pptx
Data structure.pptx

Data structure.ppt
Data structure.ppt

data structure 9.pptx
data structure 9.pptx

Data structure 8.pptx
Data structure 8.pptx

Data structure 6.pptx
Data structure 6.pptx

Data Structure.pptx
Data Structure.pptx

Data structure.pptx
Data structure.pptx

data structure3.pptx
data structure3.pptx

Data structure.pptx
Data structure.pptx

Data Structure.pptx
Data Structure.pptx

06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
Timothy Spann

aqzctr7x

[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
Vietnam Cotton & Spinning Association

hqfek

A presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
AlessioFois2

Jio cinema Retention & Engagement Strategy.pdf
Jio cinema Retention & Engagement Strategy.pdf
inaya7568

hyfjgavov

How To Control IO Usage using Resource Manager
How To Control IO Usage using Resource Manager
Alireza Kamrani

DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
Timothy Spann

Building a Quantum Computer Neutral Atom.pdf
Building a Quantum Computer Neutral Atom.pdf
cjimenez2581

Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Kaxil Naik

taqyea

bopyb

UofT毕业证如何办理
UofT毕业证如何办理
exukyp

NABLAS株式会社

writing report business partner b1+ .pdf
writing report business partner b1+ .pdf
VyNguyen709676

Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Kiwi Creative

nyvan3

tzu5xla

asyed10

06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM

[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024

A presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing

Jio cinema Retention & Engagement Strategy.pdf
Jio cinema Retention & Engagement Strategy.pdf

How To Control IO Usage using Resource Manager
How To Control IO Usage using Resource Manager

DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines

Building a Quantum Computer Neutral Atom.pdf
Building a Quantum Computer Neutral Atom.pdf

Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...

UofT毕业证如何办理
UofT毕业证如何办理

writing report business partner b1+ .pdf
writing report business partner b1+ .pdf

Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data

### Data structure.pptx

• 1. CS261 DATA STRUCTURES & ALGORITHMS (WEEK-7) LECTURE-13 & 14 INTRODUCTION TO DATA STRUCTURES & ALGORITHMS Lecturer Azka Aziz Azka.a@scocs.edu.pk
• 2. Data structures & Algorithms Lecture#13 Sorting
• 4. Sorting Arranging elements of a list / set in some particular order based on some criteria Purpose of Sorting Bringing set/list elements in some ordered / sequence Categorize elements Group elements with similar characteristics Making searching process very efficient Making merging of sorted elements very efficient
• 5. Typical Sorting orders Ascending Order Arranging elements of a list starting from smallest value to largest value e.g. A to Z, 0 to 9 Descending Order Opposite to asceinding order. It arranges elements of a list starting from largest value to smallest value e.g. Z to A, 9 to 0
• 6. Sorting Algorithms …….. Insertion Sort Say an array (to be sorted) has N elements We split array into two parts; first part contains sorted elements while second part contains elements that are not sorted yet Initially the sorted part contains only one element (as it is sorted obviously) while second part contains N-1 elements Sorted Elements Elements not sorted yet 3 4 6 22 98 35 34 18 11 65
• 7. Insertion sort process Insertion sort is an iterative process During every iteration one element (immediately next to sorted part) is taken from unsorted part and is inserted into sorted part such a way that resultant sorted part remains sorted with one more elements into it Sorted Elements Elements not sorted yet 3 4 6 22 98 35 34 18 11 65 Sorted Elements Elements not sorted yet 3 4 6 22 98 35 34 18 11 65
• 8. Insertion sort process We keep iterating until that part of list containing unsorted elements keeps no element at all At this point resultant list is sorted 6 4 3 22 98 35 34 18 11 65 4 6 3 22 98 35 34 18 11 65 3 4 6 11 18 22 34 35 65 98 3 4 6 22 98 35 34 18 11 65
• 9. Insertion sort … animation animation url: https://en.wikipedia.org/wiki/File:Insertion-sort-example-300px.gif
• 10. Sorting Algorithms …….. Insertion Sort Execute it on board for sample data:
• 11. Insertion Sort … C++ Code int data[MAX]={10, 25, 90, 5, 61, 44, 82, 72, 38, 59}; int n = MAX-1, key, j, i; for(i=1; i<MAX; i++){ key = data[i]; j = i-1; while(j>=0 && data[j] > key){ data[j+1]=data[j]; j--; } data[j+1]=key; } for(i=0; i<MAX;i++){ std::cout<<data[i]<<","; } Execute it on board for given data:
• 12. Insertion sort … characteristics Simple algorithm Efficient for small data set Stable sort (does not swap identical elements) Requires constant external memory (memory beyond data array) For data already sorted / almost sorted array requires O(N) time For reverse sorted array requires O(N2) time
• 13. Bubble sort Say an array (to be sorted) has N elements Starting from bottom of list (Nth element of data list) every element is compared with its neighboring element (immediately above it) sequentially After comparison whichever element is smaller, moves up and other moves down (like lighter air bubbles in water) When one complete round is over, smallest element is at the top of the list
• 14. Bubble sort After one round is over, we start again from bottom of the list and repeat the process Now when N-1 rounds are over, all list elements are sorted
• 15. Bubble sort process … one complete round 12 43 71 20 3 36 24 12 43 71 20 3 24 36 12 43 71 20 3 24 36 12 43 71 3 20 24 36 12 43 3 71 20 24 36 12 3 43 71 20 24 36 3 12 43 71 20 24 36 At the end of complete round, only top element is guaranteed to be the smallest (ascending sort) We have to start over from bottom for another round to get second smallest value at its right place
• 16. Bubble sort process … round 2 3 12 43 71 20 24 36 3 12 43 71 20 24 36 3 12 43 71 20 24 36 3 12 43 20 71 24 36 3 12 20 43 71 24 36 3 12 20 43 71 24 36
• 17. Bubble sort process … round 3 3 12 20 43 71 24 36 3 12 20 43 71 24 36 3 12 20 43 24 71 36 3 12 20 24 43 71 36 3 12 20 24 43 71 36
• 18. Bubble sort process … round 4 3 12 20 24 43 71 36 3 12 20 24 43 36 71 3 12 20 24 36 43 71 3 12 20 24 36 43 71
• 19. Bubble sort process … round 5 3 12 20 24 36 43 71 3 12 20 24 36 43 71 3 12 20 24 36 43 71
• 20. Bubble sort process … round 6 3 12 20 24 36 43 71 3 12 20 24 36 43 71 Final outcome: Sorted Array
• 21. Bubble sort … algorithm
• 22. Bubble sort process … Source code Code it yourself
• 23. Bubble sort … characteristics Simple algorithm Very popular algorithm (very inefficient though) Easier to implement Compares adjacent values only and swaps if necessary (if values are not in order) It is a slow sorting algorithm requiring O(N2) steps to sort an array of values
• 24. Data structures & Algorithms Lecture#14 Sorting(continue)
• 25. Selection Sort … The process 1. We have N elements in the list 2. Find out the smallest value (ascending order) from the list and replace it with 1st element in the list 3. Step 2 keeps the smallest value to its appropriate position while leaving the unsorted list’s size to one less than actual size 4. We can keep repeating steps 2 & 3 until unsorted list size reduces to 1. At that point, whole list is sorted
• 26. Selection sort process … Round 1
• 27. Selection sort process … Round 2
• 28. Selection sort process … Round 3
• 29. Selection sort process … Round 4
• 30. Selection sort process … Round 5
• 31. Selection sort process … Round 5
• 32. Selection sort process … Round 6
• 33. Selection sort process … Round 7
• 34. Selection sort process … Round 8
• 35. Sorting Algorithms …….. Selection Sort Execute it on board for sample data:
• 36. Selection sort sort process … Source code Code it yourself
• 37. Selection sort … characteristics Simple sorting technique It is called Selection Sort as it repeatedly selects the smallest/largest in a sub- array of unsorted elements An item at moves only once Method of choice for files containing very large records and small keys It is a slow sorting algorithm requiring O(N2) steps to sort an array of values in worst case