13
CS101: Fundamentals of Computer Programming Dr. Tejada [email protected] www-bcf.usc.edu/~stejada Week 11: Art of Problem Solving

Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Embed Size (px)

Citation preview

Page 1: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

                               CS101: Fundamentals of Computer Programming  Dr. Tejada [email protected] www-bcf.usc.edu/~stejada Week 11: Art of Problem Solving

Page 2: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

The Art of Problem Solving � It has been proven that the process of

problem solving (or algorithm development) is not an algorithmic process

� In 1945, George Polya (a mathematician), wrote a famous book, How to Solve It. Identified four principles for solving problems � 1. Understand the Problem � 2. Devise a Plan � 3. Carry out the Plan � 4. Look Back

Page 3: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Understanding the Problem � To ensure that you understand a problem, you

can ask yourself the following questions: �  Do you understand all the words used in stating the

problem? �  What are you asked to find or show? �  Can you restate the problem in your own words? �  Can you think of a picture or a diagram that might help

you understand the problem? �  Is there enough information to enable you to find a

solution? �  Does  program  require  user  interac1on?  �  Does  program  manipulate  data?    � What  is  the  output?  

Page 4: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Preconceptions:

Page 5: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Devise a Plan Polya mentions that there are many reasonable ways to solve problems. The skill at choosing an appropriate strategy is best learned by solving many problems. A partial list of strategies is below:

Guess and check

Make an orderly list

Eliminate possibilities

Use symmetry Consider special cases

Use direct reasoning

Solve an equation Look for a pattern Draw a picture

Solve a simpler problem Use a model Work backward

Use a formula Be ingenious Look for similar problems

Page 6: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Carry Out the Plan � This step is usually easier than devising the plan � In general, all you need is care and patience,

given that you have the necessary skills. � Keep trying with the plan that you have chosen. � Check  the  correctness  of  algorithm  

� Can  test  using  sample  data  � Some  mathema1cal  analysis  might  be  required

� If it continues not to work discard it and choose another.

Page 7: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

So=ware  Development  Cycle  

� Algorithm:    �  Step-­‐by-­‐step  problem-­‐solving  process  

�  Solu1on  achieved  in  finite  amount  of  1me  

� Programming  is  a  process  of  problem  solving  

C++ Programming: Program Design Including Data Structures, Sixth Edition

7

Page 8: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

The  Problem  Analysis–Coding–Execu1on  Cycle  � Step  1:  Analyze  the  problem  

�  Outline  the  problem  and  its  requirements  �  Design  steps  (algorithm)  to  solve  the  problem  

� Step  2:  Implement  the  algorithm  �  Implement  the  algorithm  in  code  �  Verify  that  the  algorithm  works  

� Step  3:  Maintenance  �  Use  and  modify  the  program  if  the  problem  domain  changes  

C++ Programming: Program Design Including Data Structures, Sixth Edition

8

Page 9: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Designing a Robot Interface

9

Page 10: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Lecture Exercise Interface

10

Page 11: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Poster Session due Friday April 5

11

�  Describe CS topic �  Description �  Examples �  Illustration �  Diagrams �  Papers/references �  Links/webpages �  -etc

�  Things to think about: �  Why this CS topic? �  What is interesting about? �  How does it affect everyday

life? �  How does it benefit society? �  Why does it interest you?

Page 12: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

In-Class Topic Presentation due Week 12

12

�  Describe CS topic � Description � Examples �  Illustration � Diagrams � Papers/references � Links/webpages � Post your slide on Piazza � Post your slide on your website

Things to think about: � Why this CS topic? � What is interesting about? � How does it affect

everyday life? � How does it benefit

society? � Why does it interest you?

1.  You will give a 1 minute presentation 2.  Create one slide on your CS topic and demo 3.  With 2 minutes for questions and feedback

Page 13: Fundamentals of Computer Programming - University of … · 2013-04-03 · Fundamentals of Computer Programming! ... 1. Understand the Problem ! 2. Devise a Plan ! 3. Carry out the

Lecture Exercise � Demo your robot interface to other teams �  In your team design a class for your interface

�  What are the data members? �  What are the member functions?

� Create an robotInterface.h and a robotInterface.cpp

� Post your code to your website and Piazza

13