Anna GE 3151 - ALGORITHMIC PROBLEM SOLVING

Unformatted text preview:

www rejinpaul com GE3151 Problem Solving and Python Programming Unit I Visit For More www LearnEngineering in UNIT I ALGORITHMIC PROBLEM SOLVING Algorithms building blocks of algorithms statements state control flow functions notation pseudo code flow chart programming language algorithmic problem solving simple strategies for developing algorithms iteration recursion Illustrative problems find minimum in a list insert a card in a list of sorted cards guess an integer number in a range Towers of Hanoi ALGORITHM Definition instruction Algorithm is defined as a sequence of instructions designed in such a way that if the instructions are executed in the specified sequence the desired result will be obtained It is also defined as any problem whose solution can be expressed in a list of executable Three reasons for using algorithms are efficiency abstraction and reusability Algorithms can be expressed in many different notations including natural languages Set of step by step instructions that perform a specific task or operation Natural language NOT programming language Algorithm is the sequence of steps to be performed in order to solve a problem by the Analysis of algorithms is the theoretical study of computer program performance and resource usage and is often practiced abstractly without the use of specific programming language or implementation The practical goal of algorithm analysis is to predict the performance of different Most algorithms do not perform the same in all cases normally an algorithm s computer pseudocode flowcharts and programming languages www LearnEngineering in 1 2 The instruction in an algorithm should not be repeated infinitely 3 Ensure that the algorithm will ultimately terminate 4 The algorithm should be written in sequence 5 6 The desired result should be obtained only after the algorithm terminates algorithms in order to guide program design decisions an algorithm s performance in a formal manner performance varies with the data passed to it games finance and robotics It looks like normal English Typically three cases are recognized the best case average case and worst case Worst case analysis of algorithms is considered to be crucial to applications such as Characteristics of algorithm In the algorithm each and every instruction should be precise and unambiguous O notation also known as Big O notation is the most common notation used to express Qualities of a good algorithm Time Lesser time required Memory Less memory required Accuracy Suitable or correct solution obtained Department of Information Technology Page 1 Visit For More www LearnEngineering in www rejinpaul com GE3151 Problem Solving and Python Programming Unit I Visit For More www LearnEngineering in Sequence Must be sequence and some instruction may be repeated in number of times Generability Used to solve single problem and more often algorithms are designed to or until particular condition is met handle a range of input data Examples of algorithm Problem 1 Find the area of a Circle of radius r Algorithm Expected output Problem2 Write an algorithm to read two numbers and find their sum Inputs to the algorithm Sum of the two numbers First num1 Second num2 Inputs to the algorithm Radius r of the Circle Expected output Area of the Circle Algorithm Step 1 Start Step2 Read input the Radius r of the Circle Step3 Area PI r r calculation of area Step4 Print Area Step 5 Stop www LearnEngineering in Inputs to the algorithm Temperature in Fahrenheit Expected output Temperature in Celsius Algorithm Step1 Start Step 2 Read Temperature in Fahrenheit F Step 3 C Step 4 Print Temperature in Celsius C Step5 End Step1 Start Step2 Read input the first num1 Step3 Read input the second num2 Step4 Sum Step5 Print Sum Step6 Stop num1 num2 calculation of sum Problem 3 Convert temperature Fahrenheit to Celsius 5 9 F 32 Problem 4 Find the largest number between A and B Department of Information Technology Inputs to the algorithm Page 2 Visit For More www LearnEngineering in www rejinpaul com GE3151 Problem Solving and Python Programming Unit I Visit For More www LearnEngineering in A B Expected output Largest A or B Algorithm Step 1 Start Step 2 Read A B Step 3 If A is less than B then else Else Big B Small A Print A is largest Big A Small B Problem 5 To determine a student s average grade and indicate whether successful or fail Step 1 Start Step 2 Input mid term and final Step 3 average mid term final 2 Step 4 if average 60 then Print FAIL Step 4 Write Display BIG SMALL Step 5 Stop www LearnEngineering in Problem 6 A algorithm to find the largest value of any three numbers Step1 Start Step2 Read input A B and C Step3 If A B and A C then Max A Step4 If B A and B C then Max B Step5 If C A and C B then Max C Step6 Print Max Step7 End Step 1 Start Step 2 Read n or Initialize n 99 Step 3 Initialize i 2 Step 4 If i n then goto step 5 else goto step 7 Step 5 If i 2 0 then goto step 5 1 5 2 else goto step 6 Problem 7 An algorithm to calculate even numbers between 0 and 99 Print SUCCESS Step 5 Stop Step 5 1 Print i Step 5 2 i i 1 goto step 4 Step 6 i i 1 goto step4 Step 7 Stop Department of Information Technology Page 3 Visit For More www LearnEngineering in www rejinpaul com GE3151 Problem Solving and Python Programming Unit I Visit For More www LearnEngineering in FLOWCHARTS Definitions A flowchart is a schematic representation of an algorithm or a stepwise process showing the steps as boxes of various kinds and their order by connecting these with arrows Flowcharts are used in designing or documenting a process or program A flow chart or flow diagram is a graphical representation of a process or system that details the sequencing of steps required to create output The Limitations of using flowcharts A flowchart is a picture of the separate steps of a process in sequential order The benefits of flowcharts are as follows 1 Communication Flowcharts are better way of communicating the logic of a system to all concerned 2 Effective analysis With the help of flowchart problem can be analysed in more effective way 3 Proper documentation Program flowcharts serve as a good program documentation which is needed for various purposes 4 Efficient Coding The flowcharts act as a guide or blueprint during the systems analysis and program development phase 5 Proper Debugging The flowchart helps in debugging process 6 Efficient Program Maintenance The maintenance of operating program becomes easy with the help of flowchart It helps


View Full Document

Anna GE 3151 - ALGORITHMIC PROBLEM SOLVING

Download ALGORITHMIC PROBLEM SOLVING
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view ALGORITHMIC PROBLEM SOLVING and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view ALGORITHMIC PROBLEM SOLVING 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?