DEV Community

Cover image for Trusting Yourself in Solving Algorithms
Rachel Ralston
Rachel Ralston

Posted on • Originally published at code.likeagirl.io on

Trusting Yourself in Solving Algorithms

Today’s coding lesson is about trusting yourself.

I’ve noticed a grumpy-making pattern in myself while I’m coding: I’m given issue X. I understand the problem and I lay out some logic to solve X. I implement my code but inevitably it doesn’t work.

Ok, cool, I am a zen master as I start to fix, approaching both my thinking and the project from several different angles. I spend 5 hours methodically working my way through this code and ultimately get nowhere. By this time I’m frustrated enough to go ask a technical mentor for help.

In the span of an hour the problem is solved using the initial logic I came up with in the first place.

such a zen master.

I’ve spent a lot of time this week thinking about this anti-pattern. Here are the lessons I’m taking from this repeating scenario:

  • Trust yourself. Your thinking is good, you know more than you think.
  • Don’t assume an algorithm is wrong just because the code won’t run right away.

To improve this area of newly exposed ignorance, I’m going to study turning thought into working code. My process:

  1. Take an algorithm problem (HackerRank is a favorite) and solve it on paper.
  2. Write the problem out with edge cases.
  3. Pseudocode the algorithm out in plain old english.
  4. Write the actual code. Still on paper.
  5. Go through line by line and hunt bugs. Hold your problem clearly in your mind and make sure your thinking is going to work.
  6. Finally, type it into a code editor of your choice as is and note any mistakes, see if/where it’s broken, correct your mistakes.
  7. In some comments, decompose the problem. Write about your thinking and what you think of the code.

both broccoli and learning make me feel like dancing.

I’m treating this like math homework, the thing that is a little bit painful that I do every day to hammer some knowledge deep into my psyche. Bonus Points: this also doubles as study for interviews.

Check out some examples of mine which I’ll be adding to over the next couple weeks.

This post was originally published on medium.com