Data Structure Interview Questions and Answers




Knowledge of data structures is an extremely important part of any programmer’s skill set because data structures are simply unavoidable when programming. Remember – even a simple array is a data structure. And, as a programmer, you should know the advantages and disadvantages of the different types of data structures in order to write efficient code. For almost any programming job you interview for (regardless of what languages you will be programming in), most companies will undoubtedly ask questions in the interview regarding data structures.

So, we highly recommend that you cover everything in this section on data structure interview questions. We also provide complete answers and explanations to the problems here, so be sure to read through our solutions so that you get the most out of this section.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.

  • James

    I did not miss the fact that the question said “middle”. One of the things interviewers are looking for is your ability to detect and address corner-cases in their examples.

    Interview questions are rarely just about being “technically correct” with respect to the wording of the challenge. I certainly was never that pedantic when I asked applicants interview questions at EA, and those who interviewed me at places like Amazon, Microsoft Studios, Bungie, or 343 Industries weren’t either.

    Additionally, the pseudocode answer given to the question clearly doesn’t assume the things you suggested, as it checks the target node for null, AND checks the target node’s ‘next’ pointer for null as well. So we are not guaranteed a well-populated linked list, and we are not guaranteed that the target node is somewhere in the middle of such a list.

    Add to that the technically correct fact that if the list has but ONE node in it in total, that node is both the Head and the Tail, AND technically qualifies as the “middle” of the list. This case will also fail to result in the deletion of the node.

    The reason I made my comment is because the FOLLOW-UP questions interviewers ask in response to your answers to interview challenges are just as important as the challenge question itself, and I thought it would be a good idea to mention one of the biggest corner-case issues with the listed solution.

  • Aidan

    Take a look at the example you just named. “Delete a node in the MIDDLE of a singly linked list”. This means that the linked list is not empty and is of a decent size where you are deleting a node that is not the HEAD node nor the TAIL node.

  • James

    In the “Delete a node in the middle of a singly linked list” section, one thing which wasn’t mentioned that you may want to add is that this method will FAIL if the user passes your method the TAIL node for the list. There is no “next” node for you to copy data from and delete instead, so no node will be deleted.