# CMPT-101 Lecture Notes - Lecture 1: The Algorithm

145 views2 pages
10 Feb 2016
School
Course
Professor
Algorithm
An algorithm is a step-by-step process that will result in a desired outcome.
We get steps and the necessary input in order to resolve the issue by following the steps, and not
necessarily understand how it is being resolved.
A cooking recipe is a good example of this.
We need 3 things for an algorithm.
Input
The algorithm itself
Output
Ordered
Unambiguous
Clear
Automated Process
Clear and defined end – not continuous
In a math equation with variables, the algorithm would be the equation itself. The input would be the
valuables (a,b,c). The output would be the variable we need to find (x).
In order to automate a process for a computer, we need to clarify the task through an algorithm in
the simplest steps possible so that the computer can do the required task without having to work out
how on its own.
Steps that are executed in a sequence or in order.
The standard form for sequential tasks is 1?2?3
Another way to represent sequential tasks, or algorithms in general, is on a flow chart.
Example: Finding average kilometres driven in a week.
Input – Start and end KM
AlgorithmCalculate total KM and then average KM
OutputAverage KM
1 – Get start KM
2 – Get end KM
3 – Calculate total KM (end KM minus start KM)
4 – Calculate average (total KM divided by 7)
5 – Display average
Steps that are only executed if a condition is true.
Example: A store sells a variety of items with the same price
(2\$ each, tax included). The manager offers a 10% discount to
customers who buy 10 or more items per transaction.
Input – Amount of items (8)
Algorithm – Discount cost (10%)
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

# Get access

\$10 USD/m
Billed \$120 USD annually
Homework Help
Class Notes
Textbook Notes