lecture 01 introduction - university of western...

41
CITS 1401 Problem Solving & Programming Ajmal Mian Lecture 01 – Introduction (These slides are based on John Zelle’s powerpoint slides for lectures accompanied with the text book)

Upload: others

Post on 10-Mar-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

CITS 1401 Problem Solving & Programming

Ajmal Mian

Lecture 01 – Introduction

(These slides are based on John Zelle’s powerpoint slides for lectures accompanied with the text book)

Page 2: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Organization

Unit coordinator

• Assoc. Prof Ajmal Mian

• Room 1.12

• Consultation time: 1:00 – 2:00PM Thursdays

• Website: http://www.csse.uwa.edu.au/~ajmal/

Unit website: http://undergraduate.csse.uwa.edu.au/units/CITS1401/

Two Lectures per week (1 hour each)

Three Labs per week (3 hours each)

One Workshop per week (1 hour)

2 23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction

Page 3: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Lectures

Engineering Lecture Theatre 2 (ELT2)

Mondays 1:00 – 1:50PM

Wednesdays 1:00 – 1:50PM

All lectures are recorded and will be available from LMS

All lecture slides will be available from the unit website

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 3

Page 4: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Laboratory sessions

Starting Week 2 in CSSE 2.03

Mondays 2:00 – 4:45PM

Tuesdays 9:00 – 11:45AM

Wednesdays 2:00 – 4:45PM

You are expected to attend at least one lab session

You are welcome to attend as many lab sessions as you want

Only the first two hours of each session are supervised

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 4

Page 5: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Workshop

Thursday 4:00 - 5:00PM in ELT2 (starting week 2)

Attendance is purely optional and on a need basis

Friendly embarrassment free environment for asking questions

Aimed at students who are having difficulty

Basic questions will be given priority over advanced questions

Additional examples complementing lectures

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 5

Page 6: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Online material

Everything distributed in CITS1401 will be available on the unit website

Lectures will be available on LMS

For initiating online questions and discussions, use cshelp i.e. go to

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 6

https://secure.csse.uwa.edu.au/run/help1401

Page 7: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

help1401

READ FIRST: if the answer is not there, THEN POST

Asking is useful - Sometimes formulating a question properly help you

realize the answer yourself

Answering is useful – explaining to others helps you understand better

DO NOT post assessment code on help1401

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 7

Page 8: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Announcements

Announcements will be made in any of the following three places

• Lectures

• Unit website

• Help1401

Information distributed by email will be sent to your UWA account

Please check CITS1401 webpage + help1401 + your UWA email regularly

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 8

When an announcement has been made in these

places, it will be assumed that you are aware of it

Page 9: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Text and other resources

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 9

PYTHON PROGRAMMING: AN INTRODUCTION TO COMPUTER SCIENCE

by JOHN ZELLE

Publisher: Franklin Beedle & Associates

ISBN-10: 1887902996

ISBN-13: 978-1887902991

Other resources http://undergraduate.csse.uwa.edu.au/units/CITS1401/resources/

Page 10: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Development Environment

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 10

In the lab you will use Python 3.3 IDLE

• An integrated software development environment where you can write,

edit, execute and debug programs

IDLE is a free software available for all major operating systems such as

Windows, OS, Linux

You can download it from python.org and install it on your home computer

Make sure that your submitted code (lab assignments etc) runs on the lab

computers because that is where it will be tested

Page 11: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Assessment

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 11

Assessment is based on both

• Understanding of fundamental concepts

• Practical problem-solving and programming skills

Mid-semester test in Week 8 (worth 15%)

Two programming projects

• Project 1 due in Week 8 (worth 10%)

• Project 2 due in Week 13 (worth 15%)

Final exam in June (worth 60%)

Page 12: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Passing and satisfactory progress

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 12

At least 50% overall, AND

At least 40% in Project 1 and mid semester test combined, AND

At least 40% in the final exam

CAUTION: 15-20% STUDENTS fail in CITS1401

Page 13: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Seeking help – options are many

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 13

help1401

Supervised labs

Workshops

Text and other resources

Consultation times

http://www.student.uwa.edu.au/learning

Seek help early when there is a problem, you are not alone

Page 14: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

UWA compulsory online modules

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 14

All students are required to complete three online learning modules

• Academic Conduct Essentials

• Communication and Research Skills

• Indigenous Study Essentials

The above site also contains many other helpful resources

http://www.student.uwa.edu.au/learning/resources

Page 15: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Make your Week 1 in the labs useful

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 15

Get your computer account name and password

Organize your UWA email account

Obtain your timetable from OLCR

Get familiar with the CSSE website

Get familiar with the CITS1401 website

Install Python 3 on your home computer/ laptop

Page 16: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia 23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 16

LET US BEGIN

Page 17: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

CITS1401

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 17

CITS1401 is about problem solving and programming in general

• Python is used as a platform

CITS1401 covers

• Important problem solving techniques used widely in computer science

and programming

• Writing basic program in Python (a modern high level language)

• An introduction to software engineering

Lectures, labs and the projects will complement each other.

Page 18: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Objectives of todays lecture

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 18

To understand the roles of hardware and software in a computing system.

To learn what computer scientists study and the techniques they use.

To understand the basic design of a modern computer.

To understand the form and function of programming languages.

Page 19: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

The Universal Machine

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 19

A computer is “a machine that stores and manipulates information under the

control of a changeable program.”

Two key elements

• Computers are devices for manipulating information

• Computers operate under the control of a changeable program

Page 20: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

What is a computer program?

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 20

A detailed, step-by-step set of instructions telling a computer what to do.

If we change the program, the computer performs a different set of actions

or a different task.

The machine stays the same, but the program changes!

• Hence what the machine does, also changes.

Page 21: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Computer programs

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 21

Programs are executed, or carried out.

Most computers have similar capabilities.

With a suitable program, each computer can do the things other computers

can do.

In other words, the same program will produce similar results on different

computers.

Page 22: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Program Power

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 22

Software (programs) rule the hardware (the physical machine).

The process of creating this software is called programming.

Why learn to program?

• It is a fundamental part of computer science.

• Having an understanding of programming helps understand the

strengths and limitations of computers.

Page 23: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

What is Computer Science?

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 23

It is NOT the study of computers!

“Computers are to computer science what telescopes

are to astronomy.”

Edsger Dijkstra

Since computer can carry out any process, the question really is “what

process we can describe?”

The fundamental question is “What can be computed”?

Page 24: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

What is Computer Science?

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 24

Computer scientists find the answers to questions through

1. Design

2. Analysis

3. Experimentation

Page 25: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Design

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 25

One way to show a particular problem can be solved is to actually design a

solution.

This is done by developing an algorithm

An algorithm is simply a “recipe”

Algorithm: A step-by-step process for achieving the desired result

CITS1401 teaches you how to

• Design an algorithm

• Write a program for it

Page 26: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Analysis

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 26

“Design” can only answer the question “What is computable?” in the positive.

• Not being able to design an algorithm does not mean it is unsolvable.

Analysis is the process of examining algorithms and problems mathematically.

Some seemingly simple problems are unsolvable by any algorithm.

Problems can be intractable if they would take too long or take too much

memory to be of practical use. [More on this in Week 12, Ch-13]

Page 27: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Experimentation

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 27

Some problems are too complex for analysis.

Implement a system and then study its behaviour.

Experimentation is sometimes still needed after theoretical analysis

• To verify the analysis

• To refine the analysis

Thus, computer science is about designing, analyzing and evaluating algorithms

Page 28: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Hardware Basics

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 28

The central processing unit (CPU) is the brain of the computer.

The CPU carries out all basic operations on the data e.g. simple arithmetic.

CPU

Main memory

Output

devices

Secondary

Memory

Input

devices

Page 29: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Basic Hardware

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 29

Memory stores programs and data.

CPU can only directly access information from the main memory (RAM).

Random Access Memory.

RAM is fast but volatile i.e. all information is lost when power is lost.

Secondary memory provides more permanent storage (non-volatile).

• Magnetic (hard drive, USB drives)

• Optical (CD, DVD, Blue Ray Disc)

Page 30: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Hardware Basics

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 30

Input devices – pass information to the computer

• Keyboards

• Mice

• Camera

• Microphone

Output devices – pass information back to the user

• Monitor

• Printer

• Speaker

Page 31: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

The Fetch Execute Cycle

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 31

Load program into the main memory (RAM)

Fetch the first (next) instruction from memory

Decode the instruction to see what it represents

Carry out the appropriate instruction.

Repeat

Page 32: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Programming Languages

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 32

Natural languages cannot precisely describe an algorithm.

Programming languages can express algorithms in a precise way.

Every structure in a programming language has a precise form called its

syntax.

Every structure in a programming language has a precise meaning called its

semantics.

Page 33: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Programming Languages

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 33

Programming language is like a code for writing instructions that the

computer can understand and follow.

Programs are sometimes called computer code.

The process of writing an algorithm in a programming language is often

called coding.

Page 34: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Programming Languages

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 34

High-level programming languages

• Designed to be understood and written by humans

Low-level language

• Computer hardware can only understand a very low level language

known as machine language

Page 35: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

High-level Programming Language

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 35

In a high-level language, the addition of two numbers may be written as

c = a + b

This needs to be translated to machine language so the computer can

execute it

Compilers convert programs written in a high-level language into machine

language

Page 36: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Low-level Language

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 36

The corresponding low-level language may look something like this

• Load the number from memory location 5001 into the CPU

• Load the number from memory location 5002 into the CPU

• Add the two numbers in the CPU

• Store the result into location 5003

In reality, these low-level instructions are represented in binary (1’s and 0’s).

Page 37: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Interpreters

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 37

Interpreters simulate a computer that understands a high-level language.

The source program is not translated (compiled) into machine language all

at once.

An interpreter analyzes and executes the source code instruction by

instruction.

Page 38: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Compiling vs.

Once program is compiled, it can

be executed over and over without

the source code or compiler

Compiled programs generally run

faster since the translation of the

program happens only once

Program needs to be compiled

after every minor change in it

A program compiled for Windows

will not run on OS (Mac) or Linux

Interpreting

The source code and interpreter are needed each time the program is executed

Interpreted programs run slower due to the interpretation each time it is executed

More flexible programming environment since programs can be developed and run interactively

Interpreted programs are more portable across different platforms e.g. Macs, Windows, Linux

38 23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction

Page 39: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Python

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 39

Python is an interpreted language.

If a suitable interpreter exists for two different machines with very different

CPUs, the same program will run on both.

Page 40: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Python

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 40

When you start Python, you will see something like:

Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit

(Intel)] on win32

Type "copyright", "credits" or "license()" for more information.

>>>

The “>>>” is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements.

>>> print("Hello, world“) Hello, world >>> print(2+3) 5 >>> print("2+3=", 2+3) 2+3= 5 >>>

Page 41: Lecture 01 Introduction - University of Western Australiateaching.csse.uwa.edu.au/.../Lecture01-Introduction.pdf · 2015-02-23 · The University of Western Australia Development

The University of Western Australia

Summary

Understanding the roles of hardware and software in a computing

system.

Learning what computer scientists study and the techniques they

use.

Understanding the basic design of a modern computer.

Understanding the form and function of programming languages.

23/02/2015 CITS1401 Problem Solving & Programming - Lecture 01 - Introduction 41