Every Programmer Should Understand This


I have worked with a large variety of programmers. Some were what the industry call “junior” developers (beginners) and some were “senior” developers (experts). While working with these people I started to notice that the better programmers (not necessarily the seniors) seemed to understand certain concepts much better than others.

Surprisingly, this knowledge didn’t have a direct correlation with the “level” of experience that the developer possessed. Some junior developers understood these topics better than their senior counterparts. However, some junior developers were completely oblivious to the subject matter at all. This subject matter doesn’t seem to be something that is learned on the job so much until you begin to work on more complicated systems, however, the benefits of understanding these concepts pay off greatly when developing any piece of software and should thereby be understood as fundamental knowledge for any competent programmer.

It might surprise everyone reading this to find out that the topics and subjects I am referring to are computer science basics. In fact, most of them are covered in the early stages of the computer science curriculum.

Why is this?? Why don’t some of the most “senior” developers at some companies not understand the basics?

I’m sure everyone has their theories, but I attribute it to more and more people learning to program by unconventional ways such as boot camps, websites that teach you how to code (like code academy), and people just teaching themselves how to code an application and get it up an running.

There is nothing at all wrong with learning like this (I’ve learned many subjects this way), but please realize that after completing a boot camp or code academy course, on say JavaScript, there is still A LOT more to be learned. I believe some people fall into a false sense of security thinking that they have all the tools they need to code anything and everything, but then end up failing miserably at a project that takes a much deeper understanding of computer science.

Developers need to understand data structures, algorithm development, and topics such as recursion. These are the building blocks of computer science! These aren’t as “fun” for your average new programmer that just wants to type  alert(“Hello World”) into a script and see the console print his statement. No, these are more fun when you actually have difficult problems to be solved and need an efficient and elegant solution to do the job.

Strangely, the same “senior” developers that are not familiar with these general fundamental topics are for some reason well versed in specialized topics such as the idiosyncratic behavior of a certain compiler for a certain language or the details of a certain system methods that may produce better timings in certain situations.

While the latter may be important to know and understand in certain situations (and I’m not implying that these people are not very useful), you can’t neglect the fundamentals. You need to fully understand data structures and algorithms before you start using the .Sort() function in your language of choice or any other basic algorithm that is implemented for you by the API. If you couldn’t write the basic implementation of the function you are using then you shouldn’t be using it because you don’t understand it.

It may sound harsh, but a programmer that uses functions that he doesn’t understand is kind of like a race car driver that doesn’t know how an engine works. If something goes wrong the race car driver couldn’t fix his own car. Yes, he is valuable to be able to drive the car, just as programmers that don’t understand computer science basics can still build software. However, I believe it is a recipe for disaster.

If you are programming by coincidence, then you aren’t sure why your code works the way it does, and more importantly you won’t understand why it doesn’t work. 

If you still aren’t sure what I’m talking about then here is a test. Can you reverse a singly linked list?

Proving that you can do this will mean that you at least understand the basics of computer science. To successfully develop an algorithm to do this you will need to understand pointers, recursion or iteration, and algorithm development. Like I’ve stated earlier, all of these are subject covered in computer science 101.

A linked list is probably the most basic data structure in computer science and is the main building block that other data structures consist of. Knowing this you should be able to develop and algorithm that, given the head node, will return the reversed node.

Test yourself. See if you can implement an efficient algorithm. Then check out my solution. Was it like yours?

The Idea behind Reversing a Singly Linked List

The idea is to iterate through the complete linked list and maintain three pointers as listed below:

  • Pointer to the head of unreversed list headOfUnReversedLL.
  • Pointer to the head of reversed list headOfReversedLL.
  • Pointer to the node to be reversed nodeToReverse.

In each iteration we follow the below steps:

  1. The headOfReversedLL pointer must point to the nodeToReverse. Initially the node to reverse is null, so the head of reversed linked list will point to null.
  2. The nodeToReverse pointer should point to the head of the unreversed list as we are trying to reverse that particular node.
  3. The headOfUnReversedLL pointer should move one step forward in the unreversed linked list.
  4. The next pointer of nodeToReverse node should point to the head of the reversed linked list.
    We repeat the above four steps until the headOfUnReversedLL points to null.Here is a pictorial representation of the iteration. Each row represents the state of the linked list after one iteration
    Reversing a Singly Linked List
    So, if we observe closely, the first step is actually the finalizing step of the iteration. That is the step which correctly positions the headOfReversedLL to the node which was reversed in the last iteration.

    But, when the loop exits out, we never get a chance to do that one last time. So at the end, let us re-position the headOfReversedLL to the correct node nodeToReverse

    Source Code – Reversing a Singly Linked List

    Analysis – Reversing a Singly Linked List

    Running Time

    We just run through the linked list once and hence the time complexity is O(N) where N is the size of the linked list.

    Space Complexity

    We just use three more pointers and that is not dependent on the size of the linked list, its O(1). Hence, we can say that the space used is constant.

If you were able to come to this solution or one like it then you are one of the better developers! Congrats! If not, that is okay too! You can’t become better and master a subject until you realize what you don’t fully understand. If this was difficult for you then I suggest picking up a basic computer science book and going over the basics a little more until you have a firm grasp and understanding of the subject matter.

I hope you like this post. Please comment and let me know if you disagree or agree with the article. Also please subscribe to my blog at jasonroell.com.


jroell View All →

I love to code and build new innovating solutions to people's problems!

2 Comments Leave a comment

  1. “Developers need to understand data structures, algorithm development, and topics such as RECURSION!”:

    private Node reverse(Node aNode, Node prevNode=null){
    Node nextNode = null;
    Node headOfReversedLL = null;
    if(aNode != null){
    nextNode = aNode.next;
    aNode.next = prevNode;
    headOfReversedLL = reverse(nextNode, aNode);
    headOfReversedLL = prevNode;
    return headOfReversedLL;

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: