Question

In: Computer Science

What is the difference between Array and Linkedlist. What is Array with example? What is Linkedlist...

What is the difference between Array and Linkedlist.

What is Array with example?

What is Linkedlist with example?

What is the difference?

Solutions

Expert Solution

Both Array and Linked list are used for storing data of same type.

  • Array is collection of elements of same data type and linked list is ordered collection of elements of same type that are connected by pointers.
  • Array has random access, ith index element is accessed using a[i]. Complexity of access is O(1). Linked list has sequential access, for accessing ith element, we have to traverse complete linked list till that element from starting. Complexity is O(n).
  • Elements in array are stored in contiguous memory locations whereas in linked list at random locations.
  • Insertion and deletion is fast in linked list as compared to array.
  • Array size is specified during declaration whereas linked list size is not needed to specify.
  • Extra space is equired in case of linked list to store memory space for pointers.

Thus, array is collection of elements of same type.

int a[10]; //declare integer array , a containing space for 10 elements.

Indexing in array starts from 0. Thus n elements are stored from index 0 to n-1 in array.

simple program in c:

#include<stdio.h>

void main()

{

int a[100],i,n;

printf("Enter no. of elements\n");

scanf("%d",&n);

printf("Enter elements:");

for(i=0;i<n;i++)

scanf("%d",&a[i]);

printf("Elemets of array:\n");

for(i=0;i<n;i++)

printf("%d ",a[i]);

}

Linekd list is used to store elements of same type using pointers.

Node structure of singly linked list is as:

struct node

{

int data; //data field storing element

struct node *next; //pointer to next node (link)

};


Related Solutions

What is an array-based list? What is a resizable list? What is the difference between a...
What is an array-based list? What is a resizable list? What is the difference between a list’s capacity and its size? When a list is expanded, is the size changed or is its capacity changed?
In java write a method that will take an array and change it into a linkedlist...
In java write a method that will take an array and change it into a linkedlist and then display it in the main method
What is the difference between equality and equity? Use an example.
What is the difference between equality and equity? Use an example.
What is the difference between IRR and MIRR ? Explain with an example.
What is the difference between IRR and MIRR ? Explain with an example.
3. What is the relationship between sex and gender? Provide an example of the difference between...
3. What is the relationship between sex and gender? Provide an example of the difference between gender identity and gender expression
What is the difference between Logistics and Supply Chain? Provide an example.
What is the difference between Logistics and Supply Chain? Provide an example.What is the relationship between logistics and Marketing?  What is the relationship between logistics and Production?What is the difference between logistics network design and logistics process design? Provide an example
What is the difference between an attribute and a metric? Give an example each of an...
What is the difference between an attribute and a metric? Give an example each of an attribute of a service that is done correctly, incorrectly, or not at all and a metric for it. (Performance analysis modelling class)
What is the difference between statistical and economic significance? Give an example. (Your own example, NOT...
What is the difference between statistical and economic significance? Give an example. (Your own example, NOT a pill for cancer).
This LinkedListUtil class tests various usages of the LinkedList class. The single param is an array...
This LinkedListUtil class tests various usages of the LinkedList class. The single param is an array of string. You will create a linked list with the string elements and return the linked list with all but the 1st two elements removed. Java code Complete the following file: LinkedListUtil.java import java.util.LinkedList; import java.util.ListIterator; /** This LinkedListUtil class tests various usages of the LinkedList class */ public class LinkedListUtil { /** Constructs a LinkedListUtil. @param list is the initialized list */ public...
This LinkedListUtil class tests various usages of the LinkedList class. The single param is an array...
This LinkedListUtil class tests various usages of the LinkedList class. The single param is an array of string. You will create a linked list with the string elements and return the linked list with all but the 1st two elements removed. Note: In this question use a for or while loop instead of the suggested iterator. You should also ignore CodeCheck’s error message about a missing class (LinkedListUtil.class). Your code still needs to pass all test cases. EDIT: For clarifcation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT