How Tries changed our mindset

Joel Tello
Gbox
Published in
4 min readJul 1, 2016

I’m writing my first blog after an unusual week, probably the oddest one since I moved to Silicon Valley, full of unexpected things and changes. I always try to take the bad with the good and this time has brought us good insights.

This week, we (engineering team) decided that it was a good time to brush up our algorithms and data structures knowledge, that hadn’t been revisited probably since we all left college [1]. So we decided to start solving challenges from this awesome website leetcode.com

[1]. Wanaya explaining functional programming

Everything started with the idea to solve one challenge a day. I was the first to pick and since we all were a little bit rusty [2] I chose an “easy” one. When I read the description, I couldn’t think of anything else than using a third party library to solve it, a library that we’ve been using during the last 4 years. We’re so used to reuse others’ solutions that we completely depend on them, our brain is basically deactivated…in a passive mode where you can’t get any ideas flowing. Don’t get me wrong, I’m not against it, in fact, these libraries make you so much productive, the problem is us, we stopped creating ideas and innovative solutions. Finally, after spending a couple of hours we started submitting our solutions. It felt absolutely great! We were able to use concepts like recursion, super recursion (honestly, I had no idea what that was, I had to look it up), algorithm complexity and pointers, things that you don’t use in a normal day.

[2]. This is how I felt like

I was so excited that I started a second challenge after finishing the fist one. This time I picked one with difficulty of medium (a search problem). Surprisingly, I finished coding my solution faster than the “easy” one, I guess it is all about refreshing concepts [3].

[3]. Bye bye lodash!!!!

However, when I submitted my solution, the website started complaining about the time my solution was taking to produce results using a large data set. I thought it was just a matter of making some tweaks in the algorithm so I changed a couple of things here and there…no success. Then I asked myself…what other data structures do we have in JavaScript? I couldn’t find an answer on top of my mind besides arrays and objects, so I asked the same question to one of our senior engineers Juan Pablo Franco here at Gbox, his answer was the same. We knew we were missing something here, either a data structure or search algorithm. It wasn’t until we hit the “hint” button that we knew we had to implement Prefix Trees or “Trie”. We started researching the concept and the more we read about it the more sense it made. Tries were meant to solve our search problem! Coding wasn’t an issue at all, so we finished that and voila! It worked like magic.

Why Tries changed our mindset? Well, now we are more perceptive and aware of a broader selection of existing data structures and algorithms. This wasn’t something we were applying on our daily work. With our “busy” developer lives, we were solving problems without finding the optimal solution, does it work? Yes…move on! Now I feel we can (and we should) optimize every single function in our code! We were even joking around saying that we should implement client side pagination with Trees (ok ok…there’s a limit) [4]. Anyways, I feel like we have opened a door to things we all probably knew, but we weren’t taking into consideration in our daily problem solving. All these algorithms and data structures should be in every developer’s toolbox!

[4]. Juan Pablo Franco implementing client side pagination with Trees

Rough times have passed and the birds started singing in the morning again. [5].

[5]. Phew!

Should we go back to our busy lives and keep rushing things without being thoughtful of our code? Of course not, we need to keep stimulating that part of the brain we had deactivated for so long. By doing this we’ll always have these concepts in our toolbox ready to be applied. We all knew what a Tree was, at least I did, but that knowledge was stored very deep in a part of my brain where I was never going to find it. Now, as part of our engineering culture, we decided to have this type of challenges every Friday, f*** yeah! Spending time writing code that I’ll never gonna use! [6]

[6]. Data-structure all the things!

Not really! I’m very positive this is valuable knowledge, who knows and we’ll end up reusing some of these data structures and techniques to create animations, perform our client side searches, manipulate the DOM and more important make coffee…

--

--