Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIT- I General Problem Solving Concepts

Similar presentations


Presentation on theme: "UNIT- I General Problem Solving Concepts"— Presentation transcript:

1 UNIT- I General Problem Solving Concepts

2 Contents Introduction General Problem Solving Concepts
Types of Problems Problem solving with computers Difficulties with problem solving Problem solving Aspect Problem Solving Concepts for Computer Constants and variables Data types Functions Operators Expressions and equations Programming Concepts Communicating with computers Organizing the problem Using the tools Testing the solution Coding the program Time & Space complexity Sorting Problem

3 problem A perceived gap between the existing state and a desired state
Definition A perceived gap between the existing state and a desired state

4

5 Introduction -Einstein
“If I have one hour to save the world I would spend fifty- five minutes defining the problem and only five minutes finding the solution. -Einstein

6 Six steps for problem Solving
Identify the problem Understand the problem Identify alternative ways to solve the problem Select the best way to solve the problem List instructions that enable you to solve the problem using the selected solution Evaluate the solution

7 Example: Problem what to do this evening
Indentify the Problem: How do the Individuals wish to spend the evening? Understand the problem: The knowledge base of the participants must be considered. The only solutions that should be selected are ones that everyone would know how to do. You probably would not select as a possible solution playing a game of chess if the participants do not know hot to play chess. Identify Alternatives: Watch Television Invite friends over Play games Go to the movie Play miniature golf Go to a friends party Go to the amusement park List is complete only when you can think of no more alternatives Select best way to solve the problem Cut out alternatives that are not acceptable Specify pros and Cons of each Remaining alternative Compare pros and cons to make final decision Prepare a list of steps that will result in a fun evening. Evaluate the solution. Are we having fun yet?

8 E.G. Chitti The Robot (From: PS&PC by Maureen Sprankle -pg no:463-Appendix A)

9 General Problem-Solving Concepts

10 Types of Problems Problems can be solved with series of actions
Algorithmic Solution Problems do not always have straightforward solutions Heuristic solutions Problem solver can use six steps for both algorithmic and heuristic solutions Evaluating correctness and Appropriateness of heuristic solutions are far less certain. Most problems require a combination of the two kinds of solutions

11 Problem solving with computers
Results means the outcome or the completed computer assisted answer Program means the set of instructions that make up the solution using programming language Computers are built to deal with algorithmic solutions Difficulty lies in Programming Solutions must be transformed into an algorithmic format

12 Difficulties with Problem Solving
People have many problems with problem solving Afraid to make decisions People go through one or more steps inadequately Problem solving process is not easy Problem solving on computer Difficult task of writing instructions Computer has specific system of communication

13 Problem Solving Aspect
There is no universal method for problem solving Phases Problem Definition Phase Getting started on a problem The use of Specific Examples Similarities among problems Working backwards from the solution General Problem Solving Strategies

14 Problem Definition Phase
What must be done? We must try to extract set of precisely defined tasks. E.g. Finding Square root, Greatest Common Divisor Getting Started on a Problem Sometimes, even after problem definition people do not know where to start? What can we do?

15 The use of Specific Examples
Best approach when we are stuck is to make a start on a problem is to pick a specific example Geometrical and graphical representing certain aspect of a problem can be useful Similarities among problems Bring as much as past experiences as possible New problem cannot be completely different Sometimes it blocks us from discovering a new thing In the first instance try to independently solve the problem

16 Greedy method Branch and Bound Backtracking
Working Backwards from the solution In some cases we assume that we already have solution and then try to work backwards Whatever attempts we make that we make to get started on a problem we should write it down General Problem Solving Strategies Divide and Conquer Binary doubling Dynamic Programming Greedy method Branch and Bound Backtracking

17 Problem Solving Concepts for the Computer

18 Constants and Variables
The Computer uses constants and variables to solve problems Constants is a value that never changes during processing of all instructions Can be numeric, alphabetic or special Symbol Constant is given a value and then referred to by its name In contrast, the value of a variable may change during processing In many languages variables are called Identifiers

19 Rules for naming and Using Variables
Name a variable according to what it represent Do not use spaces in variable name Start variable with a letter Do not use dash(-) in a program After introduces variable name, exact variable name must be used where data item is used Be consistent while using UPPERCASE and lowercase variables Use naming conventions specified by your company

20 Data Types To process solutions computer must have data.
Data are unorganized facts Computer Must be told the data types of each variable and constant DATA Data Processed into information Report Checks Deposits Bk Charges Calculates the Balance Balance Sheet Fig. Processing Data: How a computer Balances a Checkbook

21 Surrounded by quotation mark All letters, Numbers and Special Symbols
Data Type Data Sets Examples Numeric: Integer All whole numbers 3400 -34 Real All real Numbers (Whole + Decimal) Character : Surrounded by quotation mark All letters, Numbers and Special Symbols “a”, “1”, “A”, “F”, “%”, “&” “$” String: Combination of more than one character “Rahul” “343443” “ ” Logical True, False

22 Rules for Data Types The data that define the value of a variable or a constant will be of numeric, character, logical Computer then associate variable with desired data type Data types can not be mixed Each of the data types uses what is called a data sets Any numeric item that must be used in calculations resulting in a numeric result must be of numeric type

23 Functions Functions are small set of instructions that perform specific task and return values By using functions programmers can shorten the problem solving time and improves readability Each language has set of functions within it Most languages allows programmers to write their own functions Functions can be Mathematical functions String functions Conversion Functions Statistical functions Utility functions

24 Operators Mathematical + - / * % ^
Operators are the data connectors within expressions They tell the computer how to process data Operators Mathematical + - / * % ^ Relational < > <= >= != [<>] Logical && || ! Operand and resultant are two concepts related to operator The data type of Operands and resultant depends on the operator

25 Expressions and Equations
Expressions and Equations make a part of instructions in the solution An Expressions processes data, operands using operators e.g. length * breadth An Equation stores the resultant of an expression e.g. area=length*breadth Setting up /Evaluating Numeric Expression Mathematical equations Relational Expression Logical expression

26 Programming Concepts

27 Communicating with the computer
We have to learn system of communication or Computer language System of communication requires instructions governed by specific rules. Syntax are the rules governing the computer operating system An error is called a bug Bug must be found and corrected, a process is called Debugging Computers are exact machines but the people working with them are not.

28 Organizing the problem
Organizational tools will help us to solve problems on the computer Tools Problem Analysis Chart Structure Chart or Interactivity Chart IPO chart Algorithms Flowcharts

29 Analyzing the Problem The given data The required Results
First programmer has to understand and analyze the requirements of the problem Good way to analyze problem is to separate it into four parts The given data The required Results The processing that required in the problem A list of solution alternatives PAC allows problem solver to eliminate the words and separate the facts from the problem

30 4. Solution Alternatives
1. Given Data 2. Required Results 3. Processing Required 4. Solution Alternatives Fig: Problem Analysis Chart

31 Grosspay=Hours*Payrate 4. Solution Alternatives
Given Data Hours Pay rate 2. Required Results Grosspay 3. Processing Required Grosspay=Hours*Payrate 4. Solution Alternatives Define the hours worked and Payrate as constants Define the hours worked and payrate as input values Fig: Problem Analysis Chart

32 Developing the Interactivity(Structure) Chart
Next task in organizing the solution is to divide the processing into subtasks called modules Connect these modules to show interaction of processing between modules Each module should contain the task to accomplish one function There will be one module that controls the flow of most of the other module[Control or Main module]

33 Control Module 1 Module 3 Module 2 Module 6 Module 7 Module 4 Module 5
Interactivity Chart Interactivity Chart for Payroll Problem Payrollcontrol Read Calc Print Until No Employee

34 Module 7 Module 6 Module 3 Module 2 Module 3 Module 1 CONTROL Module 5 Module 4 Interactivity Chart [Object Oriented Solution]

35 Object Oriented Solution
Read PayrollControl Print Calc Interactivity Chart for Payroll Problem Object Oriented Solution

36 Developing the IPO chart
The input-processing-output chart extends and organizes the information in the PAC IPO also shows that where in the solution processing takes place Sections Input The processing Module Reference Output

37 Input Processing Module reference Output All data input [From section 1 of PAC] All processing in step [From Section 3 and 4] Module reference from the interactivity chart All output requirement [from section1 and 2 from PAC] The IPO Chart Input Processing Module reference Output Hours worked Pay Rate Enter Hours Worked Enter Pay Rate Calculate Pay Print Pay End Read Calc Print Payrollcontrol Gross pay The IPO Chart for the Payroll Problem

38 e.g Joe would like to build several bookcases that are different heights and widths. All will be 12 inches in depth. The bookcases will have 3 shelves, in addition to the bottom and top. Write a solution to print the no. of feet of 12 –inch-wide boards that Joe need to complete a bookcase, given the height and width. Bob would like to know what percentage of his income his rent is. Write a solution that would calculate and print this percentage. (Hint: Percentage=Number/Total)

39 Writing the Algorithms
Next steps in organizing the solution is to develop set of instructions for the computer called algorithm Pseudo code is similar to algorithms Programmer writes a separate instructions for each module in the structure chart Hardest part of problem solving The instructions cannot assume anything Cannot skip Steps Must be executable one step at a time Must be complete

40 Drawing Flowchart From the algorithms programmer develops the flowcharts Flowcharts are the graphical representation of the algorithms Flowcharts can show errors in logic not readily visible in the other charts A flowchart shows the flow of the processing from the beginning to the end of a solution

41 Rules for drawing flowcharts
You should write instructions inside the blocks If there is something you need to remember you can write a note besides a block A flowchart always start at the top of the page and flows to the bottom Use flowchart template to draw the symbols and flow lines Make the blocks big enough to write instructions so they can be easily read Final copy of the flowchart may not be the first draft

42 Testing the Solutions When a solution is complete it is important to test it To test a solution programmers select test data, a set of values A solution should never be assumed correct. If bug is detected, the solution has to be modified it and then the testing process starts once again

43 Coding the Program Next step is writing the solution into a computer language If programmer follows the proper steps in developing solution there should be few logic errors in the program

44 Pointers of structuring program
Use modules 4 Logic structures Sequential structure Decision structure Loop structure Case structure

45 Modules Rules for designing modules
Solution breaks always in modules Rules for designing modules Each module is an entity itself with entrance and exit It should not jump in between Only with Single function or task Easily readable and modified No. of instructions to complete the function should be governed by functions Order of processing

46 Types of modules Control module Initialization module Process module
Calculation modules Print modules Read and data validation modules Wrap up modules Event module in OOP( mouse up/dw etc…)

47 Cohesion and coupling Cohesion: independent of each other Module 1
Coupling allows to share data with some interface Module 3

48 Solution development -6 steps
The problem analysis chart The interactivity chart The IPO chart Coupling diagram with design of data flow Algorithm writing Flowchart

49 PART I END


Download ppt "UNIT- I General Problem Solving Concepts"

Similar presentations


Ads by Google