KEMBAR78
Algorithm | PDF | Computer Program | Programming
0% found this document useful (0 votes)
4 views24 pages

Algorithm

Uploaded by

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

Algorithm

Uploaded by

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

Algorithm, Design

and Problem solving


Program Development Life Cycle
PDLC is divided into 5 stages:
• Program definition: What is the problem?
• Problem Analysis :What exactly is required from the program? It uses
abstraction and decomposition
• Design (Algorithm and Development) : how the program should be
developed? How the task can be performed together? This is formally
documented using structure charts, flow charts and pseudocode
• Coding (coding and documentation): Program or set of programs are
developed & perform iterative testing to check if it is correctly working
• Testing (testing & debugging): developed program has to be run many
times with different data sets.
• Maintenance :
Computer system, Sub-system and
decomposition
• Definition – It is defined as a software, Hardware, data,
communication and people within.
• Each computer system can be divided into a set of sub-
system
• Each sub-system is divided into more sub-systems until
each sub-system performs just a single task.
• Sub-systems or sub tasks are the events that could happen
within a system
• Eg- alarm program is a small program (sub-system)
• Eg- weather forecast obtains information from very large
computer
Decomposing a problem
Every problem that uses computer system for its solution needs to be
decomposed into small components.
• Input – The data used by the system and need to be entered by user
• Processes- task need to be performed using input data and any other
previous data
• Output- information that needs to be displayed for the user
• Storage – data that need to be stored in file for future use.
ALARM CLOCK APP
Alarm clock can be decomposed into:
• Input – time to set the alarm, remove a previously set alarm, switch
an alarm off, press snooze button
• Processes – continuously check current time with the alarm time,
storage of alarm time and managing snooze
• Output – continuous sound /tune set for the alarm
• Storage - time for alarm set.
Methods used to design and construct
a solution
• Structure diagrams
• Flowcharts
• Pseudocode
Structured diagrams:
• Used to show in top-down design in diagrammatic form
• They are hierarchical (each sub-system is divided into more detailed
breakdown)
o Eg- Alarm clock
Flowchart :
• A flowchart shows diagrammatically the steps required to complete the
task and the sequence that they have to be performed. These steps with
an order are called an Algorithm.
START

GET TIME

Time= Alarm No Wait 30


time sec

Yes
Sound Alarm
Standard flowchart symbols
Pseudocode
• It is a simple method of showing algorithm
• It is not bound by strict syntax rules of any programing language
• It is easily understandable by others
• Data items to be processed by algorithm are given meaningful names in
the same way that the variables and constants are in a high level
programming language
• All keywords are written in capital letters
• All names given to data items and subroutines start with capital letter
• Where conditions and loop statements are used repeated pr selected
statements are intended nu two spaces
• Assignment statement (
Assignment operators in pseudocode
• Assigment operator (=)
• Mathematical operators (+,-,*,/,^, ())
Cost <--10 Cost has value 10
Price <-- Cost*2 Price has value 20
Tax <--Price * 0.12 Tax has value 2.4

SellingPrice <-- Price + Tax SellingPrice has value 22.4


Gender <-- "M" Gender has value M
Chosen <-- False Choosen has the value False
Purpose of an algorithm
• To complete a given task
• Shown as a flowchart or pseudocode
Algorithm to check the current time and if it matches then output the alarm
sound.
REPEAT
wait(10)
get (Time)
UNTIL Time = Alarm_Time
OUTPUT Alarmsound

# print the largest number(Activity)


Linear Search
• Linear Search or a sequential search is a method to find a value in a list
that checks each element in a sequence until the desired element is
found or list is exhausted
• The list need not be ordered
• Working: It keep on comparing each element with the element to search
until the desired element is found or list ends.
• Eg -
Linear search
Linear search (cont..)
Bubble sort
Bubble Sort algorithm,
• traverse from left and compare adjacent elements
and the higher one is placed at right side.
• In this way, the largest element is moved to the
rightmost end at first.
• This process is then continued to find the second
largest and place it and so on until the data is
sorted.
Steps to sort
Standard methods
When an algorithm is turned into program the same method may be
repeated thousand times.
Some of the standard methods are:
• Totalling
• Counting
• Finding maximum, minimum and average (mean) values
• Searching using linear search
• Sorting using a bubble sort
Standard methods cont...
Totalling – finding sum of values
Total<-- 0
FOR var <-- 1 to arraysize
Total <-- Total + studentmarks(var)
Next var
Counting – Counting number of times an action is performed.
Maximum – Finding largest value in a list
Minimum – Finding smallest value in a list
Average - finding an average of a given list of values
Validation and Verification check
• Validation is the process of checking that an input from the user meets the criteria
expected and is therefore most likely valid data.
• It is the automated checking by a program that data is reasonable before it is
accepted into a computer system
o If data is validated it is accepted by the computer system
o If data is not validated it should reject and message should be given explaining why data is
rejected.
• if you ask the user their age then you expect a number to be typed in, a validation
check will check that the input was a number.
– range check
– length check
– type check
– presence check
– format check
– check digit
.Cont ….
Range check -A range check checks if the data given is within a pre-set range.
Length Check-Checks that the number of characters entered is within a given length
For example, a full UK mobile telephone number is typically 11 digits long
Type Check - Checks the type of data entered, for example, if it is text or a
number. If you ask the user their age the Type check will check that a number was
entered and not text.
Presence Check- ensures that fields are not left blank, in other words data must be
present. For example, you cannot leave an email address filed blank.
Format Check - The format check checks the structure of the data entered matches
a pre-set value.
For example, a student ID might be two letters followed by 4 numbers (ST1001)
Digital check - A check digit is a number added to the input value that can be
calculated from all or part of the input value. Check digits are used for barcodes,
Product code , Vehicle identification numbers.
Verification
Verification -The process of verification is to check the data is accurate, in its original
form as expected.
Eg – input in a computer or transferred from one part of a computer system to another.
Visual check - this is a visual check done by the user, to proofread and check the data
entered or received is correct.

Double entry - this is when the user is asked to enter


the data twice, this is frequently seen when completing
online forms, they will often ask you to enter your
email address twice, a comparison is then done and if
both email addresses match, then the form is
accepted. This is done on fields such as email
addresses because people often mistype and get the
email address incorrect.
Test Data
A normal data test involves inputting data Extreme data testing involves inputting values
that is expected to be processed at the extreme ends of what is acceptable to
successfully by the system under normal ensure the system can handle edge cases.
conditions. It checks for standard operations Example: If a text field accepts a maximum of
and outcomes.
Example: For a calculator program, 50 characters, entering a 50-character string
entering 2 + 2 to check if the output tests the system's handling of maximum length
is 4 tests normal operation. inputs.
An abnormal data test, also known as an Boundary data testing checks the system's
error path test, inputs data that the response to data values at or just outside the
program should not accept, to ensure it limits of what it is designed to handle, to
handles errors gracefully without crashing.
Example: Entering letters abc into a field identify any boundary-related errors.
that expects an age in numbers to ensure Example: For a program that accepts ages from
the program prompts for correct input type 1 to 100, testing with values 0 (just below the
without error. boundary), 1 (lower boundary), 100 (upper
boundary), and 101 (just above the boundary)
to ensure it accurately enforces limits.
Trace table to document dry runs of algorithm
• Trace table – can be used to record the results from each step in an algorithm
• It is used to record the value of an item each time that it changes
• The manual exercise of working through an algorithm step by step is called dry run.
A B C X Output
0 0 100

You might also like