CS211 Computers and Programming http:www.cs.cornell.educoursescs2112004sp - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

CS211 Computers and Programming http:www.cs.cornell.educoursescs2112004sp

Description:

News Group: Use frequently. Learn about it in section. ... in an organized, mathematical, disciplined fashion that leads to short, clear, ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 28
Provided by: tri5194
Category:

less

Transcript and Presenter's Notes

Title: CS211 Computers and Programming http:www.cs.cornell.educoursescs2112004sp


1
CS211 Computers and Programminghttp//www.cs.corn
ell.edu/courses/cs211/2004sp/
  • Instructor David Gries, Olin 167
  • gries_at_cs.cornell.edu, dgries_at_twcny.rr.com
  • Staff coordinator Stacey Shirk, Upson 403
  • shirk_at_cs.cornell.edu
  • TAs Each TA leads 1 or 2 recitation sections.
    Your TA is your main contact for the course get
    to know TA well.
  • Consultants in Upson 304
  • Office hours to be announced
  • News Group Use frequently. Learn about it in
    section.

Education is one of the few things a person is
willing to pay for and not get. William Lowe
Bryan
2
CS211 Computers and ProgrammingLectures and
sections
  • Lecture Tues, Thurs. 1005AM. Attendance
    expected.
  • Lecture notes online. Print them before the
    lecture and bring them to lecture.
  • Readings posted online, with lecture notes.

Sign up for one section. Attendance expected
sections may teach new material. Its okay to
switch sections no permission needed. But end up
sticking with one section.
3
CS211 ObjectivesLearn about
  • Concepts in modern programming languages
  • recursion, induction
  • classes, objects, inheritance, interfaces
  • Efficiency of programs
  • Correctness issues and testing/debugging
  • Data structures arrays, lists, stacks, queues,
    priority queues,trees, binary search trees, hash
    tables, graphs
  • Software engineering. How to design, organize,
    test, debug, maintain large programs.
  • Practice in writing/testing/debugging programs
  • NOT A COURSE SIMPLY ON JAVA PROGRAMMING

4
CS212
  • one-credit project course.
  • one lecture per week.
  • substantial design and programming.
  • required for CS majors.
  • take with or after CS211. Taking 211-212
    together advised.

AEW Workshop
  • one-credit S/U course.
  • meets once per week for 2 hours.
  • grade depends solely on attendance.
  • students work together in a cooperative learning
    environment.

5
Grades
  • Following are weights for parts of course.
    Subject to change
  • Assignments 39
  • Exercises 3
  • Quizzes 4
  • Prelim 1 13
  • Prelim 2 15
  • Final exam 25
  • Course evaluation 1
  • Generally, grades come out 1/3 As, 1/3 Bs, 1/3
    Cs, but everyone can get an A if they do A work.
    Exams are most important factor.

6
Java bootcamp
  • You are expected to know what CS100 teaches about
    Java
  • classes, objects, how we draw them.
  • instance methods variables, static methods
    variables,
  • subclasses, inheritance, overriding of methods
  • apparent and real class-types of a variable.
  • Java bootcamp will go over these things
  • Olin 155, 7301030, Tuesday, 27 January

7
Assignments
  • Assignments done in teams of 1 or 2 students
  • You need not keep the same partner for every
    semester
  • See the website for academic integrity statement

Exercises
  • Pencil and paper things.
  • Do exercises alone not partners allowed.

Quizzes
  • In lecture. Will tell you precisely what they
    will cover.
  • Given to let you know what I think is important
    and should be learned immediately.
  • Everyone is expected to get 100/100 on them.

8
About me and my expectations
  • CS100J last semester, people either liked me or
    hated me

I definitely appreciate Griess method of
developing our knowledge from the foundations.
Helped me, as a beginner. An excellent
instructor! Gries was brilliant.
Get rid of Gries. Gries should change his
teaching methods. Worst course I have had.
9
The manila folder concept
I think the whole manila folder concept was
brilliant. It definitely helped me understand the
material better. The folder analogy was very
helpful for understanding all the OO concepts we
learned. The filing cabinet / manila folder
concept made it easy to grasp the class / object
relationship.
File/folder analogy for class/objects was pretty
poor. Manila folders bear no relation to actual
programming. Stupid. File/folder analogy screws
everything up.
10
Invariant
Analysis of the invariant and its relation to a
loop was most helpful for my learning. Idea of
invariant was hard to grasp, but when I did get
it, everything came together!
the use of invariants inhibited my natural
programming ability. Invariants are evil. Worst
part of course failed to see their importance.
11
Order of topics
It was good to be exposed to the fundamental
structure of Java early on Gries is probably
right in teaching main concepts first before
getting into loops
Should be more focused on logic and algorithms
not OO. Dont start with OO write a simple
Hello World program.
12
About Gries.
Teaching computer science since 1966. Main area
of research programming methodology, the formal
development of programs, calculational
logic. Cornell Weiss Fellow, awarded for
contributions to undergraduate teaching. Several
international awards for contributions to
computer science education. Currently, 1/2 time
Associate Dean for Undergraduate Programs
(Engineering College). I really am interested in
teaching and care about you. I am here to serve.
I am approachable and am willing to talk with any
of you at almost any time, within my schedule
constraints.
13
About programming
  • Kline More than anything, mathematics is method.
  • That applies to programming even more than
    mathematics.
  • Research has developed a formal methodology of
    program-ming, which, if practiced consciously,
    can lead to more effective programming and
    clearer programs, with fewer bugs.
  • We try to teach you some of that methodology in a
    practical, informal way. But it requires you to
    change you thinking habits, your way of thinking
    about the programming process.

Mark Twain Nothing needs changing so much as the
habits of others.
14
About programming
  • Two ways you can proceed
  • Hack away, and dont think about good programming
    practices. Just program in your natural way.
    Consequence, spend a lot of time
    testing/debugging and still end up with a buggy
    program.
  • Learn to think in an organized, mathematical,
    disciplined fashion that leads to short, clear,
    well-documented programs that rarely have
    mistakes and that can even help you find
    solutions, solve problems.
  • Consequence YOU are in control of the process.

Student the use of invariants inhibited my
natural programming ability. Reply Natural
abilities are rarely the best and are often the
worst. They can always be improved.
15
Development of a loop The problem
Consider problem of adding two positive
integers 4 7 2 9
6 3 1 1 0 1 0 3
b0..bs-1 2, 7, 4 bs 3 c0..cs-1
1, 3, 6, 9 cs 4 Problem write an
algorithm to store in array d and int variable ds
so that d0..ds-1 is the sum of the integers in
b0..bs-1 and c0..cs-1, and dds-1 !
0. Assume that all variables are already declared.
Digits of an integer are stored in an array with
least significant digit first
Answer ds 5 d0..ds-1 3, 0, 1, 0, 1
16
Development of a loop the invariant
Pre b0..bs-1 and c0..cs-1 are positive
integers Post d0..ds-1 is the sum of the
integers in b, c dk-1 ! 0 Use a loop. Need to
know the definition of variables used within the
loop (written as a loop invariant)
4 7 2
9 6 3 1
1 0 3 Invariant d0..k-1 is
the sum of b0..k-1 and c0..k-1, with
dk being the carry (0 or 1)
Here, k 2
these have been calculated
carry from previous pos.
17
Development of a loop init
Pre b0..bs-1 and c0..cs-1 are positive
integers Post d0..ds-1 is the sum of the
integers in b, c dk-1 ! 0 k 0 dk 0 /
invariantd0..k-1 is the sum of b0..k-1 and
c0..k-1, with dk being the carry (0
or 1) / while ( ? ) ? When
can the loop stop? How does it make progress
toward termination?
4 7 2 9 6 3 1 1
0 3 in this case, k 2
18
Development of a looploop condition, progress
toward termination
Pre b0..bs-1 and c0..cs-1 are positive
integers Post d0..ds-1 is the sum of the
integers in b, c dk-1 ! 0 k 0 dk 0 /
invariantd0..k-1 is the sum of b0..k-1 and
c0..k-1, with dk being the carry (0
or 1) / while ( k lt bs k lt cs)
k k 1 How to keep invariant true?
4 7 2 9 6 3 1 1
0 3 in this case, k 2
19
Development of a loop the repetend
Pre b0..bs-1 and c0..cs-1 are positive
integers Post d0..ds-1 is the sum of the
integers in b, c dk-1 ! 0 k 0 dk 0 /
invariantd0..k-1 is the sum of b0..k-1 and
c0..k-1, with dk being the carry (0
or 1) / while ( k lt bs k lt cs)
Calculate dk and the carry into dk1
k k 1 How do we refine the first statement
of the repetend?
4 7 2 9 6 3 1 1
0 3 in this case, k 2
20
Development of a loop the repetend
Pre b0..bs-1 and c0..cs-1 are positive
integers Post d0..ds-1 is the sum of the
integers in b, c dk-1 ! 0 k 0 dk 0 /
invariantd0..k-1 is the sum of b0..k-1 and
c0..k-1, with dk being the carry (0
or 1) / while ( k lt bs k lt cs) if (k
lt bs) dk dk bk if (k lt cs) dk
dk ck dk1 dk / 10 dk
dk 10 k k 1 Upon termination, is
most significant digit 1?
4 7 2 9 6 3 1 1
0 3 in this case, k 2
21
Final loop
// Pre b0..bs-1 and c0..cs-1 are positive
integers // Post d0..ds-1 is the sum of the
integers in b c dk-1 ! 0 k 0 dk 0 /
invariantd0..k-1 is the sum of b0..k-1 and
c0..k-1, with dk being the carry (0
or 1) / while ( k lt bs k lt cs) if (k
lt bs) dk dk bk if (k lt cs) dk
dk ck dk1 dk / 10 dk
dk 10 k k 1 if (dk ! 0) k
k1
4 7 2 9 6 3 1 1 0 1 0
3 in this case, k 4
22
Final loop without annotation
k 0 dk 0 while ( k lt bs k lt
cs) if (k lt bs) dk dk bk
if (k lt cs) dk dk ck
dk1 dk / 10 dk dk 10
k k 1 if (dk ! 0) k
k1
23
int ds 0 while (bs ! b.length ds !
c.length) if (bs b.length cs !
c.length) dds dds ccs
if (dds gt 10) dds dds-10 dds1
1 else dds1 0 ds
ds1 cs cs1 if (bs ! b.length
cs c.length) dds dds
bbs if (dds gt 10) dds
dds-10 dds1 1 else dds1
0 ds ds1 bs bs1
else dds bbs ccs dds
if ( ) else
ds ds 1
one of the better student sols.
d0 not initialized. bs, cs not initialized
should not be changed not solving stated
problem. repetend far too complicated. at
end, increase ds only if dds 1.
24
Design of larger programs important, too
Sam Loyds 8-puzzle
Try to get to this final configuration
three different configurations
25
Questions concerning the 8-puzzle
  • Suppose we want to write a program to play the
    puzzle.
  • What operations should program support?
  • How do we represent configurations?
  • How do we specify an initial config.?
  • What algorithm will solve the puzzle?
  • What kind of GUI makes sense?
  • Should program work for 3 x 3 or
  • a more general n x n?

N
S
E
W
26
Math behind the 8-puzzle
Each configuration is called a state. State Y is
adjacent to state X if Y can be reached from X in
one move. State transition diagram shows
all states, with labeled arrows between adjacent
states.
N
S
E
W
27
Graphs
  • State transition diagram is an example of a
    graph.
  • Nodes of graph the states.
  • Edges of graph connections between nodes.
  • Edges may be labeled.
  • Examples of graphs airline routes,
  • roadmaps.
  • Path problems
  • Is there a path from node X to node Y?
  • Shortest path?
  • Is there a cycle (loop) from X to X?
  • We cover graphs later in the course.

N
S
Write a Comment
User Comments (0)
About PowerShow.com