SlideShare a Scribd company logo
Analysis and Design of Algorithms
Sorting Algorithms II
Analysis and Design of Algorithms
Counting Sort
Radix Sort
Merge Sort
Analysis and Design of Algorithms
Counting Sort
Analysis and Design of Algorithms
Counting sort is a sorting technique based on keys
between a specific range. It works by counting the
number of objects having distinct key values (kind of
hashing). Then doing some arithmetic to calculate
the position of each object in the output sequence.
Analysis and Design of Algorithms
Algorithm:
 Step1: Create a count array to store the count of each unique
object
 Step2 : Modify count array by adding the previous number.
 Step3 : Create output array by decrease count array
Analysis and Design of Algorithms
 Example 1 Assume the following Array in range of 0 to 5:
1 4 3 2 3 5 2
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 0 0 0 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 0 0 0 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 0 0 0 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 0 0 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 0 0 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 0 0 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 0 0 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 0 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 0 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 0 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 1 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 1 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 0 1 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 1 1 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 1 1 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 1 2 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 1 2 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 1 2 1 0
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 1 2 1 1
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 1 2 1 1
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 1 2 1 1
Analysis and Design of Algorithms
 Create a count array to store the count of each unique object:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 2 2 1 1
Analysis and Design of Algorithms
 Modify count array by adding the previous number :
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 2 2 1 1
Analysis and Design of Algorithms
 Modify count array by adding the previous number :
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 2 2 1 1
Analysis and Design of Algorithms
 Modify count array by adding the previous number :
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 2 1 1
Analysis and Design of Algorithms
 Modify count array by adding the previous number :
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 5 1 1
Analysis and Design of Algorithms
 Modify count array by adding the previous number :
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 5 6 1
Analysis and Design of Algorithms
 Modify count array by adding the previous number :
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 5 6 7
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 5 6 7
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 5 6 7
1 2 3 4 5 6 7
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 5 6 7
1 2 3 4 5 6 7
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 5 6 7
1 2 3 4 5 6 7
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 1 3 5 6 7
1 2 3 4 5 6 7
1
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 5 6 7
1 2 3 4 5 6 7
1
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 5 6 7
1 2 3 4 5 6 7
1
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 5 5 7
1 2 3 4 5 6 7
1 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 5 5 7
1 2 3 4 5 6 7
1 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 5 5 7
1 2 3 4 5 6 7
1 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 5 5 7
1 2 3 4 5 6 7
1 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 4 5 7
1 2 3 4 5 6 7
1 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 4 5 7
1 2 3 4 5 6 7
1 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 4 5 7
1 2 3 4 5 6 7
1 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 3 4 5 7
1 2 3 4 5 6 7
1 2 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 4 5 7
1 2 3 4 5 6 7
1 2 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 4 5 7
1 2 3 4 5 6 7
1 2 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 4 5 7
1 2 3 4 5 6 7
1 2 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 4 5 7
1 2 3 4 5 6 7
1 2 3 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 3 5 7
1 2 3 4 5 6 7
1 2 3 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 3 5 7
1 2 3 4 5 6 7
1 2 3 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 3 5 7
1 2 3 4 5 6 7
1 2 3 3 4
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 3 5 7
1 2 3 4 5 6 7
1 2 3 3 4 5
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 3 5 6
1 2 3 4 5 6 7
1 2 3 3 4 5
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 3 5 6
1 2 3 4 5 6 7
1 2 3 3 4 5
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 3 5 6
1 2 3 4 5 6 7
1 2 3 3 4 5
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 2 3 5 6
1 2 3 4 5 6 7
1 2 2 3 3 4 5
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 1 3 5 6
1 2 3 4 5 6 7
1 2 2 3 3 4 5
Analysis and Design of Algorithms
 Output each object from the input sequence followed by
decreasing its count by 1:
1 4 3 2 3 5 2
0 1 2 3 4 5
0 0 1 3 5 6
1 2 3 4 5 6 7
1 2 2 3 3 4 5
Analysis and Design of Algorithms
 Array is now sorted
1 2 2 3 3 4 5
Analysis and Design of Algorithms
2 4 1 1 3
 Example 2:
0 1 2 3 4
0 2 1 1 1
0 2 3 4 5
2
Count
Range=[0-4]
Add
1 2 3 4 5
Output
0 1 2 3 4
0 2 2 4 5Reduce
0 1 2 3 4
2 4
1 2 3 4 5
Output
0 2 2 4 4Reduce
0 1 2 3 4
1 2 4
1 2 3 4 5
Output
0 1 2 4 4Reduce
0 1 2 3 4
1 1 2 4
1 2 3 4 5
Output
0 0 2 4 4Reduce
0 1 2 3 4
1 1 2 3 4
1 2 3 4 5
Output
1 1 2 3 4
1 2 3 4 5
Sorted
Analysis and Design of Algorithms
 Python
Code
Analysis and Design of Algorithms
Analysis and Design of Algorithms
Analysis and Design of Algorithms
 Time Complexity: O(n+k) where n is the number of elements in input
array, and k is the range of input.
 Example of worst case
 Range between 1 to 10K
10 5 10k 5k 200
Analysis and Design of Algorithms
Radix Sort
Analysis and Design of Algorithms
 Radix sort is an algorithm that sorts numbers by processing digits
of each number either starting from the least significant digit (LSD)
or starting from the most significant digit (MSD).
 The idea of Radix Sort is to do digit by digit sort starting from
least significant digit to most significant digit. Radix sort uses
counting sort as a subroutine to sort.
Analysis and Design of Algorithms
Algorithm:
 Step1: Take the least significant digit of each element
 Step2 : Sort the list of elements based on that digit
 Step3 : Repeat the sort with each more significant digit
Analysis and Design of Algorithms
 Assume the following Array:
170 45 75 90 802 24 2 66
Analysis and Design of Algorithms
 The Sorted list will appear after three steps
170 45 75 90 802 24 2 66
170 90 802 2 24 45 75 66
802 2 24 45 66 170 75 90
2 24 45 66 75 90 170 802
Analysis and Design of Algorithms
 Step1: Sorting by least significant digit (1s place)
170 45 75 90 802 24 2 66
170 90 802 2 24 45 75 66
Analysis and Design of Algorithms
 Step2: Sorting by next digit (10s place)
170 90 802 2 24 45 75 66
802 2 24 45 66 170 75 90
Analysis and Design of Algorithms
 Step3: Sorting by most significant digit (100s place)
802 2 24 45 66 170 75 90
2 24 45 66 75 90 170 802
Analysis and Design of Algorithms
 Array is now sorted
2 24 45 66 75 90 170 802
Analysis and Design of Algorithms
 Example 2
1 2 3
5 8 3
1 5 4
5 6 7
6 8 9
6 2 5
4 5 6
1 2 3
5 8 3
1 5 4
6 2 5
4 5 6
5 6 7
6 8 9
1 2 3
6 2 5
1 5 4
4 5 6
5 6 7
5 8 3
6 8 9
1 2 3
1 5 4
4 5 6
5 6 7
5 8 3
6 2 5
6 8 9
1s 10s 100s
Analysis and Design of Algorithms
Analysis and Design of Algorithms
 Python Code
Analysis and Design of Algorithms
 Python Code
Analysis and Design of Algorithms
Time Complexity: O(n+k/d) where n is the number
of elements in input array, k is the range of input,
and d is number of digits.
Analysis and Design of Algorithms
Merge Sort
Analysis and Design of Algorithms
 Merge Sort is a Divide and Conquer algorithm. It
divides input array in two halves, calls itself for the
two halves and then merges the two sorted halves.
Analysis and Design of Algorithms
Algorithm:
 Step1: Divide the list recursively into two halves until it can
no more be divided
 Step2 : Merge (Conquer) the smaller lists into new list in
sorted order
Analysis and Design of Algorithms
 Assume the following Array:
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Divide
85 24 63 45 17 31 96 50
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Divide
85 24 63 45 17 31 96 50
85 24 63 45 17 31 96 50
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Divide
85 24 63 45 17 31 96 50
85 24 63 45 17 31 96 50
85 24 63 45 17 31 96 50
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 85
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 85
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 85 45 63
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 85 45 63
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 85 45 63 17 31
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 85 45 63 17 31
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 85 45 63 17 31 50 96
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 85 45 63 17 31 50 96
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24
24 85 45 63 17 31 50 96
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 45
24 85 45 63 17 31 50 96
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 45 63
24 85 45 63 17 31 50 96
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 45 63 85
24 85 45 63 17 31 50 96
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
24 45 63 85 17 31 50 96
24 85 45 63 17 31 50 96
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Sort & Merge
17 24 31 45 50 63 85 96
24 45 63 85 17 31 50 96
24 85 45 63 17 31 50 96
85 24 63 45 17 31 96 50
Analysis and Design of Algorithms
 Array is now sorted
17 24 31 45 50 63 85 96
Analysis and Design of Algorithms
 Example 2
Analysis and Design of Algorithms
Analysis and Design of Algorithms
Analysis and Design of Algorithms
Analysis and Design of Algorithms
Time Complexity: O(n * log(n) )
Analysis and Design of Algorithms
facebook.com/mloey
mohamedloey@gmail.com
twitter.com/mloey
linkedin.com/in/mloey
mloey@fci.bu.edu.eg
mloey.github.io
Analysis and Design of Algorithms
www.YourCompany.com
© 2020 Companyname PowerPoint Business Theme. All Rights Reserved.
THANKS FOR
YOUR TIME

More Related Content

PDF
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
PDF
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
PDF
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
PDF
Algorithms Lecture 3: Analysis of Algorithms II
Mohamed Loey
 
PDF
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
PDF
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
PDF
Sorting Algorithms
Mohammed Hussein
 
PPT
Bai giang thuat toan tim kiem va sap xep
tran0phu
 
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
Algorithms Lecture 3: Analysis of Algorithms II
Mohamed Loey
 
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Sorting Algorithms
Mohammed Hussein
 
Bai giang thuat toan tim kiem va sap xep
tran0phu
 

What's hot (20)

PDF
Algorithms Lecture 8: Pattern Algorithms
Mohamed Loey
 
PPTX
Sorting algorithms
Eleonora Ciceri
 
DOCX
Best,worst,average case .17581556 045
university of Gujrat, pakistan
 
PPT
Dinive conquer algorithm
Mohd Arif
 
PPTX
Analysis of algorithm
Rajendra Dangwal
 
PPT
Algorithm: Quick-Sort
Tareq Hasan
 
PPTX
Searching & Sorting Algorithms
Rahul Jamwal
 
PPT
Hashing PPT
Saurabh Kumar
 
PDF
Binary Search Tree
International Islamic University
 
PPTX
Sorting algorithms
Trupti Agrawal
 
PDF
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
PPTX
Quick Sort
Shweta Sahu
 
PPTX
Asymptotic Notation
Protap Mondal
 
PPTX
Divide and conquer - Quick sort
Madhu Bala
 
PDF
Design and analysis of algorithms
Dr Geetha Mohan
 
PPT
Time complexity
Katang Isip
 
PPT
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
PPT
Divide and conquer
Dr Shashikant Athawale
 
DOC
Data structures question paper anna university
sangeethajames07
 
PPT
how to calclute time complexity of algortihm
Sajid Marwat
 
Algorithms Lecture 8: Pattern Algorithms
Mohamed Loey
 
Sorting algorithms
Eleonora Ciceri
 
Best,worst,average case .17581556 045
university of Gujrat, pakistan
 
Dinive conquer algorithm
Mohd Arif
 
Analysis of algorithm
Rajendra Dangwal
 
Algorithm: Quick-Sort
Tareq Hasan
 
Searching & Sorting Algorithms
Rahul Jamwal
 
Hashing PPT
Saurabh Kumar
 
Sorting algorithms
Trupti Agrawal
 
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Quick Sort
Shweta Sahu
 
Asymptotic Notation
Protap Mondal
 
Divide and conquer - Quick sort
Madhu Bala
 
Design and analysis of algorithms
Dr Geetha Mohan
 
Time complexity
Katang Isip
 
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
Divide and conquer
Dr Shashikant Athawale
 
Data structures question paper anna university
sangeethajames07
 
how to calclute time complexity of algortihm
Sajid Marwat
 
Ad

Viewers also liked (6)

PDF
Deep Learning - Overview of my work II
Mohamed Loey
 
PDF
Convolutional Neural Network Models - Deep Learning
Mohamed Loey
 
PDF
Computer Security Lecture 7: RSA
Mohamed Loey
 
PDF
PMP Lecture 1: Introduction to Project Management
Mohamed Loey
 
PDF
Computer Security Lecture 5: Simplified Advanced Encryption Standard
Mohamed Loey
 
PPSX
C++ Programming Language
Mohamed Loey
 
Deep Learning - Overview of my work II
Mohamed Loey
 
Convolutional Neural Network Models - Deep Learning
Mohamed Loey
 
Computer Security Lecture 7: RSA
Mohamed Loey
 
PMP Lecture 1: Introduction to Project Management
Mohamed Loey
 
Computer Security Lecture 5: Simplified Advanced Encryption Standard
Mohamed Loey
 
C++ Programming Language
Mohamed Loey
 
Ad

Similar to Algorithms Lecture 5: Sorting Algorithms II (20)

PDF
Basics in algorithms and data structure
Eman magdy
 
PPTX
UNEC__1683196273.pptx
huseynmusayev2
 
PPTX
Apriori algorithm
Mainul Hassan
 
PPTX
Feature Selection for Document Ranking
Andrea Gigli
 
PDF
Lecture6[1]
ZINABU HAILE
 
PPTX
2.4 Lecture.pptx
TDeutsch1
 
PPT
Cis435 week06
ashish bansal
 
PPTX
Splunk Enterprise for Information Security (Hands-On)
Splunk
 
PPTX
How Computer Games Help Children Learn (Stockholm University Dept of Educatio...
dws1d
 
PPT
Encoder decoder
dennis gookyi
 
PPTX
Kishan Kaushik - Red Black Tree Overview
protonhtml5
 
PPTX
Kishan Kaushik - Red Black Tree PPT.pptx
protonhtml5
 
PPT
Lec25
Nikhil Chilwant
 
PPTX
Optimizing Set-Similarity Join and Search with Different Prefix Schemes
HPCC Systems
 
PDF
Binary Search Tree (BST) Explained Step-by-Step
scientistfromuet
 
PPTX
Data Mining Lecture_4.pptx
Subrata Kumer Paul
 
PPTX
Lecture 10-cs648=2013 Randomized Algorithms
Anshul Yadav
 
PPT
Data Structure (MC501)
Kamal Singh Lodhi
 
PDF
Android application - Tic Tac Toe
Sarthak Srivastava
 
Basics in algorithms and data structure
Eman magdy
 
UNEC__1683196273.pptx
huseynmusayev2
 
Apriori algorithm
Mainul Hassan
 
Feature Selection for Document Ranking
Andrea Gigli
 
Lecture6[1]
ZINABU HAILE
 
2.4 Lecture.pptx
TDeutsch1
 
Cis435 week06
ashish bansal
 
Splunk Enterprise for Information Security (Hands-On)
Splunk
 
How Computer Games Help Children Learn (Stockholm University Dept of Educatio...
dws1d
 
Encoder decoder
dennis gookyi
 
Kishan Kaushik - Red Black Tree Overview
protonhtml5
 
Kishan Kaushik - Red Black Tree PPT.pptx
protonhtml5
 
Optimizing Set-Similarity Join and Search with Different Prefix Schemes
HPCC Systems
 
Binary Search Tree (BST) Explained Step-by-Step
scientistfromuet
 
Data Mining Lecture_4.pptx
Subrata Kumer Paul
 
Lecture 10-cs648=2013 Randomized Algorithms
Anshul Yadav
 
Data Structure (MC501)
Kamal Singh Lodhi
 
Android application - Tic Tac Toe
Sarthak Srivastava
 

More from Mohamed Loey (18)

PDF
Lecture 6: Deep Learning Applications
Mohamed Loey
 
PDF
Lecture 5: Convolutional Neural Network Models
Mohamed Loey
 
PDF
Lecture 4: Deep Learning Frameworks
Mohamed Loey
 
PDF
Lecture 4: How it Works: Convolutional Neural Networks
Mohamed Loey
 
PPTX
Lecture 3: Convolutional Neural Networks
Mohamed Loey
 
PDF
Lecture 2: Artificial Neural Network
Mohamed Loey
 
PDF
Lecture 1: Deep Learning for Computer Vision
Mohamed Loey
 
PDF
Design of an Intelligent System for Improving Classification of Cancer Diseases
Mohamed Loey
 
PDF
Computer Security - CCNA Security - Lecture 2
Mohamed Loey
 
PDF
Computer Security - CCNA Security - Lecture 1
Mohamed Loey
 
PDF
Computer Security Lecture 4.1: DES Supplementary Material
Mohamed Loey
 
PDF
PMP Lecture 4: Project Integration Management
Mohamed Loey
 
PDF
Computer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Mohamed Loey
 
PDF
Computer Security Lecture 3: Classical Encryption Techniques 2
Mohamed Loey
 
PDF
Computer Security Lecture 2: Classical Encryption Techniques 1
Mohamed Loey
 
PDF
Computer Security Lecture 1: Overview
Mohamed Loey
 
PDF
PMP Lecture 3: Project Management Processes
Mohamed Loey
 
PDF
PMP Lecture 2: Project Management Framework
Mohamed Loey
 
Lecture 6: Deep Learning Applications
Mohamed Loey
 
Lecture 5: Convolutional Neural Network Models
Mohamed Loey
 
Lecture 4: Deep Learning Frameworks
Mohamed Loey
 
Lecture 4: How it Works: Convolutional Neural Networks
Mohamed Loey
 
Lecture 3: Convolutional Neural Networks
Mohamed Loey
 
Lecture 2: Artificial Neural Network
Mohamed Loey
 
Lecture 1: Deep Learning for Computer Vision
Mohamed Loey
 
Design of an Intelligent System for Improving Classification of Cancer Diseases
Mohamed Loey
 
Computer Security - CCNA Security - Lecture 2
Mohamed Loey
 
Computer Security - CCNA Security - Lecture 1
Mohamed Loey
 
Computer Security Lecture 4.1: DES Supplementary Material
Mohamed Loey
 
PMP Lecture 4: Project Integration Management
Mohamed Loey
 
Computer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Mohamed Loey
 
Computer Security Lecture 3: Classical Encryption Techniques 2
Mohamed Loey
 
Computer Security Lecture 2: Classical Encryption Techniques 1
Mohamed Loey
 
Computer Security Lecture 1: Overview
Mohamed Loey
 
PMP Lecture 3: Project Management Processes
Mohamed Loey
 
PMP Lecture 2: Project Management Framework
Mohamed Loey
 

Recently uploaded (20)

PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 

Algorithms Lecture 5: Sorting Algorithms II

  • 1. Analysis and Design of Algorithms Sorting Algorithms II
  • 2. Analysis and Design of Algorithms Counting Sort Radix Sort Merge Sort
  • 3. Analysis and Design of Algorithms Counting Sort
  • 4. Analysis and Design of Algorithms Counting sort is a sorting technique based on keys between a specific range. It works by counting the number of objects having distinct key values (kind of hashing). Then doing some arithmetic to calculate the position of each object in the output sequence.
  • 5. Analysis and Design of Algorithms Algorithm:  Step1: Create a count array to store the count of each unique object  Step2 : Modify count array by adding the previous number.  Step3 : Create output array by decrease count array
  • 6. Analysis and Design of Algorithms  Example 1 Assume the following Array in range of 0 to 5: 1 4 3 2 3 5 2
  • 7. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2
  • 8. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 0 0 0 0
  • 9. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 0 0 0 0
  • 10. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 0 0 0 0
  • 11. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 0 0 0
  • 12. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 0 0 0
  • 13. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 0 0 0
  • 14. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 0 0 0
  • 15. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 0 1 0
  • 16. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 0 1 0
  • 17. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 0 1 0
  • 18. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 1 1 0
  • 19. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 1 1 0
  • 20. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 0 1 1 0
  • 21. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 1 1 1 0
  • 22. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 1 1 1 0
  • 23. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 1 2 1 0
  • 24. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 1 2 1 0
  • 25. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 1 2 1 0
  • 26. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 1 2 1 1
  • 27. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 1 2 1 1
  • 28. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 1 2 1 1
  • 29. Analysis and Design of Algorithms  Create a count array to store the count of each unique object: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 2 2 1 1
  • 30. Analysis and Design of Algorithms  Modify count array by adding the previous number : 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 2 2 1 1
  • 31. Analysis and Design of Algorithms  Modify count array by adding the previous number : 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 2 2 1 1
  • 32. Analysis and Design of Algorithms  Modify count array by adding the previous number : 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 2 1 1
  • 33. Analysis and Design of Algorithms  Modify count array by adding the previous number : 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 5 1 1
  • 34. Analysis and Design of Algorithms  Modify count array by adding the previous number : 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 5 6 1
  • 35. Analysis and Design of Algorithms  Modify count array by adding the previous number : 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 5 6 7
  • 36. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 5 6 7
  • 37. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 5 6 7 1 2 3 4 5 6 7
  • 38. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 5 6 7 1 2 3 4 5 6 7
  • 39. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 5 6 7 1 2 3 4 5 6 7
  • 40. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 1 3 5 6 7 1 2 3 4 5 6 7 1
  • 41. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 5 6 7 1 2 3 4 5 6 7 1
  • 42. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 5 6 7 1 2 3 4 5 6 7 1
  • 43. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 5 5 7 1 2 3 4 5 6 7 1 4
  • 44. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 5 5 7 1 2 3 4 5 6 7 1 4
  • 45. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 5 5 7 1 2 3 4 5 6 7 1 4
  • 46. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 5 5 7 1 2 3 4 5 6 7 1 3 4
  • 47. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 4 5 7 1 2 3 4 5 6 7 1 3 4
  • 48. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 4 5 7 1 2 3 4 5 6 7 1 3 4
  • 49. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 4 5 7 1 2 3 4 5 6 7 1 3 4
  • 50. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 3 4 5 7 1 2 3 4 5 6 7 1 2 3 4
  • 51. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 4 5 7 1 2 3 4 5 6 7 1 2 3 4
  • 52. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 4 5 7 1 2 3 4 5 6 7 1 2 3 4
  • 53. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 4 5 7 1 2 3 4 5 6 7 1 2 3 4
  • 54. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 4 5 7 1 2 3 4 5 6 7 1 2 3 3 4
  • 55. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 3 5 7 1 2 3 4 5 6 7 1 2 3 3 4
  • 56. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 3 5 7 1 2 3 4 5 6 7 1 2 3 3 4
  • 57. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 3 5 7 1 2 3 4 5 6 7 1 2 3 3 4
  • 58. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 3 5 7 1 2 3 4 5 6 7 1 2 3 3 4 5
  • 59. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 3 5 6 1 2 3 4 5 6 7 1 2 3 3 4 5
  • 60. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 3 5 6 1 2 3 4 5 6 7 1 2 3 3 4 5
  • 61. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 3 5 6 1 2 3 4 5 6 7 1 2 3 3 4 5
  • 62. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 2 3 5 6 1 2 3 4 5 6 7 1 2 2 3 3 4 5
  • 63. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 1 3 5 6 1 2 3 4 5 6 7 1 2 2 3 3 4 5
  • 64. Analysis and Design of Algorithms  Output each object from the input sequence followed by decreasing its count by 1: 1 4 3 2 3 5 2 0 1 2 3 4 5 0 0 1 3 5 6 1 2 3 4 5 6 7 1 2 2 3 3 4 5
  • 65. Analysis and Design of Algorithms  Array is now sorted 1 2 2 3 3 4 5
  • 66. Analysis and Design of Algorithms 2 4 1 1 3  Example 2: 0 1 2 3 4 0 2 1 1 1 0 2 3 4 5 2 Count Range=[0-4] Add 1 2 3 4 5 Output 0 1 2 3 4 0 2 2 4 5Reduce 0 1 2 3 4 2 4 1 2 3 4 5 Output 0 2 2 4 4Reduce 0 1 2 3 4 1 2 4 1 2 3 4 5 Output 0 1 2 4 4Reduce 0 1 2 3 4 1 1 2 4 1 2 3 4 5 Output 0 0 2 4 4Reduce 0 1 2 3 4 1 1 2 3 4 1 2 3 4 5 Output 1 1 2 3 4 1 2 3 4 5 Sorted
  • 67. Analysis and Design of Algorithms  Python Code
  • 68. Analysis and Design of Algorithms
  • 69. Analysis and Design of Algorithms
  • 70. Analysis and Design of Algorithms  Time Complexity: O(n+k) where n is the number of elements in input array, and k is the range of input.  Example of worst case  Range between 1 to 10K 10 5 10k 5k 200
  • 71. Analysis and Design of Algorithms Radix Sort
  • 72. Analysis and Design of Algorithms  Radix sort is an algorithm that sorts numbers by processing digits of each number either starting from the least significant digit (LSD) or starting from the most significant digit (MSD).  The idea of Radix Sort is to do digit by digit sort starting from least significant digit to most significant digit. Radix sort uses counting sort as a subroutine to sort.
  • 73. Analysis and Design of Algorithms Algorithm:  Step1: Take the least significant digit of each element  Step2 : Sort the list of elements based on that digit  Step3 : Repeat the sort with each more significant digit
  • 74. Analysis and Design of Algorithms  Assume the following Array: 170 45 75 90 802 24 2 66
  • 75. Analysis and Design of Algorithms  The Sorted list will appear after three steps 170 45 75 90 802 24 2 66 170 90 802 2 24 45 75 66 802 2 24 45 66 170 75 90 2 24 45 66 75 90 170 802
  • 76. Analysis and Design of Algorithms  Step1: Sorting by least significant digit (1s place) 170 45 75 90 802 24 2 66 170 90 802 2 24 45 75 66
  • 77. Analysis and Design of Algorithms  Step2: Sorting by next digit (10s place) 170 90 802 2 24 45 75 66 802 2 24 45 66 170 75 90
  • 78. Analysis and Design of Algorithms  Step3: Sorting by most significant digit (100s place) 802 2 24 45 66 170 75 90 2 24 45 66 75 90 170 802
  • 79. Analysis and Design of Algorithms  Array is now sorted 2 24 45 66 75 90 170 802
  • 80. Analysis and Design of Algorithms  Example 2 1 2 3 5 8 3 1 5 4 5 6 7 6 8 9 6 2 5 4 5 6 1 2 3 5 8 3 1 5 4 6 2 5 4 5 6 5 6 7 6 8 9 1 2 3 6 2 5 1 5 4 4 5 6 5 6 7 5 8 3 6 8 9 1 2 3 1 5 4 4 5 6 5 6 7 5 8 3 6 2 5 6 8 9 1s 10s 100s
  • 81. Analysis and Design of Algorithms
  • 82. Analysis and Design of Algorithms  Python Code
  • 83. Analysis and Design of Algorithms  Python Code
  • 84. Analysis and Design of Algorithms Time Complexity: O(n+k/d) where n is the number of elements in input array, k is the range of input, and d is number of digits.
  • 85. Analysis and Design of Algorithms Merge Sort
  • 86. Analysis and Design of Algorithms  Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves.
  • 87. Analysis and Design of Algorithms Algorithm:  Step1: Divide the list recursively into two halves until it can no more be divided  Step2 : Merge (Conquer) the smaller lists into new list in sorted order
  • 88. Analysis and Design of Algorithms  Assume the following Array: 85 24 63 45 17 31 96 50
  • 89. Analysis and Design of Algorithms  Divide 85 24 63 45 17 31 96 50 85 24 63 45 17 31 96 50
  • 90. Analysis and Design of Algorithms  Divide 85 24 63 45 17 31 96 50 85 24 63 45 17 31 96 50 85 24 63 45 17 31 96 50
  • 91. Analysis and Design of Algorithms  Divide 85 24 63 45 17 31 96 50 85 24 63 45 17 31 96 50 85 24 63 45 17 31 96 50 85 24 63 45 17 31 96 50
  • 92. Analysis and Design of Algorithms  Sort & Merge 85 24 63 45 17 31 96 50
  • 93. Analysis and Design of Algorithms  Sort & Merge 85 24 63 45 17 31 96 50
  • 94. Analysis and Design of Algorithms  Sort & Merge 24 85 85 24 63 45 17 31 96 50
  • 95. Analysis and Design of Algorithms  Sort & Merge 24 85 85 24 63 45 17 31 96 50
  • 96. Analysis and Design of Algorithms  Sort & Merge 24 85 45 63 85 24 63 45 17 31 96 50
  • 97. Analysis and Design of Algorithms  Sort & Merge 24 85 45 63 85 24 63 45 17 31 96 50
  • 98. Analysis and Design of Algorithms  Sort & Merge 24 85 45 63 17 31 85 24 63 45 17 31 96 50
  • 99. Analysis and Design of Algorithms  Sort & Merge 24 85 45 63 17 31 85 24 63 45 17 31 96 50
  • 100. Analysis and Design of Algorithms  Sort & Merge 24 85 45 63 17 31 50 96 85 24 63 45 17 31 96 50
  • 101. Analysis and Design of Algorithms  Sort & Merge 24 85 45 63 17 31 50 96 85 24 63 45 17 31 96 50
  • 102. Analysis and Design of Algorithms  Sort & Merge 24 24 85 45 63 17 31 50 96 85 24 63 45 17 31 96 50
  • 103. Analysis and Design of Algorithms  Sort & Merge 24 45 24 85 45 63 17 31 50 96 85 24 63 45 17 31 96 50
  • 104. Analysis and Design of Algorithms  Sort & Merge 24 45 63 24 85 45 63 17 31 50 96 85 24 63 45 17 31 96 50
  • 105. Analysis and Design of Algorithms  Sort & Merge 24 45 63 85 24 85 45 63 17 31 50 96 85 24 63 45 17 31 96 50
  • 106. Analysis and Design of Algorithms  Sort & Merge 24 45 63 85 17 31 50 96 24 85 45 63 17 31 50 96 85 24 63 45 17 31 96 50
  • 107. Analysis and Design of Algorithms  Sort & Merge 17 24 31 45 50 63 85 96 24 45 63 85 17 31 50 96 24 85 45 63 17 31 50 96 85 24 63 45 17 31 96 50
  • 108. Analysis and Design of Algorithms  Array is now sorted 17 24 31 45 50 63 85 96
  • 109. Analysis and Design of Algorithms  Example 2
  • 110. Analysis and Design of Algorithms
  • 111. Analysis and Design of Algorithms
  • 112. Analysis and Design of Algorithms
  • 113. Analysis and Design of Algorithms Time Complexity: O(n * log(n) )
  • 114. Analysis and Design of Algorithms facebook.com/mloey [email protected] twitter.com/mloey linkedin.com/in/mloey [email protected] mloey.github.io
  • 115. Analysis and Design of Algorithms www.YourCompany.com © 2020 Companyname PowerPoint Business Theme. All Rights Reserved. THANKS FOR YOUR TIME