You are on page 1of 3

Like arrays, linked lists are used as a building block for many other data

structures, such as stacks, queues and their variations. A linked list data
structure might work well in one case, but cause problems in another. There are
some common tradeoffs involving linked list structures. In general, if you have a
dynamic collection, where elements are frequently being added and deleted, and the
location of new elements added to the list is significant, then benefits of a
linked list increase.

Linked lists vs. arrays

Elements can be inserted into linked lists indefinitely, while an array will
eventually either fill up or need to be resized, an expensive operation that may
not even be possible if memory is fragmented.
Array allows random access, while linked lists allow only sequential access to
elements.
Extra storage is needed for linked lists for references, which often makes them
impractical for lists of small data items such as characters or boolean values.
Doubly linked vs. singly linked

Doubly linked lists require more space per node, and their operations are more
expensive; but they are easier to manipulate because they allow sequential access
in both directions.
For example, insert or delete a node in constant number of operations given only
that node's address.
Circularly linked vs. linearly linked

Circular linked lists are most useful for describing naturally circular structures,
and have the advantage of a regular structure and being able to traverse the list
starting at any point. They also allow quick access to the first and last records
through a single pointer (the address of the last element). Their main disadvantage
is the complexity of iteration, which has subtle special cases.
Sentinel nodes

Sentinel nodes may simplify certain list operations, by ensuring that the next
and/or previous nodes exist for every element. However sentinel nodes use up extra
space (especially in applications that use many short lists), and they may
complicate other operations. To avoid the extra space requirement the sentinel
nodes can often be reused as references to the first and/or last node of the list.

=====================

2 Marks Questions 10 Marks

1: Define Linked List? Discuss its types?


Ans: A linked list can be viewed as a group of items, each of which points to the
item in its neighbourhood. An item in a linked list is known as a node.
A node contains a data part and one or two pointer part which contains the
address of the neighbouring nodes in the list.
Linked list is a data structure that supports dynamic memory allocation and
hence it solves the problems of using an array.
Types of linked lists
The different types of linked lists include:
1. Singly linked lists 2. Circular linked lists 3 Doubly linked
lists
2: What are the advantages of Linked List?
Ans: Linked List is Dynamic data Structure .
Linked List can grow and shrink during run time.
Insertion and Deletion Operations are Easier
Efficient Memory Utilization ,i.e no need to pre-allocate memory
Faster Access time,can be expanded in constant time without memory overhead
Linear Data Structures such as Stack,Queue can be easily implemeted using
Linked list

3: List any three disadvantages of linked list?


Ans: 1. Wastage of Memory Pointer Requires extra memory for storage.
2. No Random Access
In array we can access nth element easily just by using a[n].
In Linked list no random access is given to user, we have to access
each node sequentially.
Suppose we have to access nth node then we have to traverse linked list
n times.
3 . Time Complexity
Array can be randomly accessed , while the Linked list cannot be
accessed Randomly
Individual nodes are not stored in the contiguous memory Locations.
Access time for Individual Element is O(n) whereas in Array it is O(1).
4. Reverse Traversing is difficult
In case if we are using singly linked list then it is very difficult to
traverse linked list from end. If using doubly linked list then though it
becomes easier to traverse from end but still it increases again storage
space for back pointer.

4: Write any two applications of queue and Stacks?

Ans: Queue Applications:

1. Typical uses of queues are in simulations and operating systems.


Operating systems often maintain a queue of processes that are ready to
execute or that are waiting for a particular event to occur.
2. Computer systems must often provide a holding area for messages between
two processes, two programs, or even two systems. This holding area is usually
called a buffer and is often implemented as a queue.
3. Our software queues have counterparts in real world queues. We wait in
queues to buy pizza, to enter movie theaters, to drive on a turnpike, and to
ride on a roller coaster. Another important application of the queue data
structure is to help us simulate and analyze such real world queues.

Stack Applications
Three applications of stacks are presented here.
1. Expression evaluation
2. Backtracking (game playing, finding paths, exhaustive searching)
3. Memory management, run-time environment for nested language features.

5: How to create an empty list ? Write Steps?

5 Marks Questions (Attempt any Four) 20 Marks


6: What is meant by Pop Operation? Write the algoritm for Stack?
7: What do you mean by enquue operation ? Write the algorithm for same?
8: Write an algoritm to insert an element in two way list?
9: Write an algorithm to delete a node from doubly linked list?
10: Write the steps to traverse doubly list in reverse order?
10 Marks Questions 10 Marks

11: Write algorithm or steps for following


(a) Create an empty doubly List 3M
Ans: Create doubly linked list Algorithm
CreateDll(info,prev,next,start,end)
1. create a new node and address in assigned to ptr.
2. set Info[ptr]=item;
3. set prev[ptr] = next[ptr] = NULL
4. set start = end = ptr
5. Exit.
(b) Insert two elements say AA, BB in this list 3M

Ans: Fuction For Insert at begining


void insertAtBeg(node **start,node **end,int item )
{

ptr->info=item;
if(*start==NULL)
{
*start=ptr;
*end=ptr;
}
else
{
ptr->prev = NULL;
ptr->next=*start;
(*start)->prev=ptr;
*start=ptr;
}
}
(c) Add another element say DD after AA element in list? 4M
12:
(A) Write steps for following
(a) Create a empty stack using array 1M
(b) insert 24 , 55 , 66 elements in this stack? 2M
(B) Write stepts or algoritm for following
(a) Create an empty queue using array 1M
(b) Add 10,20,44, 50 elements in queue? 2M
(c) Now apply dequeue operation on the queue and find which element will be
gone out from queue? 4M

You might also like