When is a Linked List not a Linked List?

11 May 2014

C#


Well, when is it? It sounds like a trick question, but the truth of the matter is there's no such trick to the question at all.

I've recently had the opportunity to complete a number of coding exercises as part of the interview process. I've noticed that my code has been appraised in a number of ways, including:

Whilst there are various arguments for and against the above two points, the major issue here is that by dismissing a completed coding exercise simply because regions appear in the code, and that no unit tests are supplied indicates that a company is willing to overlook a potential candidate based on coding style, and not whether they are actually capable of problem solving at all. The bottom line is that by adopting this methodology, you're doing us both a favour: who would want to work for a company who's selection process is so shallow? No, neither would I.

As it turns out, one of Australia's 'leading' major consultancies evaluates candidates using these exact rules. They shall remain nameless for fear of retribution, but also to protect the reputation of the team that evaluates these programming exercises. That aside, I am able to reveal the following gem, which answers the question posed earlier: when is a linked list not a linked list?


The Challenge

I won't publish the entire question, but I will detail that the instructions contained the expression "singly linked-list of integers".


The Code

Here's my code (note that I've removed the regions for the princesses amongst us, and that code sensitive to the exercise has been removed completely):



public class LinkedList 
{ 
    public LinkedList(int[] Values) 
    { 
        LinkedListElement oCurrentElement = null; 

        //  It is possible to construct this class with a null array
        if (Values != null) 
        { 
            foreach (int i in Values) 
            { 
                if (oRootElement == null) 
                { 
                    oRootElement = new LinkedListElement(i); 
                    oCurrentElement = oRootElement; 
                } 
                else 
                { 
                    oCurrentElement.NextElement = new LinkedListElement(i); 
                    oCurrentElement = oCurrentElement.NextElement; 
                } 
            } 
        } 
    } 

    private LinkedListElement oRootElement; 
} 

public class LinkedListElement 
{ 
    public LinkedListElement(int Value) 
    { 
        iValue = Value; 
    } 

    private LinkedListElement oNextElement; 
    private int iValue; 

    public LinkedListElement NextElement 
    { 
        get 
        { 
            return oNextElement; 
        } 
        set 
        { 
            oNextElement = value; 
        } 
    } 

    public int Value 
    { 
        get 
        { 
            return iValue; 
        } 
    } 
} 


The Response

"Linked List: There is no LinkedList implementation that encapsulates the list functionality. Rather a chain of Nodes is used."


Err, OK then.

This response really had me scratching my head. For a moment I doubted that I knew what a linked list actually was. How could I have gotten it wrong all these years? Surely a linked list is a chain of nodes? It certainly was for both my Java units at University, and remained a "chain of nodes" for my C/C++ unit too. In addition, according to Wikipedia (which is really rather a good resource for information that can be scientifically proven or disproven), a linked list is "a group of nodes which together represent a sequence" - this certainly sounds like a "chain of nodes" to me.

Unfortunately, there's no coming back from this, you can't discuss these points with the marking team of a potential employer, it's simply not open for debate. It's just better to make sure you know your stuff, even if they don't, and move on.


 

Copyright © 2024 carlbelle.com