Top Banner
DATA STRUCTURES DATA STRUCTURES INTRODUCTION INTRODUCTION CSC 172 SPRING 2004
29
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

DATA STRUCTURESDATA STRUCTURESINTRODUCTIONINTRODUCTION

CSC 172

SPRING 2004

Page 2: DATA STRUCTURES INTRODUCTION 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

Page 3: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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?

Page 4: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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)

Page 5: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

AbstractionAbstraction

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

- Mirriam Webster’s 9th Collegiate

Page 6: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 7: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 8: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 9: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 10: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 11: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

Which Which Abstractions/Implementations?Abstractions/Implementations?

ListsStacksQueuesTreesSetsGraphs

Page 12: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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)

Page 13: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 14: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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);

}

Page 15: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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?

Page 16: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 17: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 18: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 19: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 20: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

TextText

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

Workshops

Page 21: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 22: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 23: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 24: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

WORKSHOPSWORKSHOPS

Sign up Tuesday

Page 25: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

EXAMSEXAMS

Page 26: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

WorkshopsWorkshops

Required - attendance10% of GradePositive effect on grades

– Independent of extra credit

Group skills are valued by employers – Industrial & academic

Page 27: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 28: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

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

Page 29: DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.

Q&AQ&A

Do you understand what is expected of you?