Docsity

Problem Solving Techniques - Computer Fundamentals - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Problem Solving Techniques - Computer Fundamentals - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Contents

  • Today's Topic: Problem Solving Techniques
  • We will learn
    1. Problem Statement.
    2. Algorithm  Types, Example
    3. Flowchart  Symbols, Examples.

Problem Solving Techniques

Algorithm:

The algorithm is part of the blueprint or plan for the computer program, an algorithm is: “An effective procedure for solving a class of problems in a finite number of steps.”

Every algorithm should have the following 5 characteristic feature:

  1. Input
  2. Output
  3. Definiteness
  4. Effectiveness
  5. Termination

Algorithm (Contd…):

  • To find largest of three numbers
  1. Start
  2. Read 3 numbers: num1, num2, num
  3. if num1 > num2 then go to step 5
  4. if num2 > num3 then print num2 is largest else print num3 is largest goto step 6
  5. if num1 > num3 then print num1 is largest else print num3 is largest
  6. end.

Algorithm (Contd…):

Formal description: Written in prose but much closer to the high-level language of a computer program, the following is the more formal coding of the algorithm in pseudo code (find the largest number in an (unsorted) list of numbers)

Algorithm LargestNumber

Input: A non-empty list of numbersL. Output: Thelargest number in the listL.

  1. largest ← L 0 for eachitem in the listL, do
  2. if theitem >largest, then
  3. largest ← the item
  4. returnlargest

Flowchart:

What is a Flowchart?

  • The flowchart is a means of visually presenting the flow of control through an information processing systems, the operations performed within the system and the sequence in which they are performed.
  • It is a graphic representation of how a process works, showing, at a minimum, the sequence of steps.
  • Flowcharts are generally drawn in the early stages of formulating computer solutions.

Flowchart (Contd…):

A set of useful standard Flowchart

symbols:

  • Rounded box use it to represent an event which occurs automatically.
  • Rectangle or box use it to represent an event which is controlled within the process. Typically this will be a step or action which is taken.
  • Diamond use it to represent a decision point in the process.
  • Circle use it to represent a point at which the flowchart connects with another process.

ADVANTAGES OF USING

FLOWCHARTS:

  • Communication: Flowcharts are better way of communicating the logic of a system
  • Effective analysis: Problem can be analyzed in more effective way.
  • Proper documentation: Flowcharts serve as a good program documentation
  • Efficient Coding: Flowcharts act as a guide or blueprint during the systems analysis and program development phase.

Flow chart of the while loop :

Flow chart of the for loop:

The flow chart of the if…else statement :

The flow chart of the switch statement:

Flowchart (Example):

Flowchart to find the sum of first 50 natural numbers.

Start

Read A, B

Is A > B

Print A Print B

End

Yes (^) No

Flow Chart to find largest of two numbers: