Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Spring 2015 -- CSC 2700 Section 01

[Isaac's Home Page ]  [Mailing List ]  [Class Page ]  [Printable ]  
 Home
 Outline/Policy
 Summary
 Approach
 References
 Discussion
 
 Homework
   View
   Upload
 
 Problems:
   Categories
   Guidelines
   Solve
 
 UVA
   Archive
   Archive Mirror
   LSU
   Problems
 
 Coding
   Tips
 
 Contests:
   NA Qualifier
   Regional
 
 Extra:
   Grades
   Names (you should know)
 
 
 
 Class:
   CSC 2700 Section 01
   Tureaud 116
   Tuesday
   6:30 PM - 8:30 PM
 
 Previous:
   2013 Fall
   2013 Spring
   2012 Fall
   2012 Spring
   2011 Fall
 

How to Approach Solving a UVA Problem


Requirements Analysis


Before going any further, lets make sure we really understand the problem.

Read and Understand the Problem

Suggestions:

  • Glance over problem
  • Read it thoroughly once
  • Make sure input and output make sense to you
  • Make sure you can get the output from the given input

Analyze the Problem

Questions to answer before moving on:

  • Are there any gotchas?
  • What is the domain (how might input vary)?
  • How does input/processing stop?
  • What is the range (how might the output vary)?
  • What are the edge/corner cases?
  • What kind of problem is this? (big number, sort, flood fill, ...)


Design

Questions to answer?

  • What will be the general program layout? (trailer card, counted, EOF, custom)
  • What data structures make sense?
  • What algorithms make sense?
  • What will run time be? (Big O)
  • Will data fit into memory constraints?


Incremental Implementation Testing (testing in yellow)

At this point, I would deviate a little from the classic Software Development Cycle. Because these problems are relatively small and time to implement is constrained, I would suggest doing iterative implementation and testing. In other words, right the overall program structure and make sure it compiles. The proceed through each section one at a time.

This basic approach is a top-down design process. By going in this manner, you will avoid wiritng utility code that you never use (maybe you write a sort thinking you need and then realize you don't). Pretend the program is actually a big software system. First you implement the workflow structure (main program). Then you devlope each separate program/module in the system. So, in actuality, we are not deviating from the SDLC, we are simply using it recursively inside a single program.


Input

Write the code to load the data in. If complicated, write a dump function to display the imput to make sure it was loaded properly. Resist the temptation to do input inline of the processing. If the input is anything other than trivial, making the input logic and the processing logic work together can be tricky. Our goal is to simplify.


Base Processing

Now start writing the asic processing code that you will need to solve the problem. As details or sub-processes come up make function calls for them. Then go write dummy function stubs as placeholders.

Ge tthis basic logic working. At this point you also stuff in the desired output code. Here is a good chance to ensure that your planning has everything you need to output.


Iteratively fill in the stubs

Now you should start writing the various utility functions you determined you needed (maybe a sort or search, or an insert, ...). As you write each one, compile it and test it as best as you can.


What to do if something goes wrong?

The first step is to go back to the beginning:

  • reread the problem
  • make sure you can process the sampe data properly
  • confirm your data structures and algorithms
  • talk to teammates/classmates
  • use the steps below


Cannot figure out what algorithm to use

This might also be phrased as "I do not know where to start". In a contest, this means that you should not do this problem. Either someone else on the team needs to do it or it needs to be skipped. If everything else is done and you are doing this becuase time is left over, then soldier forward. Brainstorm. Work as a team on this. Resort to bottom up. Ge thte basic strucutre done. Make sure input works. Then start throwing code at it...

If you are not in a contest, you have more options. Here are some:

  • Sleep on it and/or go to another problem
  • Restart the entire process (reread, ...)
  • If you know what algorithm to use but do not know how to implement that algorithm, try these:


Output for sample data is wrong

Here are some things to do:

  • Reread the problem - make sure you understand
  • Can you manually get the output from the input? If not, then figure out how. If you can do it manually, figure out where your code is not doing what you are?
  • Are all cases wrong?
    • Confirm data is still being loaded correctly.
    • Did all variables get initialized properly?
    • Make sure routines are getting called (did you wite a sort and forget to call it?).
    • Review your computation to make sure it is correct.
    • Start inserting output statements to trace runtime and figure out where the codes operation deviates from your expectation.
    • Explain your code to somebody (not necessary for them to know the language, but it can help).
  • First case right, all others wrong. Almost always this relates to not clearing/reseting some value after the first iteration. Carefully make sure that every variable starts out with the right initial value(s).
  • Some cases wrong.
    • What do these case have in common? This could point ot a section of code that contains the error.
    • What do the right answers have in common. Sometimes it is the other way around. Sometimes the wrong ones seem to be random. Usually, this implies that the right ones have something in common that the wrong ones do differently.
    • It is possible that more than one thing is broken tha tis causing multiple different wrong answers.
    • It is possible that all of the right answers are not right because your code is. People have written code that gets the right answer (sometimes/always) wihtout doing the correct computation.
    • Take advantage of people/class/mailing list.
    • Use uDebug to process the sample input to make sure that the sample output is correct (problem statements have been know to wrong. Maybe formatting is messed up because of html misleading you).


Run time error

These can be frustrating. Here are a few ideas:

  • Do you get runtime error on sample data? -- see Output for sample data is wrong
  • Sample data right, but runtime error from judge
    • Try more input data
      • Make some up yourself
      • Check uDebug for additional input files
      • Check the UVA Forums for additional sample data (run the input through uDebug and compare to that output)
    • Make sure verything is properly initialized (overall and each iteration)
    • Check limits -- make sure any limit you have in your code (array size, loops, stack, ...) match the problem definition.
    • Try increasing limits (a problem I just did said there would be at most 100 input cases but the forum said the input had over 300)
    • Avoid storing lists of things unnecssarily. If something is not needed long term, don't load it in a list and then process the list -- just process it dynamically. Without a list, you cannot run out of space to save entries.
    • Try steps listed under Cannot figure out what algorithm to use. The resources there may help you spot the problem.
    • If you have a table or something declare the table big enough to have a border around it make sure that border area (where nothing should ever write) remains pristine.


Sample data works, but Wrong Answer judgement

This is very similar to Run time error. Make sure you are testing all data cases.





[ Powered by Red Hat Linux ] [ Powered by Apache ] [ Powered by PHP ]

The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015