SlideShare a Scribd company logo
1 of 29
Algorithms and
Problem Solving
• Learn about problem solving skills
• Explore the algorithmic approach for
problem solving
• Learn about algorithm development
• Become aware of problem solving process
Lecture Objectives
Problem Solving
• Programming is a process of problem
solving
• Problem solving techniques
 Analyze the problem
 Outline the problem requirements
 Design steps (algorithm) to solve the problem
• Algorithm:
 Step-by-step problem-solving process
 Solution achieved in finite amount of time
Problem Solving Process
• Step 1 - Analyze the problem
 Outline the problem and its requirements
 Design steps (algorithm) to solve the problem
• Step 2 - Implement the algorithm
 Implement the algorithm in code
 Verify that the algorithm works
• Step 3 - Maintenance
 Use and modify the program if the problem
domain changes
Analyze the Problem
• Thoroughly understand the problem
• Understand problem requirements
 Does program require user interaction?
 Does program manipulate data?
 What is the output?
• If the problem is complex, divide it into
subproblems
 Analyze each subproblem as above
What is an algorithm?
• The idea behind the computer program
• Stays the same independent of
 Which kind of hardware it is running on
 Which programming language it is written in
• Solves a well-specified problem in a general
way
• Is specified by
 Describing the set of instances (input) it must work on
 Describing the desired properties of the output
• Before a computer can perform a task, it must
have an algorithm that tells it what to do.
• Informally: “An algorithm is a set of steps that
define how a task is performed.”
• Formally: “An algorithm is an ordered set of
unambiguous executable steps, defining a
terminating process.”
 Ordered set of steps: structure!
 Executable steps: doable!
 Unambiguous steps: follow the directions!
 Terminating: must have an end!
What is an algorithm? (Cont’d)
What is an algorithm? (Cont’d)
Important Properties of Algorithms
• Correct
 always returns the desired output for all legal
instances of the problem.
• Unambiguous
• Precise
• Efficient
 Can be measured in terms of
• Time
• Space
 Time tends to be more important
Representation of Algorithms
• A single algorithm can be represented in
many ways:
 Formulas: F = (9/5)C + 32
 Words: Multiply the Celsius by 9/5 and add 32.
 Flow Charts.
 Pseudo-code.
• In each case, the algorithm stays the same;
the implementation differs!
 A program is a representation of an algorithm
designed for computer applications.
 Process: Activity of executing a program, or execute
the algorithm represented by the program
  Process: Activity of executing an algorithm.
Representation of Algorithms (Cont’d)
Expressing Algorithms
• English description
• Pseudo-code
• High-level
programming
language
More
precise
More easily
expressed
• Pseudocode is like a programming language
but its rules are less stringent.
• Written as a combination of English and
programming constructs
 Based on selection (if, switch) and iteration (while,
repeat) constructs in high-level programming
languages
• Design using these high level primitives
 Independent of actual programming language
Pseudocode
Example: The sequential search algorithm in
pseudocode
Pseudocode (Cont’d)
Algorithm Discovery
• The Two Steps of Program Development:
 1. Discover the algorithm.
 2. Represent the algorithm as a program.
• Step 2 is the easy step!
• Step 1 can be very difficult!
• To discover an algorithm is to solve the
problem!
Problem Solving: A creative process
• Problem solving techniques are not unique
to Computer Science.
• The CS field has joined with other fields to
try to solve problems better.
• Ideally, there should be an algorithm to
find/develop algorithms.
• However, this is not the case as some
problems do not have algorithmic solutions.
• Problem solving remains an art!
Problem Solving Strategies
• Working backwards
 Reverse-engineer
 Once you know it can be done, it is much easier to do
 What are some examples?
• Look for a related problem that has been solved before
 Java design patterns
 Sort a particular list such as: David, Alice, Carol and Bob
to find a general sorting algorithm
• Stepwise Refinement
 Break the problem into several sub-problems
 Solve each subproblem separately
 Produces a modular structure
• K.I.S.S. = Keep It Simple Stupid!
Stepwise Refinement
• Stepwise refinement is a top-down methodology
in that it progresses from the general to the
specific.
• Bottom-up methodologies progress from the
specific to the general.
 These approaches complement each other
• Solutions produced by stepwise refinement
posses a natural modular structure - hence its
popularity in algorithmic design.
Object-Oriented Design Methodology
• Four stages to the decomposition process
 Brainstorming
 Filtering
 Scenarios
 Responsibility algorithms
Class-Responsibility-Collaboration (CRC) Cards
Brainstorming
• A group problem-solving technique that
involves the spontaneous contribution of
ideas from all members of the group
 All ideas are potential good ideas
 Think fast and furiously first, and ponder later
 A little humor can be a powerful force
• Brainstorming is designed to produce a list
of candidate classes
Filtering
• Determine which are the core classes in the
problem solution
• There may be two classes in the list that
have many common attributes and behaviors
• There may be classes that really don’t belong
in the problem solution
Scenarios
• Assign responsibilities to each class
• There are two types of responsibilities
 What a class must know about itself (knowledge)
 What a class must be able to do (behavior)
• Encapsulation is the bundling of data and
actions in such a way that the logical
properties of the data and actions are
separated from the implementation details
Responsibility Algorithms
• The algorithms must be written for the
responsibilities
 Knowledge responsibilities usually just return the
contents of one of an object’s variables
 Action responsibilities are a little more complicated,
often involving calculations
Computer Example
• Let’s repeat the problem-solving process for
creating an address list
• Brainstorming and filtering
 Circling the nouns and underlining the verbs
• First pass at a list of classes
Computer Example (Cont’d)
• Filtered list
Computer Example (Cont’d)
CRC Cards
Responsibility Algorithms

More Related Content

What's hot

What's hot (19)

Design and analysis of computer algorithms
Design and analysis of computer algorithmsDesign and analysis of computer algorithms
Design and analysis of computer algorithms
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design Presentation
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Ada notes
Ada notesAda notes
Ada notes
 
#1 designandanalysis of algo
#1 designandanalysis of algo#1 designandanalysis of algo
#1 designandanalysis of algo
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Fundamental of Algorithms
Fundamental of Algorithms Fundamental of Algorithms
Fundamental of Algorithms
 
Algorithm Design
Algorithm DesignAlgorithm Design
Algorithm Design
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
 
Aad introduction
Aad introductionAad introduction
Aad introduction
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
Design and analysis of algorithms - Abstract View
Design and analysis of algorithms - Abstract ViewDesign and analysis of algorithms - Abstract View
Design and analysis of algorithms - Abstract View
 
01 Analysis of Algorithms: Introduction
01 Analysis of Algorithms: Introduction01 Analysis of Algorithms: Introduction
01 Analysis of Algorithms: Introduction
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Lecture 1 objective and course plan
Lecture 1   objective and course planLecture 1   objective and course plan
Lecture 1 objective and course plan
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
 

Similar to Problem solving

Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptxShaistaRiaz4
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structureSelf-Employed
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object DesignMichael Heron
 
Csci101 lect00 introduction
Csci101 lect00 introductionCsci101 lect00 introduction
Csci101 lect00 introductionElsayed Hemayed
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxsatvikkushwaha1
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithmsiqbalphy1
 
Program Synthesis, DreamCoder, and ARC
Program Synthesis, DreamCoder, and ARCProgram Synthesis, DreamCoder, and ARC
Program Synthesis, DreamCoder, and ARCAndrey Zakharevich
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.pptChapter1.1 Introduction.ppt
Chapter1.1 Introduction.pptTekle12
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.pptChapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.pptTekle12
 
Agile software development
Agile software developmentAgile software development
Agile software developmentHemangi Talele
 
01 introduction to cpp
01   introduction to cpp01   introduction to cpp
01 introduction to cppManzoor ALam
 
Computational thinking
Computational thinkingComputational thinking
Computational thinkingr123457
 

Similar to Problem solving (20)

[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP
 
Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptx
 
Unit no_1.pptx
Unit no_1.pptxUnit no_1.pptx
Unit no_1.pptx
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object Design
 
Csci101 lect00 introduction
Csci101 lect00 introductionCsci101 lect00 introduction
Csci101 lect00 introduction
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
PPS_Unit 1.pptx
PPS_Unit 1.pptxPPS_Unit 1.pptx
PPS_Unit 1.pptx
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithms
 
Program Synthesis, DreamCoder, and ARC
Program Synthesis, DreamCoder, and ARCProgram Synthesis, DreamCoder, and ARC
Program Synthesis, DreamCoder, and ARC
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
 
Chapter1.1 Introduction.ppt
Chapter1.1 Introduction.pptChapter1.1 Introduction.ppt
Chapter1.1 Introduction.ppt
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.pptChapter1.1 Introduction to design and analysis of algorithm.ppt
Chapter1.1 Introduction to design and analysis of algorithm.ppt
 
Lecture 1 (bce-7)
Lecture   1 (bce-7)Lecture   1 (bce-7)
Lecture 1 (bce-7)
 
Agile software development
Agile software developmentAgile software development
Agile software development
 
01 introduction to cpp
01   introduction to cpp01   introduction to cpp
01 introduction to cpp
 
5-CEN6016-Chapter1.ppt
5-CEN6016-Chapter1.ppt5-CEN6016-Chapter1.ppt
5-CEN6016-Chapter1.ppt
 
Computational thinking
Computational thinkingComputational thinking
Computational thinking
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 

Problem solving

  • 2. • Learn about problem solving skills • Explore the algorithmic approach for problem solving • Learn about algorithm development • Become aware of problem solving process Lecture Objectives
  • 3. Problem Solving • Programming is a process of problem solving • Problem solving techniques  Analyze the problem  Outline the problem requirements  Design steps (algorithm) to solve the problem • Algorithm:  Step-by-step problem-solving process  Solution achieved in finite amount of time
  • 4. Problem Solving Process • Step 1 - Analyze the problem  Outline the problem and its requirements  Design steps (algorithm) to solve the problem • Step 2 - Implement the algorithm  Implement the algorithm in code  Verify that the algorithm works • Step 3 - Maintenance  Use and modify the program if the problem domain changes
  • 5. Analyze the Problem • Thoroughly understand the problem • Understand problem requirements  Does program require user interaction?  Does program manipulate data?  What is the output? • If the problem is complex, divide it into subproblems  Analyze each subproblem as above
  • 6. What is an algorithm? • The idea behind the computer program • Stays the same independent of  Which kind of hardware it is running on  Which programming language it is written in • Solves a well-specified problem in a general way • Is specified by  Describing the set of instances (input) it must work on  Describing the desired properties of the output
  • 7. • Before a computer can perform a task, it must have an algorithm that tells it what to do. • Informally: “An algorithm is a set of steps that define how a task is performed.” • Formally: “An algorithm is an ordered set of unambiguous executable steps, defining a terminating process.”  Ordered set of steps: structure!  Executable steps: doable!  Unambiguous steps: follow the directions!  Terminating: must have an end! What is an algorithm? (Cont’d)
  • 8. What is an algorithm? (Cont’d)
  • 9. Important Properties of Algorithms • Correct  always returns the desired output for all legal instances of the problem. • Unambiguous • Precise • Efficient  Can be measured in terms of • Time • Space  Time tends to be more important
  • 10. Representation of Algorithms • A single algorithm can be represented in many ways:  Formulas: F = (9/5)C + 32  Words: Multiply the Celsius by 9/5 and add 32.  Flow Charts.  Pseudo-code. • In each case, the algorithm stays the same; the implementation differs!
  • 11.  A program is a representation of an algorithm designed for computer applications.  Process: Activity of executing a program, or execute the algorithm represented by the program   Process: Activity of executing an algorithm. Representation of Algorithms (Cont’d)
  • 12. Expressing Algorithms • English description • Pseudo-code • High-level programming language More precise More easily expressed
  • 13. • Pseudocode is like a programming language but its rules are less stringent. • Written as a combination of English and programming constructs  Based on selection (if, switch) and iteration (while, repeat) constructs in high-level programming languages • Design using these high level primitives  Independent of actual programming language Pseudocode
  • 14. Example: The sequential search algorithm in pseudocode Pseudocode (Cont’d)
  • 15. Algorithm Discovery • The Two Steps of Program Development:  1. Discover the algorithm.  2. Represent the algorithm as a program. • Step 2 is the easy step! • Step 1 can be very difficult! • To discover an algorithm is to solve the problem!
  • 16. Problem Solving: A creative process • Problem solving techniques are not unique to Computer Science. • The CS field has joined with other fields to try to solve problems better. • Ideally, there should be an algorithm to find/develop algorithms. • However, this is not the case as some problems do not have algorithmic solutions. • Problem solving remains an art!
  • 17. Problem Solving Strategies • Working backwards  Reverse-engineer  Once you know it can be done, it is much easier to do  What are some examples? • Look for a related problem that has been solved before  Java design patterns  Sort a particular list such as: David, Alice, Carol and Bob to find a general sorting algorithm • Stepwise Refinement  Break the problem into several sub-problems  Solve each subproblem separately  Produces a modular structure • K.I.S.S. = Keep It Simple Stupid!
  • 18. Stepwise Refinement • Stepwise refinement is a top-down methodology in that it progresses from the general to the specific. • Bottom-up methodologies progress from the specific to the general.  These approaches complement each other • Solutions produced by stepwise refinement posses a natural modular structure - hence its popularity in algorithmic design.
  • 19. Object-Oriented Design Methodology • Four stages to the decomposition process  Brainstorming  Filtering  Scenarios  Responsibility algorithms
  • 21. Brainstorming • A group problem-solving technique that involves the spontaneous contribution of ideas from all members of the group  All ideas are potential good ideas  Think fast and furiously first, and ponder later  A little humor can be a powerful force • Brainstorming is designed to produce a list of candidate classes
  • 22. Filtering • Determine which are the core classes in the problem solution • There may be two classes in the list that have many common attributes and behaviors • There may be classes that really don’t belong in the problem solution
  • 23. Scenarios • Assign responsibilities to each class • There are two types of responsibilities  What a class must know about itself (knowledge)  What a class must be able to do (behavior) • Encapsulation is the bundling of data and actions in such a way that the logical properties of the data and actions are separated from the implementation details
  • 24. Responsibility Algorithms • The algorithms must be written for the responsibilities  Knowledge responsibilities usually just return the contents of one of an object’s variables  Action responsibilities are a little more complicated, often involving calculations
  • 25. Computer Example • Let’s repeat the problem-solving process for creating an address list • Brainstorming and filtering  Circling the nouns and underlining the verbs
  • 26. • First pass at a list of classes Computer Example (Cont’d)
  • 27. • Filtered list Computer Example (Cont’d)