How to Develop Your Pattern Recognition Skills

title: How to Develop Your Pattern Recognition Skills excerpt: The ability to recognize coding patterns in the solution is critical to build the basic blocks that can be combined to solve new coding problems.

Syntax vs Semantics

Do you describe your code syntactically or with an understanding of the underlying semantics? You are able to see the code as a single coherent construct if your description of the code is based upon the underlying semantics and not a line-by-line description of the code at a syntactic level.

Purpose of the Code

Expert programmers form abstract representations based upon the purpose of the code. For example, when you see code that follows this pattern:

  • Iterate over the elements in an array
  • Put elements into a new array based on a condition

You recognize it as a filter and think about this block of code as a filter. You are not thinking in terms of the syntax of the code: “A loop, with an if condition that then puts some items from the old array into a new array”.

The higher level concept of filter is recognized due to your ability to grasp the meaning of the code block. You can recognize the intent of the code that expresses a certain concept.

Recognize Coding Patterns

These programming constructs are applicable to any language. Once you start recognizing and start naming them, you now have an index to the knowledge base you have built over time. It’s easy to retrieve it when you need it.

During study, name language independent coding patterns that you find in the solutions. For instance, sliding window technique applies to many subarray problems. These coding constructs are reused in solutions to different problems. This becomes part of your vocabulary of programming concepts.

So when you have names for the coding patterns that you recognize in the code, you can talk at a very high level about coding. You can say, “Hey, I’m using a sliding window for this problem.” Naming and recognizing them develops your pattern recognition skills.

Conclusion

Over time, your study notes will be filled with coding patterns. Before you go to the interview, you can brush up on the topics by revising your own notes. You can quickly recall what approach to take at a high level. It will already be in your toolbox.