views:

119

answers:

4

In an interview when I ask the recent graduate students that what is the difference between array and linked list, the first answer normally is "In array you have same data types and in the linked list you can have different data types." When I told them to explain they will say that they have just read it somewhere or that they don't know exactly how.
I am really failing to understand from where this idea is coming into their brain? Can someone help me to understand why a college graduate thinks this? Or do you think this is really a difference?

+3  A: 

It is possible that these students have been taught arrays with statically typed languages and linked lists with dynamically typed languages, so they have come to identify the data structure with the paradigm of the language they were using it in.

For instance, they may have used arrays in C and linked lists in Scheme. Or whatever the fashionable names are for today's languages that are essentially like C, respectively Scheme.

Pascal Cuoq
Or, similarly, they were taught Linked Lists in conjunction with polymorphism and nobody ever went back and said "hey this polymorphism thing can work with other structures like arrays, too!"
Tyler McHenry
@Tyler: I think that's most likely the case. I remember that's how I was introduced to polymorphism.
slebetman
+1  A: 

Well I can't speak for them but when you learn to program you get some assignments. On one you are asked to save data in an array and on another you are asked to build a linked list to save the data. When you do that you learn that both help you... save data in the memory... each with advantages and disadvantages.

So it feels the same but their limited experience is:

when they learn to declare an array it's something like

int[] myArray = new int[20];

So they learn that they must determine the type...

and when they build a node

prev= object;
next = object;

they learn that they are not bound to a specific type or object.

This is my best guess. Hope it helps.

P.S: It would be interesting to see the answer as you would give it... who knows, some of them may see it and learn something :)

Asaf
Because in C, they use operator new frequently.
DeadMG
1. why is the new make any difference?! The question is about people not understanding a subject in the same way the author of the question understands it... how can any answer be good or bad for this type of question?! I just made a guess nothing more.
Asaf
A: 

Isnt it that searching in the linked list is easy while in array is complicated,same goes for various other functions performed i.e deletion and insertion.(In deletion you need to remove the hole that you made and an insertion you have to make a hole and then move ALL the elements). Moreover,i guess the explanation to the question you asked was easy as an array can hold one data type for example names or roll numbers while Linked list can hold both of them together.

fahad
Yes, thank you. Now people will know what I am talking about. And no searching in linked list is more complicated than in array.
Manoj R
+1  A: 

May be would have read perl, where lists can have any data types...but there perl and list are somewhat similar. Also c has concept of void *, so that we can do to have any datatype pointer typecasted to void pointer.