Beruflich Dokumente
Kultur Dokumente
Lecture Objectives
Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development Become aware of problem solving process
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
Step 3 - Maintenance
Use and modify the program if the problem domain changes
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
Ordered set of steps: structure! Executable steps: doable! Unambiguous steps: follow the directions! Terminating: must have an end!
Representation of Algorithms
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!
Expressing Algorithms
English description
More More easily expressed precise
Pseudo-code
Pseudocode
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
Pseudocode (Contd)
Example: The sequential search algorithm in pseudocode
Algorithm Discovery
Step 2 is the easy step! Step 1 can be very difficult! To discover an algorithm is to solve the problem!
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!
Stepwise Refinement
Stepwise refinement is a top-down methodology in that it progresses from the general to the specific.
Solutions produced by stepwise refinement posses a natural modular structure - hence its popularity in algorithmic design.
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
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 dont 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 objects variables Action responsibilities are a little more complicated, often involving calculations
Computer Example
Lets repeat the problem-solving process for creating an address list Brainstorming and filtering
Circling the nouns and underlining the verbs
CRC Cards
Responsibility Algorithms