First Step of Problem Solving Using Data Structure and Algorithm

What is problem ?

  • A state of difficulty that need to be resolve
  • A problem exist and its solution needs to be  attain either correct or incorrect
  • A problem gives an opportunity to improve the current state
  • A problem is a difference between the  current state and goal state

Problem Faced in daily life
      
Like making the decisions
  • what should i wear today to look good?
  • what career?
  • what job?
  • what shoes?
  • what course?

What happens when bad decisions are made?

Wastage of time and resource

 


Six steps to ensure  a Best decision in PROBLEM SOLVING
  • Identify the problem first
  • understand the problem
  • Identify the different way to solve the problem (efficient)
  • Select the best one solution among the various alternative solutions
  • Identify the list of steps to solve a problem (instructions)
  • Evaluate the solution of given problem (different set of inputs)
Take the problem of and apply the six step of problem solving 

   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?



What I am Expecting
  •       Identify the problem and find out the initial state and goal      state.
  •        Locate the inputs given in the statements
  •        How to map it in computer programming language
  •        What data structure is suitable to solve this     problem efficiently
  •        Identify the type of the problem (algorithmic or heuristic)
  •        How many solutions can have a given problem
  •        Which one is the best among the other solution.


Approaches to solve a problem

         Algorithmic Solution : Solutions can be find out with a series                                                             of  known actions.

         Ex:  How to make a coffee, 

                  To find the largest number among three numbers
          



        Heuristic Solution : Solution can be find out using the self                                                              learning approach (multiple try).
    
      Ex: How to buy a best stock ?
              How to play a chess ?   

Problem solving with computers

Computers use the algorithmic solutions

Programs:  Set of instructions that solve a given problem

Results    :  Output of the ruining programs

Testing    : Are the outcome what you expected and correct

Documentation : Two types
  •      Manual documentation
  •      Instructions manual                                 

Steps of Problem solving with Computer
  •       Clearly define a problem
  •       Analyse the problem and formulate the method to solve it
  •       Describe the Solution in terms of Algorithm
  •       Draw a flow graph of the given problem or Algorithm
  •       Write the computer programs
  •       Compile and run the program (Debugging)
  •       Test the program (Debugging)
  •       Interpretation of results

Algorithm and Flow charts

 A programming task usually divided into two phases:
  •       Problem Solving Phase : Produce an order sequence of steps to solve a given problem
  •      Implementation Phase : Implement the program in some programming language

Steps in Problem Solving
  •      First produce a general algorithm (use Pseudo code)
  •      Refine the general algorithm to get a step by step    detail algorithm that is close to a computer language.
  •      Pseudo code is a informal language that helps a  programmer to develop a algorithms. Pseudo code is  similar to general English.

  Pseudo code &Algorithm

EX : 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.

Pseudo code:

 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”

Detailed Algorithm 

      Step 1:   Input M1,M2,M3,M4
      Step 2:   GRADE <-- span="">(M1+M2+M3+M4)/4
      Step 3:   if (GRADE < 50) then
                Print “FAIL”
            else
                Print “PASS”
            endif

The Flowchart


A schematic representation of a sequence of operations.


A graphical representation of the sequence of operations

in an information system or program.


Information system flowcharts show how data flows 

from source  to destination.


Program flowcharts show the sequence of instructions in

a single program or subroutine.


Different symbols are used to draw each type of 

flowchart.





Flowchart of Previous Example:




Try Yourself this example : Write an algorithm and 

draw a flowchart that will read the two sides of a 

rectangle and calculate its area.

(a) Write Pseudo Code

(b) Write Algorithm

(c) Draw a Flowchart


Few more Flowcharts


Decision Making     




      


Always Remember




::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
PPT of this topic find at below link......
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Comments

Popular posts from this blog

Types of Algorithm and Its Complexity Analysis

Asymptotic Notations