Christopher Moh 2005 Competition Programming Analyzing and Solving problems
Christopher Moh 2005 Steps in solving a problem Reading the problem Formulation of a solution Implementation the solution Testing the solution
Christopher Moh 2005 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 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 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 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 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 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 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 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 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 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 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 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?