CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25 Dan Garcia (ddgarcia) Kathy...

23
CS61B L01 Introduction (1) Garcia / Yelick Fall 2003 © U 2003-08-25 Dan Garcia (www.cs.berkeley.edu/~ddgarcia) Kathy Yelick (www.cs.berkeley.edu/~yelick) inst.eecs.berkeley.edu/~cs61b/ www.ucwise.org 4 Handouts: notes, accounts, cheating, hw0 Computer Science 61B Data Structures and Advanced Programming Lecture 1 – Introduction QuickTime™ and a TIFF (Uncompressed) decompressor are nee

Transcript of CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25 Dan Garcia (ddgarcia) Kathy...

Page 1: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (1) Garcia / Yelick Fall 2003 © UCB

2003-08-25 Dan Garcia

(www.cs.berkeley.edu/~ddgarcia)

Kathy Yelick (www.cs.berkeley.edu/~yelick)

inst.eecs.berkeley.edu/~cs61b/www.ucwise.org

4 Handouts: notes, accounts, cheating, hw0

Computer Science 61BData Structures and Advanced Programming

Lecture 1 – Introduction

QuickTime™ and a TIFF (Uncompressed) decompressor are needed to see this picture.

Page 2: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (2) Garcia / Yelick Fall 2003 © UCB

Course Goals "You will…"

1)Learn how to write great code 2)Understand abstraction3)Design efficient data structures and

algorithms that use them4)Learn Java and object-oriented

programming

Page 3: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (3) Garcia / Yelick Fall 2003 © UCB

Understanding Abstraction• Webster’s definition of abstraction: “Leaving out of consideration one or

more qualities of a complex object so as to attend to others.”

• Kinds of abstraction:– Procedural abstraction

» I.e., functions in 61a, more of this in 61b– Data abstraction

» Object model in 61a, a lot more in 61b– Iteration abstraction

» Like map in 61a, more of this in 61b

Page 4: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (4) Garcia / Yelick Fall 2003 © UCB

Why Use Java?• Supports data abstraction and iteration

abstraction – Programming in the large

• Hides some details of the underlying machine– Memory management (malloc and free)

• Programmer efficiency– Anectodal evidence says 2 more efficient than

C++ • Not because:

– One can safely download Java programs from others

– It has lots of libraries for writing cool animations– It’s the #1 language for job openings in software

Page 5: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (5) Garcia / Yelick Fall 2003 © UCB

Object-Oriented Programming

• Objects: some data and operations that manipulate that data

• Classes: factories for "generating" objects

• Methods: an operation on an object or a class

• Variables: names for the data in objects, classes, and methods

• Object-Oriented: uses data abstraction (classes) and inheritance

Page 6: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (6) Garcia / Yelick Fall 2003 © UCB

A Design Problem•You've just been hired by Google. –They need a data structure to lookup pages by keywords

–About 100M keywords –About 3 billion web pages; always growing

•What data structure should you use?

•What order do you rank the results?

Connectivity matrix of the web(dot = a link from one page to another)

0 105

01

05

Page-number

Pag

e-n

um

ber

Page 7: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (7) Garcia / Yelick Fall 2003 © UCB

Possible Solutions• From 61A: A linked list of keyword/URL pairs

– Time: O(n) to lookup

• A Binary Search Tree, keyed by keywords– Time: O(log n) to lookup, if balanced. – Can we ensure balance? (61b topic)

• A sorted array of keywords, lookup using binary search (divide and conquer)

– Time: O(log n) to lookup (61b topic)

• A hash table– Time: O(1) to lookup (61b topic)

• Note: big-O hides important factors in real performance (61b topic)

Page 8: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (8) Garcia / Yelick Fall 2003 © UCB

Administrivia• Our background

– Remarkably similar– MIT undergrads (same dorm, even!)– MIT/Cal grads– Now both on Cal faculty. Research interests:

» KY: Parallel computing (Using computers to understand the world)

» DG: Combinatorial Game Theory, Graphics, Mac OS X Programming

• Your background– Freshman / Sophomores / Juniors / Seniors / Grads– Who has taken 61A? E77?– Majors: EECS vs L&S vs others?– Own computers? PCs? Macs?– Scheme vs. Java?

Page 9: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (9) Garcia / Yelick Fall 2003 © UCB

Unauthorized Collaboration• Unauthorized collaboration (cheating) will:

– be reported to the Office of Student Conduct – result in grade penalties (including failing the

course).• Discussion about general solution strategies, or

help debugging is encouraged.• No Code Rule: Never have a copy of someone

else's program in your possession & never give your program to someone else.

• If you receive a significant idea from someone, acknowledge it.

– “someone” includes the web, students from previous semesters, your parents, old solutions, etc.

– May still receive a 0, but protects you from academic misconduct.

• These rules also apply to groups.

Page 10: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (10) Garcia / Yelick Fall 2003 © UCB

Current Events•CA Governor's race

–What do folks think of the "Govenator"?

• A's franchise-first!– First double-grand-

slam in their history– Tejada, Hernandez

go yard

QuickTime™ and a TIFF (Uncompressed) decompressor are needed to see this picture.QuickTime™ and a TIFF (Uncompressed) decompressor are needed to see this p icture.

Page 11: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (11) Garcia / Yelick Fall 2003 © UCB

Texts• Introduction to Programming Using

Java: An Object-Oriented Approach, 2nd Edition, by Arnow and Weiss.

– Note that this book is currently not yet available in the bookstore (but we are told it will be in by Wednesday 2003-08-27).

• Program Development in Java, by Liskov and Guttag, Chapters 4 and 10 only. 

– These two chapters are shrink-wrapped with the Arnow and Weiss book, if purchased through the campus bookstores.  

• Data Structures and Algorithms in Java (2nd Ed.) by Goodrich and Tamassia.

• Reading assignments on course portal

QuickTime™ and a TIFF (Uncompressed) decompressor are needed to see this picture.

QuickTime™ and a TIFF (Uncompressed) decompressor are needed to see this picture.

Page 12: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (12) Garcia / Yelick Fall 2003 © UCB

Lecture : Peer Instruction• Increase real-time learning in

lecture, test understanding of concepts vs. details

• As complete a “segment” ask multiple choice question– 1-2 minutes to decide yourself, vote– 3 minutes in pairs to reach

consensus. Teach others! Vote as a team.

– 5-7 minute discussion of answers, questions, clarifications

– How shall we record votes?

Page 13: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (13) Garcia / Yelick Fall 2003 © UCB

PRS and Lecture Format• PRS (Personal Response System)

– Electronic devices sold in bookstore for $37.25» Can use in other classes as Cal student» Can also sell back to bookstore for half-price and

end– Room is wired with receivers -- every vote

counts!• Typical 50-minute Lecture Format

– 18-minute lec, 2-min admin break– 18-minute lec, 8-min Peer instruct, 4-min close

Attention

Time20 min. Break Next-thing

Page 14: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (14) Garcia / Yelick Fall 2003 © UCB

FormatLecture - Discussion - Lecture - Lab - Lecture

• There IS discussion and lab this week…

QuickTime™ and a TIFF (Uncompressed) decompressor are needed to see this picture.

Page 15: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (15) Garcia / Yelick Fall 2003 © UCB

Homeworks, Labs and Projects•Lab exercises (every wk; due at

worst first 1/2-hour next lab)

•Homework exercises (~ every week)–First homework (HW 0) passed out today,

due in section next week.

•Projects (every ~4 weeks)• All exercises, reading, homeworks,

projects on course portal: www.ucwise.org

Page 16: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (16) Garcia / Yelick Fall 2003 © UCB

Quiz, Midterm & Final

• Quiz– In-class on Java basics

• Midterm: Wed 7-9pm Nov 5th room TBA– Review: Sun Nov 2nd, 2pm Room TBA

• Final: Tue 12:30-3:30pm Dec 18th – 1 week before Christmas, for everyone– No plane ticket excuse

Page 17: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (17) Garcia / Yelick Fall 2003 © UCB

Your Final Grade• Grading (probably won't change, but might)

– 5% Labs– 10% Homework– 10% Project 1– 12% Project 2– 13% Project 3– 8% Quiz– 17% Midterm– 25% Final

• Grade distributions– Similar to CS61A, in the absolute scale. No curve!– Perfect score is 300 points. 10-20-10 for A+, A, A-– Similar for Bs and Cs (40 pts per letter-grade)– Differs: … C+, C, C-, D, F (No D+ or D- distinction)

50% Assignments

50% Exams

Page 18: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (18) Garcia / Yelick Fall 2003 © UCB

Extra Credit: EPA!• Effort

– Attending office hours, completing all assignments

• Participation– Attending lecture and voting using the PRS

system– Asking great questions in discussion and lecture

and making it more interactive• Altruism

– Helping others in lab or on the newsgroup• EPA! extra credit points have the

potential to bump students up to the next grade level!

Page 19: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (19) Garcia / Yelick Fall 2003 © UCB

•David Parks [Head TA]•Igor Gammer•Rishi Kant•Ram Gudavalli

TAs

Page 20: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (20) Garcia / Yelick Fall 2003 © UCB

The “Hello, world” Program in Java

/* In a file called HelloWorld.java */ public class HelloWorld { public static void main (String[] args){

System.out.println("Hello, world");}

}

1) The HelloWorld class is a "factory" for HelloWorld objects.

2) The class knows how to do the "main" operation.3) Calls the System class to get an output stream &

does a print operation on it using the "Hello, world" string.

Page 21: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (21) Garcia / Yelick Fall 2003 © UCB

Anatomy of "Hello, World" in Java

• The classes are:– HelloWorld– System– String

• The objects are: – System.out, "Hello, world"

• The methods are: – main (on the HelloWorld class)– println (on the OutputStream class)

Page 22: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (22) Garcia / Yelick Fall 2003 © UCB

Differences Between Java & Scheme

• Everything in Java has a type, and you have to "declare" it. E.g., int x = 1; vs. (let ((x 1)) ... )

• Java has a compiler & a non-interactive interpreter.

Scheme, Matlab Java C, C++, Pascal

program.scm

answer

eval

Program.java

answer

eval

program.c

answer

cc

Program.class

javac

java

program

run

Let's demonstrate!

Page 23: CS61B L01 Introduction (1)Garcia / Yelick Fall 2003 © UCB 2003-08-25  Dan Garcia (ddgarcia) Kathy Yelick  (yelick)

CS61B L01 Introduction (23) Garcia / Yelick Fall 2003 © UCB

And in Conclusion…• In CS61B you will…

1) Learn how to write great code

2) Understand abstraction

3) Design efficient data structures and algorithms that use them

4) Learn Java and object-oriented programming