How Computers Solve Problems
How Computers Solve Problems
Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step at a time Complex Human Algorithms must be broken down into simple step-by-step instructions BEFORE they can be translated into computer code
Algorithm
It is the set of instructions to solve any problem. These are the steps followed after one another. These steps for solving a problem, to process some input for obtaining the desired result or output is called ALGORITHM
Characteristics
It should have input Steps that are included in the algorithm should be executable by the computer. Each step must be finite and small and unambiguous Every step of algorithm should yield some result. Should be written in a very simple language Algorithm validation
Algorithm:
1. 2. 3.
4.
FindLargest Input: 1000 positive integers Set Largest to 0 Set Counter to 0 while (Counter less than 1000) 3.1 if (the integer is greater than Largest) then 3.1.1 Set Largest to the value of the integer End if 3.2 Increment Counter End while Return Largest End
Algorithm :
1. 2. 3.
Iterative factorial
4.
Factorial Input: A positive integer num Set FactN to 1 Set i to 1 while (i is less than or equal to num) 3.1 Set FactN to FactN x I 3.2 Increment i End while Return FactN End
1. Start 2. Read the roll number and marks of 1 student. This is the highest marks found so far as marks of only one student has been read 3. Is there any more student in the class 4. If yes, then go to step 5 .If not ,then goto step 8 5. Read next roll number and its marks .Compare the marks of this next roll number with the highest marks find so far 6. If marks read in step 5 is greater than the highest marks found so far , then erase the previously noted highest marks , and replace it by the marks read in step 5 .Also replace the roll number, if marks of step 5 are less than the highest marks, then do nothing. 7. Repeat the step 3 through 5 till all the roll numbers of class have been entered. 8. Print the roll number of the student with the highest marks and percentage of the student. 9. Stop
7. Repeat the step 3 through 5 till all the roll numbers of class have been entered. 8. Print the roll number of the student with the highest marks and percentage of the student. 9. Stop
Problem Solving
Problem Solving is the ability to understand what you have, what you want, and creating a set of instructions to change what you have into what you want Good Problem Solving Skills are based on knowledge, experience and logic Good Programmers NEVER make assumptions
Flowcharts
A Flowchart is a Visual Representation of an algorithm A Flowchart uses easy-to-understand symbols to represent actions on data and the flow of data Flowcharts aid in breaking down a problem into simple steps
Advantages
Each symbol denotes the instruction Pictorial representation it becomes easy to understand and explain the problem. It gives clear picture of flow of data in any program It helps the programmer to determine the type of logic control to be used in the program It is easy to detect the error with the help of flow chart It serves as a guiding document for program writing or coding
Limitations
Time consuming and laborious too especially for complex problems Redrawing is even more difficult and time consuming. Difficult to include new step in the existing flowchart If an algorithm has complex branches and loops , flowchart become very difficult to draw.
Pseudo Code
Pseudo means pretend or false Pseudo Code is pretend or false computer code; generic English-like terms that are somewhat like computer code Pseudo Code is not as standardized as flowcharts, and does not facilitate the breaking down of problems as well as a flowchart does
Be consistent
Prefer formulas over English language descriptions
THREE CONSTRUCTS
Three constructs
Start or stop
Process
Input or output
Flowchart Elements
Simple IF statement
T Account_ balance < $300? F
Service_charge = $5
Service_charge = $2
x<0
T X= -x
Combined IF statement
F Student = P/T AND Gender = F? T
Increment Female_part_time_count
Nested IF statement
T
Record Code =`A
F
? T
Record
F
Code =`A
Increment Counter_A
?
Record Code =`A
F ?
Increment Counter_B
T
Increment Error_counter
Increment Counter_C
Case Structure
Case Of variable
Value 1
Value 2
Value 3
Value 4
Statement_a
Statement_b
Statement_c
Statement_d
Summation
More numbers
Product