0% found this document useful (0 votes)
27 views20 pages

Introduction To Computer Programming Problem Solving & Algorithms

The document discusses problem solving techniques in computer programming such as asking questions, looking for similarities, means-ends analysis, divide and conquer, and merging solutions. It also provides examples of algorithms for converting between Fahrenheit and Celsius scales and calculating the average grade of 3 tests for a class.

Uploaded by

Alpha Romeo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views20 pages

Introduction To Computer Programming Problem Solving & Algorithms

The document discusses problem solving techniques in computer programming such as asking questions, looking for similarities, means-ends analysis, divide and conquer, and merging solutions. It also provides examples of algorithms for converting between Fahrenheit and Celsius scales and calculating the average grade of 3 tests for a class.

Uploaded by

Alpha Romeo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Introduction to Computer

Programming
Problem Solving & Algorithms
Jehangir Arshad Meo

Lec#5

Mechanical Engineering Department

COMSATS Institute of Information Technology

Sahiwal
Problem Solving
Problem Solving is a key factor of human intelligence.

Consider the example:

1- In mathematical problems we have several


solutions to a problem.

2- In daily life we can use easy ways to solve our daily


life issues
Problem Solving
From our daily life experience we know that the
best way to solve a problem is to divide it into
small steps.

Then to carry out these steps one by one to


achieve the desired goal.

If look at a cheff following a recipe to make a meal


we will observe that he is following certain steps.
Problem Solving
How we give solution to a given problem?

Algorithms
Algorithm
A concept that pervades all areas of computer
science.

Algorithm is a process that a computer could carry


out to complete a well defined task within finite
time and resources.

The objective of computer science is to solve


problems by developing, analyzing, and
implementing algorithmic solutions.
5
Al-Khwarizmi Principle:
 All complex problems can be broken into simpler sub-problems.

 Solve a complex problem by breaking it down into smaller sub-


problems and then solve them (in a specified order), one at a
time.

 When all the steps are solved, the original problem itself has also
been solved.

 This process is called Algorithm.

6
Computer Programming
Computer is a powerful tool

It is not intelligent!

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.

These instructions are called computer program.

This process is called computer programming.

The person giving these instructions is called a computer programmer.

7
Computer Programming
Analyze the problem

Develop a sequence of instructions for solving the


problem.

Communicate it to the computer.

8
Phases of software(program) life cycle:
1. Requirement definition {Given in the question or statement}

2. Analysis and design

3. Coding

4. Testing

5. Implementation

6. Maintenance

9
Problem Solving Techniques
1. Ask questions

2. Look for things that are similar

3. Means-ends analysis

4. Divide and Conquer

5. Merging solutions
10
1- Ask Questions
Ask questions until you have developed a clear understanding
of the problem.

Who, What, Why, Where, When.

What do I have to work with? (my data or input)


How much data is there?
What should my output look like?
How many times is the process going to be repeated?
What are the exceptions to the main course?
What special error condition might come up?

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.

You need to devise the transformation function.

Ends are defined – you need to analyze your means


of getting between them.

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.

Breakup the large problem into smaller units and then


solve them one at a time.

Building block approach.

14
4)- Divide and Conquer
Hard Problem

Easy Sub-problem Hard Sub-problem Easy Sub-problem

Easy Sub-problem Easy Sub-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?

What are the data?


What is given?

What is the condition?


By what condition the unknown is linked to the data?

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;

1. Title page { Subject: Introduction to computer programming………. Name:……………, Registration Number:


BSME- Fo13……………Instructor Mr. Jehangir Arshad , Submission Date: 8 march 2013,Friday 12:30}

2. Assignment must be hand written and should be on A4 size paper.

3. Assignment on Register pages will not be accepted.

4. All headings must be given with marker.

Statement:

Why (r)’s and (r-1)’s complements are used in computing? [4 marks]


Write down the examples of :

1 - (2)’s and (2-1)’s complements (1.5 + 1.5 = 3 marks)


2 – (10)’s and (10-1)’s complement (1.5 + 1.5 = 3 marks)

You might also like