welcome and introduction 15-211 fundamental data structures and algorithms margaret reid-miller and...

61
Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Upload: philomena-ward

Post on 03-Jan-2016

230 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Welcome and Introduction

15-211 Fundamental Data Structures and Algorithms

Margaret Reid-Miller

and Aleks Nanevski

January 13, 2004

Page 2: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

What is this course about?

Page 3: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

What is this course about?

How to solve computing problems.

Problem analysis, to abstract away details and divide into smaller subproblems.

Mathematical foundations for precise formulations of problems and solutions.

Data structures and algorithms to solve problems correctly and efficiently.

Java programming and modular software construction for good implementations.

Page 4: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

An Example

Page 5: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Generating mazes

We want to write a program to generate mazes.

We want every maze to be solvable.

Page 6: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Generating mazes, cont’d

Also: We want mazes to be fun, i.e.,

We want maze solutions to be unique.

We want every “room” to be reachable.

How should we think about this?

Page 7: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Let’s hack!

Page 8: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

2am in the WeH cluster…

Page 9: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

No, let’s think!

Page 10: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Thinking about the problem

Think about a grid of rooms separated by walls.

Each room can be given a name.

a b c d

hgfe

i j k l

ponm

Randomly knock out walls until we get a good maze.

Page 11: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Mathematical formulation

A set of rooms:{a, b, c, d, e, f, g, h,

i, j, k, l, m, n, o, p}

Pairs of adjacent rooms that have an open wall between them.For example, (a,b)

and (g,k) are pairs.

a b c d

hgfe

i j k l

ponm

Page 12: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Graphs

Abstractly, this is a mathematical structure called a graph.

Informally, a graph consists of a set of nodes and a set of edges.

Page 13: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Mazes as graphs

A maze is a graph whereeach node represents a room, and

an edge from node x to node y indicates that rooms x and y are adjacent and there is no wall in between them.

A part of this course will be about graph algorithms.

Page 14: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Why math?

Q: Why is it useful to formulate the problem so that mazes are graphs?

A: Data structures are typically defined as mathematical structures.

A: Mathematics can be used to reason about the correctness and efficiency of data structures and algorithms.

A: Mathematical structures make it easier to think — to abstract away from unnecessary details and avoid “hacking”.

Page 15: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Mazes as graphs

a b c d

hgfe

i j k l

ponm

{(a,b), (b,c), (a,e), (e,i), (i,j), (f,j), (f,g), (g,h), (d,h), (g,k), (m,n), (n,o), (k,o), (o,p), (l,p)}

Page 16: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Mazes as graphs

{(a,b), (b,c), (a,e), (e,i), (i,j), (f,j), (f,g), (g,h), (d,h), (g,k), (m,n), (n,o), (k,o), (o,p), (l,p)}

a b c d

e f g h

i j k l

m n o p

Page 17: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Unique solutions

What property must the graph have for the maze to have a solution?A path from (a) to (p).

What property must it have for the maze to have a unique solution?Graph must be a tree.

a b c d

e f g h

i j k l

m n o p

Page 18: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Mazes as trees

Informally, a tree is a graph:with a unique root

node, and

each node having a unique parent.

A spanning tree is a tree that includes all of the nodes.Why is it good to

have a spanning tree?

a

b

c

d

e

f

gh

i

j

k

lm

no

p

Trees have no cycles!

Page 19: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

What is this course about?

1. Thinking about problems abstractly.

Page 20: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Algorithm

Now that we have a data structure in mind, we can think about the algorithm.

Essentially:

Randomly pick a wall and delete it (add it to the tree) if it won’t create a cycle.

Stop when a spanning tree has been created.

This is Kruskal’s Algorithm.

Page 21: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Creating a spanning tree

When adding a wall to the tree, how do we detect that it won’t create a cycle?

When adding wall (x,y), we want to know if there is already a path from x to y in the tree.

In fact, there is a fast algorithm for doing exactly this, called union-find.

Page 22: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Using the union-find algorithm

We put rooms into an equivalence class if there is a path connecting them.

Before adding an edge (x,y) to the tree, make sure that x and y are not in the same equivalence class.

a b c d

e f g h

i j k l

m n o p

Partially-constructed maze

Page 23: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

How fast?

Is this a fast way to generate mazes?

How much time will it take to generate a maze?

What do we mean by “fast”?

In addition to finding the right algorithms, analyzing the performance of algorithms will be a major part of this course.

Page 24: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Performance and Scaling

Suppose we have three algorithms to choose from.

Which one to select?

Systematic analysis reveals performance characteristics.

For a problem of size n (i.e., detecting cycles out of n nodes).

1. 100n sec

2. 7n2 sec

3. 2n sec

Page 25: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Performance and Scaling

n 100n sec 7n2 sec 2n sec

1 100 s 7 s 2 s

5 .5 ms 175 s 32 s

10 1 ms .7 ms 1 ms

45 4.5 ms 14 ms 1 year

100 … … …

1,000

10,000

1,000,000

Page 26: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Performance and Scaling

n 100n sec 7n2 sec 2n sec

1 100 s 7 s 2 s

5 .5 ms 175 s 32 s

10 1 ms .7 ms 1 ms

45 4.5 ms 14 ms 1 year

100 … … …

1,000

10,000

1,000,000

Page 27: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

What?! One year?

210 = 1,0241024 sec 1 ms

245 = 35,184,372,088,8323.5 * 1013 sec = 3.5 * 107 sec

1.1 year

Page 28: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Performance and Scaling

n 100n sec 7n2 sec 2n sec

1 100 s 7 s 2 s

5 .5 ms 175 s 32 s

10 1 ms .7 ms 1 ms

45 4.5 ms 14 ms 1 year

100 100 ms 7 sec 1016 year

1,000 1 sec 12 min --

10,000 10 sec 20 hr --

1,000,000 1.6 min .22 year --

Page 29: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

What is this course about?

2. Selecting good data structures and fast algorithms.

Page 30: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Modular design

By thinking about the problem, we have strong hints about the structure of our programGrids, Graphs (with edges and nodes),

Spanning trees, Union-find.

With disciplined programming, we can write our program to reflect this structure.

Modular programs are usually easier to get right and easier to understand.

Page 31: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Modular design

SpanningTree

Maze

GraphGrid

MazeDraw

UnionFindReusable components

Page 32: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Is it correct?

How will we know if we implemented our solution correctly?What do we mean by “correct”?

Will it generate the right answers?

Will it terminate?

We will spend some time in this course on techniques for proving the correctness of programs.

Page 33: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

What is this course about?

3. Implementing programs that are understandable and correct.

Page 34: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Instant Quiz

Page 35: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Instant quiz: Two questions

Given that we are using trees to represent mazes, what would be a simple algorithm for solving mazes?

Besides insisting on spanning trees, what other criteria might one want in order to improve the “quality” or “fun factor” of the mazes?

a

b

c

d

e

f

gh

i

j

k

lm

no

p

Page 36: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

What is this course about?

Page 37: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

The science in CS

Not “hacking”, but:

Thinking about problems abstractly.

Selecting good data structures and obtaining correct and fast algorithms.

Implementing programs that are understandable and correct.

Page 38: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

How the Course Works

Page 39: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Course staff

A complete listing of the course staff (including instructors and teaching assistants) will be available on the course Blackboard site.

http://www.cmu.edu/blackboard

Page 40: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Prerequisites

Basic programming skills.

Provided by 15-111 or 15-200.

Basic discrete math and logic.

Provided by 21-127.

This course is not about Java programming, but about how to solve problems on a computer.

Page 41: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

How will 15-211 be different?

Faster pace.Lots of reading, thinking, programming.

Assumption of mature work habits.Starting early, overcoming obstacles.

Larger homework assignments.Typically requiring several days of work.

More open-ended problems to solve.Sometimes no single “right” answer.

Page 42: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Textbook

Mark Allen Weiss, Data Structures & Algorithm Analysis in Java.

http://www.cs.fiu. edu/~weiss

Addison-Wesley, 2002.

Page 43: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Recitations

Starts tomorrow!

Questions are answered, new material is covered, and homeworks might be graded.

Some TAs will insist that you go to recitation in order to get a grade on your homeworks!

Switching sections is possible.But the sections must be balanced.Talk to the TAs – they are in charge.

Page 44: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Recitations and your TA

Recitation sessions are also the place for you to get to know your TA…

…and for your TA to get to know you

Your TA will be responsible for assigning almost all of your grades for this course!

Page 45: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Go to Recitation!!!

Page 46: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Handouts and information

Everything on Blackboard (Bb) system.

http://www.cmu.edu/blackboard

User id: your Andrew id.

Password: your Andrew password.

Page 47: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

The Blackboard (Bb) system

Check Bb frequently for

Announcements.

Course policies.

You must read the cheating policy.

Contact information.

Course schedule and calendar.

Discussion bboard.

Page 48: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Requirements

Participation in lectures and recitations.

Reading assignments.

Homework assignments.

Online quizzes.

In-class and final exams.

Page 49: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Grades

1 “warmup”.

3 small homeworks.

3 large homeworks.

3 quizzes.

Midterm exam.

Final exam.

TA discretion.

39 points.

50 points each.

100 points each.

20 points each.

125 points.

275 points.

50 points.

SUBJECT TO CHANGE

Page 50: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Homework assignments

Goal: Reinforce and apply what is taught in class.

Early homeworks will be small individual programming assignments.

Later homeworks will be much larger assignments, working in groups of two.

Page 51: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

What kind of Assignments?

How do we write our own little search engine?

How do we compress a file?

lossless (winzip)

lossy (jpeg)

How do we design and program a game?

How to analyze the game board?

How to pick the best move?

Page 52: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Homework administration

Electronic handout (on Bb), handin, & handback.

All due on Mondays 11:59pm.

Cluster hours on some evenings, to be announced.

Up to 24 hours late for -50%.No handins accepted after 24 hours.

Page 53: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

If you need an extension

DO NOT SEND EMAIL!

All emails on this topic will be ignored.

You must see an instructor face-to-face and explain the reasons.

We will be reasonable.

Page 54: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

If you need an extension

DO NOT SEND EMAIL!

Page 55: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Homework assignment 0

HW0 is available now!

Download and get started today.

HW0 due on Monday at 11:59pm!

Handin of a working assignment will get the full 40 points credit.

Gets you started with the software tools used in this course.

Page 56: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Software tools

We recommend the use of standard tools.

Sun’s Java development kit (J2SE 1.4.1).

Emacs text editor.

Unix (Linux, Solaris, MacOS X, Cygwin).

Web-based handin system.

Page 57: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Cheating

There is no need to cheat in this course.

If you are in trouble, come and talk to us.

We are here to help you.

We expect you to know what is useful collaboration and what is cheating.

We will be using advanced data-mining tools to monitor the originality of all programs that are handed in

Page 58: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Original code

For programming assignments, you will be required to hand in your own original code

You may discuss your homeworks with others, but if doing so impairs your ability to write truly original code, then you are cheating

More on this as the semester goes on…

Page 59: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Consequences of cheating

If you cheat, you should come to us immediately for help.

We will try to be lenient.

If we catch you, you will either

lose at least double credit, or

fail the course.

Especially bad cases will be officially reported to the Associate Dean.

Page 60: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Homework discipline

Start early.

Most assignments will require more than 1 evening to complete.Larger assignments will require several

days of group work.

Remember:Don’t start by sitting at a blank screen.

Humans will be trying to understand your code when grading it.

Page 61: Welcome and Introduction 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller and Aleks Nanevski January 13, 2004

Summary

Go to recitation

Check out the Blackboard site

And welcome to the course!