Introduction To Computer Programming Problem Solving & Algorithms
Introduction To Computer Programming Problem Solving & Algorithms
Programming
Problem Solving & Algorithms
Jehangir Arshad Meo
Lec#5
Sahiwal
Problem Solving
Problem Solving is a key factor of human intelligence.
Algorithms
Algorithm
A concept that pervades all areas of computer
science.
When all the steps are solved, the original problem itself has also
been solved.
6
Computer Programming
Computer is a powerful tool
In order to use computer to solve our problems, we must tell it what we
want done and the order in which we want it done.
7
Computer Programming
Analyze the problem
8
Phases of software(program) life cycle:
1. Requirement definition {Given in the question or statement}
3. Coding
4. Testing
5. Implementation
6. Maintenance
9
Problem Solving Techniques
1. Ask questions
3. Means-ends analysis
5. Merging solutions
10
1- Ask Questions
Ask questions until you have developed a clear understanding
of the problem.
11
2)- Look for things that are Similar
Do not reinvent the wheel!
Draw analogy
12
3)- Means-Ends analysis
Starting point and ending state are known.
Lahore to Islamabad
What are the options?
Narrow down the options?
Figure out the details?
13
4)- Divide and Conquer
Same as the Al-khwarizmi Principle.
14
4)- Divide and Conquer
Hard Problem
15
5)- Merging Solution
Sometimes merging two independent solutions solves
the problem more efficiently?
Calculate Average:
Count values
Sum Values
Divide sum by count
16
Problem Solving Techniques
What is the unknown?
What is required?
17
Conversion from Fahrenheit to Celsius
Output
Temperature in Celsius (C)
Inputs
Temperature in Fahrenheit (F)
Process
5
C (F 32)
9
18
Calculate and print the average grade of 3 tests
for the entire class
Input
3 test scores for each student
output
Average of 3 tests for each student
Process
1. Get three scores
2. Add them together
3. Divide by three to get the average
4. Print the average
5. Repeat step 1 to 4 for next student
6. Stop if there are no more students
19
Assignment 1: Total =10 marks
Instructions;
Statement: