ron2794's blog

By ron2794, 11 years ago, In English

i often find it hard to read other's code than to write mine own version of code but competitive programming is not just all about writing codes. i have often heard people that you learn a lot when you read other's code whether its when you are trying to learn something out of other's code or you are trying to hack a solution in any contest.

can you throw some light on how one can increase his ability to read totally unfamiliar code easily and understand the algorithm working behind it swiftly.

  • Vote: I like it
  • +13
  • Vote: I do not like it

| Write comment?
»
11 years ago, # |
  Vote: I like it +7 Vote: I do not like it

Like any other thing, you can improve it by practice! Go through other people's solutions and try to understand them as quickly as possible.

»
11 years ago, # |
  Vote: I like it +4 Vote: I do not like it

To learn art of reading code, have a look here

»
3 weeks ago, # |
  Vote: I like it -12 Vote: I do not like it

Here are some tips to help you enhance this skill:

1. Start with Familiarizing Yourself with Common Algorithms and Data Structures: Before diving into unfamiliar code, make sure you have a solid understanding of common algorithms and data structures. This will provide you with a framework to understand the logic behind the code you encounter.

2. Break Down the Code into Smaller Parts: Instead of trying to understand the entire codebase at once, break it down into smaller, manageable parts. Identify functions, classes, and modules, and try to understand each part individually before putting them together to understand the whole.

3. Trace Execution: Mentally trace the execution of the code by following the flow of control and tracking the values of variables. This can help you understand how different parts of the code interact with each other and how the algorithm works step by step.

4. Compare with Known Solutions: If you're trying to understand a solution to a specific problem, compare it with known solutions or algorithms for that problem. Look for similarities and differences, and try to understand the reasoning behind any deviations from standard approaches.

5. Experiment with Modifications: Once you have a basic understanding of the code, try making small modifications or tweaks and observe how they affect the behavior of the program. This can deepen your understanding of how different parts of the code work together and how changes impact overall functionality.

6. Read Documentation and Comments: If the code you're trying to understand is well-documented, start by reading the comments and any accompanying documentation. This can provide valuable insights into the purpose and functionality of different parts of the code.