SlideShare ist ein Scribd-Unternehmen logo
1 von 92
Downloaden Sie, um offline zu lesen
Analysis and Design of Algorithms
Sorting Algorithms I
Analysis and Design of Algorithms
Sorting Algorithms
Bubble Sort
Selection Sort
Insertion Sort
Analysis and Design of Algorithms
 Sorting Algorithm is an algorithm made up of a series of instructions
that takes an array as input, and outputs a sorted array.
 There are many sorting algorithms, such as:
 Selection Sort, Bubble Sort, Insertion Sort, Merge Sort,
Heap Sort, QuickSort, Radix Sort, Counting Sort, Bucket
Sort, ShellSort, Comb Sort, Pigeonhole Sort, Cycle Sort
Analysis and Design of Algorithms
Bubble Sort
Analysis and Design of Algorithms
Bubble Sort is the simplest sorting algorithm
that works by repeatedly swapping the
adjacent elements if they are in wrong
order.
Analysis and Design of Algorithms
Algorithm:
 Step1: Compare each pair of adjacent elements in the list
 Step2: Swap two element if necessary
 Step3: Repeat this process for all the elements until the
entire array is sorted
Analysis and Design of Algorithms
 Example 1 Assume the following Array:
5 1 4 2
Analysis and Design of Algorithms
 First Iteration:
 Compare
5 1 4 2

j

j+1
Analysis and Design of Algorithms
 First Iteration:
 Swap
1 5 4 2

j

j+1
Analysis and Design of Algorithms
 First Iteration:
 Compare
1 5 4 2

j

j+1
Analysis and Design of Algorithms
 First Iteration:
 Swap
1 4 5 2

j

j+1
Analysis and Design of Algorithms
 First Iteration:
 Compare
1 4 5 2

j

j+1
Analysis and Design of Algorithms
 First Iteration:
 Swap
1 4 2 5

j

j+1
Analysis and Design of Algorithms
1 4 2 5
Analysis and Design of Algorithms
 Second Iteration:
 Compare
1 4 2 5

j

j+1
Analysis and Design of Algorithms
 Second Iteration:
 Compare
1 4 2 5

j

j+1
Analysis and Design of Algorithms
 Second Iteration:
 Swap
1 2 4 5

j

j+1
Analysis and Design of Algorithms
1 2 4 5
Analysis and Design of Algorithms
 Third Iteration:
 Compare
1 2 4 5

j

j+1
Analysis and Design of Algorithms
1 2 4 5
Analysis and Design of Algorithms
 Array is now sorted
1 2 3 4
Analysis and Design of Algorithms
5 4 2 1 3
4 5 2 1 3
4 2 5 1 3
4 2 1 5 3
4 2 1 3 5
4 2 1 3 5
2 4 1 3 5
2 1 4 3 5
2 1 3 4 5
2 1 3 4 5
1 2 3 4 5
1 2 3 4 5
 Example 2:
Analysis and Design of Algorithms
 What is the output of bubble sort after the 1st iteration given the
following sequence of numbers: 13 2 9 4 18 45 37 63
a) 2 4 9 13 18 37 45 63
b) 2 9 4 13 18 37 45 63
c) 13 2 4 9 18 45 37 63
d) 2 4 9 13 18 45 37 63
Analysis and Design of Algorithms
 What is the output of bubble sort after the 1st iteration given the
following sequence of numbers: 13 2 9 4 18 45 37 63
a) 2 4 9 13 18 37 45 63
b) 2 9 4 13 18 37 45 63
c) 13 2 4 9 18 45 37 63
d) 2 4 9 13 18 45 37 63
Analysis and Design of Algorithms
 Python Code
Analysis and Design of Algorithms
Analysis and Design of Algorithms
 Time Complexity: O(n2) as there are two nested loops
 Example of worst case
5 4 3 2 1
Analysis and Design of Algorithms
Selection Sort
Analysis and Design of Algorithms
The selection sort algorithm sorts an array by
repeatedly finding the minimum element
(considering ascending order) from unsorted
part and putting it at the beginning.
Analysis and Design of Algorithms
Algorithm:
 Step1: Find the minimum value in the list
 Step2: Swap it with the value in the current position
 Step3: Repeat this process for all the elements until the
entire array is sorted
Analysis and Design of Algorithms
 Example 1 Assume the following Array:
8 12 5 9 2
Analysis and Design of Algorithms
 Compare
8 12 5 9 2

i

j

min
Analysis and Design of Algorithms
 Compare
8 12 5 9 2

i

j

min
Analysis and Design of Algorithms
 Move
8 12 5 9 2

j

i

min
Analysis and Design of Algorithms
 Compare
8 12 5 9 2

i

min

j
Analysis and Design of Algorithms
 Compare
8 12 5 9 2

i

min

j
Analysis and Design of Algorithms
 Move
8 12 5 9 2

i

j

min
Analysis and Design of Algorithms
 Smallest
8 12 5 9 2

i

min
Analysis and Design of Algorithms
 Swap
8 12 5 9 2

min

i
Analysis and Design of Algorithms
 Sorted
 Un Sorted
2 12 5 9 8

Sorted

Un Sorted
Analysis and Design of Algorithms
 Compare
2 12 5 9 8

i

min

j

Sorted
Analysis and Design of Algorithms
 Move
2 12 5 9 8

i

min

j

Sorted
Analysis and Design of Algorithms
 Compare
2 12 5 9 8

Sorted

i

j

min
Analysis and Design of Algorithms
 Compare
2 12 5 9 8

Sorted

i

j

min
Analysis and Design of Algorithms
 Smallest
2 12 5 9 8

Sorted

i

min
Analysis and Design of Algorithms
 Swap
2 12 5 9 8

Sorted

i

min
Analysis and Design of Algorithms
 Sorted
 Un Sorted
2 5 12 9 8

Sorted

Un Sorted
Analysis and Design of Algorithms
 Compare
2 5 12 9 8

Sorted

i

j

min
Analysis and Design of Algorithms
 Move
2 5 12 9 8

Sorted

i

j

min
Analysis and Design of Algorithms
 Compare
2 5 12 9 8

Sorted

i

min

j
Analysis and Design of Algorithms
 Move
2 5 12 9 8

Sorted

i

min

j
Analysis and Design of Algorithms
 Smallest
2 5 12 9 8

Sorted

i

min
Analysis and Design of Algorithms
 Swap
2 5 12 9 8

Sorted

i

min
Analysis and Design of Algorithms
 Sorted
 Un Sorted
2 5 8 9 12

Sorted

Un Sorted
Analysis and Design of Algorithms
 Compare
2 5 8 9 12

Sorted

i

min

j
Analysis and Design of Algorithms
 Sorted
 Un Sorted
2 5 8 9 12

Sorted

Un Sorted
Analysis and Design of Algorithms
 Sorted
 Un Sorted
2 5 8 9 12

Sorted

i

min
Analysis and Design of Algorithms
 Array is now sorted
2 5 8 9 12

Sorted
Analysis and Design of Algorithms
12 10 16 11 9 7 Example 2:
7 10 16 11 9 12
7 9 16 11 10 12
7 9 10 11 16 12
7 9 10 11 16 12
7 9 10 11 12 16
12 10 16 11 9 7
Analysis and Design of Algorithms
 What is the output of selection sort after the 2nd iteration given
the following sequence of numbers: 13 2 9 4 18 45 37 63
a) 2 4 9 13 18 37 45 63
b) 2 9 4 13 18 37 45 63
c) 13 2 4 9 18 45 37 63
d) 2 4 9 13 18 45 37 63
Analysis and Design of Algorithms
 What is the output of selection sort after the 2nd iteration given
the following sequence of numbers: 13 2 9 4 18 45 37 63
a) 2 4 9 13 18 37 45 63
b) 2 9 4 13 18 37 45 63
c) 13 2 4 9 18 45 37 63
d) 2 4 9 13 18 45 37 63
Analysis and Design of Algorithms
 Python Code
Analysis and Design of Algorithms
Analysis and Design of Algorithms
 Time Complexity: O(n2) as there are two nested loops
 Example of worst case
2 3 4 5 1
Analysis and Design of Algorithms
Insertion Sort
Analysis and Design of Algorithms
Insertion sort is a simple sorting
algorithm that works the way we sort
playing cards in our hands.
Analysis and Design of Algorithms
 Algorithm:
 Step1: Compare each pair of adjacent elements in the list
 Step2: Insert element into the sorted list, until it occupies correct
position.
 Step3: Swap two element if necessary
 Step4: Repeat this process for all the elements until the entire
array is sorted
Analysis and Design of Algorithms
 Assume the following Array:
5 1 4 2
Analysis and Design of Algorithms
 Compare
 Store=
5 1 4 2

i

j

j+1
1
Analysis and Design of Algorithms
 Move
 Store=
5 4 2

i

j

j+1
1
Analysis and Design of Algorithms
 Move
 Store=
1 5 4 2

i

j+1
Analysis and Design of Algorithms
 Compare
 Store=
1 5 4 2

i

j
4

j+1
Analysis and Design of Algorithms
 Move
 Store=
1 5 2

i

j
4

j+1
Analysis and Design of Algorithms
 Compare
 Store=
1 5 2

i

j
4

j+1
Analysis and Design of Algorithms
 Move
 Store=
1 4 5 2

i

j

j+1
Analysis and Design of Algorithms
 Compare
 Store=
1 4 5 2

i

j
2

j+1
Analysis and Design of Algorithms
 Move
 Store=
1 4 5

i

j
2

j+1
Analysis and Design of Algorithms
 Compare
 Store=
1 4 5

i

j
2

j+1
Analysis and Design of Algorithms
 Move
 Store=
1 4 5

i

j
2

j+1
Analysis and Design of Algorithms
 Compare
 Store=
1 4 5

i

j
2

j+1
Analysis and Design of Algorithms
 Compare
 Store=
1 2 4 5

i

j

j+1
Analysis and Design of Algorithms
 Array is now sorted
1 2 4 5
Analysis and Design of Algorithms
5 1 8 3 9 2
 Example 2:
1 5 8 3 9 2
1 5 8 3 9 2
1 3 5 8 9 2
1 3 5 8 9 2
1 2 3 5 8 9
5 1 8 3 9 2
Analysis and Design of Algorithms
 What is the output of insertion sort after the 1st iteration given the
following sequence of numbers: 7 3 5 1 9 8 4 6
a) 3 7 5 1 9 8 4 6
b) 1 3 7 5 9 8 4 6
c) 3 4 1 5 6 8 7 9
d) 1 3 4 5 6 7 8 9
Analysis and Design of Algorithms
 What is the output of insertion sort after the 1st iteration given the
following sequence of numbers: 7 3 5 1 9 8 4 6
a) 3 7 5 1 9 8 4 6
b) 1 3 7 5 9 8 4 6
c) 3 4 1 5 6 8 7 9
d) 1 3 4 5 6 7 8 9
Analysis and Design of Algorithms
 What is the output of insertion sort after the 2nd iteration given the
following sequence of numbers: 7 3 5 1 9 8 4 6
a) 3 5 7 1 9 8 4 6
b) 1 3 7 5 9 8 4 6
c) 3 4 1 5 6 8 7 9
d) 1 3 4 5 6 7 8 9
Analysis and Design of Algorithms
 What is the output of insertion sort after the 2nd iteration given the
following sequence of numbers: 7 3 5 1 9 8 4 6
a) 3 5 7 1 9 8 4 6
b) 1 3 7 5 9 8 4 6
c) 3 4 1 5 6 8 7 9
d) 1 3 4 5 6 7 8 9
Analysis and Design of Algorithms
 Python Code
Analysis and Design of Algorithms
Analysis and Design of Algorithms
 Time Complexity: O(n2)
 Example of worst case
5 4 3 2 1
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

Weitere ähnliche Inhalte

Was ist angesagt?

Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsMohamed Loey
 
Selection sort
Selection sortSelection sort
Selection sortstella D
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithmMohd Arif
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked ListNinad Mankar
 
Topological Sorting
Topological SortingTopological Sorting
Topological SortingShahDhruv21
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST Kathirvel Ayyaswamy
 

Was ist angesagt? (20)

Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Selection sort
Selection sortSelection sort
Selection sort
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Linked list
Linked listLinked list
Linked list
 
Binary search
Binary searchBinary search
Binary search
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 

Andere mochten auch

Convolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningConvolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningMohamed Loey
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IMohamed Loey
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIMohamed Loey
 
Computer Security Lecture 7: RSA
Computer Security Lecture 7: RSAComputer Security Lecture 7: RSA
Computer Security Lecture 7: RSAMohamed Loey
 
PMP Lecture 1: Introduction to Project Management
PMP Lecture 1: Introduction to Project ManagementPMP Lecture 1: Introduction to Project Management
PMP Lecture 1: Introduction to Project ManagementMohamed Loey
 
Computer Security Lecture 5: Simplified Advanced Encryption Standard
Computer Security Lecture 5: Simplified Advanced Encryption StandardComputer Security Lecture 5: Simplified Advanced Encryption Standard
Computer Security Lecture 5: Simplified Advanced Encryption StandardMohamed Loey
 
Deep Learning - Overview of my work II
Deep Learning - Overview of my work IIDeep Learning - Overview of my work II
Deep Learning - Overview of my work IIMohamed Loey
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 

Andere mochten auch (8)

Convolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningConvolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep Learning
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
 
Computer Security Lecture 7: RSA
Computer Security Lecture 7: RSAComputer Security Lecture 7: RSA
Computer Security Lecture 7: RSA
 
PMP Lecture 1: Introduction to Project Management
PMP Lecture 1: Introduction to Project ManagementPMP Lecture 1: Introduction to Project Management
PMP Lecture 1: Introduction to Project Management
 
Computer Security Lecture 5: Simplified Advanced Encryption Standard
Computer Security Lecture 5: Simplified Advanced Encryption StandardComputer Security Lecture 5: Simplified Advanced Encryption Standard
Computer Security Lecture 5: Simplified Advanced Encryption Standard
 
Deep Learning - Overview of my work II
Deep Learning - Overview of my work IIDeep Learning - Overview of my work II
Deep Learning - Overview of my work II
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 

Ähnlich wie Algorithms Lecture 4: Sorting Algorithms I

Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applicationsyazad dumasia
 
Computer notes - Sorting
Computer notes  - SortingComputer notes  - Sorting
Computer notes - Sortingecomputernotes
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure Eman magdy
 
Is sort andy-le
Is sort andy-leIs sort andy-le
Is sort andy-leSumedha
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET Journal
 
Lecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptxLecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptxxalahama3
 
computer notes - Data Structures - 38
computer notes - Data Structures - 38computer notes - Data Structures - 38
computer notes - Data Structures - 38ecomputernotes
 
Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Spencer Fox
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting TechniquesRafay Farooq
 
Dat 305 dat305 dat 305 education for service uopstudy.com
Dat 305 dat305 dat 305 education for service   uopstudy.comDat 305 dat305 dat 305 education for service   uopstudy.com
Dat 305 dat305 dat 305 education for service uopstudy.comULLPTT
 
List intersection for web search: Algorithms, Cost Models, and Optimizations
List intersection for web search: Algorithms, Cost Models, and OptimizationsList intersection for web search: Algorithms, Cost Models, and Optimizations
List intersection for web search: Algorithms, Cost Models, and OptimizationsSunghwan Kim
 
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 printAbdii Rashid
 

Ähnlich wie Algorithms Lecture 4: Sorting Algorithms I (20)

Sorting
SortingSorting
Sorting
 
UNEC__1683196273.pptx
UNEC__1683196273.pptxUNEC__1683196273.pptx
UNEC__1683196273.pptx
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
 
Computer notes - Sorting
Computer notes  - SortingComputer notes  - Sorting
Computer notes - Sorting
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
 
geekgap.io webinar #1
geekgap.io webinar #1geekgap.io webinar #1
geekgap.io webinar #1
 
Is sort andy-le
Is sort andy-leIs sort andy-le
Is sort andy-le
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
 
sorting.pptx
sorting.pptxsorting.pptx
sorting.pptx
 
Lecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptxLecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptx
 
sorting_part1.ppt
sorting_part1.pptsorting_part1.ppt
sorting_part1.ppt
 
computer notes - Data Structures - 38
computer notes - Data Structures - 38computer notes - Data Structures - 38
computer notes - Data Structures - 38
 
Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016
 
Sortings .pptx
Sortings .pptxSortings .pptx
Sortings .pptx
 
chapter 1
chapter 1chapter 1
chapter 1
 
Algorithm Design and Analysis
Algorithm Design and AnalysisAlgorithm Design and Analysis
Algorithm Design and Analysis
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
Dat 305 dat305 dat 305 education for service uopstudy.com
Dat 305 dat305 dat 305 education for service   uopstudy.comDat 305 dat305 dat 305 education for service   uopstudy.com
Dat 305 dat305 dat 305 education for service uopstudy.com
 
List intersection for web search: Algorithms, Cost Models, and Optimizations
List intersection for web search: Algorithms, Cost Models, and OptimizationsList intersection for web search: Algorithms, Cost Models, and Optimizations
List intersection for web search: Algorithms, Cost Models, and Optimizations
 
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
 

Mehr von Mohamed Loey

Lecture 6: Deep Learning Applications
Lecture 6: Deep Learning ApplicationsLecture 6: Deep Learning Applications
Lecture 6: Deep Learning ApplicationsMohamed Loey
 
Lecture 5: Convolutional Neural Network Models
Lecture 5: Convolutional Neural Network ModelsLecture 5: Convolutional Neural Network Models
Lecture 5: Convolutional Neural Network ModelsMohamed Loey
 
Lecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning FrameworksLecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning FrameworksMohamed Loey
 
Lecture 4: How it Works: Convolutional Neural Networks
Lecture 4: How it Works: Convolutional Neural NetworksLecture 4: How it Works: Convolutional Neural Networks
Lecture 4: How it Works: Convolutional Neural NetworksMohamed Loey
 
Lecture 3: Convolutional Neural Networks
Lecture 3: Convolutional Neural NetworksLecture 3: Convolutional Neural Networks
Lecture 3: Convolutional Neural NetworksMohamed Loey
 
Lecture 2: Artificial Neural Network
Lecture 2: Artificial Neural NetworkLecture 2: Artificial Neural Network
Lecture 2: Artificial Neural NetworkMohamed Loey
 
Lecture 1: Deep Learning for Computer Vision
Lecture 1: Deep Learning for Computer VisionLecture 1: Deep Learning for Computer Vision
Lecture 1: Deep Learning for Computer VisionMohamed Loey
 
Design of an Intelligent System for Improving Classification of Cancer Diseases
Design of an Intelligent System for Improving Classification of Cancer DiseasesDesign of an Intelligent System for Improving Classification of Cancer Diseases
Design of an Intelligent System for Improving Classification of Cancer DiseasesMohamed Loey
 
Computer Security - CCNA Security - Lecture 2
Computer Security - CCNA Security - Lecture 2Computer Security - CCNA Security - Lecture 2
Computer Security - CCNA Security - Lecture 2Mohamed Loey
 
Computer Security - CCNA Security - Lecture 1
Computer Security - CCNA Security - Lecture 1Computer Security - CCNA Security - Lecture 1
Computer Security - CCNA Security - Lecture 1Mohamed Loey
 
Algorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsAlgorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsMohamed Loey
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsMohamed Loey
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Computer Security Lecture 4.1: DES Supplementary Material
Computer Security Lecture 4.1: DES Supplementary MaterialComputer Security Lecture 4.1: DES Supplementary Material
Computer Security Lecture 4.1: DES Supplementary MaterialMohamed Loey
 
PMP Lecture 4: Project Integration Management
PMP Lecture 4: Project Integration ManagementPMP Lecture 4: Project Integration Management
PMP Lecture 4: Project Integration ManagementMohamed Loey
 
Computer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Computer Security Lecture 4: Block Ciphers and the Data Encryption StandardComputer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Computer Security Lecture 4: Block Ciphers and the Data Encryption StandardMohamed Loey
 
Computer Security Lecture 3: Classical Encryption Techniques 2
Computer Security Lecture 3: Classical Encryption Techniques 2Computer Security Lecture 3: Classical Encryption Techniques 2
Computer Security Lecture 3: Classical Encryption Techniques 2Mohamed Loey
 
Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1Mohamed Loey
 
Computer Security Lecture 1: Overview
Computer Security Lecture 1: OverviewComputer Security Lecture 1: Overview
Computer Security Lecture 1: OverviewMohamed Loey
 
PMP Lecture 3: Project Management Processes
PMP Lecture 3: Project Management ProcessesPMP Lecture 3: Project Management Processes
PMP Lecture 3: Project Management ProcessesMohamed Loey
 

Mehr von Mohamed Loey (20)

Lecture 6: Deep Learning Applications
Lecture 6: Deep Learning ApplicationsLecture 6: Deep Learning Applications
Lecture 6: Deep Learning Applications
 
Lecture 5: Convolutional Neural Network Models
Lecture 5: Convolutional Neural Network ModelsLecture 5: Convolutional Neural Network Models
Lecture 5: Convolutional Neural Network Models
 
Lecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning FrameworksLecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning Frameworks
 
Lecture 4: How it Works: Convolutional Neural Networks
Lecture 4: How it Works: Convolutional Neural NetworksLecture 4: How it Works: Convolutional Neural Networks
Lecture 4: How it Works: Convolutional Neural Networks
 
Lecture 3: Convolutional Neural Networks
Lecture 3: Convolutional Neural NetworksLecture 3: Convolutional Neural Networks
Lecture 3: Convolutional Neural Networks
 
Lecture 2: Artificial Neural Network
Lecture 2: Artificial Neural NetworkLecture 2: Artificial Neural Network
Lecture 2: Artificial Neural Network
 
Lecture 1: Deep Learning for Computer Vision
Lecture 1: Deep Learning for Computer VisionLecture 1: Deep Learning for Computer Vision
Lecture 1: Deep Learning for Computer Vision
 
Design of an Intelligent System for Improving Classification of Cancer Diseases
Design of an Intelligent System for Improving Classification of Cancer DiseasesDesign of an Intelligent System for Improving Classification of Cancer Diseases
Design of an Intelligent System for Improving Classification of Cancer Diseases
 
Computer Security - CCNA Security - Lecture 2
Computer Security - CCNA Security - Lecture 2Computer Security - CCNA Security - Lecture 2
Computer Security - CCNA Security - Lecture 2
 
Computer Security - CCNA Security - Lecture 1
Computer Security - CCNA Security - Lecture 1Computer Security - CCNA Security - Lecture 1
Computer Security - CCNA Security - Lecture 1
 
Algorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsAlgorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern Algorithms
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Computer Security Lecture 4.1: DES Supplementary Material
Computer Security Lecture 4.1: DES Supplementary MaterialComputer Security Lecture 4.1: DES Supplementary Material
Computer Security Lecture 4.1: DES Supplementary Material
 
PMP Lecture 4: Project Integration Management
PMP Lecture 4: Project Integration ManagementPMP Lecture 4: Project Integration Management
PMP Lecture 4: Project Integration Management
 
Computer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Computer Security Lecture 4: Block Ciphers and the Data Encryption StandardComputer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Computer Security Lecture 4: Block Ciphers and the Data Encryption Standard
 
Computer Security Lecture 3: Classical Encryption Techniques 2
Computer Security Lecture 3: Classical Encryption Techniques 2Computer Security Lecture 3: Classical Encryption Techniques 2
Computer Security Lecture 3: Classical Encryption Techniques 2
 
Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1
 
Computer Security Lecture 1: Overview
Computer Security Lecture 1: OverviewComputer Security Lecture 1: Overview
Computer Security Lecture 1: Overview
 
PMP Lecture 3: Project Management Processes
PMP Lecture 3: Project Management ProcessesPMP Lecture 3: Project Management Processes
PMP Lecture 3: Project Management Processes
 

Kürzlich hochgeladen

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 

Kürzlich hochgeladen (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Algorithms Lecture 4: Sorting Algorithms I

  • 1. Analysis and Design of Algorithms Sorting Algorithms I
  • 2. Analysis and Design of Algorithms Sorting Algorithms Bubble Sort Selection Sort Insertion Sort
  • 3. Analysis and Design of Algorithms  Sorting Algorithm is an algorithm made up of a series of instructions that takes an array as input, and outputs a sorted array.  There are many sorting algorithms, such as:  Selection Sort, Bubble Sort, Insertion Sort, Merge Sort, Heap Sort, QuickSort, Radix Sort, Counting Sort, Bucket Sort, ShellSort, Comb Sort, Pigeonhole Sort, Cycle Sort
  • 4. Analysis and Design of Algorithms Bubble Sort
  • 5. Analysis and Design of Algorithms Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
  • 6. Analysis and Design of Algorithms Algorithm:  Step1: Compare each pair of adjacent elements in the list  Step2: Swap two element if necessary  Step3: Repeat this process for all the elements until the entire array is sorted
  • 7. Analysis and Design of Algorithms  Example 1 Assume the following Array: 5 1 4 2
  • 8. Analysis and Design of Algorithms  First Iteration:  Compare 5 1 4 2  j  j+1
  • 9. Analysis and Design of Algorithms  First Iteration:  Swap 1 5 4 2  j  j+1
  • 10. Analysis and Design of Algorithms  First Iteration:  Compare 1 5 4 2  j  j+1
  • 11. Analysis and Design of Algorithms  First Iteration:  Swap 1 4 5 2  j  j+1
  • 12. Analysis and Design of Algorithms  First Iteration:  Compare 1 4 5 2  j  j+1
  • 13. Analysis and Design of Algorithms  First Iteration:  Swap 1 4 2 5  j  j+1
  • 14. Analysis and Design of Algorithms 1 4 2 5
  • 15. Analysis and Design of Algorithms  Second Iteration:  Compare 1 4 2 5  j  j+1
  • 16. Analysis and Design of Algorithms  Second Iteration:  Compare 1 4 2 5  j  j+1
  • 17. Analysis and Design of Algorithms  Second Iteration:  Swap 1 2 4 5  j  j+1
  • 18. Analysis and Design of Algorithms 1 2 4 5
  • 19. Analysis and Design of Algorithms  Third Iteration:  Compare 1 2 4 5  j  j+1
  • 20. Analysis and Design of Algorithms 1 2 4 5
  • 21. Analysis and Design of Algorithms  Array is now sorted 1 2 3 4
  • 22. Analysis and Design of Algorithms 5 4 2 1 3 4 5 2 1 3 4 2 5 1 3 4 2 1 5 3 4 2 1 3 5 4 2 1 3 5 2 4 1 3 5 2 1 4 3 5 2 1 3 4 5 2 1 3 4 5 1 2 3 4 5 1 2 3 4 5  Example 2:
  • 23. Analysis and Design of Algorithms  What is the output of bubble sort after the 1st iteration given the following sequence of numbers: 13 2 9 4 18 45 37 63 a) 2 4 9 13 18 37 45 63 b) 2 9 4 13 18 37 45 63 c) 13 2 4 9 18 45 37 63 d) 2 4 9 13 18 45 37 63
  • 24. Analysis and Design of Algorithms  What is the output of bubble sort after the 1st iteration given the following sequence of numbers: 13 2 9 4 18 45 37 63 a) 2 4 9 13 18 37 45 63 b) 2 9 4 13 18 37 45 63 c) 13 2 4 9 18 45 37 63 d) 2 4 9 13 18 45 37 63
  • 25. Analysis and Design of Algorithms  Python Code
  • 26. Analysis and Design of Algorithms
  • 27. Analysis and Design of Algorithms  Time Complexity: O(n2) as there are two nested loops  Example of worst case 5 4 3 2 1
  • 28. Analysis and Design of Algorithms Selection Sort
  • 29. Analysis and Design of Algorithms The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning.
  • 30. Analysis and Design of Algorithms Algorithm:  Step1: Find the minimum value in the list  Step2: Swap it with the value in the current position  Step3: Repeat this process for all the elements until the entire array is sorted
  • 31. Analysis and Design of Algorithms  Example 1 Assume the following Array: 8 12 5 9 2
  • 32. Analysis and Design of Algorithms  Compare 8 12 5 9 2  i  j  min
  • 33. Analysis and Design of Algorithms  Compare 8 12 5 9 2  i  j  min
  • 34. Analysis and Design of Algorithms  Move 8 12 5 9 2  j  i  min
  • 35. Analysis and Design of Algorithms  Compare 8 12 5 9 2  i  min  j
  • 36. Analysis and Design of Algorithms  Compare 8 12 5 9 2  i  min  j
  • 37. Analysis and Design of Algorithms  Move 8 12 5 9 2  i  j  min
  • 38. Analysis and Design of Algorithms  Smallest 8 12 5 9 2  i  min
  • 39. Analysis and Design of Algorithms  Swap 8 12 5 9 2  min  i
  • 40. Analysis and Design of Algorithms  Sorted  Un Sorted 2 12 5 9 8  Sorted  Un Sorted
  • 41. Analysis and Design of Algorithms  Compare 2 12 5 9 8  i  min  j  Sorted
  • 42. Analysis and Design of Algorithms  Move 2 12 5 9 8  i  min  j  Sorted
  • 43. Analysis and Design of Algorithms  Compare 2 12 5 9 8  Sorted  i  j  min
  • 44. Analysis and Design of Algorithms  Compare 2 12 5 9 8  Sorted  i  j  min
  • 45. Analysis and Design of Algorithms  Smallest 2 12 5 9 8  Sorted  i  min
  • 46. Analysis and Design of Algorithms  Swap 2 12 5 9 8  Sorted  i  min
  • 47. Analysis and Design of Algorithms  Sorted  Un Sorted 2 5 12 9 8  Sorted  Un Sorted
  • 48. Analysis and Design of Algorithms  Compare 2 5 12 9 8  Sorted  i  j  min
  • 49. Analysis and Design of Algorithms  Move 2 5 12 9 8  Sorted  i  j  min
  • 50. Analysis and Design of Algorithms  Compare 2 5 12 9 8  Sorted  i  min  j
  • 51. Analysis and Design of Algorithms  Move 2 5 12 9 8  Sorted  i  min  j
  • 52. Analysis and Design of Algorithms  Smallest 2 5 12 9 8  Sorted  i  min
  • 53. Analysis and Design of Algorithms  Swap 2 5 12 9 8  Sorted  i  min
  • 54. Analysis and Design of Algorithms  Sorted  Un Sorted 2 5 8 9 12  Sorted  Un Sorted
  • 55. Analysis and Design of Algorithms  Compare 2 5 8 9 12  Sorted  i  min  j
  • 56. Analysis and Design of Algorithms  Sorted  Un Sorted 2 5 8 9 12  Sorted  Un Sorted
  • 57. Analysis and Design of Algorithms  Sorted  Un Sorted 2 5 8 9 12  Sorted  i  min
  • 58. Analysis and Design of Algorithms  Array is now sorted 2 5 8 9 12  Sorted
  • 59. Analysis and Design of Algorithms 12 10 16 11 9 7 Example 2: 7 10 16 11 9 12 7 9 16 11 10 12 7 9 10 11 16 12 7 9 10 11 16 12 7 9 10 11 12 16 12 10 16 11 9 7
  • 60. Analysis and Design of Algorithms  What is the output of selection sort after the 2nd iteration given the following sequence of numbers: 13 2 9 4 18 45 37 63 a) 2 4 9 13 18 37 45 63 b) 2 9 4 13 18 37 45 63 c) 13 2 4 9 18 45 37 63 d) 2 4 9 13 18 45 37 63
  • 61. Analysis and Design of Algorithms  What is the output of selection sort after the 2nd iteration given the following sequence of numbers: 13 2 9 4 18 45 37 63 a) 2 4 9 13 18 37 45 63 b) 2 9 4 13 18 37 45 63 c) 13 2 4 9 18 45 37 63 d) 2 4 9 13 18 45 37 63
  • 62. Analysis and Design of Algorithms  Python Code
  • 63. Analysis and Design of Algorithms
  • 64. Analysis and Design of Algorithms  Time Complexity: O(n2) as there are two nested loops  Example of worst case 2 3 4 5 1
  • 65. Analysis and Design of Algorithms Insertion Sort
  • 66. Analysis and Design of Algorithms Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands.
  • 67. Analysis and Design of Algorithms  Algorithm:  Step1: Compare each pair of adjacent elements in the list  Step2: Insert element into the sorted list, until it occupies correct position.  Step3: Swap two element if necessary  Step4: Repeat this process for all the elements until the entire array is sorted
  • 68. Analysis and Design of Algorithms  Assume the following Array: 5 1 4 2
  • 69. Analysis and Design of Algorithms  Compare  Store= 5 1 4 2  i  j  j+1 1
  • 70. Analysis and Design of Algorithms  Move  Store= 5 4 2  i  j  j+1 1
  • 71. Analysis and Design of Algorithms  Move  Store= 1 5 4 2  i  j+1
  • 72. Analysis and Design of Algorithms  Compare  Store= 1 5 4 2  i  j 4  j+1
  • 73. Analysis and Design of Algorithms  Move  Store= 1 5 2  i  j 4  j+1
  • 74. Analysis and Design of Algorithms  Compare  Store= 1 5 2  i  j 4  j+1
  • 75. Analysis and Design of Algorithms  Move  Store= 1 4 5 2  i  j  j+1
  • 76. Analysis and Design of Algorithms  Compare  Store= 1 4 5 2  i  j 2  j+1
  • 77. Analysis and Design of Algorithms  Move  Store= 1 4 5  i  j 2  j+1
  • 78. Analysis and Design of Algorithms  Compare  Store= 1 4 5  i  j 2  j+1
  • 79. Analysis and Design of Algorithms  Move  Store= 1 4 5  i  j 2  j+1
  • 80. Analysis and Design of Algorithms  Compare  Store= 1 4 5  i  j 2  j+1
  • 81. Analysis and Design of Algorithms  Compare  Store= 1 2 4 5  i  j  j+1
  • 82. Analysis and Design of Algorithms  Array is now sorted 1 2 4 5
  • 83. Analysis and Design of Algorithms 5 1 8 3 9 2  Example 2: 1 5 8 3 9 2 1 5 8 3 9 2 1 3 5 8 9 2 1 3 5 8 9 2 1 2 3 5 8 9 5 1 8 3 9 2
  • 84. Analysis and Design of Algorithms  What is the output of insertion sort after the 1st iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6 a) 3 7 5 1 9 8 4 6 b) 1 3 7 5 9 8 4 6 c) 3 4 1 5 6 8 7 9 d) 1 3 4 5 6 7 8 9
  • 85. Analysis and Design of Algorithms  What is the output of insertion sort after the 1st iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6 a) 3 7 5 1 9 8 4 6 b) 1 3 7 5 9 8 4 6 c) 3 4 1 5 6 8 7 9 d) 1 3 4 5 6 7 8 9
  • 86. Analysis and Design of Algorithms  What is the output of insertion sort after the 2nd iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6 a) 3 5 7 1 9 8 4 6 b) 1 3 7 5 9 8 4 6 c) 3 4 1 5 6 8 7 9 d) 1 3 4 5 6 7 8 9
  • 87. Analysis and Design of Algorithms  What is the output of insertion sort after the 2nd iteration given the following sequence of numbers: 7 3 5 1 9 8 4 6 a) 3 5 7 1 9 8 4 6 b) 1 3 7 5 9 8 4 6 c) 3 4 1 5 6 8 7 9 d) 1 3 4 5 6 7 8 9
  • 88. Analysis and Design of Algorithms  Python Code
  • 89. Analysis and Design of Algorithms
  • 90. Analysis and Design of Algorithms  Time Complexity: O(n2)  Example of worst case 5 4 3 2 1
  • 91. 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
  • 92. Analysis and Design of Algorithms www.YourCompany.com © 2020 Companyname PowerPoint Business Theme. All Rights Reserved. THANKS FOR YOUR TIME