ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2253)
 C++ interview questions  C++ Interview Questions (1111)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (646)
Question
what is the difference between arrays and linked list
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
arrays are linear data structure
while linked lists are linear and non-linear
in case of linked list :-from point of access strategy it
is linear and from point of storage strategy it is non
linear
 
Is This Answer Correct ?    210 Yes 53 No
Sumit Thokal
 
Answer
# 2
the main differance between arrays and linked list is:

In array we follow static memory allocation.
i.e we assign memory to the particular element in advance.


in linked list -> dynamic memory allocation.
i.e we assign memory to the particular element at run-time..


hence we reserve only the amount of memory which is
required.

there is no problem of memory shortage or wastage, in
linked list. which we very frequently come accross in the
arrays..
 
Is This Answer Correct ?    113 Yes 19 No
Shruti
 
 
 
Answer
# 3
>Array is a simple sequence of numbers which are not
>concerned about each-others positions.
This is not true, what about arrays of objects ? They may be
concerned about each other in some way.

>adding,removing or modifying any array element is very >easy.
This is untrue also, adding, removing elements in array is
significantly more complex than removing or adding elements
in linked list. This is because removing elements from array
causes all elements after it to be shifted back, whereas
with linked list, its merely traversing the list to find the
node, previous node, and the next node and setting pointers,
and inserting element into array will probably call for
1) resizing the whole array size (ie. assingning a new,
bigger memory chunk for it)
2) copying elements from the former smaller array to the new
- bigger one.
This is a huge trade off, provided that in list, its simply
matter of setting the NEXT pointer of one of the nodes.

Main differences between the two are:
1) arrays are RANDOM ACCESS structures, where you can access
elements in random/indexed manner, whereas list is a
sequential access structure. This makes such algorithms like
heap sort or binary search to work much faster on arrays
2) arrays are static/fixed size whereas lists are dynamic
size structures. It means that when creating an array (both
on stack or heap), you HAVE to specify its size. With lists,
you just create an empty list and freely expand it
3) array consist of continuous chunks of memory, ie. nth
element is at the memory location of :
address_of_array + sizeof(array_element_type) * n
this always holds true, that is why following will always work :
for(int i=0;i < ARRAY_SIZE; i++)
cout << *(array++);
List is a sequence of nodes, connected by NEXT pointers, so
consequent nodes may lie WHEREVER in memory
 
Is This Answer Correct ?    112 Yes 19 No
Jaroosh
 
Answer
# 4
Array is a simple sequence of numbers which are not
concerned about each-others positions. they are independent
of each-others positions. adding,removing or modifying any
array element is very easy.Compared to arrays ,linked list
is a comlicated sequence of numbers.each number in the
linked list is connected to its previous & next no. via a
link which is nothieng but a pointer.Addition,removal of
no.s in linked list is related to this pointer direction &
linking that no. to the no. which is already present in the
list.
 
Is This Answer Correct ?    128 Yes 45 No
Kshama
 
Answer
# 5
Both are nothing but the data structures where in arrays
data can be accessed using subscript but in linked list
data can be accessed by the pointer present in its previous
node...
 
Is This Answer Correct ?    52 Yes 13 No
Yoga
 
Answer
# 6
the main difference is that in array data is not linked to
each other but in linked lists data is connected to each
other as every node is connected to previous node.
 
Is This Answer Correct ?    37 Yes 12 No
Bhumika Garg
 
Answer
# 7
1.array is fixed length and Array is a simple sequence of
numbers which are not concerned about each-others positions
but linked list is variable length
2.in array values are accessing easy but linked list is
some time taken process bcoz search aither forword or
backword
3.in array updating operations are time taken comparing
with linkedlist
4.array is not growble and linkedlist is growble
 
Is This Answer Correct ?    32 Yes 13 No
Vasu Kanneganti
 
Answer
# 8
All elements of array stored in contiguous memory location.
While in case of linked list each node does not stored in
contiguous memory location
 
Is This Answer Correct ?    20 Yes 5 No
Priya
 
Answer
# 9
Arrays
Strengths

1.Easy to use
2.No memory management needed
3.Can access any element by index
4.Fairly quick to loop
Weaknesses

1.Static size (cant increase the size)
2.Most likely not enough or too much memory (you never know
how many elements are needed)
Linked Lists
Strengths

1.Dynamic size (can increase or decrease the list)
2.No memory is wasted
Weaknesses

1.Lots of overhead code (lots of malloc calls and assigning
pointers)
2.Must traverse entire list to go to the nth node.
Now I know that other languages such as C# and Java have
better data structures than arrays and linked lists (like
ArrayLists and Vectors), but this is for the C language and
it doesnt have those. So based on what youve read above
you can decide which is better for the job needed. Neither
arrays nor linked lists are better but they do have their
specific purposes.
 
Is This Answer Correct ?    17 Yes 2 No
Durairaj
 
Answer
# 10
1)Array has a static storage where as in linked list it is
dynamic.
2)To add some elements in an array is impossible since the
size is predefined.For the same case we can add elements at
the beginning,in the middle and also in the end.
3)To access the data from array is very easy while to access
data from linked list is some complex.
 
Is This Answer Correct ?    16 Yes 7 No
Soumen Goswami
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.   5
Write code for initializing one dimentional and two dimentional array in a C Program? Deshaw 5
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting. TCS 1
In the following control structure which is faster? 1.Switch 2.If-else and which consumes more memory?   4
Can u return two values using return keyword? If yes, how? If no, why?   7
Write any data structure program (stack implementation) HTC 1
what is the difference between call by value and call by reference? Infosys 5
what is the diff between the printf and sprintf functions?? and what is the syntax for this two functions ??   5
which one is not preprocessor directive a)#if b)#elif c)#undef d)#pragma Wipro 16
multiple of 9 without useing +,* oprator   3
#include<stdio.h> main() { int a[3]; int *I; a[0]=100;a[1]=200;a[2]=300; I=a; Printf(%d\n, ++*I); Printf(%d\n, *++I); Printf(%d\n, (*I)--); Printf(%d\n, *I); } what is the o/p a. 101,200,200,199 b. 200,201,201,100 c. 101,200,199,199 d. 200,300 Tieto 2
18)struct base {int a,b; base(); int virtual function1(); } struct derv1:base{ int b,c,d; derv1() int virtual function1(); } struct derv2 : base {int a,e; } base::base() { a=2;b=3; } derv1::derv1(){ b=5; c=10;d=11;} base::function1() {return(100); } derv1::function1() { return(200); } main() base ba; derv1 d1,d2; printf("%d %d",d1.a,d1.b) o/p is a)a=2;b=3; b)a=3; b=2; c)a=5; b=10; d)none 19) for the above program answer the following q's main() base da; derv1 d1; derv2 d2; printf("%d %d %d",da.function1(),d1.function1(),d2.function1 ()); o/p is a)100,200,200; b)200,100,200; c)200,200,100; d)none 20)struct { int x; int y; }abc; you can not access x by the following 1)abc-->x; 2)abc[0]-->x; abc.x; (abc)-->x; a)1,2,3 b)2&3 c)1&2 d)1,3,4   1
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com