1 / 14

Competition Programming

Competition Programming. Analyzing and Solving problems. Steps in solving a problem. Reading the problem Formulation of a solution Implementation the solution Testing the solution. Reading the problem. Read the WHOLE problem!

prisca
Download Presentation

Competition Programming

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. Competition Programming Analyzing and Solving problems Christopher Moh 2005

  2. Steps in solving a problem • Reading the problem • Formulation of a solution • Implementation the solution • Testing the solution Christopher Moh 2005

  3. Reading the problem • Read the WHOLE problem! • May have subtle details in problem descriptions that are essential to solve the problem efficiently • Examining Time and Space constraints • Watching out for obvious properties Christopher Moh 2005

  4. Time and Space Constraints • Time Constraints usually are more important than Space Constraints • What kind of algorithm works? • Good average case? • Good worst case? • Gives an idea of the kind of algorithm that solves the problem • E.g. Huge graph problems usually imply some linear-time traversal solution Christopher Moh 2005

  5. Time and Space Constraints • Does the problem specify the size of the test cases? • If there are only one or two test cases that are huge compared to the rest… • DON’T SOLVE FOR THESE TEST CASES IF YOU DON’T KNOW THE ADVANCED ALGORITHM • There usually will be a basic algorithm that will solve the rest with suitable optimizations and data structures Christopher Moh 2005

  6. Properties I • What unique properties are explicitly stated or easily implied? • Unique Numbers? • At most one path between any two nodes implies a forest of trees • Exactly one path between any two nodes implies a tree • No return path may imply a DAG • Classification in a system of “black” and “white” etc may imply a bipartite graph Christopher Moh 2005

  7. Formulation • How can I solve this problem? • As a Graph problem? • As a DP problem? • Sorting problem? • Clever data structures? • Using unique properties of the problem? • Brute Force? Christopher Moh 2005

  8. Breaking down problems • Can this problem be broken down into a decent number of sub-problems that can be combined to solve the problem? • Is there an inherent, or maybe a subtle implied order that we can use? • Can I use a solution to a similar problem of a smaller dimension? Christopher Moh 2005

  9. Properties II • Are there number properties I can use? • Is this a special graph with unique properties e.g. trees, DAGs, etc.? • Is sorting allowed and what advantage can sorting give me? • Does a greedy solution work? Christopher Moh 2005

  10. Implementation • Data Structures • Can I get away with using simple data structures and still beat the time limit? • If not, what works? • Heaps? • Interval trees? • Cumulative Sum data structures? [ See IOI 2001 Day 1 Q1 ] Christopher Moh 2005

  11. Implementation • Dynamic Programming solution • What do I have to keep track of? • How can I evaluate the recurrence relation? How should my loops be oriented? • Do I have to keep track of the solution if I need to backtrack to output the actual solution instead of the optimal result? • Should I use memoization? • Is there an important space constraint? Christopher Moh 2005

  12. Implementation • Graph solutions • Should I use an adjacency list or a matrix? • Space and time constraints • Is my graph formulation solvable in polynomial time? • How many vertices/edges does my formulation produce? Is there a way to compress vertices/edges to improve runtime while still preserving accuracy of output? Christopher Moh 2005

  13. Implementation • Brute Force solutions • What pruning methods are available? • Are there ways to generate output without going through redundancy or irrelevant search areas? [ See IOI 2001 Day 2 Q3 ] • Can a simple backtracking work? Or perhaps more advanced search methods e.g. Iterative Deepening, A* search are needed? Christopher Moh 2005

  14. Testing • Testing for Accuracy with extreme cases • Isolated vertices? • Complete graphs? • Completely negative numbers? • Testing for Speed • How fast does the solution run when faced with a huge input? Christopher Moh 2005

More Related