SlideShare a Scribd company logo
Data Structure
Software Engineering
Radix sort
Radix sort is a non-comparative integer sorting
algorithm that sorts data with integer keys by
grouping keys by the individual digits which share
the same significant position and value.
Radix sort is one of the linear sorting algorithms for
integers.
Example
 The Original unsorted list
170, 045, 075, 090, 002, 024, 802, 066
 Sorting by least significant digit (1s place) gives:
170, 90, 802, 2, 24, 45, 75, 66
Notice that we keep 802 before 2, because 802 occurred before 2 in the original
and similarly for pairs 170 & 90 and 45 & 75.
 Sorting by next digit (10s place) gives:
802, 2, 24, 45, 66, 170, 75, 90
Notice that 802 again comes before 2 as 802 comes before 2 in the previous list.
 Sorting by most significant digit (100s place) gives:
2, 24, 45, 66, 75, 90, 170, 802
First counting
 The first counting pass starts on the least significant digit of
each key, producing an array of bucket sizes:
2 (bucket size for digits of 0: 170, 090)
2 (bucket size for digits of 2: 002, 802)
1 (bucket size for digits of 4: 024)
2 (bucket size for digits of 5: 045, 075)
1 (bucket size for digits of 6: 066)
Second counting
 A second counting pass on the next more significant digit of
each key will produce an array of bucket sizes:
2 (bucket size for digits of 0: 002, 802)
1 (bucket size for digits of 2: 024)
1 (bucket size for digits of 4: 045)
1 (bucket size for digits of 6: 066)
2 (bucket size for digits of 7: 170, 075)
1 (bucket size for digits of 9: 090)
Third and Final counting
 A third and final counting pass on the most significant digit of
each key will produce an array of bucket sizes:
6 (bucket size for digits of 0: 002, 024, 045, 066, 075, 090)
1 (bucket size for digits of 1: 170)
1 (bucket size for digits of 8: 802)
Alogrithm
 RADIX-SORT (A,d)
1. for I = 1 to d
2. use a stable sort to sort array A on digit i
Disadvantages
Still, there are some tradeoffs for Radix Sort that can
make it less preferable than other sorts.
The speed of Radix Sort largely depends on the inner
basic operations, and if the operations are not efficient
enough, Radix Sort can be slower than some other
algorithms such as Quick Sort and Merge Sort.
These operations include the insert and delete functions
of the sublists and the process of isolating the digit you
want.
Bucket sort
Bucket sort, or bin sort, is a sorting algorithm that
works by partitioning an array into a number
of buckets.
Bucket Sort is a sorting method that subdivides the
given data into various buckets depending on certain
characteristic order, thus partially sorting them in the
first go.
Example
 The Elements are distributed among bins
 The Then, elements are sorted within each bin
The Algorithm of Bucket-SORT
BUCKET SORT (A)
1. Let B[0..n – 1] be a new array
2. N = A.length
3. For I = 0 to n – 1
4. make B[i] an empty list
5. For I = 1 to n
6. insert A[i] into list B[[nA[i]]]
7. For I = 0 to n – 1
8. sort list B[i] with insertion sort
9. Concatenate the lists B[0], B[1],..B[n-1] together in order.
Quick sort
 Quick sort, or partition-exchange sort, is a sorting algorithm
developed by Tony Hoare that, on average, makes O(n log
n) comparisons to sort n items. Quick sort is a very efficient
sorting algorithm invented by C.A.R. Hoare.
 It has two phases:
• the partition phase and
• the sort phase
Example
 Short Example of a Quick sort Routine (Pivots chosen "randomly")
Input: [13 81 92 65 43 31 57 26 75 0]
Pivot: 65
Partition: [13 0 26 43 31 57] 65 [ 92 75 81]
Pivot: 31 81
Partition: [13 0 26] 31 [43 57] 65 [75] 81 [92]
Pivot: 13
Partition: [0] 13 [26] 31 [43 57] 65 [75] 81 [92]
Combine: [0 13 26] 31 [43 57] 65 [75 81 92]
Combine: [0 13 26 31 43 57] 65 [75 81 92]
Combine: [0 13 26 31 43 57 65 75 81 92]
Algorithm:
1. QUICKSORT(A, p, r)
2. if p < r
3. q = PARTITION(A, p, r)
4. QUICKSORT(A, p, q -1)
5. QUICKSORT(A, q +1, r)
Advantage
 One of the fastest algorithms on average.
 Does not need additional memory (the sorting takes place in
the array - this is called in-place processing). Compare with
merge sort: merge sort needs additional memory for
merging.
Merge sort
 Merge sort is an O(n log n) comparison-
based sorting algorithm.
 Most implementations produce a stable sort, meaning that
the implementation preserves the input order of equal
elements in the sorted output.
 It is a divide and conquer algorithm.
 Merge sort is based on the divide-and-conquer paradigm.
• Divide Step
If a given array A has zero or one element, simply return; it is
already sorted. Otherwise, split A[p .. r] into two
subarrays A[p .. q] and A[q + 1 .. r], each containing about half
of the elements of A[p .. r]. That is, q is the halfway point
of A[p .. r].
• Combine Step
Combine the elements back in A[p .. r] by merging the two sorted
subarrays A[p .. q] and A[q + 1 .. r] into a sorted sequence. To
accomplish this step, we will define a procedure MERGE
(A, p, q, r).
• Conquer Step
Conquer by recursively sorting the two subarrays A[p .. q]
and A[q + 1 .. r].
Example
Algorithm:
 MERGE-SORT (A, p, r)
IF p < r // Check for base case
THEN q = FLOOR[(p + r)/2] // Divide step
MERGE (A, p, q) // Conquer step.
MERGE (A, q + 1, r) // Conquer step.
MERGE (A, p, q, r) // Conquer step.
Counting sort
In computer science, counting sort is an algorithm
for sorting a collection of objects according to keys
that are small integers; that is, it is an
integer sorting algorithm
Example
 Input array {3, 4, 3, 2, 1}, the maximum entry is 4 and size is 5
Create a counting array {0, 0, 0, 0}, size is 4
Iterate over the input array, and add count to the appropriate index:
{3, 4, 3, 2, 1} -> {0, 0, 1, 0}
{3, 4, 3, 2, 1} -> {0, 0, 1, 1}
{3, 4, 3, 2, 1} -> {0, 0, 2, 1}
{3, 4, 3, 2, 1} -> {0, 1, 2, 1}
{3, 4, 3, 2, 1} -> {1, 1, 2, 1}
 The counting array is currently {1, 1, 2, 1}, we now can override the input
array to create our sorted list.
{0, 1, 2, 1} -> {1, 4, 3, 2, 1}
{o, o, 2, 1} -> {1, 2, 3, 2, 1}
{o, o, 1, 1} -> {1, 2, 3, 2, 1}
{o, o, o, 1} -> {1, 2, 3, 3, 1}
{o, o, o, o} -> {1, 2, 3, 3, 4}
 We are now done, the input (now output) array consists of {1, 2, 3, 3, 4} in
the proper order.
Algorithm
1. Counting-Sort (A,B,k)
2. For I = 0 to k
3. C[i] = 0
4. For j = 1 to A.length
5. C[A[j]] = C[A[j]] + 1
6. // C[i] now contains the number of elements equal to I
7. For I = 1 to k
8. C[i] = C[i] + C[I – 1]
9. // C[i] now contains the number of elements less than or equal to i.
10. For j = A.length downto 1
11. B[C[A[j]]] = A[j]
12. C[A[j]] = C[A[j]] – 1
Sorting ppt

More Related Content

PPT
Graph coloring problem
PPT
SINGLE-SOURCE SHORTEST PATHS
PPTX
Merge Sort
PPT
Spanning trees
PPTX
Asymptotic notations
PPTX
PPTX
Knapsack Problem
PDF
All pairs shortest path algorithm
Graph coloring problem
SINGLE-SOURCE SHORTEST PATHS
Merge Sort
Spanning trees
Asymptotic notations
Knapsack Problem
All pairs shortest path algorithm

What's hot (20)

PPTX
Binary Tree Traversal
PPTX
Asymptotic Notation
PPT
minimum spanning tree
PPTX
PPTX
Algorithms and Flowcharts
PPTX
Single source Shortest path algorithm with example
PPT
Graph traversal-BFS & DFS
PPT
1.1 binary tree
PPTX
Three Address code
PPT
PPTX
Matrix chain multiplication
PPT
Hash table
PDF
backtracking algorithms of ada
PDF
Lecture Note-1: Algorithm and Its Properties
PPT
Graph colouring
PPTX
Prim's algorithm
PPTX
Dijkstra’S Algorithm
PPT
16. Concurrency Control in DBMS
DOC
Unit 2 in daa
PPTX
Sum of subset problem.pptx
Binary Tree Traversal
Asymptotic Notation
minimum spanning tree
Algorithms and Flowcharts
Single source Shortest path algorithm with example
Graph traversal-BFS & DFS
1.1 binary tree
Three Address code
Matrix chain multiplication
Hash table
backtracking algorithms of ada
Lecture Note-1: Algorithm and Its Properties
Graph colouring
Prim's algorithm
Dijkstra’S Algorithm
16. Concurrency Control in DBMS
Unit 2 in daa
Sum of subset problem.pptx
Ad

Similar to Sorting ppt (20)

PPTX
Linear Sorting
PPT
Counting sort(Non Comparison Sort)
PPT
Sorting Seminar Presentation by Ashin Guha Majumder
PPTX
Sorting2
PPTX
Data structure using c module 3
PPTX
Data Structure and algorithms for software
PPTX
Sortings .pptx
PPTX
Different Searching and Sorting Methods.pptx
PPT
Quicksort
PPTX
Advance Algorithm_unit_2_czcbcnhgjy.pptx
PPTX
2.Problem Solving Techniques and Data Structures.pptx
PPT
MergesortQuickSort.ppt
PPT
presentation_mergesortquicksort_1458716068_193111.ppt
PPTX
Dsa – data structure and algorithms sorting
PPTX
Sorting Algorithms
PPTX
All Searching and Sorting Techniques in Data Structures
PPT
Insert Sort & Merge Sort Using C Programming
Linear Sorting
Counting sort(Non Comparison Sort)
Sorting Seminar Presentation by Ashin Guha Majumder
Sorting2
Data structure using c module 3
Data Structure and algorithms for software
Sortings .pptx
Different Searching and Sorting Methods.pptx
Quicksort
Advance Algorithm_unit_2_czcbcnhgjy.pptx
2.Problem Solving Techniques and Data Structures.pptx
MergesortQuickSort.ppt
presentation_mergesortquicksort_1458716068_193111.ppt
Dsa – data structure and algorithms sorting
Sorting Algorithms
All Searching and Sorting Techniques in Data Structures
Insert Sort & Merge Sort Using C Programming
Ad

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
history of c programming in notes for students .pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
System and Network Administraation Chapter 3
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Introduction to Artificial Intelligence
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
AI in Product Development-omnex systems
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Softaken Excel to vCard Converter Software.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Which alternative to Crystal Reports is best for small or large businesses.pdf
Transform Your Business with a Software ERP System
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Adobe Illustrator 28.6 Crack My Vision of Vector Design
history of c programming in notes for students .pptx
Wondershare Filmora 15 Crack With Activation Key [2025
System and Network Administraation Chapter 3
PTS Company Brochure 2025 (1).pdf.......
L1 - Introduction to python Backend.pptx
Introduction to Artificial Intelligence
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
AI in Product Development-omnex systems
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Migrate SBCGlobal Email to Yahoo Easily

Sorting ppt

  • 2. Radix sort Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value. Radix sort is one of the linear sorting algorithms for integers.
  • 3. Example  The Original unsorted list 170, 045, 075, 090, 002, 024, 802, 066  Sorting by least significant digit (1s place) gives: 170, 90, 802, 2, 24, 45, 75, 66 Notice that we keep 802 before 2, because 802 occurred before 2 in the original and similarly for pairs 170 & 90 and 45 & 75.  Sorting by next digit (10s place) gives: 802, 2, 24, 45, 66, 170, 75, 90 Notice that 802 again comes before 2 as 802 comes before 2 in the previous list.  Sorting by most significant digit (100s place) gives: 2, 24, 45, 66, 75, 90, 170, 802
  • 4. First counting  The first counting pass starts on the least significant digit of each key, producing an array of bucket sizes: 2 (bucket size for digits of 0: 170, 090) 2 (bucket size for digits of 2: 002, 802) 1 (bucket size for digits of 4: 024) 2 (bucket size for digits of 5: 045, 075) 1 (bucket size for digits of 6: 066)
  • 5. Second counting  A second counting pass on the next more significant digit of each key will produce an array of bucket sizes: 2 (bucket size for digits of 0: 002, 802) 1 (bucket size for digits of 2: 024) 1 (bucket size for digits of 4: 045) 1 (bucket size for digits of 6: 066) 2 (bucket size for digits of 7: 170, 075) 1 (bucket size for digits of 9: 090)
  • 6. Third and Final counting  A third and final counting pass on the most significant digit of each key will produce an array of bucket sizes: 6 (bucket size for digits of 0: 002, 024, 045, 066, 075, 090) 1 (bucket size for digits of 1: 170) 1 (bucket size for digits of 8: 802)
  • 7. Alogrithm  RADIX-SORT (A,d) 1. for I = 1 to d 2. use a stable sort to sort array A on digit i
  • 8. Disadvantages Still, there are some tradeoffs for Radix Sort that can make it less preferable than other sorts. The speed of Radix Sort largely depends on the inner basic operations, and if the operations are not efficient enough, Radix Sort can be slower than some other algorithms such as Quick Sort and Merge Sort. These operations include the insert and delete functions of the sublists and the process of isolating the digit you want.
  • 9. Bucket sort Bucket sort, or bin sort, is a sorting algorithm that works by partitioning an array into a number of buckets. Bucket Sort is a sorting method that subdivides the given data into various buckets depending on certain characteristic order, thus partially sorting them in the first go.
  • 10. Example  The Elements are distributed among bins
  • 11.  The Then, elements are sorted within each bin
  • 12. The Algorithm of Bucket-SORT BUCKET SORT (A) 1. Let B[0..n – 1] be a new array 2. N = A.length 3. For I = 0 to n – 1 4. make B[i] an empty list 5. For I = 1 to n 6. insert A[i] into list B[[nA[i]]] 7. For I = 0 to n – 1 8. sort list B[i] with insertion sort 9. Concatenate the lists B[0], B[1],..B[n-1] together in order.
  • 13. Quick sort  Quick sort, or partition-exchange sort, is a sorting algorithm developed by Tony Hoare that, on average, makes O(n log n) comparisons to sort n items. Quick sort is a very efficient sorting algorithm invented by C.A.R. Hoare.  It has two phases: • the partition phase and • the sort phase
  • 14. Example  Short Example of a Quick sort Routine (Pivots chosen "randomly") Input: [13 81 92 65 43 31 57 26 75 0] Pivot: 65 Partition: [13 0 26 43 31 57] 65 [ 92 75 81] Pivot: 31 81 Partition: [13 0 26] 31 [43 57] 65 [75] 81 [92] Pivot: 13 Partition: [0] 13 [26] 31 [43 57] 65 [75] 81 [92] Combine: [0 13 26] 31 [43 57] 65 [75 81 92] Combine: [0 13 26 31 43 57] 65 [75 81 92] Combine: [0 13 26 31 43 57 65 75 81 92]
  • 15. Algorithm: 1. QUICKSORT(A, p, r) 2. if p < r 3. q = PARTITION(A, p, r) 4. QUICKSORT(A, p, q -1) 5. QUICKSORT(A, q +1, r)
  • 16. Advantage  One of the fastest algorithms on average.  Does not need additional memory (the sorting takes place in the array - this is called in-place processing). Compare with merge sort: merge sort needs additional memory for merging.
  • 17. Merge sort  Merge sort is an O(n log n) comparison- based sorting algorithm.  Most implementations produce a stable sort, meaning that the implementation preserves the input order of equal elements in the sorted output.  It is a divide and conquer algorithm.  Merge sort is based on the divide-and-conquer paradigm.
  • 18. • Divide Step If a given array A has zero or one element, simply return; it is already sorted. Otherwise, split A[p .. r] into two subarrays A[p .. q] and A[q + 1 .. r], each containing about half of the elements of A[p .. r]. That is, q is the halfway point of A[p .. r].
  • 19. • Combine Step Combine the elements back in A[p .. r] by merging the two sorted subarrays A[p .. q] and A[q + 1 .. r] into a sorted sequence. To accomplish this step, we will define a procedure MERGE (A, p, q, r). • Conquer Step Conquer by recursively sorting the two subarrays A[p .. q] and A[q + 1 .. r].
  • 21. Algorithm:  MERGE-SORT (A, p, r) IF p < r // Check for base case THEN q = FLOOR[(p + r)/2] // Divide step MERGE (A, p, q) // Conquer step. MERGE (A, q + 1, r) // Conquer step. MERGE (A, p, q, r) // Conquer step.
  • 22. Counting sort In computer science, counting sort is an algorithm for sorting a collection of objects according to keys that are small integers; that is, it is an integer sorting algorithm
  • 23. Example  Input array {3, 4, 3, 2, 1}, the maximum entry is 4 and size is 5 Create a counting array {0, 0, 0, 0}, size is 4 Iterate over the input array, and add count to the appropriate index: {3, 4, 3, 2, 1} -> {0, 0, 1, 0} {3, 4, 3, 2, 1} -> {0, 0, 1, 1} {3, 4, 3, 2, 1} -> {0, 0, 2, 1} {3, 4, 3, 2, 1} -> {0, 1, 2, 1} {3, 4, 3, 2, 1} -> {1, 1, 2, 1}  The counting array is currently {1, 1, 2, 1}, we now can override the input array to create our sorted list. {0, 1, 2, 1} -> {1, 4, 3, 2, 1} {o, o, 2, 1} -> {1, 2, 3, 2, 1} {o, o, 1, 1} -> {1, 2, 3, 2, 1} {o, o, o, 1} -> {1, 2, 3, 3, 1} {o, o, o, o} -> {1, 2, 3, 3, 4}  We are now done, the input (now output) array consists of {1, 2, 3, 3, 4} in the proper order.
  • 24. Algorithm 1. Counting-Sort (A,B,k) 2. For I = 0 to k 3. C[i] = 0 4. For j = 1 to A.length 5. C[A[j]] = C[A[j]] + 1 6. // C[i] now contains the number of elements equal to I 7. For I = 1 to k 8. C[i] = C[i] + C[I – 1] 9. // C[i] now contains the number of elements less than or equal to i. 10. For j = A.length downto 1 11. B[C[A[j]]] = A[j] 12. C[A[j]] = C[A[j]] – 1