How to Solve Any Algorithm
Ask questions—establish an understanding of the problem
does this look like a problem you have seen before?
what do you remember about similar problems?
what immediately stands out about it to you?
NOTE: you can always ask questions later on as they come up, you don't need to nail down every constraint now
Examples
try a lot of examples reduces the risk of over fitting
approach this step with a scientific mindset
try being random with your inputs
try to break your assumptions
figure out the edge case & test them
start specific and then slowly generalize your solution
NOTE: the harder the problem, the more examples you should play around with
Become the algorithm
Diagram 6
Distill the problem to its essence
Pseudocode
Two types of pseudocode
high-level in plain abbreviated english 9
answers the "what" you are going to do
low-level
answers the "how"
lays out step-by-step
spell out any additional variables
auxiliary data structures or actions
algorithm needs to perform adding, swapping, traversing, instantiating
written in such a way that you can code out each line one at a time and not have to hold too much info about the rest of your solution in your head
Time to do some coding
NOTE: on code DRYness - it's ok to start with a solution that does not use the fewest number of if/else statements or the most clever optimizations
know your syntax, especially for strictly typed languages
debug your code
study other code and see how they solved it
start to look for patterns fo space/time complexity