How can I improve at algorithm design and breaking complex problems down?
Asked by
the_long_division
I've read parts of several algorithms books covering familiar topics like sorting, searching, graph traversal, trees, and hash tables. They explain how established algorithms work, but I'm struggling to learn the thinking process behind inventing or decomposing a solution.
For example, I recently needed to create an attractive, intuitive layout for a control-flow graph. The problem turned out to have been studied by Sugiyama in the 1980s, but I wouldn't have known how to break it down from scratch. How can I practice algorithmic problem solving and develop the ability to design solutions independently, without immediately getting stuck or looking up the established answer?
Answers
Decomposition becomes easier when you stop treating the entire task as one problem. For a graph-layout problem, you might separately consider the graph representation, ordering nodes into layers, reducing edge crossings, assigning coordinates, and rendering the result. Each piece can then be tested and improved independently.
Itโs normal not to rediscover famous algorithms from scratch. The goal of practice is to become better at identifying useful subproblems, choosing workable representations, and refining a solutionโnot to independently recreate every major result in computer science.
Reply to this answer
There isnโt really a step-by-step formula that turns someone into an exceptional algorithm designer. A lot of this ability develops through repeated practice, much like learning a physical skill.
Try solving smaller problems without looking at the solution first. If you get stuck, donโt immediately search for the answerโset the problem aside and return to it later. Another useful technique is to simplify the problem: remove constraints, reduce the input size, or solve a narrower version first. The simpler version often reveals the idea needed for the original problem.
Itโs also important to distinguish understanding an existing solution from inventing one. Reading a solution can teach you a lot, but it doesnโt provide the same practice as struggling with the problem yourself. Programming challenge sites and practical work involving APIs, services, or data processing can all help build this skill.
Reply to this answer
Start with a concrete problem and attempt to solve it before studying the standard algorithm. For instance, take a small list of numbers and think through how you would sort it manually, then consider how to reduce the number of operations or memory used. Afterward, compare your approach with known algorithms and identify what makes them more efficient.
Vary the constraints as you practice: limit memory, minimize execution steps, handle much larger inputs, or consider whether the work could be parallelized. Optimization games and programming puzzles can also be useful because they force you to find procedures that satisfy explicit constraints.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions