You are on page 1of 13

KOGI STATE UNIVERSITY. P.M.B. 1008, ANYIGBA, KOGI STATE, NIGERIA.

FACULTY OF NATURAL SCIENCES


DEPARTMENT OF COMPUTER SCIENCE
CSC 102: INTRDUCTION TO PROBLEM SOLVING
COURSE OUTLINES
• Introduction to Computer
• Introduction to Problem Solving
• Role of Algorithms in problem solving process
• Concepts and properties of Algorithms
• Implementation strategies
• Developments of flow charts
• Pseudo codes
• Object Programs
• Implementation of Algorithms in a programming Language -Visual
BASIC/JAVA/C/C++
1.0 Introduction to Computer
A computer system can be defined as an electronic device for storing and processing data,
typically in binary form, according to instructions given to it in a variable program. A computer
is an electronic device that manipulates information, or data. It has the ability to store, retrieve,
and process data. You may already know that you can use a computer to type documents, send
email, play games, and browse the Web. You can also use it to edit or create spreadsheets,
presentations, and even videos.
1.1 Data Acceptance in Computer
A computer system accepts data in different forms. These could be but not limited to numbers,
alphabets, alphanumeric, audios, videos, different picture formats and so on. The computer
system accepts data/information through input devices such as mouse, keyboard, monitor,
joystick, scanner and even some external devices like USB flash drives, hard disk, Bluetooth,
etc.
1.2 Data Processing in Computer
Data, simply put, data is a raw fact processed into information. Data can be numbers, strings
of characters or images. All data must be entered into the computer for it to be processed. Data
can be read out of a file, typed in via the keyboard or scanned in like a bar code. From a
computer programmer's viewpoint, this is considered raw data that needs to be processed.
Computers process very large amounts of data because they can interpret the data much more
quickly than a person. Most data processing is mundane, and would be prone to human error if
not processed by computer. Computers process data so fast that their speed is measured in
MIPS (Millions of Instructions Per Second). Processing data is the transformation of the input
data to a more meaningful form (information) in the CPU.
1.3 Output Generation in Computer

1
The final activity in the data processing cycle is producing the desired output also referred to
as information. This information can be distributed to the target group or stored for future use.
Distribution is making information available to those who need it and is sometimes called
information dissemination. This process of dissemination may involve electronic presentation
over the radio or television, distribution of hard copies, broadcasting messages over the internet
or mobile phones etc. The output generation can be through screen or monitor, printer, or can
be saved for future use in external devices like USB flash drive, hard disk, etc.
1.4 Computer Operating System
An operating system is a program that acts as an interface between a user of a computer and
the computer resources. The purpose of an operating system is to provide an environment in
which a user may execute programs. The general architecture of an Operating System is giving
below.

The kernel is a computer program at the core of a computer's operating system and has
complete control over everything in the system. It is the "portion of the operating system code
that is always resident in memory", and facilitates interactions between hardware and software
components. A full kernel controls all hardware resources (e.g. I/O, memory, Cryptography)
via device drivers, arbitrates conflicts between processes concerning such resources, and
optimizes the utilization of common resources e.g. CPU & cache usage, file systems, and
network sockets.
The shell, is a computer program which exposes an operating system's services to a human user
or other program. In general, operating system shells use either a command-line interface (CLI)
or graphical user interface (GUI), depending on a computer's role and particular operation. It
is named a shell because it is the outermost layer around the operating system.
Application software, or app for short, is software that performs specific tasks for an end-user.
Effectively, if the user is interacting directly with a piece of software it is application software.
For example, Microsoft Word or Excel are application software, as are common web browsers
such as Firefox or Google Chrome.
A GUI or user interface (UI) is the part of an OS that permits an operator to get the information.
A user interface based on text displays the text as well as its commands which are typed over
a command line with the help of a keyboard. A user is the one or person that is operating the
computer system and also that keys in data for processing into information.

2
2.0 Introduction to Problem Solving
A computer is a very powerful and versatile machine capable of performing a multitude of
different tasks, yet it has no intelligence or thinking power. The intelligence Quotient (I.Q) of
a computer is zero. A computer performs many tasks exactly in the same manner as it is told
to do. This places responsibility on the user to instruct the computer in a correct and precise
manner, so that the machine is able to perform the required job in a proper way. A wrong or
ambiguous instruction may sometimes prove disastrous. In order to instruct a computer
correctly, the user must have clear understanding of the problem to be solved. A part from this
he should be able to develop a method, in the form of series of sequential steps, to solve it.
Once the problem is well-defined and a method of solving it is developed, then instructing
he computer to solve the problem becomes relatively easier task. Thus, before attempt to write
a computer program to solve a given problem.
It is necessary to formulate or define the problem in a precise manner. Once the problem is
defined, the steps required to solve it, must be stated clearly in the required order.

2.1 Procedure (Steps Involved in Problem Solving)


A computer cannot solve a problem on its own. One has to provide step by step solutions of
the problem to the computer. In fact, the task of problem solving is not that of the computer. It
is the programmer who has to write down the solution to the problem in terms of simple
operations which the computer can understand and execute.
In order to solve a problem by the computer, one has to pass though certain stages or steps.
They are:
i. Understanding the problem
ii. Analyzing the problem
iii. Developing the solution
iv. Coding and implementation.

i. Understanding the Problem: Here we try to understand the problem to be solved in


totally. Before with the next stage or step, we should be absolutely sure about the
objectives of the given problem.
ii. Analyzing the Problem: After understanding thoroughly the problem to be solved, we
look different ways of solving the problem and how to evaluate. The idea here is to
search an appropriate solution to the problem under consideration. The end result of
this stage is a broad overview of the sequence of operations that are to be carries out to
solve the given problem.
iii. Developing the Solution: Here the overview of the sequence of operations that was
the result of analysis stage is expanded to form a detailed step by step solution to the
problem under consideration.
iv. Coding and Implementation: The last stage of the problem solving is the conversion
of the detailed sequence of operations in to a language that the computer can
understand. Here each step is converted to its equivalent instruction or instructions in
the computer language that has been chosen for the implementation.
3.0 Algorithms
Definition: A set of sequential steps usually written in Ordinary Language to solve a given
problem is called Algorithm. An algorithm can be defined as a complete, unambiguous,
finite number of logical steps for solving a specific problem.
It may be possible to solve to problem in more than one way, resulting in more than one
algorithm. The choice of various algorithms depends on the factors like reliability, accuracy
and easy to modify. The most important factor in the choice of algorithm is the time

3
requirement to execute it, after writing code in High-level language with the help of a computer.
The algorithm which will need the least time when executed is considered the best.

You may have heard the term algorithm recently, whether it was online or perhaps in some
conversation about technology. It's a word that gets thrown around a lot, but what does it mean
exactly? An algorithm is simply a set of steps used to complete a specific task. They're the
building blocks for programming, and they allow things like computers, smartphones, and
websites to function and make decisions. In addition to being used by technology, a lot of
things we do on a daily basis are similar to algorithms. Let's say you want to make
some spaghetti. In order to do this successfully, there's a certain set of steps you need to follow
in a particular order. First, you'll need to boil a pot of water. Once it's boiling, you then add
the spaghetti and cook it for a set amount of time, stirring occasionally. Once it's finished,
you drain the water, then it's ready to be served with a sauce of your choice.
This entire process is actually an algorithm. Because you followed these steps in a particular
order, you reached your desired outcome: a delicious pasta dish. But if you were to make a
mistake like overcooking or undercooking your noodles, it probably wouldn't be as good.
Programs work in a similar way. Their code is made up of algorithms telling them what to
do.
3.1 Importance of Algorithm
Algorithms give us the most ideal option of accomplishing a task. Here is some importance of
algorithms in computer programming.
▪ To improve the efficiency of a computer program: In programming, there are
different ways of solving a problem. However, the efficiency of the methods available
vary. Some methods are well suited to give more accurate answers than others.
Algorithms are used to find the best possible way of solving a problem. In doing so
they improve the efficiency of a program.
▪ Proper utilization of resources: A typical computer has different resources. One of
them is computer memory. During the execution phase, a computer program will
require some amount of memory. Some programs use more memory space than others.
The usage of computer memory depends on the algorithm that has been used.
▪ Building block of a computer program: Algorithm in computer program is just like
the building plan for engineers. Without following that step by step to completing a
task, it might take a programmer some time to come up with something valuable.
▪ It serves as a guide to solving problem: In programming, algorithm gives direction
and how to use code to implement a particular program. If a programmer fails to adhere
to rules to achieving and completing a task accordingly, then failure will set in.
3.2 Steps Involved in Algorithm Development
1. Identification of input: For an algorithm, there are quantities to be supplied called
input and these are fed externally. The input is to be identified first for any specified
problem.
2. Identification of output: From an algorithm, at least one quantity is produced, called
for any specified problem.
3. Identification the processing operations: All the calculations to be performed in order
to lead to output from the input are to be identified in an orderly manner.

4
4. Processing Definiteness: The instructions composing the algorithm must be clear and
there should not be any ambiguity in them.
5. Processing Finiteness: If we go through the algorithm, then for all cases, the algorithm
should terminate after a finite number of steps.
6. Possessing Effectiveness: The instructions in the algorithm must be sufficiently basic
and in practice they can be carries out easily.

3.3 Types of Algorithms


Algorithms are classified based on the concepts that they use to accomplish a task. While there
are many types of algorithms, the most fundamental types of computer science algorithms are:
▪ Divide and Conquer Algorithms: Divide the problem into smaller subproblems of the
same type; solve those smaller problems, and combine those solutions to solve the
original problem. Examples are Binary and Merge sorts.
▪ Brute Force Algorithms: Try all possible solutions until a satisfactory solution is
found. More technically it is just like iterating every possibility available to solve that
problem. Example is trying to guess a 4-digit pin of an ATM card.
▪ Randomize Algorithms: Use a random number at least once during the computation
to find a solution to the problem. Examples are Las Vegas algorithms and Monte-Carlo
algorithms.
▪ Heuristic Algorithm: It’s considered as a shortcut. It’s a technique designed for
solving a problem more quickly when classic methods are too slow or finding an
approximate solution when classic methods fail to find the exact solution. There is no
definite formular heuristic algorithm.
▪ Greedy Algorithms: Find an optimal solution at the local level with the intent of
finding an optimal solution for the whole problem. In the Greedy Algorithm, the
solution is built part by part. Examples are Prim’s and Kruskal’s algorithms.
▪ Recursive Algorithms: Solve the lowest and simplest version of a problem then solve
increasingly larger versions of the problem until the solution to the original problem is
found. In recursion, a problem is solved by breaking it into subproblems of the same
type and calling own self again and again until the problem is solved with the help of a
base condition. Examples are factorial of a number and Fibonacci series.
▪ Backtracking Algorithms: In Backtracking Algorithm, the problem is solved in an
incremental way, i.e. it is an algorithmic-technique for solving problems recursively by
trying to build a solution incrementally, one piece at a time, removing those solutions
that fail to satisfy the constraints of the problem at any point of time. Examples are Rat
in the maze problem and N Queen problem.

3.4 Concepts and Properties


The concept of an algorithm is fundamental to computer science. Algorithms exist for many
common problems, and designing efficient algorithms plays a crucial role in developing large-
scale computer systems.
3.5 Properties of Algorithms
In order for an algorithm to be useful, it must help us find a solution to a specific problem. For
that to happen, an algorithm must satisfy five properties.

5
Input: The inputs used in an algorithm must come from a specified set of elements,
where the amount and type of inputs are specified.
Output: The algorithm must specify the output and how it is related to the input.
Definiteness: The steps in the algorithm must be clearly defined and detailed. Each
instruction of the algorithm should be clear and unambiguous.
Effectiveness: The steps in the algorithm must be doable and effective. Every
instruction must be basic enough to be carried out theoretically or by using paper and
pencil.
Finiteness: The algorithm must come to an end after a specific number of steps.
Independent: An algorithm should have step-by-step directions, which should be
independent of any programming code.
Feasibility: Should be feasible with the available resources.
Unambiguous: Algorithm should be clear and unambiguous. Each of its steps (or
phases), and their inputs/outputs should be clear and must lead to only one meaning.
3.6 Example
Suppose we want to find the average of three numbers, the algorithm is as follows.
Step 1 Read the numbers a, b, c
Step 2 Compute the sum of a, b and c
Step 3 Divide the sum by 3
Step 4 Store the result in variable d
Step 5 Print the value of d
Step 6 End of the program
Write an algorithm to calculate the simple interest using the formula.
Simple interest = P*N* R/100.
Where P is principal Amount, N is the number of years and R is the rate of interest.
Step 1: Read the three input quantities’ P, N and R.
Step 2: Calculate simple interest as Simple interest = P* N* R/100.
Step 3: Print simple interest.
Step 4: Stop.

4.0 Flowchart
A flow chart is a step-by-step diagrammatic representation of the logic paths to solve a given
problem. Or A flowchart is visual or graphical representation of an algorithm.
The flowcharts are pictorial representation of the methods to be used to solve a given problem
and help a great deal to analyze the problem and plan its solution in a systematic and orderly
manner. A flowchart when translated in to a proper computer language, results in a complete
program.

4.1 Advantages of Flowcharts


1. The flowchart shows the logic of a problem displayed in pictorial fashion which felicitates
easier checking of an algorithm.
2. The Flowchart is good means of communication to other users. It is also a compact means
of recording an algorithm solution to a problem.
3. The flowchart allows the problem solver to break the problem into parts. These parts can be
connected to make master chart.
4. The flowchart is a permanent record of the solution which can be consulted at a later time.

6
4.2 Differences between Algorithm and Flowchart
• A method of representing the step-by-step logical procedure for solving a problem,
while flowchart is diagrammatic representation of an algorithm. It is constructed using
different types of boxes and symbols.
• It contains step-by-step English descriptions, each step representing a particular
operation leading to solution of problem, on the other hand the flowchart employs a
series of blocks and arrows, each of which represents a particular step in an algorithm.
• These are particularly useful for small problems, while flow charts are useful for
detailed representations of complicated programs.
• For complex programs, algorithms prove to be inadequate while for complex programs,
prove to be adequate.

4.3 Symbols used in Flow-Charts


The symbols that we make use while drawing flowcharts as given below are as per conventions
followed by International Standard Organization (ISO). A flowchart is a pictorial
(diagrammatic) representation of a program that shows the sequence of operations to be
performed to arrive at the solution to a problem. Flowcharts are quite helpful in understanding
the logic of complicated problems.

A flowchart is drawn before writing an actual program to understand the sequence of actions
taken by the solution to solve the problem. It usually draws flowcharts using some standard
symbols as shown below.

7
4.4 Simple Problem using Flowchart
Draw the Flowchart to find Roots of Quadratic equation ax2+ bx + c = 0. The coefficients a,
b, c are the input data.

8
9
10
Draw a flow chart to calculate the average of three numbers.

11
5.0 Pseudo Codes
The Pseudo code is neither an algorithm nor a program. It is an abstract form of a program. It
consists of English like statements which perform the specific operations. It is defined for an
algorithm. It does not use any graphical representation. In pseudo code, the program is
represented in terms of words and phrases, but the syntax of program is not strictly followed.
In computer science, pseudocode is a plain language description of the steps in an algorithm or
another system. Pseudocode often uses structural conventions of a normal programming
language, but is intended for human reading rather than machine reading.
Often at times, algorithms are represented with the help of pseudo codes as they can be
interpreted by programmers no matter what their programming background or knowledge is.
Pseudo code, as the name suggests, is a false code or a representation of code which can be
understood by even a layman with some school level programming knowledge.

5.1 Advantages of Pseudo Codes


a. It is fairly easy to understand, even for non-programmers.
b. Easy to modify.
c. It can be quickly and easily converted into an actual programming language as it is
similar to a programming language.
d. Changes to the design can be incorporated quite easily.
e. Since it is language-independent it can be used by most programmers it allows the
developer to express the design in plain and natural language.
f. It is easier to develop a program from a pseudo-code as compared to the flow chart.
Programmers do not have to think about syntax, we simply have to concentrate on the
underline logic. The focus is on the steps to solve a problem rather than how to use the
computer language.
g. Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
h. Acts as a bridge between the program and the algorithm or flowchart. Also works as a
rough documentation, so the program of one developer can be understood easily when
a pseudo code is written out. In industries, the approach of documentation is essential.
i. The main goal of a pseudo code is to explain what exactly each line of a program should
do, hence making the code construction phase easier for the programmer.

5.2 Disadvantages of Pseudo Codes


a. It can be hard to see how a program flow.
b. It can be time consuming to produce.
c. There are no proper formats for writing the for pseudocode.
d. Pseudo code does not provide a visual representation of the logic of programming.

5.3 Examples of Pseudo Codes


Write pseudo codes to determine the sum and average of three numbers.
• Step 1- Start
• Step 2- Declare 5 variables N1, N2, N3 & Sum as integer & Avg as Float type.
• Step 3- Initialise the values as 0.
• Step 4- Enter the values of the 3 variables (N1, N2 & N3).
• Step 5- Add the three numbers (N1+N2+N3) and store in variable Sum & Print Sum.
• Step 6- Divide the sum of the three numbers by 3 and store in the variable Avg & Print
Avg.
• Step 7- Stop.

12
6.0 Program Objects
Object Programs are programs in machine language form. Normally users write computer
program using high level languages or assembly languages. If program is written in high level
language, then it is to get converted to machine executable form using a Compiler. If program
is prepared in assembly language, it is usually to be converted to machine executable form
using an assembler. Output of compiler or even assemblers are called object program. They
can be directly accomplished by machine.

13

You might also like