algorithms and complexity 1: introduction

17
John Levine, Computer and Information Sciences, Strathclyde University http://www.cis.strath.ac.uk/~johnl/ 1 Algorithms and Complexity 1: Introduction John Levine [email protected] 1

Upload: reya

Post on 30-Jan-2016

47 views

Category:

Documents


0 download

DESCRIPTION

Algorithms and Complexity 1: Introduction. John Levine [email protected]. 1. Introductory Lecture. What’s an algorithm then? Intro and brief history Sample use of algorithms Sample algorithm Course overview Lectures, practical, labs/tuts, the exam. First, who am I?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

1

Algorithms and Complexity1: Introduction

John [email protected]

1

Page 2: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

2

Introductory Lecture

• What’s an algorithm then?– Intro and brief history– Sample use of algorithms– Sample algorithm

• Course overview– Lectures, practical, labs/tuts, the exam

Page 3: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

3

First, who am I?

• Senior Lecturer in Comp Sci

• Contact details– [email protected]– www.cis.strath.ac.uk/~johnl/– Livingston Tower L13.21– Contact me on ext 4524

• Background in AI planning, artificial evolution and AI in computer games

Page 4: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

4

What’s an Algorithm then?

• Top level of programming– Algorithm (e.g. Binary search)– Program source (e.g. Java)– Byte code (e.g. Java VM)– Machine code (e.g. PowerPC, Pentium III)

Page 5: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

5

COOKING GUIDELINESFor best results cook from frozenTo microwave:  Remove sleeve and pierce film lid several times.

750 watt or category D oven: 3 minute full powerTurn dish 3 minute full power

650 watt or category B oven: 3 minute full powerTurn dish 3 minute full power

To Oven Bake:  Remove sleeve and pierce film lid several times.  Place on a Baking tray in a pre-heated oven 190 °C, 375 °F, Gas Mark 5 for 35 - 40 minutes. 

Adjust cooking times according to your particular oven.  For fan assisted ovens cooking times should be reduced.  For best results refer to the manufacturers handbook.CHECK FOOD IS PIPING HOT BEFORE SERVING.  DO NOT REHEAT.

Page 6: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

6

Euclid – c300BC

• Greatest common factor (GCD) of 2 integers:– divide the larger by the smaller– divide the smaller by the remainder of 1st – divide remainder of 1st by the remainder of 2nd – repeat until you get a remainder of zero– answer is last non-zero remainder

Page 7: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

7

Abu Jafar Mohammed ibm Musa Al Khwarizmi

• Invented mechanical method for adding numbers in AD800

Page 8: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

8

Toy Story

• Algorithms often used to make doable unfeasibly large computations, e.g.:– Pixar chair Steve Jobs may be the cover

boy, and director John Lasseter may get the creative glory, but animator Ed Catmull is the quiet techie whose algorithms put the zing into films like Toy Story and November's A Bug's Life -

– Wired Oct 98

Page 9: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

9

Monsters Inc

• 2.3 million hairs on Sulley

• each shot (usually 3-10 seconds), took one to two hours to create

Page 10: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

10

Monsters Inc“The rendering was completed in the Pixar Renderfarm, which is powered by 250 Sun ... servers, ... each using – 14 UltraSPARC™ II microprocessors– 14 gigabytes of system memory– and 196 gigabytes of local disk space

for a total of 3,500 processors in production with nearly four terabytes of main memory.”

Also see http://cgw.pennnet.com/ & search for “Monster Mash”

Page 11: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

11

Room count

• Approach 1:– Sequential from front right in looping rows

• Approach 2:– Parallel from left to right then back to front

Page 12: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

12

Complexity analysis

• Approach 1– If it takes 0.6 seconds per person then the

total time will be 0.6n secs for n people

• Approach 2– If it takes 0.6 seconds per person to add 1

and 6 seconds to add at end of row, then total will be 0.6(n/r) + 6r for n people and r rows

Page 13: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

13

Time to count

0

2

4

6

8

10

12

0 500 1000 1500

Number in room (rows of 50 max)

min

ute

s to

co

un

t

Page 14: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

14

Course Content

• Introduction (1 week approx)

• Searching and sorting (1)

• Binary trees (2)

• Graph algorithms (3)

• Permutations and combinations (2)

Page 15: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

15

Course Details• Java Collections

Watt & Brown• 20 Lectures

– lecture & notes style

• 20 Practicals• 20% coursework• 80% exam • www.cis.strath.ac.uk/~johnl/ac/• news:strath.cis.teaching.ug.ac

Page 16: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

16

@home: The travelling seller

• Mary, a computer seller, needs to visit 3 shops in a day (starting and finishing at the office): what’s the shortest route?

5km

3km

2km

8km

12km

Page 17: Algorithms and Complexity 1: Introduction

John Levine, Computer and Information Sciences, Strathclyde Universityhttp://www.cis.strath.ac.uk/~johnl/

17

Next time

• Size matters

• Complexity notation

• Calculating complexities

• Read chapter 2 in advance