0% found this document useful (0 votes)
31 views8 pages

7 Algorithm Design and Problem Solving Part 2

The document discusses algorithm design and problem solving. It explains that a computer system solves problems by breaking them down into sub-problems in a top-down design approach. An algorithm is a sequence of steps to solve a specific task, and there are different ways to represent algorithms like structure diagrams, flowcharts, and pseudocode. Subroutines allow breaking problems down into reusable units.

Uploaded by

Sadhika Auckloo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
31 views8 pages

7 Algorithm Design and Problem Solving Part 2

The document discusses algorithm design and problem solving. It explains that a computer system solves problems by breaking them down into sub-problems in a top-down design approach. An algorithm is a sequence of steps to solve a specific task, and there are different ways to represent algorithms like structure diagrams, flowcharts, and pseudocode. Subroutines allow breaking problems down into reusable units.

Uploaded by

Sadhika Auckloo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

7 algorithm design and problem solving

 A computer system is a device which performs tasks or solves problem. It is made up


of hardware and software. The computer system is made up of sub-systems. These
sub-systems are in turn broken down into further sub-system until they only perform
a single task.
 Top-down design
 It is the breaking down of a computer system into a set of sub-systems, then
breaking each sub-system down into a set of smaller sub-systems, until each
sub-system just performs a single action.
 This is an effective way of designing a computer system to provide a solution
to a problem, since each part of the problem is broken down into smaller
more manageable problems.
 The process of breaking down into smaller sub-systems is called stepwise
refinement.
 This structured approach works for the development of both large
and small computer systems. When large computer systems are being
developed this means that several programmers can work
independently to develop and test different sub-systems for the same
system at the same time. This reduces the development and testing
time.

Mrs Shraddha Kulloo Mangal 1


7 algorithm design and problem solving

 Any problem that uses a computer system for its solution needs to be decomposed into
its component parts.
 The component parts of any computer system are:
 Input – the data used by the system that needs to be entered while the system is
active.
 Process – the tasks that need to be performed using the input data and any other
previously stored data.
 Output – information that needs to be displayed or printed for the users of the
system.
 Storage – data that needs to be stored in files on an appropriate medium for use
in the future.

 For Example: The alarm app can be decomposed into:


 Input – time to set the alarm, remove a previously set alarm time, switch an alarm
off, press snooze button
 Process – continuously check if the current time matches an alarm time that has
been set, storage and removal of alarm times, management of snooze
 Output – continuous sound/tune (at alarm time or after snooze time expired)
 Storage – time(s) for alarms set.

Mrs Shraddha Kulloo Mangal 2


7 algorithm design and problem solving

 What is an algorithm?
 An algorithm is a sequence of instructions that describe the steps to carry out a
specific task. A programmer writes a program to instruct the computer to do
certain tasks as desired. The computer then follows the steps written in the
program code. Therefore, the programmer first prepares a design/plan of the
program to be written, before actually writing the code.
 This plan is actually the algorithm.
 Writing an algorithm is the first step to programming. If the algorithm is correct,
the computer will run the program correctly, every time.
 So, the purpose of using an algorithm is to increase the reliability, accuracy and
efficiency of obtaining solutions.
 There are various methods of presenting solution namely:
1. Structure diagrams
2. Flowchart
3. Pseudocode
 Structure Diagrams
 Structure diagrams can be used to show top-down design in a diagrammatic form.
 Structure diagrams are hierarchical, showing how a computer system solution can
be divided into sub-systems with each level giving a more detailed breakdown.
 If necessary, each sub-system can be further divided.

Mrs Shraddha Kulloo Mangal 3


7 algorithm design and problem solving

 Example 1: Structure Diagram of an Alarm clock

 Example 2: Structure Diagram to calculate and output the average of two numbers.

Mrs Shraddha Kulloo Mangal 4


7 algorithm design and problem solving

 Flowcharts
 A flowchart is a visual representation of an algorithm. It illustrates the solution to a
particular problem.
 It includes shapes/symbols which describe the individual tasks to be carried to
solve a particular problem.
 Flowcharts Symbols:

Mrs Shraddha Kulloo Mangal 5


7 algorithm design and problem solving

 Example of Flowchart:
The purpose of this flowchart is to calculate the sum of two numbers:
1. Insert first number
2. Insert second number
3. Calculate Sum
4. Output Sum

Mrs Shraddha Kulloo Mangal 6


7 algorithm design and problem solving

 Pseudocode
 It is considered as a non-formal language that helps programmers to write
algorithm.
 It is a detailed description of instructions that a computer must follow in a
particular order.
 It is intended for human reading and cannot be executed directly by the computer.
 Pseudocode is written in a form that can be easily converted into any programming
language statements.
 Example 1: Pseudocode that will input two numbers and output the total.
BEGIN
DECLARE Number1, Number2: Integer
INPUT Number1, Number2
Sum= Number1 + Number2
OUTPUT Sum
END
 Note: The above program can be easily interpreted by a non-programmer.

Mrs Shraddha Kulloo Mangal 7


7 algorithm design and problem solving

 Library Routines and Subroutines


 A subroutine (procedure or function) is a block of codes that perform a specific
task, packaged as a unit.
 This unit is self-contained (independent) thus it can be used in programs whenever
it is required.
 The subroutine is often coded so that it can be started (called) several times and/or
from several places during a single execution of the program, including from other
subroutines, and then return back to the next instruction after the “call” once the
subroutine’s task is done.
 Programmers write subroutines, test them to remove errors and store them in a
collection of other subroutines.
 This collection is known as a library since the programmer can reuse the subroutine
in other programs.

Mrs Shraddha Kulloo Mangal 8

You might also like