0% found this document useful (0 votes)
47 views14 pages

UNIT-IV Linked List

Uploaded by

lightb812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views14 pages

UNIT-IV Linked List

Uploaded by

lightb812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

DATA STRUCTURE IMPORTANT

QUESTIONS LIST WITH ANSWERS

Author:

“Prof. Vishal Jadhav”


[BE in Computer Engineering and Having 8.5 years of IT industry experience.
VJTech Academy, Awasari(KH), Contact No: +91-9730087674 / 7743909870
Email id: [email protected])]

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 1
 UNIT-IV : Linked List: Total Marks: 16

1. Describe any two terms from the following: Node, Null pointer, empty list with respect to
linear linked list with diagram.
Node:
 A linked list is a linear data structure where each element is a separate object.
 Each element is called as a node of a linked list.
 Every node consists of two fields, first is data and second is address of next node.

Null pointer:

 It is used to specify the end of the list.


 The last element of list contains NULL pointer to specify end of list.

Empty list:

 A linked list is said to be empty if head node contains NULL pointer. i.e. head=NULL.

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 2
2. Describe any two terms from the following: information Field/ Data field, Address, Next
Pointer with respect to circular linked list with diagram.

information Field/ Data field:

 It is used to store the data inside the node.

Next Pointer:

 It is used to store the address of next node.

Address:

 In CLL, every node consists of two fields, first is data and second is address.
 Address field contain the memory address of next node.

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 3
3. List and define operations of linked list.
The basic operations that can be performed on a list are:
1. Creation: This operation is used to create a node in the linked list.
2. Insertion: This operation is used to insert a new node in the linked list.
● Inser ng node at the beginning of the list.
● Inser ng node at the middle of the list.
● Inser ng node at the end of the list.

3. Deletion: This operation is used to delete node from the linked list.
● Dele ng node from the beginning of the list.
● Dele ng node from the middle of the list.
● Dele ng node from the end of the list.

4. Traversing: It is a process of going through all the nodes of a linked list from one end to the
other end.

5. Display: This operation is used to print all nodes information field.

6. Searching: To search a specific element in given linked list.

7. Count: To count number of nodes present in list.

8. Concatenation: Concatenating two linked lists.

9. Sorting: Sorting of an elements stored in a linked list.

10. Separating a linked list in two linked lists.

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 4
4. Write algorithm for ‘search’ operation in an unsorted linked list.
● Algorithm:

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 5
5. WAP to search an element in a linked list.

void search(node *p)


{
int key,flag=0;
printf("\nEnter Key Node for Searching:");
scanf("%d",&key);
while(p!=NULL)
{
if(key==p->data)
{
flag=1;
break;
}
p=p->next;
}
if(flag==1)
{
printf("\nNode is present in given SLL");
}
else
{
printf("\nNode is not present in given SLL");
}
}

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 6
6. Explain insertion at the beginning and at end operations on linked list with example.
 In a single linked list, the insertion operation can be performed in three ways.
 They are as follows.
1. Inserting at Beginning of the list
2. Inserting at End of the list
3. Inserting at Middle of the list
Inserting At Beginning of the list:
 In this operation, new node can be created and added at the beginning of a list.
 New node points to existing first node and after that make new node as head node
 In this operation, first we create new node q and assign value to data and next field.
 Assign head to next field of q node.
 At last, make q node as head node.

Inserting At End of the list:

 In this operation, new node can be created and added at the end of a list.
 In this operation, first we create new node q and assign value to data and next field.
 Then we assign head to pointer p and traverse pointer p to last node.
 At last make the link between p and q.

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 7
7. Write a ‘C’ program to insert new node at the end of linear linked list.
node* Insert_At_End(node *head)
{
if(head==NULL)
{
printf("\nLinked list is Empty hence unable to insert node at end");
}
else
{
node *q,*p;
int x;
printf("\nEnter Data for insertion:");
scanf("%d",&x);
q=(node*)malloc(sizeof(node));
q->data=x;
q->next=NULL;
p=head;
while(p->next!=NULL)
{
p=p->next;
}
//insert node at end
p->next=q;
return(head);
}
}

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 8
8. Write algorithm to delete an intermediate node from a Singly Linked List.

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 9
9. Write an algorithm to insert a new node as the last of a singly linked list. Give example.
In this operation, new node can be created and added at the end of a list.
Algorithm:
1. Start
2. Allocates memory for the new node q.
q=(node*)malloc(sizeof(node));
3. Assign data to the data field and NULL to the next field of the new node q.
q->data=x;
q->next=NULL;
4. Check whether linked list is Empty if (head is ‘NULL’) then
print “Linked list is empty” and goto step 7
5. Otherwise initialize p with head and keep moving the p to its next node until it
reaches to the last node in the list
p=head
while(p->next !=NULL)
p=p->next;

6. Make link between last node and new node. p->next=q;

7. Stop

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 10
10. Write an algorithm to traverse a singly linked list.

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 11
11. Write an algorithm to count no of nodes in the singly linked list.

12. Create a Singly Linked List using data fields 10, 20, 30, 40, 50 and show procedure step-by step
with the help of diagram from start to end.
13. Create a Singly Linked List using data fields 10, 20, 30, 40, 50. Search a node 40 from the SLL and
show procedure step-by-step with the help of diagram from start to end.

14. Describe advantage of circular linked list over linear linked list with example.

Advantages of Circular Linked Lists:

 It is possible to traverse from the last node back to the first i.e. the head node.
 The starting node does not matter as we can traverse each and every node
 The previous node can be easily identified.
 No requirement for a NULL assignment in the code. The circular list never points
to a NULL pointer unless fully deallocated.
 Circular linked list also performs all regular functions of a singly linked list.
 Circular linked lists are advantageous for end operations since beginning and end
coincide.

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 12
15. With example, describe how circular linked list works when a node is deleted from beginning
of list
In this operation, first node is deleted from the linked list.
● Algorithm:
1. Start
2. Create temporary node pointer variable q & p.
3. Check whether linked list is Empty. i.e if (head = = NULL) then
Display 'List is Empty,Deletion is not possible' and goto step 7.
4. Assign address of first node head to p i.e p=head.
5. Move the p node to next node until it reaches to the last node. i.e
while(p->next!=head)
{
p=p->next;
}
6. Set q=head, head=head->next, p->next=head and delete q node.
7. Stop

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 13
16. Difference between Array and Linked List:

17. Define Linked List


Definition:
 Linked list is used to represent linear data structure.
 Linked list is a collection of nodes, every node consists of two fields.
1. Data field - It contains information of data element.
2. Next field - It is a pointer variable which contains address of next node. Data Next Fig.
Single Node structure

 There are four types of linked list:


1. Singly Linked List
2. Circular Linked List
3. Doubly Linked List
4. Doubly Circular Linked List.

DS IMP Questions by Mr. Vishal Jadhav Sir’s (VJTech Academy, contact us: +91-9730087674) 14

You might also like