SlideShare a Scribd company logo
1 of 31
Download to read offline
Presented by
Ewurama ..…
ALL YOU NEED TO KNOW ABOUT
ALGORITHMS
❖ A step-by-step procedure to solve a problem
❖ Every program is the instantiation of some algorithm
❖ Algorithm can be presented in a pseudocode or
flowchart
ALGORITHM
❖ sorting
❖ data retrieval
❖ network routing
❖ Games etc...
Study problems these techniques can be applied to
Pseudocode is an artificial and informal language that helps
programmers develop algorithms.
Pseudocode may be an informal english, combinations of
computer languages and spoken language.
Whatever works for you.
Pseudocode
❖ Algorithms are all around us in everyday life.
❖ In the recipe of a cook book.
❖ In assembling a toy.
❖ In setting the table.
❖ In preparing a cup of tea.
❖ In calling your friend on the phone.
Hard to design algorithms that are
❖ correct
❖ efficient
❖ implementable
Need to know about design and modeling techniques
resources - don't reinvent the wheel
Challenges
❖ Determine the feasibility of solution w.r.t. memory requirements,
performance constraints … etc.
❖ Manually review and validate pseudo code
❖ Analyze the complexity of the algorithm using the big O notation to
determine the complexity w.r.t. to time and storage.
❖ Other criteria include: Clarity, Maintainability, Portability
Analyze Performance
❖ Understand the Problem (requirement analysis)
❖ Select Data structure (data structure is a particular way of organizing data in a computer
so that it can be used efficiently)
❖ Write Pseudo Code
❖ Analyze Performance
❖ Implement using suitable programming language
Guidelines for Algorithm Designing and Analysis:
To understand their behavior, and (Job -- Selection,
performance, modify) improve them. (Research)
Why Analyze Performance
Correctness: Does the input/output relation match algorithm requirement?
Amount of work done (aka complexity):Basic operations to do task
Amount of space used: Memory used
Simplicity, clarity: Verification and implementation.
Optimality: Is it impossible to do better?
What do we analyze about them?
Testing is divided into 2 main parts:
❖ Trying to break the function of the program by entering unexpected data.
❖ Debugging: It is concerned with finding out what is what caused the
program to function in incorrectly.
Test to resolve syntax and logic errors
The complexity of an algorithm is simply the amount of work the algorithm
performs to complete its task.
Time complexity is a main issue in evaluating an algorithm.
It reflects how the algorithm responds to the increase in data size (n) it
handles, by measuring the corresponding increase in number of instructions
to be performed.
Time Complexity of an
Algorithm
❖ How does the algorithm behave as the problem
size gets very large?
❖ Running time
❖ Memory/storage requirements
❖ Bandwidth/power requirements/logic gates/etc.
Analysis using Asymptotic Notation(Big-O)
Big O notation also called Landau's symbol, is a symbolism used in complexity
theory, computer science, and mathematics to describe the asymptotic behavior of functions.
Basically, it tells you how fast a function grows or declines.
Landau's symbol comes from the name of the German number theoretician Edmund
Landau who invented the notation.
The letter O is used because the rate of growth of a function is also called its order.
For example, when analyzing some algorithm, one might find that the time (or the
number of steps) it takes to complete a problem of size n is given by T(n) = 4 n2
- 2 n + 2
O(n2
): known as Quadratic complexity
● 1 item: 1 second
● 10 items: 100 seconds
● 100 items: 10000 seconds
Notice that the number of items increases by a factor of 10, but the time increases by a factor of 102
. Basically,
n=10 and so O(n2
) gives us the scaling factor n2
which is 102.
O(n): known as Linear complexity
● 1 item: 1 second
● 10 items: 10 seconds
● 100 items: 100 seconds
This time the number of items increases by a factor of 10, and so does the time. n=10 and so O(n)'s scaling
factor is 10.
Big-Oh Notation
Big-Oh Notation
O(1): known as Constant complexity
● 1 item: 1 second
● 10 items: 1 second
● 100 items: 1 second
The number of items is still increasing by a factor of 10, but the scaling factor of O(1) is always 1.
O(log n): known as Logarithmic complexity
● 1 item: 1 second
● 10 items: 2 seconds
● 100 items: 3 seconds
● 1000 items: 4 seconds
● 10000 items: 5 seconds
The number of computations is only increased by a log of the input value. So in this case, assuming each
computation takes 1 second, the log of the input n is the time required, hence log n.
Divide and conquer
Greedy method
Dynamic Programming
Basic Search and Traversal Technique
Graph Theory
Linear Programming
Approximation Algorithm
NP Problem
General approaches to algorithm design
❖ Heart of computer
❖ Promote analytical skills
Donald Knuth:
“ A person does not understand something until after
teaching it to someone else.
Actually: A person does not understand something until
after he teaches it to a ……COMPUTER!”
Why study Algorithms?
❖ Algorithms help us to understand scalability.
❖ Performance often draws the line between what is feasible and what is
impossible.
❖ Algorithmic mathematics provides a language for talking about program
behavior.
❖ Performance is the currency of computing.
❖ The lessons of program performance generalize to other computing
resources.
Why study algorithms and performance?
Write an algorithm that reads two values, determines the largest value and
prints the largest value with an identifying message.
ALGORITHM
Step 1: Input VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX VALUE1
else
MAX VALUE2
endif
Step 3: Print “The largest value is”, MAX
Algorithm e.g 1
Write an algorithm that reads three numbers and prints the value of the largest
number.
Algorithm e.g 2
Step 1: Input N1, N2, N3
Step 2: if (N1>N2) then
if (N1>N3) then
MAX N1 [N1>N2, N1>N3]
else
MAX N3 [N3>N1>N2]
endif
else
if (N2>N3) then
MAX N2 [N2>N1, N2>N3]
else
MAX N3 [N3>N2>N1]
endif
Algorithm e.g 2
Flowchart: Draw the flowchart of the above Algorithm
Algorithm e.g 2
Write an algorithm and draw a flowchart to read an
employee name (NAME), overtime hours worked
(OVERTIME), hours absent (ABSENT) and determine the
bonus payment (PAYMENT).
Algorithm e.g 3
Algorithm e.g 3
Step 1: Input NAME,OVERTIME,ABSENT
Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then
PAYMENT 50
else if (OVERTIME–(2/3)*ABSENT > 30) then
PAYMENT 40
else if (OVERTIME–(2/3)*ABSENT > 20) then
PAYMENT 30
else if (OVERTIME–(2/3)*ABSENT > 10) then
PAYMENT 20
else
PAYMENT 10
endif
Algorithm e.g 3
Draw the flowchart of the above algorithm?
Algorithm e.g 3
END

More Related Content

Similar to Algorithms overview

Module 1_ Introduction.pptx
Module 1_ Introduction.pptxModule 1_ Introduction.pptx
Module 1_ Introduction.pptxnikshaikh786
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfMemMem25
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit onessuserb7c8b8
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity CalculationAkhil Kaushik
 
01 intro to algorithm--updated 2015
01 intro to algorithm--updated 201501 intro to algorithm--updated 2015
01 intro to algorithm--updated 2015Hira Gul
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxJeevaMCSEKIOT
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptxrajesshs31r
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxrajesshs31r
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptxNishaS88
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialTo Sum It Up
 

Similar to Algorithms overview (20)

Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
Module 1_ Introduction.pptx
Module 1_ Introduction.pptxModule 1_ Introduction.pptx
Module 1_ Introduction.pptx
 
chapter 1
chapter 1chapter 1
chapter 1
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
01 intro to algorithm--updated 2015
01 intro to algorithm--updated 201501 intro to algorithm--updated 2015
01 intro to algorithm--updated 2015
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study material
 

Recently uploaded

What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 

Recently uploaded (20)

What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 

Algorithms overview

  • 2. ALL YOU NEED TO KNOW ABOUT ALGORITHMS
  • 3. ❖ A step-by-step procedure to solve a problem ❖ Every program is the instantiation of some algorithm ❖ Algorithm can be presented in a pseudocode or flowchart ALGORITHM
  • 4. ❖ sorting ❖ data retrieval ❖ network routing ❖ Games etc... Study problems these techniques can be applied to
  • 5. Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode may be an informal english, combinations of computer languages and spoken language. Whatever works for you. Pseudocode
  • 6.
  • 7. ❖ Algorithms are all around us in everyday life. ❖ In the recipe of a cook book. ❖ In assembling a toy. ❖ In setting the table. ❖ In preparing a cup of tea. ❖ In calling your friend on the phone.
  • 8. Hard to design algorithms that are ❖ correct ❖ efficient ❖ implementable Need to know about design and modeling techniques resources - don't reinvent the wheel Challenges
  • 9. ❖ Determine the feasibility of solution w.r.t. memory requirements, performance constraints … etc. ❖ Manually review and validate pseudo code ❖ Analyze the complexity of the algorithm using the big O notation to determine the complexity w.r.t. to time and storage. ❖ Other criteria include: Clarity, Maintainability, Portability Analyze Performance
  • 10. ❖ Understand the Problem (requirement analysis) ❖ Select Data structure (data structure is a particular way of organizing data in a computer so that it can be used efficiently) ❖ Write Pseudo Code ❖ Analyze Performance ❖ Implement using suitable programming language Guidelines for Algorithm Designing and Analysis:
  • 11. To understand their behavior, and (Job -- Selection, performance, modify) improve them. (Research) Why Analyze Performance
  • 12. Correctness: Does the input/output relation match algorithm requirement? Amount of work done (aka complexity):Basic operations to do task Amount of space used: Memory used Simplicity, clarity: Verification and implementation. Optimality: Is it impossible to do better? What do we analyze about them?
  • 13. Testing is divided into 2 main parts: ❖ Trying to break the function of the program by entering unexpected data. ❖ Debugging: It is concerned with finding out what is what caused the program to function in incorrectly. Test to resolve syntax and logic errors
  • 14. The complexity of an algorithm is simply the amount of work the algorithm performs to complete its task. Time complexity is a main issue in evaluating an algorithm. It reflects how the algorithm responds to the increase in data size (n) it handles, by measuring the corresponding increase in number of instructions to be performed. Time Complexity of an Algorithm
  • 15. ❖ How does the algorithm behave as the problem size gets very large? ❖ Running time ❖ Memory/storage requirements ❖ Bandwidth/power requirements/logic gates/etc. Analysis using Asymptotic Notation(Big-O)
  • 16. Big O notation also called Landau's symbol, is a symbolism used in complexity theory, computer science, and mathematics to describe the asymptotic behavior of functions. Basically, it tells you how fast a function grows or declines. Landau's symbol comes from the name of the German number theoretician Edmund Landau who invented the notation. The letter O is used because the rate of growth of a function is also called its order. For example, when analyzing some algorithm, one might find that the time (or the number of steps) it takes to complete a problem of size n is given by T(n) = 4 n2 - 2 n + 2
  • 17. O(n2 ): known as Quadratic complexity ● 1 item: 1 second ● 10 items: 100 seconds ● 100 items: 10000 seconds Notice that the number of items increases by a factor of 10, but the time increases by a factor of 102 . Basically, n=10 and so O(n2 ) gives us the scaling factor n2 which is 102. O(n): known as Linear complexity ● 1 item: 1 second ● 10 items: 10 seconds ● 100 items: 100 seconds This time the number of items increases by a factor of 10, and so does the time. n=10 and so O(n)'s scaling factor is 10. Big-Oh Notation
  • 18. Big-Oh Notation O(1): known as Constant complexity ● 1 item: 1 second ● 10 items: 1 second ● 100 items: 1 second The number of items is still increasing by a factor of 10, but the scaling factor of O(1) is always 1. O(log n): known as Logarithmic complexity ● 1 item: 1 second ● 10 items: 2 seconds ● 100 items: 3 seconds ● 1000 items: 4 seconds ● 10000 items: 5 seconds The number of computations is only increased by a log of the input value. So in this case, assuming each computation takes 1 second, the log of the input n is the time required, hence log n.
  • 19. Divide and conquer Greedy method Dynamic Programming Basic Search and Traversal Technique Graph Theory Linear Programming Approximation Algorithm NP Problem General approaches to algorithm design
  • 20. ❖ Heart of computer ❖ Promote analytical skills Donald Knuth: “ A person does not understand something until after teaching it to someone else. Actually: A person does not understand something until after he teaches it to a ……COMPUTER!” Why study Algorithms?
  • 21. ❖ Algorithms help us to understand scalability. ❖ Performance often draws the line between what is feasible and what is impossible. ❖ Algorithmic mathematics provides a language for talking about program behavior. ❖ Performance is the currency of computing. ❖ The lessons of program performance generalize to other computing resources. Why study algorithms and performance?
  • 22. Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. ALGORITHM Step 1: Input VALUE1, VALUE2 Step 2: if (VALUE1 > VALUE2) then MAX VALUE1 else MAX VALUE2 endif Step 3: Print “The largest value is”, MAX Algorithm e.g 1
  • 23.
  • 24. Write an algorithm that reads three numbers and prints the value of the largest number. Algorithm e.g 2
  • 25. Step 1: Input N1, N2, N3 Step 2: if (N1>N2) then if (N1>N3) then MAX N1 [N1>N2, N1>N3] else MAX N3 [N3>N1>N2] endif else if (N2>N3) then MAX N2 [N2>N1, N2>N3] else MAX N3 [N3>N2>N1] endif Algorithm e.g 2
  • 26. Flowchart: Draw the flowchart of the above Algorithm Algorithm e.g 2
  • 27. Write an algorithm and draw a flowchart to read an employee name (NAME), overtime hours worked (OVERTIME), hours absent (ABSENT) and determine the bonus payment (PAYMENT). Algorithm e.g 3
  • 29. Step 1: Input NAME,OVERTIME,ABSENT Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then PAYMENT 50 else if (OVERTIME–(2/3)*ABSENT > 30) then PAYMENT 40 else if (OVERTIME–(2/3)*ABSENT > 20) then PAYMENT 30 else if (OVERTIME–(2/3)*ABSENT > 10) then PAYMENT 20 else PAYMENT 10 endif Algorithm e.g 3
  • 30. Draw the flowchart of the above algorithm? Algorithm e.g 3
  • 31. END