500 likes | 638 Views
CS 2050: Algorithm Design and Programming II (in Java). WELCOME !. People you should know:. Instructor : Anoop Haridas Office : EBW 347 Hours : M,W 2:30 – 3:30 pm. Email : ahkrc@mizzou.edu . Course webpage : Coming soon !. Tell us about yourself !.
E N D
CS 2050: Algorithm Design and Programming II (in Java) WELCOME !
People you should know: • Instructor : Anoop Haridas Office: EBW 347 Hours: M,W 2:30 – 3:30 pm. Email: ahkrc@mizzou.edu. Course webpage : Coming soon !
What’s it about ? • Learn about : • (1) Algorithms • (2) Data structures • Implement these in Java.
When and where ? • Lectures: • M, W, F E1419 Lafferre Hall. (12:10 to 1:10 p.m.) • Labs: • T, R 124B GCB. (12:10 to 2:10 p.m.)
Main Text • “Data Structures & Other Objects Using JAVA” (3rd Edition), by Michael Main. • Please see : • http://www.mubookstore.com/textbooks.asp for more information.
Other Sources of Information • There are many other textbooks that provide good explanations of the topics covered in this course. • You may also want to look at material on the internet for alternative explanations of course concepts.
Prerequisites • Each student is assumed to have completed CS 1050 (or its equivalent) with no less than a C- grade. • This course assumes that each student is familiar with the Java programming language. • Java will be used for all assignments, so students unfamiliar with Java should expect to spend some extra time at the beginning of the semester to develop practical proficiency with it.
Topics to be covered • Java classes and information hiding • Collection classes • Linked lists • Generic programming • Stacks and queues • Recursion • Trees • Searching • Sorting
Grading • 40% - Programming assignments. • 60% - Exams: One or two + Final. • 90% or above of the total points guarantees a grade in the A range; above 80% guarantees a grade of B- or above; and so on. • The instructor reserves the right to apply a more generous curve.
Course & Exam Schedule • Will be made available on the course webpage.
Exams & Programming Projects • Exams will be multiple-choice, usually with 20-30 questions. • Exam dates will be announced in lecture and posted on the course web page. The key for each exam will be posted immediately after the test. There will be no makeup exams.
(contd.) • The programming assignments will be posted in the form of a program specification that describes what is expected, how it will be graded, and when it will be graded. • Questions about an assignment should be asked during the lab periods. Appointments can be made for answering specific questions about concepts or about administrative issues with regard to grading.
What is expected: • General questions should be asked during the lab periods whenever possible. Only questions that are very specific to a student or his/her program should be asked during office hours or by email. • Students should make every effort to debug their own programs – that’s the real learning process when it comes to programming. • Code should be properly documented.
About programming assignments • It is assumed that everyone in the class understands Java sufficiently to track down and correct syntax errors. • Submissions that fail to compile may be given a zero without further consideration. • Lab assignments should be started soon enough to avoid problems near the due date.
Dropping this course • As many of you know, there is a university policy that allows students to re-take up to 3 classes and have their new grade substituted for their original one for GPA calculation. • If after the first or second exam you feel that you are at significant risk of failing this course, you are in most cases better off dropping the class rather than failing before you re-take it. • If you feel like you cannot drop the class because you will drop below full-time, come see me and I can suggest ways of dealing with that problem. If you feel overwhelmed and think that you may do badly in most of your classes, come see me.
Academic Dishonesty • When you turn in an exam or programming assignment, it is assumed to represent your individual effort. • Plagiarism can affect both your grade and your university standing. • Never distribute an electronic copy of your work on a programming assignment. If you work on a copy of your program on one of the computer lab machines, be sure to erase it from the local disk when you're done. Don’t throw away hardcopies of your program in the computer lab.
Special Needs • If you need accommodations because of a disability, if you have emergency information you need to share with the instructor, or if you need special arrangements in case the building must be evacuated, please inform the instructor immediately. • To request academic accommodations (for example, a note taker), students must also register with Disability Services, A038 Brady Commons, 882-4696. It is the campus office responsible for reviewing documents provided by students requesting academic accommodations and for accommodations planning in cooperation with students and instructors, as needed and consistent with course requirements. Another resource is MU’s Adaptive Computing Technology Center, 884-2828.
Short Quiz … • (1) The primary goal of CS-1050 was to teach Java. TRUE or FALSE?
contd … • (1) The primary goal of CS-1050 was to teach Java. TRUE or FALSE? FALSE
contd … • (2)Which of the following statements is true? (a) An algorithm is another name for a computer program. (b) An algorithm consists of a series of instructions in a particular programming language. (c) None of the above are true.
contd … • (2)Which of the following statements is true? (a) An algorithm is another name for a computer program. (b) An algorithm consists of a series of instructions in a particular programming language. (c) None of the above are true.
contd … • (3)Which of the following statements is true? (a) Computer science and computer programming are essentially the same thing. (b) Computer programming is what computer scientists do. (c) None of the above are true.
contd … • 3)Which of the following statements is true? (a) Computer science and computer programming are essentially the same thing. (b) Computer programming is what computer scientists do. (c) None of the above are true. • Saying that programming is what computer scientists do is like saying that word processing is what novelists do.
What’s the difference ? • "How is developing an algorithm not the same as writing a program?“ • An algorithm defines the procedural steps for solving a given problem. Programming is the conversion of those steps into lines of code in some computer language. • An assignment in 1050 typically describes an algorithm as part of the assignment description, so the assignment is purely a programming exercise. • An assignment description in 2050 specifies what a program is supposed to do, but not the algorithm for doing it. The objective of the assignment is not to produce a working piece of code, but rather a good algorithm.
What you should know from CS1050 • 1) How variables are used in computer programs. • 2) How if-else structures are used to implement decisions. • 3) How loop structures are used to repeat steps of an algorithm. • 4) How to apply the above knowledge to implement an algorithm. • 5) Some familiarity with interfaces and objects. • What isn’t so important are the details of a particular programming language, e.g., Java. Learning new programming languages should be relatively straightforward once the basic concepts of programming are understood.
Why CS 2050? A short story… • It was spring of 1999, and four friends were planning to attend interviews with companies that were visiting their campus. • Frank had just re-taken CS 1050 that semester, and he received an A. Carol, Joe, and Miguel had just completed CS 2050. • This was the peak of the dot-com era, and all four friends were immediately hired at different companies.
Coincidentally, it turns out that all four companies were bidding for the same contract from NASA. • The goal of the project was to create a system to allow companies to send requests for specified satellite photos and have them sent electronically. • NASA funded each of the four companies to develop prototypes for evaluation. Based on the results of the evaluation, some subset of the companies would receive funding to continue development.
Frank's company, Icarus Industries, was desperate for the NASA project, so the boss wined and dined the appropriate NASA managers, took them golfing, and gave them Icarus Industries coffee mugs and mouse pads. • As long as Frank could produce a reasonably good prototype, the company would be in good shape to make it to the next round of development.
Frank's team members were all hired at $100K each straight out of high school, so Frank's two semesters of CS-1050 made him the most experienced programmer. • Because of that experience, the boss of Icarus Industries gave Frank the job of designing and implementing the critical search and retrieval component of the system. • This module would have to search a sample dataset of 1 million satellite images for the one with the specified I.D. number.
Frank decided that the problem was actually not too hard, it basically just required a simple loop: for (i = 0; I < NumberOfImages; i++) { if (image[i].id == request.id) requested_image = image[i]; } return ( requested_image );
After one day of working on the problem, Frank reported to his boss that he was almost done with his module. • The boss was impressed because he had heard that programmers at the competitor companies had barely even begun doing their algorithm designs. • Frank scoffed, "Gee, the algorithm is simple. Those guys must be a bunch of losers.“ • The boss was very pleased with Frank's productivity, and he suggested that Frank devote his time to squeezing every bit of speed out of his code as possible.
Frank looked at his code and determined that there really wasn't much room for improvement, so he decided that the only way to speed it up was to try programming it in a different language. for (i = 0; i<NumberOfImages; i++) { if (image[i].id == request.id) requested_image = image[i]; } return ( requested_image );
Frank had implemented his algorithm in Java, but he had heard that C might improve performance. • Frank spent a couple of days learning C, and realized that it looked just like Java. for (i = 0; i<NumberOfImages; i++) { if (image[i].id == request.id) requested_image = image[i]; } return ( requested_image );
After re-coding his routine in C, Frank discovered that the system improved from being able to process 507 requests per minute to being able to process 549 requests per minute. • Frank informed his boss of the 8% improvement, and his boss was impressed: "Wow, an 8% advantage over our competitors would clinch the project for us. See what else you can do.“ • Frank spent a few weeks studying assembler language. Unfortunately, he discovered that it didn't provide any performance improvement over his C implementation.
Frank was disappointed that the time he spent on an implementation in assembler language didn't yield any improvements in speed. • However, while looking at his code he suddenly had a brainstorm: He could terminate the loop as soon as the requested image is found: for (i = 0; i<NumberOfImages; i++) { if (image[i].id == request.id) return ( image[i] ); }
Frank realized that on average the requested image would be found after examining only half of the images. • His test results revealed a speedup of 45%, which dwarfed the 8% improvement he had obtained from re-coding in C. • When Frank told his boss about the 45% improvement in speed, his boss immediately offered him a pay raise and a move to a spacious corner office.
Based on the extensive code optimizations he had done, combined with his boss's cozy relationship with the NASA managers, Frank was sure that Icarus Industries would have no problem flying through the evaluation process. • Frank was looking forward to seeing the reactions of Carol, Joe, and Miguel when they see how well the Icarus system performs compared to theirs.
On Monday, NASA engineers received the prototypes developed by the four competing companies. A battery of tests had been developed, and the Icarus system was tested first. • On Tuesday, the results of the Icarus evaluation were announced: The Icarus system was able to process almost 1000 requests per minute. • Frank smiled because that's exactly the level of performance that he expected. Frank's boss took him out to dinner to celebrate.
On Wednesday, the results of the evaluation of Carol's system were announced: It was able to process over 10,000 requests per minute. Frank's system: 1000 rpm Carol's system: 10,000 rpm • Frank was shocked. It was impossible, he thought. There must be some sort of mistake. How could her program run ten times faster?
Frank caught Carol as she was leaving the NASA building and asked her how she managed to make her code so fast. He wondered if she had made use of some sort of special something in the operating system. • Carol wasn't sure why her code was ten times faster than Frank's, but Frank understood once she explained her algorithm. • Carol had realized that certain images were likely to be requested more often than others, so whenever an image was requested, her program moved it nearer to the beginning of her array so that it would be found more quickly the next time.
Frank explained to his boss that Carol had come up with a really clever algorithm, but it sort of cheated because it made use of the fact that different images are accessed at different frequencies. Frank even suggested that in some sense the test wasn't fair. • Frank's boss said that the test was fair but that the results weren't necessarily disastrous. He reminded Frank that NASA planned to continue funding more than one of the competitors, so there was still a good chance that Icarus Industries could make it through to the next round of development.
On Thursday, the results of the evaluation of Joe's system were announced: It was able to process over 10 million requests per minute. Frank's system: 1000 rpm Carol's system: 10,000 rpm Joe's system: 10,000,000 rpm • Frank was flabbergasted. This was truly impossible, he thought. Even if Joe had used the same algorithm as Carol and coded it in C, the performance should have only been 8% faster than Carol's. Something was definitely wrong.
Frank caught Joe outside of the NASA building and asked him how his code could be so fast. • Joe wasn't sure, but he said that he got his binary tree code out of his 2050 book. "Binary what?" asked Frank. • That night Frank read about binary trees and realized why Joe's code was so fast: If the million image I.Ds were stored in the form of a binary tree, then the requested image could be found after checking only around 20 I.Ds. • Frank felt sick.
On Friday, the results of the evaluation of Miguel's system were announced: It was able to process over 100 million requests per minute. Frank's system: 1000 rpm Carol's system: 10,000 rpm Joe's system: 10,000,000 rpm Miguel's system: 100,000,000 rpm • Frank couldn't believe it. He had spent so much time trying to make his code as fast as possible, and in the end his code was 100,000 times slower than Miguel's.
Frank learned that Miguel had stored his images in something called a hash table, but it didn't really matter: Icarus Industries was dead. • Frank went back to school, took CS-2050, and eventually realized that the difference between programming and algorithm design is analogous to the difference between drafting and architectural design: • Having Frank design the retrieval algorithm for Icarus was like having a draftsman design their corporate building.
All four of the friends returned to school after the collapse of the dot-com bubble. • Although Frank had started out a semester behind his three friends, the early demise of Icarus allowed him to finish his degree before them. • Frank is now designing flight control algorithms for a major aircraft manufacturer.
Morals of the story … • 1) Knowing a programming language is not the same thing as knowing how to program. • 2) It is the algorithm that matters most, not the choice of programming language or the fine details of a correct implementation. • 3) Without a background in algorithm design and data structures, it is impossible for someone to understand why such experience is so critical. • 4) Many safety-critical systems are only as reliable as the computer algorithms that support them.
Other lessons … • 1) Anyone who hires computer scientists needs to be able to distinguish between someone who can develop algorithms from someone who can only do simple coding tasks. • 2) Anyone who manages a software development project needs to be able to understand and assess the relative merits of different proposed algorithms for solving a given problem. • 3) A few bad programmers can wreck a company.
People you should know: • Instructor : Anoop Haridas Office: EBW 347 Hours: M,W 2:30 – 3:30 pm. Email: ahkrc@mizzou.edu. Course webpage : Coming soon !