NotesWeek1.Aug 23-27 - CS 180 Problem Solving and Object Oriented Programming Fall 2010 hMp/www.cs.purdue.edu/homes/apm/courses/CS180Fall2010 Notes

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 180 Problem Solving and Object Oriented Programming Fall 2010 hMp://www.cs.purdue.edu/homes/apm/courses/CS180Fall2010/ Notes for Week 1: August 2327, 2010 Aditya Mathur Department of Computer Science Purdue University West LafayeMe, IN, USA About CS 180 8/23/10 CS 180. Fall 2010. Week 1 2 Course Web Site and Other Resources Course Web site: hMp://www.cs.purdue.edu/homes/apm/courses/CS180Fall2010/ Java Resources: hMp://download.oracle.com/javase/1.4.2/docs/api/ hMp://download.oracle.com/javase/tutorial/ 8/23/10 CS 180. Fall 2010. Week 1 3 Please note.... Classes will begin at 4:30pm and end at 5:20pm. Please try to be in your seat a few minutes before the class begins and leave aWer the class ends. All students are encouraged to ask quesYons. You may interrupt the instructor at any Yme. The instructor is here to help you learn. Make full use of the instructor. Make full use of the instructor's office hours I want you to succeed in this class and in your major. I will do all I can to help you succeed; this is my primary responsibility as a professor at Purdue. 8/23/10 CS 180. Fall 2010. Week 1 4 AssumpYons You have liMle or no experYse in computer programming using Java. You are hard working. You will not sleep during classes, an if you do, you will not snore! You will not use phones during class and turn them off when you enter the class and leave them off unYl the class is adjourned. You will not disturb others by talking to your neighbors. You will try to parYcipate in the class by asking quesYons and responding to quesYons asked by the instructor. You will use iClickers in the class when requested. 8/23/10 CS 180. Fall 2010. Week 1 5 Impact of AssumpYons Some of you may get bored during the first four weeks of classes, but others may find appealing the slow pace. For those with some Java experience, we recommend parYcipaYng in the programming compeYYon. Refer to the course web site for details. Please buy an iClicker. You should skip the class if you need to discuss important maMers with your friends. But skipping a class is not a good idea! So maybe you might consider rescheduling the important maMers with your friend. 8/23/10 CS 180. Fall 2010. Week 1 6 ExpectaYons: Academic Honesty Unless specified otherwise, all labs, projects, and exams are to be completed by you without assistance from anyone else other than the course instructor and the graders. Read the Policies page on the course web site. 8/23/10 CS 180. Fall 2010. Week 1 7 ExpectaYons: AMendance You will aMend all lectures, labs, and recitaYons. AMendance is not mandatory but highly recommended. If you miss a lecture, lab or recitaYon then it is your responsibility to (a) learn on your own the material covered (b) find out if there were any announcements that might affect your course grade. 8/23/10 CS 180. Fall 2010. Week 1 8 Textbook Title A Gentle IntroducYon to Concurrent Programming. Barry WiMman, Aditya Mathur, and Tim Korb DraW 3.0, 2010 Authors EdiYon Avaialble at Boiler CopyMaker, Room 157, Purdue Memorial Union. AddiYonal resource iClickers Java Tutorial You may buy an iClicker from one of several local bookstores. 8/23/10 CS 180. Fall 2010. Week 1 9 Grading Component Weight (%) 15 15 15 2 3 4 6 Points 480 480 540 64 96 128 192 320 960 3260 Exam 1: W 9/29. 810pm. EE 129. Exam 2: Tue 11/09. 810pm. EE 192. Lab exercises [14] Project 1 [Individual] Project 2 [Individual] Project 3 [Individual] Project 4 [Team of 2] Project 5 [Team of 3] Final Exam TOTAL 10 30 100 8/23/10 RelaYve grading (curved). CS 180. Fall 2010. Week 1 10 Exams You will be allowed to consult one book of your choice during the all exams. 8/23/10 CS 180. Fall 2010. Week 1 11 Feedback Weekly feedback: anonymous via iClickers Tell us about the lectures, labs, recitaYons How are we doing? Weekly feedback: open Tell us in an open forum what needs to improve. ConstrucYve criYcism of the class is highly appreciated. 8/23/10 CS 180. Fall 2010. Week 1 12 Week 1: August 2327, 2010 What is Computer Science? 8/23/10 CS 180. Fall 2010. Week 1 13 Computer Science... ...is a discipline just as any other discipline like Mechanical Engineering, Electrical Engineering, Biomedical Engineering,... ...educates and trains students to work as soWware engineers, informaYon security specialists, systems engineers,.... ...deals with soWware that drives a large number of devices and systems that we use in our day to day lives,... ...consists of subfields such as algorithms, arYficial intelligence, computaYonal science and engineering, databases, graphics and visualizaYon, informaYon retrieval, informaYon security, machine learning, modeling and simulaYon, networking, programming languages and compilers, soWware engineering,... 8/23/10 CS 180. Fall 2010. Week 1 14 Computer ScienYsts... ...develop soWware that drives consumer devices such as smart phones, TVs, stereo systems,... ...develop soWware systems that control and manage aircraWs, automobiles, health care networks, power grids, intelligent transportaYon systems,... ...develop systems soWware such as compilers, operaYng systems, databases, and search engines on which are built a myriad of other user applicaYons,.... ...work alongside engineers to develop soWware that drives devices such as smart phones or more complex systems such as aircraWs,... 8/23/10 CS 180. Fall 2010. Week 1 15 Week 1: August 2327, 2010 Readings And Learning Outcomes 8/23/10 CS 180. Fall 2010. Week 1 16 Readings and Exercises from the textbook: Week 1 Chapter 1: 1.1, 1.2 Solve: 1.3, 1.4, 1.7, 1.11, 1.14, 1.26 8/23/10 CS 180. Fall 2010. Week 1 17 Learning Outcome1 Through a sequence of well defined steps you will be able to map a problem statement presented in natural language to a computer program wriMen in the Java programming language. 8/23/10 CS 180. Fall 2010. Week 1 18 Learning Outcome2 You will learn the basics of computer programming that will aid you in learning programming languages other than Java. Some of these other languages include C#, Python, and C. 8/23/10 CS 180. Fall 2010. Week 1 19 Learning Outcome3 You will learn the differences between sequenYal and concurrent soluYons to given problem. This will allow you to write concurrent programs that exploit the power of mulYcore microprocessors. 8/23/10 CS 180. Fall 2010. Week 1 20 Learning Outcome4 You will learn about Computer Science as a discipline. This will help you decide whether or not Computer Science is for you! 8/23/10 CS 180. Fall 2010. Week 1 21 Learning Outcome5 You will learn how to use DrJava to edit, compile, debug, and execute Java programs. 8/23/10 CS 180. Fall 2010. Week 1 22 Learning Outcome6 You will learn how to program RidgeSoW robots using Java. 8/23/10 CS 180. Fall 2010. Week 1 23 Learning Outcome7 You will learn how to program Androidbased smart phones using Java. 8/23/10 CS 180. Fall 2010. Week 1 24 Learning OpportuniYes in CS 180 Lectures: Basic concepts and techniques Labs: PracYce solving simple problems on the computer; use robots and smart phones RecitaYons: PracYce solving simple problems by hand; lots of discussion and parYcipaYon; work in small teams Projects: Solve more complex problems; design, implement, test, document. 8/23/10 CS 180. Fall 2010. Week 1 25 Learning in CS 180: Prerequisite Desire to learn and the ability to work hard. 8/23/10 26 Learning in CS 180 PracYce, pracYce and pracYce You will write programs that do not compile at first And when they compile they do not run as expected And when they run as expected, you scream Yippee! So do not be discouraged by errors, these are a part of life's challenges; overcome them! We are here to help you. 8/23/10 CS 180. Fall 2010. Week 1 27 Week 1: August 2327, 2010 Problem Solving and OO Programming 8/23/10 CS 180. Fall 2010. Week 1 28 What is "problem solving?" "Problem solving" refers to a set of acYviYes performed in order to solve a given problem. This is a generic term and applies to all disciplines, not only to Computer Science. The following sequence of steps for solving a problem was proposed by George Polya in the 1950's : Understand the problem Devise a plan Execute the plan Review the soluYon 8/23/10 CS 180. Fall 2010. Week 1 29 What is OO programming? OO, or Object Oriented, programming refers to a set of acYviYes that lead to a computer program, wriMen in an objectoriented language, that when executed on a computer will solve a problem. Java is an OO language used in CS 180. Other OO languages include C++, C#, Delphi, Modula, Oberon, ObjecYve C, Simula, Smalltalk, and many more! 8/23/10 CS 180. Fall 2010. Week 1 30 What is Problem solving and OO programming? Problem solving and OO programming refers to a set of acYviYes that allow the mapping of a problem to a computer program, wriMen in an objectoriented language, that when executed on a computer will solves the problem. Here is a simplisYc summary of acYviYes that aid in solving a problem using OO programming: 8/23/10 Understand the problem Design a soluYon using objects Implement the design as a well documented program in an OO language Test, debug, and correct the program CS 180. Fall 2010. Week 1 31 What is a mulYcore microprocessor? A mulYcore microprocessor is a microprocessor chip that contains two or more cores. Each core is capable of execuYng its own sequence of instrucYons. A dualcore microprocessor contains 2cores. A quadcore microprocessor contains 4cores, and so on. 8/23/10 CS 180. Fall 2010. Week 1 32 What is a parallel computer? A computer capable of execuYng two or more programs in parallel is oWen referred to as a parallel computer. A computer containing a mulYcore microprocessor is a parallel computer. A computer containing two or more singlecore microprocessors is also a parallel computer. Nearly every desktop and laptop today is a parallel computer containing a mulYcore microprocessor. 8/23/10 CS 180. Fall 2010. Week 1 33 What is a sequenYal program? A sequenYal program is one that is executed by a computer in a strict sequence, one instrucYon at a Yme. Thus, every instrucYon in the program is executed strictly in the specified sequence. 8/23/10 CS 180. Fall 2010. Week 1 34 What is a concurrent program? A concurrent program is one that contains instrucYons that may be executed in parallel, or concurrently, by a parallel computer. A concurrent program wriMen in Java contains two or more threads. Each thread may be executed concurrently on a parallel computer. 8/23/10 CS 180. Fall 2010. Week 1 35 Example 1: Problem solving Problem: Find the maximum in a given set of N integers. Step 1: Understand the problem 1. We know what is a set, an integer and what does "maximum" mean. 2. Can N be zero? Can N be negaYve? We assume that N>0. 3. Suppose the given set is: {4, 5, 29, 4}. N=4. 4. The maximum in this set is 29. 8/23/10 CS 180. Fall 2010. Week 1 36 Example 1: Problem solving: SequenYal program Pictorial representaYon of a sequenYal algorithm: SequenYal computaYon Input: Given set Find the maximum Output: max integer in S 8/23/10 CS 180. Fall 2010. Week 1 37 Example 1: SequenYal program Step 2: Design a sequenYal soluYon 1. Let S denote the given set. 2. Let S.next() denote the next element from the set. S.next() is empty if we have examined all elements of S. 3. Let currentMax=S.next(); 4. Scan each element of S unYl we have scanned all. The following two steps are performed for each element in S starYng from the second. a) Let newElement=S.next(); b) If currentMax<newElement then reset currentMax to newElement; 5. Display currentMax, it is the desired maximum. 8/23/10 CS 180. Fall 2010. Week 1 38 Example 1: SequenYal program Step 3: Implement the design as a well documented program in an OO language We will write a Java program later in this course. Step 4: Test, debug, and correct the program We will do this aWer we have wriMen the program. 8/23/10 CS 180. Fall 2010. Week 1 39 Example 1: Problem solving: Parallel program Problem: Find the maximum in a given set of N integers. Step 1: Understand the problem 1. We know what is a set, an integer and what does "maximum" mean. 2. Can N be zero? Can N be negaYve? We assume that N>0. 3. Suppose the given set is: {4, 5, 29, 4}. N=4. 4. The maximum in this set is 29. 5. We can divide S into disjoint sets S1 and S2 such that their union is S. 6. For example, S1={4, 5}, S2={29, 4}. Maximum of S1 is 4 and of S2 is 29. The maximum of these two maximums is 29 which is the desired maximum. 8/23/10 CS 180. Fall 2010. Week 1 40 Example 1: Problem solving: Parallel program Pictorial representaYon of the parallel algorithm: SequenYal computaYon Input: Given set Split into S1 and S2 such that S=S1 U S2 Parallel computaYon Find max of each set using sequenYal method. Find max of max of each set. Output: max integer in S SequenYal computaYon 8/23/10 CS 180. Fall 2010. Week 1 41 Example 1: Problem solving: Parallel program Step 2a: Design a concurrent soluYon assuming a dual core machine is to be used for execuYng this soluYon. 1. Let S denote the given set. 2. Let S.next() denote the next element from the set. S.next() is empty if we have examined all elements of S. 3. Divide S into sets S1 and S2 such that S=S1 U S2 4. Let maxS1= max(S1) and maxS2=max(S2). 5. Let max be the larger of maxS1 and maxS2 6. max is the desired maximum. 8/23/10 CS 180. Fall 2010. Week 1 42 Example 1: Problem solving: Parallel program Step 2b: Design a concurrent soluYon: max(S) denotes the maximum of integers in set S. 1. Let S.next() denote the next element from the set. S.next() is empty if we have examined all elements of S. 2. Let currentMax=S.next(); 3. Scan each element of S unYl we have scanned all. The following two steps are performed for each element in S starYng from the second. a) Let newElement=S.next(); b) If currentMax<newElement then reset currentMax to newElement; 4. currentMax, is the desired maximum. 8/23/10 CS 180. Fall 2010. Week 1 43 Why parallel program? For faster soluYon to a problem. Example: search the enYre internet for a keyword. For quick response to a request. Example: Customer request for bank balance. 8/23/10 CS 180. Fall 2010. Week 1 44 Example 2: Problem Solving Problem: Given real numbers a, b, and c, compute the value of the following expression: (b * b - 4 * a * c) Step 1: Understand the problem This one is easy! So let us say we have understood the problem! 8/23/10 CS 180. Fall 2010. Week 1 45 Example 2: Problem Solving: SequenYal SoluYon Step 2: Design a sequenYal soluYon 1: Get a, b, and c. 2: Compute x=b*b 3: Compute y=4*a*c 4: Compute z=xy 5: Compute p= z 6: Output p 8/23/10 CS 180. Fall 2010. Week 1 46 Example 2: Problem Solving: Parallel SoluYon Problem: Given real numbers a, b, and c, compute the value of the following expression: (b * b - 4 * a * c) 1: Compute x=b*b 2: Compute y=4*a*c 3: Compute z=xy 4: Compute p= z 5: Output p 8/23/10 CS 180. Fall 2010. Week 1 47 Example 2: Problem solving: Parallel program Pictorial representaYon of the parallel algorithm: SequenYal computaYon Parallel computaYon Input: Given numbers Compute sub expressions Compute another, dependent, subexpression SequenYal computaYon z Compute the square root Output: value of the given expression 8/23/10 CS 180. Fall 2010. Week 1 48 Discussion What differences do you noYce in the two problems? What impact would these differences have on a concurrent soluYon? We solved the problem assuming a dual core computer. Would your soluYon be different of it were to for a quadcore computer? A concurrent program consists of sequenYal and concurrent steps. Why? What impact do these steps have on the total Yme to solve a problem on a mulYcore computer? 8/23/10 CS 180. Fall 2010. Week 1 49 Parallelism in real life: Alice In Wonderland 8/23/10 CS 180. Fall 2010. Week 1 50 Week 1: August 2327, 2010 DissecYng a Java program 8/23/10 CS 180. Fall 2010. Week 1 51 The edit, compile, execute cycle No syntax error Program correct Execute your program Edit a Java program Compile your program Syntax error Run Yme Error or incorrect output In CS 180 we shall use DrJava for ediYng, compiling and execuYon. DrJava is an Integrated Development Environment also known as an IDE. Eclipse, JBuilder, and IntelliJ IDEA are a few other Java IDEs. For programming the RidgeSoW robot we shall use RoboJDE. 8/23/10 CS 180. Fall 2010. Week 1 52 Elements of a SequenYal Java Program Program to be dissected: Program 1.4 in Chapter 1 pages 1213. Go through this program line by line and understand the meaning of each line. 8/23/10 CS 180. Fall 2010. Week 1 53 Elements of a Concurrent Java Program Program to be dissected: Program 1.7 in Chapter 1 pages 2930. Go through this program line by line and understand the meaning of each line. 8/23/10 CS 180. Fall 2010. Week 1 54 Week 1: August 2327, 2010 Hope you enjoyed this week! 8/23/10 CS 180. Fall 2010. Week 1 55 ...
View Full Document

This note was uploaded on 02/05/2012 for the course CS 180 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Ask a homework question - tutors are online