1 / 27

CS211 Computers and Programming cs.cornell/courses/cs211/2004sp/

CS211 Computers and Programming http://www.cs.cornell.edu/courses/cs211/2004sp/. Instructor: David Gries, Olin 167 gries@cs.cornell.edu , dgries@twcny.rr.com Staff coordinator: Stacey Shirk, Upson 403 shirk@cs.cornell.edu

sikora
Download Presentation

CS211 Computers and Programming cs.cornell/courses/cs211/2004sp/

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS211 Computers and Programminghttp://www.cs.cornell.edu/courses/cs211/2004sp/ Instructor: David Gries, Olin 167 gries@cs.cornell.edu, dgries@twcny.rr.com Staff coordinator: Stacey Shirk, Upson 403 shirk@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. 10:05AM. 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. It’s 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 AEW Workshop 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. • 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 A’s, 1/3 B’s, 1/3 C’s, 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, 7:30—10:30, Tuesday, 27 January

  7. Assignments Exercises • Pencil and paper things. • Do exercises alone — not partners allowed. 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 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 I definitely appreciate Gries’s method of developing our knowledge from the foundations. Helped me, as a beginner. An excellent instructor! Gries was brilliant. CS100J last semester, people either liked me or hated me: Get rid of Gries. Gries should change his teaching methods. Worst course I have had.

  9. 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. The manila folder concept 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]. Don’t start with OO; write a simple “Hello World” program.

  12. 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. About Gries.

  13. 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. About programming Mark Twain: Nothing needs changing so much as the habits of others.

  14. Two ways you can proceed: • Hack away, and don’t 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. About programming 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. Consider problem of adding two positive integers: 4 7 2 + 9 6 3 1 = 1 0 1 0 3 b[0..bs-1] = {2, 7, 4} bs = 3 c[0..cs-1] = {1, 3, 6, 9} cs = 4 Problem: write an algorithm to store in array d and int variable ds so that d[0..ds-1] is the sum of the integers in b[0..bs-1] and c[0..cs-1], and d[ds-1] != 0. Assume that all variables are already declared. Development of a loop: The problem Digits of an integer are stored in an array with least significant digit first Answer: ds = 5 d[0..ds-1] = {3, 0, 1, 0, 1}

  16. Pre: b[0..bs-1] and c[0..cs-1] are positive integers Post: d[0..ds-1] is the sum of the integers in b, c; d[k-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 = 10 3 Invariant: d[0..k-1] is the sum of b[0..k-1] and c[0..k-1], with d[k] being the carry (0 or 1) Development of a loop: the invariant Here, k = 2 carry from previous pos. these have been calculated

  17. Pre: b[0..bs-1] and c[0..cs-1] are positive integers Post: d[0..ds-1] is the sum of the integers in b, c; d[k-1] != 0 k= 0; d[k]= 0; /* invariant:d[0..k-1] is the sum of b[0..k-1] and c[0..k-1], with d[k] being the carry (0 or 1) */ while ( ? ) { ? } When can the loop stop? How does it make progress toward termination? Development of a loop: init 4 7 2 + 9 6 3 1 = 10 3 in this case, k = 2

  18. Development of a loop:loop condition, progress toward termination Pre: b[0..bs-1] and c[0..cs-1] are positive integers Post: d[0..ds-1] is the sum of the integers in b, c; d[k-1] != 0 k= 0; d[k]= 0; /* invariant:d[0..k-1] is the sum of b[0..k-1] and c[0..k-1], with d[k] being the carry (0 or 1) */ while ( k < bs || k < cs) { k= k + 1; } How to keep invariant true? 4 7 2 + 9 6 3 1 = 10 3 in this case, k = 2

  19. Pre: b[0..bs-1] and c[0..cs-1] are positive integers Post: d[0..ds-1] is the sum of the integers in b, c; d[k-1] != 0 k= 0; d[k]= 0; /* invariant:d[0..k-1] is the sum of b[0..k-1] and c[0..k-1], with d[k] being the carry (0 or 1) */ while ( k < bs || k < cs) { Calculate d[k] and the carry into d[k+1]; k= k + 1; } How do we refine the first statement of the repetend? Development of a loop: the repetend 4 7 2 + 9 6 3 1 = 10 3 in this case, k = 2

  20. Pre: b[0..bs-1] and c[0..cs-1] are positive integers Post: d[0..ds-1] is the sum of the integers in b, c; d[k-1] != 0 k= 0; d[k]= 0; /* invariant:d[0..k-1] is the sum of b[0..k-1] and c[0..k-1], with d[k] being the carry (0 or 1) */ while ( k < bs || k < cs) { if (k < bs) d[k]= d[k] + b[k]; if (k < cs) d[k]= d[k] + c[k]; d[k+1]= d[k] / 10; d[k]= d[k] % 10; k= k + 1; } Upon termination, is most significant digit 1? Development of a loop: the repetend 4 7 2 + 9 6 3 1 = 10 3 in this case, k = 2

  21. // Pre: b[0..bs-1] and c[0..cs-1] are positive integers // Post: d[0..ds-1] is the sum of the integers in b c; d[k-1] != 0 k= 0; d[k]= 0; /* invariant:d[0..k-1] is the sum of b[0..k-1] and c[0..k-1], with d[k] being the carry (0 or 1) */ while ( k < bs || k < cs) { if (k < bs) d[k]= d[k] + b[k]; if (k < cs) d[k]= d[k] + c[k]; d[k+1]= d[k] / 10; d[k]= d[k] % 10; k= k + 1; } if (d[k] != 0) k= k+1; Final loop 47 2 + 9 63 1 = 1 0 10 3 in this case, k = 4

  22. k= 0; d[k]= 0; while ( k < bs || k < cs) { if (k < bs) d[k]= d[k] + b[k]; if (k < cs) d[k]= d[k] + c[k]; d[k+1]= d[k] / 10; d[k]= d[k] % 10; k= k + 1; } if (d[k] != 0) k= k+1; Final loop without annotation

  23. int ds= 0; while (bs != b.length || ds != c.length) { if (bs == b.length && cs != c.length) { d[ds]= d[ds] + c[cs]; if (d[ds] >= 10) {d[ds]= d[ds]-10; d[ds+1]= 1;} else d[ds+1]= 0; ds= ds+1; cs= cs+1; } if (bs != b.length && cs == c.length) { d[ds]= d[ds] + b[bs]; if (d[ds] >= 10) {d[ds]= d[ds]-10; d[ds+1]= 1;} else d[ds+1]= 0; ds= ds+1; bs= bs+1; } else { d[ds]= b[bs] + c[cs] + d[ds]; if ( … ) { …} else … } ds= ds + 1; one of the better student sols. • d[0] not initialized. • bs, cs not initialized; should not be changed; not solving stated problem. • repetend far too complicated. • at end, increase ds only if d[ds] = 1.

  24. Sam Loyd’s 8-puzzle: Design of larger programs important, too Try to get to this final configuration three different configurations

  25. 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? Questions concerning the 8-puzzle N S E W

  26. 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. Math behind the 8-puzzle N S E W

  27. 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. Graphs N S

More Related