SlideShare a Scribd company logo
Lesson 5
Algorithm: Sorting and Searching
Algorithm Analysis
• Motivation
• What to do with algorithms?
• Programmer needs to develop a working solution
• Client wants problem solved efficiently
• Theoretician wants to understand
• Why analyze algorithms?
• To compare different algorithms for the same task
• To predict performance in a new environment
• To set values of algorithm parameters
Running Time
• We are interested in the design of "good" data structures and algorithms.
• Measure of "goodness":
- Running time (most important)
- Space usage
• The running time of an algorithm typically grows with the input size, and is
affected by other factors:
- Hardware environments: processor, memory, disk.
- Software environments: OS, compiler.
• Focus: input size vs. running time.
Pseudocode
• High-level description of an
algorithm
• More structured than English
prose
• Less detailed than a program
source code
• Preferred notation for
describing algorithms
• Hides program design issues
Pseudocode Details
• Control flow
- if … then … [else …]
- while … do …
- repeat … until …
- for … do …
- Indentation replaces braces
• Method declaration
- Algorithm method (arg [, arg…])
Input …
Output …
• Method call
var.method (arg [, arg…])
• Return value
return expression
• Expressions
Counting Primitive
Operations
By inspecting the pseudocode, we can determine the
maximum number of primitive operations executed by
an algorithm, as a function of the input size
Growth Rates
• Growth rates of
functions:
• Linear n≈
• Quadratic n≈ 2
• Cubic n≈ 3
Big-Oh Notation
• Given functions f(n) and
g(n), we say that f(n) is
O(g(n)) if there are
positive constants c and
n0 such that
f(n) ≤ cg(n) for n ≥ n0
Big-Oh Notation Example
• Example: 2n + 10 is O(n)
• 2n + 10 ≤ cn
• (c − 2) n 10≥
• n 10/(≥ c − 2)
• Pick c = 3 and n0 = 10
Big-Oh Notation Example
• Example: the function n2
is not
O(n)
• n2
≤ cn
• n ≤ c
• The above inequality cannot
be satisfied since c must be
a constant
More Big-Oh Examples
Seven Important Functions
Sort Algorithm
• Bubble Sort
• Insertion Sort
• Merge Sort
• Quick Sort
Bubble Sort
1. Compare each pair of adjacent elements from the
beginning of an array and, if they are in reversed
order, swap them
2. If at least one swap has been done, repeat step 1.
Bubble Sort pseudocode
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
Bubble Sort performance
• Worst-case & average-case: O(n2
)
• Best-case: (over an already-sorted list) :O(n)
Bubble Sort Animation
http://www.sorting-algorithms.com/bubble-sort
Insertion Sort
Insertion Sort pseudocode
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
Insertion Sort performance
• Worst-case & average-case: O(n2
)
• Best-case: (over an already-sorted list) :O(n)
Insertion Sort Animation
http://www.sorting-algorithms.com/insertion-sort
Divide-and-Conquer
Merge Sort
Merging Two Sorted
Sequences
Merge-Sort Execution
Merge-Sort Execution
Merge-Sort Execution
Merge-Sort Execution
Merge-Sort Execution
Merge-Sort Execution
Merge-Sort Execution
Merge-Sort Execution
Merge-Sort Execution
Merge-Sort Execution
Analysis of Merge-Sort
Quick-Sort
Quick-Sort Execution
Quick-Sort Execution
Quick-Sort Execution
Quick-Sort Execution
Quick-Sort Execution
Quick-Sort Execution
Quick-Sort Execution
Expected Running Time
Summary of Sorting
Algorithms
HW
1. Perform the mergesort algorithm with the input
sequence: 30, 40, 24, 58, 48, 26, 11, 13. Use a
diagram to illustrate the sorting process.
2. Repeat above question but using quicksort instead.
3. Repeat above question but using bubble sort
instead.
4. Repeat above question but using insertion sort
instead.
Graph
Adjacency Matrix
Structure
Structure
Graph Traversal
• Depth First Search
• Breath First Search
Depth First Search
DFS Example
DFS Example
DFS Algorithm
Breadth-First Search
BFS Example
BFS Example
BFS Example
BFS Algorithm

More Related Content

What's hot (20)

PPTX
Top down parsing
LakshmiSamivel
 
PPTX
Complexity analysis in Algorithms
Daffodil International University
 
PPTX
Insertion Sorting
FarihaHabib123
 
PPTX
Decision Table Based Testing
Himani Solanki
 
PDF
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
Khushboo Pal
 
PPTX
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
PPTX
Introduction to software testing
Hadi Fadlallah
 
PPTX
Breadth First Search & Depth First Search
Kevin Jadiya
 
PPTX
Agents in Artificial intelligence
Lalit Birla
 
PPTX
6-Practice Problems - LL(1) parser-16-05-2023.pptx
venkatapranaykumarGa
 
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
PPTX
Asymptotic Notations
Rishabh Soni
 
PPTX
Predictive parser
Jothi Lakshmi
 
PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPTX
Python
Sangita Panchal
 
PPT
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
PPT
Data structure lecture 1
Kumar
 
PPTX
N queens using backtracking
srilekhagourishetty
 
PPT
Dinive conquer algorithm
Mohd Arif
 
Top down parsing
LakshmiSamivel
 
Complexity analysis in Algorithms
Daffodil International University
 
Insertion Sorting
FarihaHabib123
 
Decision Table Based Testing
Himani Solanki
 
Intelligent Agent PPT ON SLIDESHARE IN ARTIFICIAL INTELLIGENCE
Khushboo Pal
 
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
Introduction to software testing
Hadi Fadlallah
 
Breadth First Search & Depth First Search
Kevin Jadiya
 
Agents in Artificial intelligence
Lalit Birla
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
venkatapranaykumarGa
 
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Asymptotic Notations
Rishabh Soni
 
Predictive parser
Jothi Lakshmi
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
Data structure lecture 1
Kumar
 
N queens using backtracking
srilekhagourishetty
 
Dinive conquer algorithm
Mohd Arif
 

Viewers also liked (20)

PPTX
Searching algorithms
ashish gupta
 
PPT
Perform brute force
SHC
 
PPTX
sorting algorithm graphical method
Shantanu Mishra
 
PPTX
Sorting algorithms
Trupti Agrawal
 
PPTX
Parallel sorting algorithm
Richa Kumari
 
PPT
Sorting Algorithms
multimedia9
 
PPT
មេរៀនៈ Data Structure and Algorithm in C/C++
Ngeam Soly
 
PPT
Data Structures - Searching & sorting
Kaushal Shah
 
PPT
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
PPTX
Introduction to datastructure and algorithm
Pratik Mota
 
PPTX
Sorting Algorithm
Al Amin
 
PPTX
Brute force-attack presentation
Mahmoud Ibra
 
PPTX
Password cracking and brute force
vishalgohel12195
 
PPT
Introduction of data structure
eShikshak
 
KEY
The Scientific Revolution
John Lynch
 
PPT
Introduction to Information Technology ch 01_b
Shahi Raz Akhtar
 
PPT
Google
vibhabehl
 
KEY
History of Creationism, Parts II & III
John Lynch
 
PPT
Introduction to Information Technology ch 02_a
Shahi Raz Akhtar
 
PDF
Algorithms - Aaron Bloomfield
Reggie Niccolo Santos
 
Searching algorithms
ashish gupta
 
Perform brute force
SHC
 
sorting algorithm graphical method
Shantanu Mishra
 
Sorting algorithms
Trupti Agrawal
 
Parallel sorting algorithm
Richa Kumari
 
Sorting Algorithms
multimedia9
 
មេរៀនៈ Data Structure and Algorithm in C/C++
Ngeam Soly
 
Data Structures - Searching & sorting
Kaushal Shah
 
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
Introduction to datastructure and algorithm
Pratik Mota
 
Sorting Algorithm
Al Amin
 
Brute force-attack presentation
Mahmoud Ibra
 
Password cracking and brute force
vishalgohel12195
 
Introduction of data structure
eShikshak
 
The Scientific Revolution
John Lynch
 
Introduction to Information Technology ch 01_b
Shahi Raz Akhtar
 
Google
vibhabehl
 
History of Creationism, Parts II & III
John Lynch
 
Introduction to Information Technology ch 02_a
Shahi Raz Akhtar
 
Algorithms - Aaron Bloomfield
Reggie Niccolo Santos
 
Ad

Similar to Hub 102 - Lesson 5 - Algorithm: Sorting & Searching (20)

PPT
Insersion & Bubble Sort in Algoritm
Ehsan Ehrari
 
PPTX
9.Sorting & Searching
Mandeep Singh
 
PDF
Data Structure - Lecture 1 - Introduction.pdf
donotreply20
 
PDF
01-Slides.pdf
emo1421
 
PDF
Quick sort,bubble sort,heap sort and merge sort
abhinavkumar77723
 
PPT
Sorting Seminar Presentation by Ashin Guha Majumder
Ashin Guha Majumder
 
PPT
Introduction
pilavare
 
PPTX
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
PPTX
Algorithm analysis (All in one)
jehan1987
 
PPTX
Different Searching and Sorting Methods.pptx
Minakshee Patil
 
PPT
Algorithm Design and Analysis
Reetesh Gupta
 
PPT
Sorting
Samsil Arefin
 
DOCX
Ds
Mohit Saini
 
PPTX
sorting-160810203705.pptx
VarchasvaTiwari2
 
PPTX
Analysis of algorithms
Asen Bozhilov
 
PPTX
Sorting algorithms
Eleonora Ciceri
 
PPT
Quicksort
Gayathri Gaayu
 
PPT
Cis435 week01
ashish bansal
 
PPTX
Chapter 2. data structure and algorithm
SolomonEndalu
 
Insersion & Bubble Sort in Algoritm
Ehsan Ehrari
 
9.Sorting & Searching
Mandeep Singh
 
Data Structure - Lecture 1 - Introduction.pdf
donotreply20
 
01-Slides.pdf
emo1421
 
Quick sort,bubble sort,heap sort and merge sort
abhinavkumar77723
 
Sorting Seminar Presentation by Ashin Guha Majumder
Ashin Guha Majumder
 
Introduction
pilavare
 
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Algorithm analysis (All in one)
jehan1987
 
Different Searching and Sorting Methods.pptx
Minakshee Patil
 
Algorithm Design and Analysis
Reetesh Gupta
 
Sorting
Samsil Arefin
 
sorting-160810203705.pptx
VarchasvaTiwari2
 
Analysis of algorithms
Asen Bozhilov
 
Sorting algorithms
Eleonora Ciceri
 
Quicksort
Gayathri Gaayu
 
Cis435 week01
ashish bansal
 
Chapter 2. data structure and algorithm
SolomonEndalu
 
Ad

Recently uploaded (20)

PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Hashing Introduction , hash functions and techniques
sailajam21
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 

Hub 102 - Lesson 5 - Algorithm: Sorting & Searching