Docsity

Problem Solving: Understanding the Process and Tools for Effective Algorithm Development, Exercises of C programming

Partial preview of the text

Download Problem Solving: Understanding the Process and Tools for Effective Algorithm Development and more Exercises C programming in PDF only on Docsity!

Introduction to problem Solving

  • (^) As in our day to day life, while developing software also we come across variety of situations(problem) that we need to deal with and overcome
  • (^) examples
  • (^) calculation
  • (^) searching
  • (^) listprocessing
  • (^) Graph processing
  • (^) Image processing
  • (^) Sound processing
  • (^) Storage
  • (^) Sharing and more

steps to solve a problem

  • (^) understand and analysis the problem(why and which)
  • (^) Design the solution by using appropriate problem solving tool
  • (^) code- the solution by using appropriate programming language
  • (^) Run and test the solution for correctness and efficiency
  • (^) document solution

Problem solving tools It help us to design solutions to problem

  • (^) Algorithm
  • (^) pseudo code
  • (^) Flowchart
  • (^) DFD(Data flow diagram)
  • (^) UML(Unified Modeling Language)

Pseudo code

  • (^) Pseudo code(natural language + programming language[words and phrases, expressions]
  • (^) pseudo meaning is false. Hence pseudo code is not an actual code instead of statements/instructions/words/ phrases/expressions
  • (^) pseudo codes are written with respect to programming language but programming language syntax or grammar is not strictly followed
  • (^) pseudo code is minimized version of an algorithm
  • (^) its nither algorithm nor program

Characteristics of good algorithm

  • (^) input: Accept zero or more inputs
  • (^) Definite: steps are precisely defined and unambiguous
  • (^) output: produces one or more correct outputs(Correct)
  • (^) Finite: algorithm should terminate after finite steps
  • (^) Efficient: memory and time efficient

Flow chart symbols

Peudocode for Linear Search

FUNCTION linearSearch(list, searchTerm): FOR index FROM 0 -> length(list): IF list[index] == searchTerm THEN RETURN index ENDIF ENDLOOP RETURN - END FUNCTION

Program for Linear Search

int search(int arr[], int n, int x) { int i; for (i = 0; i < n; i++) if (arr[i] == x) return i; return -1; }

Flowchart of If.. Else statement

Flowchart of nested if...else statement

Flowchart of for loop

Flowchart of while loop