CMPT-101 Lecture Notes - Lecture 1: The Algorithm

145 views2 pages
10 Feb 2016
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
In addition, algorithms must be;
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.
Tasks
Sequential Tasks
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
Conditional Tasks
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.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class
Class+
$8 USD/m
Billed $96 USD annually
Homework Help
Class Notes
Textbook Notes
30 Verified Answers
Study Guides
1 Booster Class