Lec 1
Lec 1
– Go to your labs
http://pragprog.com/book/gwpy2/practical-programming
If you want a paper copy of the book order it on amazon.ca since the
shipping and customs costs on pragprog.com are excessive.
https://www.amazon.ca/gp/cart/view.html/ref=gno_cart
Other recommended books
Free book: "Think Python, How to Think Like a Computer Scientist" by
Allen Downey
• You should have been assigned to one of the available lab sections,
and you must attend that session each week.
–Your lab section assignment is available via BB – Assignment folder
You may discuss assignments with friends and classmates, but only up to a point: you may discuss and
compare general approaches and also how to get around particular difficulties, but you should not leave
such a discussion with any written material. You should not look at another student's solution to an
assignment on paper or on the computer screen, even in draft form. The actual coding of your programs,
analysis of results, writing of reports and answering assignment questions must be done individually.
Downloading code or any other material from the Internet, and submitting it as your own work without
credit is also plagiarism. If you do talk with anyone about an assignment, please state this in your assignment
and state the extent of your discussion. If you use another resource (such as textbooks, internet resources,
etc) when solving your assignment, include the proper reference.
Note that it is also a serious offense to help someone commit plagiarism. Do not lend your assignment
answers, printouts, reports or diskettes, and do not let others copy or read them. To protect yourself against
people copying your work without your knowledge, retain all of your old printouts and draft notes until the
assignments have been graded and returned to you. If you suspect that someone has stolen a printout or
diskette, contact your instructor immediately.
Helping Each Other
Although you must not solve your assignments with the help of others, there are still many ways in
which students can help each other. For instance, you can go over difficult lecture or lab material,
work through exercises, or help each other understand an assignment handout. This sort of course
collaboration can be done in study groups or through the discussion group.
The Blackboard Learn discussion forum can be used to discuss techniques and tools used in
assignments, but the discussions should never mention or present any potential or partial solutions
to assignment questions. You can consider creating a study group.
If in doubt about whether a question you are asking or answering is against these guidelines, ask
your TA (teaching assistant) the question instead.
Detecting Plagiarism
1. TAs have been instructed to report any suspicious of plagiarism they find, when they mark
assignments, to the professor.
2. Programs that you submit may be screened using plagiarism detection software that is very
effective at detecting similarities. The professor will take appropriate measures, once plagiarism
is detected on part or on the whole of an assignment. Note that copying or lending is
considered to be equally serious offenses.
Reference
This document is a translation of the the French document prepared by Daniel Amyot and is based
in part on "Policy on Plagiarism" by Dr. Amy Felty (Septembre 2002).
Faculty Eng. Regulations
• Mandatory withdrawal, if second failure in a
mandatory course
• Academic standing is evaluated after students have
attempted 24 course credits
–Mandatory withdrawal, if CGPA is below 3.5
–Probation, if 3.5 ≤ CGPA < 4.5
• Note that the passing grade for first year courses is D
(2), whereas 3.5 is between D+ and C, and 4.5 is
between C and C+ (65-69%)
• http://www.uottawa.ca/about/policies-and-regulations
Faculty regulations (2016)
• Mandatory withdrawal, if second failure in a
mandatory course
• Academic standing is evaluated after students
have attempted 24 course credits
– Mandatory withdrawal, if CGPA is below 3
– Probation, if 3 ≤ CGPA < 5
• 5 corresponds to C+ (65-69%)
General Suggestions
• Based on problems identified by the the Committee on
Academic Standing
– Stay engaged: attend classes, tutorials, etc.
– Understand academic regulations
• Do not take too many courses,
• Consider dropping a course in which you have low
average
– Take university seriously
– Do not work too many hours (in part-time jobs)
– Not making connect between mathematics and science to
engineering and computer science applications
Suggestions for ITI1120
– Do not fall behind
– Program as much as possible (assignments, labs …)
– After class, run the code we did in class. See if you
understand why it does what it does. Play with it.
– Consider bringing the laptop to lectures and type as I
do (if you are fast typer and can multitask)
– When programming, do not be afraid to make
mistakes (make sure each small part of program is
correct before moving to next part)
– Make use of office hours
Mentoring Centre
• Designed to compliment tutorials and office hours.
https://www.youtube.com/watch?v=nKIu9yen5nc
Why are you here?
For instance: Call your friend on the phone and give her
instructions to find your favorite café. Or explain how to bake a
cake.
Kinds of errors:
• Syntax error. Python cannot understand your program, and
refuses to execute it.
• Runtime error. When executing your program (at runtime),
your program suddenly terminates with an error message.
• Semantic (logical) error. Your program runs without error
messages, but does not do what it is supposed to do.
Why is programming fun?
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.4 Computer Software 38
Writing programs at this “low level” is tedious and error-
prone. Therefore, most programs are written in a “high-level”
programming language such as Python. Since the instructions
of such programs are not in machine code that a CPU can
execute, a translator program must be used.
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.4 Computer Software 39
Compiler
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.4 Computer Software 40
Interpreter
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.4 Computer Software 41
Why do we care about running time?
The Traveling Salesman Problem
The algorithm for solving this problem is a simple one. Determine the lengths of all
possible routes that can be taken, and find the shortest one – a brute force
approach. The computational issue, therefore, is for a given set of cities, how
many possible routes are there to consider?
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.1 What is Computer Science?
If we consider a route to be a specific sequence of names of cities, then how many
permutations of that list are there?
etc.
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.1 What is Computer Science? 44
Below are the number of permutations (and thus the number of routes) there are
for varies numbers of cities:
If we assume that a computer could compute the routes of one million cities per
second:
• for fifty cities, it would take longer than the age of the universe!
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.1 What is Computer Science? 45
The Game of Chess
When a computer plays chess against a human
opponent, both have to “think ahead” to the
possible outcomes of each move it may make.
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.1 What is Computer Science? 46
There are approximately 10120 possible chess games that can be played. This is
related to the average number of look-ahead steps needed for deciding each move.
and an estimated
Thus, there are more possible chess games that can be played than grains of sand
to fill the universe solid!
Therefore, for problems such as this and the Traveling Salesman problem in which a
brute-force approach is impractical to use, clever and more efficient problem-
solving methods must be discovered that find either an exact or an approximate
solution to the problem.
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.1 What is Computer Science? 47
• How many combinations you estimate in
Rubik Cube? GUESS A NUMBER !!!!!!
Computer Algorithms
An algorithm is a finite number of clearly
described, unambiguous “doable” steps
that can be systematically followed to
produce a desired result for given input in
a finite amount of time (that is, it
eventually terminates).
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 50
Algorithms and Computers: A Perfect Match
Computer algorithms are central to computer science. They provide
step-by-step methods of computation that a machine can carry out.
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 51
Euclid’s Algorithm
One of the Oldest Known Algorithms
Euclid’s Algorithm is an algorithm for computing the greatest
common denominator (GCD) of two given integers (A,B). It is one of
the oldest numerical algorithms still in common use.
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 52
Example Use
Finding the GCD of 18 and 20
1. Assign M the value of the larger of the two values, and N the smaller.
M 20 N 18
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 53
Example Use
Finding the GCD of 18 and 20
1. Assign M the value of the larger of the two values, and N the smaller.
M 20 N 18
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 54
Example Use
Finding the GCD of 18 and 20 (first time through, second time through)
1. Assign M the value of the larger of the two values, and N the smaller.
M 20 N 18
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 55
Example Use
Finding the GCD of 18 and 20 (first time through, second time through)
1. Assign M the value of the larger of the two values, and N the smaller.
M 20 N 18
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 56
Example Use
Finding the GCD of 18 and 20 (first time through, second time through)
1. Assign M the value of the larger of the two values, and N the smaller.
M 20 N 18
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 57
Example Use
Finding the GCD of 18 and 20 (first time through, second time through)
1. Assign M the value of the larger of the two values, and N the smaller.
M 20 N 18
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 58
Animation of Euclid’s Algorithm
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.2 Computer Algorithms 59
Information Theory
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.3 Computer Hardware 60
Binary Digitalization
In a binary representation, each digit can be one of only two possible
values, similar to a light switch that can be either on or off. Computer
hardware, therefore, is based on the use of simple electronic “on/off”
switches called transistors that can be switched at essentially the speed
of light.
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.3 Computer Hardware 61
The Binary Number System
For representing numbers, any base (radix) can be used. For example, in
base 10, there are ten possible digits (0, 1, ..., 9), in which column values
are a power of ten:
9 9 = 99
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.3 Computer Hardware 62
For representing numbers in base 2, there are two possible digits (0, 1)
in which column values are a power of two:
128 64 32 16 8 4 2 1
27 26 25 24 23 22 21 20
01 1 0 0 0 1 1
0 + 64 + 32 + 0 +0 +0 + 2 + 1 = 99
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.3 Computer Hardware 63
Bits and Bytes
Each binary digit is referred to as a bit. A group of (usually) eight bits is
called a byte. Converting a base ten number to base two involves the
successive division of the number by 2.
Introduction to Computer Science Using Python – Dierbach Copyright 2013 John Wiley and Sons Section 1.3 Computer Hardware 64