data structures introduction csc 172 spring 2004

29
DATA STRUCTURES DATA STRUCTURES INTRODUCTION INTRODUCTION CSC 172 SPRING 2004

Post on 20-Dec-2015

224 views

Category:

Documents


3 download

TRANSCRIPT

DATA STRUCTURESDATA STRUCTURESINTRODUCTIONINTRODUCTION

CSC 172

SPRING 2004

COURSE GOALSCOURSE GOALS

Write (lots of) great codeUnderstand the use of abstraction in

computer scienceDesign efficient data structures and

algorithmsUnderstand the use of mathematical tools in

analysis for computer scienceDevelop general problem solving skills

What this course is aboutWhat this course is about Abstraction

– Specifically, abstraction in computer programming through the use of abstract data types (ADTs)

– Abstraction is powerful Complexity of detail is encapulated and hidden Allowing operations at a higher level

– Your ability to abstract directly effects your productivity (as a lot of things)

Analysis– What makes a good abstraction?

AbstractionAbstraction

“The The acts of the mind, wherein it exerts its power over simple ideas, are chiefly these three: 1. Combining several simple ideas into one compound one, and thus all complex ideas are made. 2. The second is bringing tow ideas, whether simple or complex, together, and setting them by one another so as to take a view of them at once, without uniting them into one, by which it gets all its ideas of relations. 3. The third is separating them from all other ideas that accompany them in their real existence: this is called abstraction, and thus all its general ideas are made”

- John Lock, An Essay Concerning Human Understanding (1690)

AbstractionAbstraction

“Leaving out of consideration one or more qualities of a complex object so as to attend to others.”

- Mirriam Webster’s 9th Collegiate

Computer ScienceComputer Science The Mechanization of Abstraction

“Computer Science is a science of abstraction – creating the right model for thinking about a problem and devising the appropriate mechanizable techniques to solve it”

- Alfred Aho, 1995

Creativity as ScienceCreativity as Science

“Every other science deals with the universe as it is. The physicist’s job, for example, is to understand how the world works, not to invent a world in which physical laws would be simpler or more pleasant to follow. Computer Scientists, on the other hand, must create abstractions of real-world problems that can be understood by computer users and, at the same time, that can be represented and manipulated inside a computer”

- Jeffrey Ullman, 1995

Example: Dictionary ADTExample: Dictionary ADTA dictionary is an abstract model of a

databaseIn dictionaries, we look up definitions using

words– Words : “keys”– Definitions : “elements”

The main operation supported by a dictionary is searching by key

Dictionary ADTDictionary ADT Simple container methods

– size()– isEmpty()

Querry methods– findElement(k)

Update methods– insertItem(k,e)– remove(k)

Special object– NO_SUCH_KEY, returned by an unsuccessful search

Example: Dictionary ADTExample: Dictionary ADTAs “users”, we can think about dictionaries

in terms of such functionality without worrying about how they are implemented– Abstraction, problem conceptualization

As “programmers” we can think about how dictionaries are implemented without worrying about how they are used– Analysis, what is fast & efficient

Which Which Abstractions/Implementations?Abstractions/Implementations?

ListsStacksQueuesTreesSetsGraphs

What analysis?What analysis? “Anyone” can write a computer program. What is the difference between a good solution

and a not-so-good solution?– Running time– Memory requirements

Mathematical tools– Proof by induction– Combinatorics– Probability– Asymptotic analysis (Big-Oh)

ExampleExample

One dimensional pattern recognitionInput: a vector x of n floating point

numbersOutput: the maximum sum found in any

contiguous subvector of the input.

X[2..6] or 187How would you solve this?

31 -41 59 26 -53 58 97 -93 -23 84

Obvious solutionObvious solution

Check all pairs

int sum; int maxsofar = 0;

for (int i = 0; i<x.length;i++)

for (int j = i; j<x.length;j++){

sum = 0;

for (int k = i;k<=j;k++) sum += x[k];

maxsofar = max(sum,maxsofar);

}

How long does the obvious How long does the obvious solution take?solution take?

We could “measure” it – benchmarking– What is a “good size” of input to measure?– What machine do we measure it on?

How long does the obvious How long does the obvious solution take?solution take?

We could “analyse” it – Multiply the “cost” (time required) to do

something by the number of times you have to do it.

– If n is the length of the array– Outer loop runs exactly n times– Inner loop runs at most n times– Inner most loop runs no more than n times– Let’s say the “+=“ and “max” take unit time

How long does the obvious How long does the obvious solution take?solution take?

Innermost cost = n * 1 //worst caseInnerloop cost = n * (Innermost cost) +1Outerloop cost = n * (Innerloop cost)

Outerloop cost = n * ( n * (Innermost cost) +1)

Outerloop cost = n * (n *(n + 1) +1)

Outerloop cost = n * (n2 + n + 1)

Outerloop cost = n3 + n2 +n

How long does the obvious How long does the obvious solution take?solution take?

We call this an “n3” solutionCan you think of a better (faster) way?Can you do an analysis that will prove it

better?

That is what we do in CSC 172– For some very common tasks

InstructorInstructor

Prof. Ted Pawlicki, [email protected]

CSB 722, ext. 54198

Office Hours: TR 2PM-3PM

-lunch meetings also available

Lecture:

T,R 2:00PM-3:15PM AM Dewey 1-101

TextText

Data Structures & Problem Solving using Java 2nd Ed. By Mark Allen Weiss– Class, Lab, &

Workshops

Grad TAs (Mostly Projects)Grad TAs (Mostly Projects)

Lead UG TA (Mostly grades)Lead UG TA (Mostly grades)

Labs: Taylor 30Labs: Taylor 30

MW 4:50-6:05

MW 6:15-7:30 *

MW 2:00-3:15

TR 3:25-4:40 *

Register as a class

WORKSHOPSWORKSHOPS

Sign up Tuesday

EXAMSEXAMS

WorkshopsWorkshops

Required - attendance10% of GradePositive effect on grades

– Independent of extra credit

Group skills are valued by employers – Industrial & academic

Extra Credit ReportsExtra Credit Reports

10% boost for 10-20 page analysis of the UG CS curriculum at a selected institution– Instructor assigns institution– Overview of curricular requirements– Syllabus of 1st year courses (CS1 & CS2)– Compare & contrast to UR CS curriculum– Revision expected

Is this a hard course?Is this a hard course?

YesOne course has to be the hardestAll majors have hard courses“No pain, no gain”

Start early

Q&AQ&A

Do you understand what is expected of you?