Download presentation
Presentation is loading. Please wait.
1
Problem Solving Concepts
Dr. Munesh Singh
2
POINTS TO BE DISCUSSED:
What is mean by data, information, data structure What is a problem?-Types of problems Problem Solving in everyday life. Six steps for general problem solving Problem solving concepts for computers Organising Problems Problem Analysis Charts Structure/Interactivity Charts, IPO Chart Algorithm, Flowcharts, Internal and External documentation
3
Review of Data Structure
Data is raw Unorganized facts that needs to be processed Data can be simple and seamlessly random Useless until it is organized Example: Student record is one piece of data Information When data is processed Organized or structured Presented in a given context to make it useful
4
Review of Data Structure
Data Type: a data type or simply type is a classification identifying one of various types of data: Real-valued Integer Boolean determines the possible values for that type the operations that can be done on values of that type the meaning of the data the way values of that type can be stored. Data Structure: a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.
5
Types of Data Structures
6
What is a Problem? A state of difficulty that needs to be resolved
Problems exist where goals need to be attained and there is uncertainty about solution A Problem is an opportunity for improvement A problem is the difference between your current state and your goal state
7
Problem Faced in Everyday in Life
People make decisions everyday Examples: Should I wear casual or formal today? Should I watch TV or go out to cinema? what career? what course? What shoes? Everything needs a DECISION AS A SOLUTION TO THE PROBLEM
8
What happens when bad decisions are made?
WASTAGE OF TIME AND RESOURCES
9
Six steps to ensure a Best decision in PROBLEM SOLVING
Identify the problem Understand the problem Identify alternative ways to solve the problem Select the best way to solve the problem from the list of alternative solutions List instructions that enable you to solve the problem using selected solution Evaluate the solution
10
Take the problem of what to do to get solution
A Water Jug Problem: You are given two jugs, a 4-gallon one and a 3-gallon one, a pump which has unlimited water which you can use to fill the jug, and the ground on which water may be poured. Neither jug has any measuring markings on it. How can you get exactly 2 gallons of water in the 4-gallon jug?
11
Problem Steps To solve this we have to make some assumptions not mentioned in the problem. They are 1. We can fill a jug from the pump. 2. we can pour water out of a jug to the ground. 3. We can pour water from one jug to another. 4. There is no measuring device available.
12
What I am Expecting How to approach this problem in terms traditional way. Hint. Input, output, and logic How to Map this problem in computer language Which kind of Data Structure you need to Solve this problem efficiently This problem is heuristic or Algorithmic. how many solution of this problem. And which one is the best solution with reason
13
First Solutions of the Problem
14
Second and Third Solution
15
Data structure for above problem
Graph will be the data structure to solve this problem BFS (Breadth first search) DFS (Depth first search)
16
Another Problem On one bank of a river are three missionaries and three cannibals. There is one boat available that can hold up to two people and that they would like to use to cross the river. If the cannibals ever outnumber the missionaries on either of the river’s banks, the missionaries will get eaten. How can the boat be used to safely carry all the missionaries and cannibals across the river?
17
TIC-TAC-TOE Problem
18
Approaches to solve a problem:
Algorithmic : Solutions that can be solved with a series of known actions are called Algorithmic Solutions Heuristic : Employing a self-learning approach to the solution of a problems is known as Heuristic Solutions
19
Examples Algorithmic solution: To make a cup of coffee
To find largest of three numbers Heuristic solutions: how to buy the best stock? How to play chess?
20
Problem solving with computers
Computers use algorithmic solutions Program – set of instructions that make up solution to a problem Results – outcome of running the program Testing – Are the outcomes what you expected and correct Documentation – two types manual documentation instructions telling users how to use the program
21
Problem solving with computers involves several steps
Clearly define the problem. Analyze the problem and formulate a method to solve it (see also .validation.). Describe the solution in the form of an algorithm. Draw a flowchart of the algorithm. Write the computer program. Compile and run the program (debugging). Test the program (debugging) (see also verification.). Interpretation of results.
22
ALGORITHMS AND FLOWCHARTS
A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps is called an algorithm Implementation phase implement the program in some programming language
23
Steps in Problem Solving
First produce a general algorithm (one can use pseudo code) Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language. Pseudo code is an artificial and informal language that helps programmers develop algorithms. Pseudo code is very similar to everyday English.
24
Pseudo code & Algorithm
Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.
25
Pseudo code & Algorithm
Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print “FAIL” else Print “PASS”
26
Pseudocode & Algorithm
Detailed Algorithm Step 1: Input M1,M2,M3,M4 Step 2: GRADE (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif
27
The Flowchart (Dictionary) A schematic representation of a sequence of operations, as in a manufacturing process or computer program. (Technical) A graphical representation of the sequence of operations in an information system or program. Information system flowcharts show how data flows from source documents through the computer to final distribution to users. Program flowcharts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart.
28
The Flowchart A Flowchart shows logic of an algorithm
emphasizes individual steps and their interconnections e.g. control flow from one action to the next
29
Flowchart Symbols Basic
30
Example 1 START Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4 IS GRADE<50
PRINT “FAIL” STOP Y N PRINT “PASS”
31
Example 2 Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Pseudo code: Input the length in feet (Lft) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM)
32
Flowchart
33
Example 3 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudocode Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A
34
Algorithm Step 1: Input W,L Step 2: A L x W Step 3: Print A
35
Example 4 Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation Hint: d = sqrt ( ), and the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a
36
Pseudo code: Input the coefficients (a, b, c) of the quadratic equation Calculate d Calculate x1 Calculate x2 Print x1 and x2
37
Algorithm: Step 1: Input a, b, c Step 2: d sqrt ( )
Step 3: x1 (–b + d) / (2 x a) Step 4: x2 (–b – d) / (2 x a) Step 5: Print x1, x2 START Input a, b, c d sqrt(b x b – 4 x a x c) Print x1 ,x2 STOP x1 (–b + d) / (2 x a) X2 (–b – d) / (2 x a)
38
DECISION STRUCTURES The expression A>B is a logical expression
it describes a condition we want to test if A>B is true (if A is greater than B) we take the action on left print the value of A if A>B is false (if A is not greater than B) we take the action on right print the value of B
39
DECISION STRUCTURES
40
IF–THEN–ELSE STRUCTURE
The structure is as follows: If condition then true alternative else false alternative endif
41
IF–THEN–ELSE STRUCTURE
The algorithm for the flowchart is as follows: If A>B then print A else print B endif
42
Relational Operators
43
Example 5 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
45
NESTED IFS One of the alternatives within an IF–THEN–ELSE statement
may involve further IF–THEN–ELSE statement
46
Example 6 Write an algorithm that reads three numbers and prints the value of the largest number.
48
A program that is easy to read & understand, and therefore, easy to maintain & enhance
readable program?
49
A program with correct syntax & semantics
correct program?
50
PPT you will get on the link https://shodhkarya.blogspot.in/
Queries ? PPT you will get on the link
51
ThanksYou
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.