1
Noida Institute ofEngineering and Technology,
Greater Noida
Linked lists
Dr. Sarabjeet Kaur
NIET, Greater Noida.
Department of Electronics
and Communication
Engineering.
09/03/2025
Unit: 01
UNIT 1 DS Dr. Sarabjeet Kaur
Subject Name
Data Structures
(BEC0306)
Course Details
(B Tech 3rd Sem)
2.
09/03/2025 2
• Linkedlists: Comparison of Array, List and Linked list
• Types of linked list: Singly Linked List, Doubly Linked List,
Circular Linked List
• PolynomialRepresentation and Addition of Polynomials
Content
UNIT 1 DS Dr. Sarabjeet Kaur
3.
• Introduction tobasic data structures.
• To know about the basic properties of different data structures.
• Classification and operations on data structure
• Understand algorithms and their efficiency
• Study logical and mathematical description of array and link list.
• Implementation of array and link list on computer.
• Differentiate the usage of array and link list in different scenarios.
09/03/2025
UNIT 1 DS Dr. Sarabjeet Kaur
3
Course Objective
4.
• Linked List
•Doubly Linked List
• Circularly Linked List
• Circularly Doubly Linked List
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 4
Basic Terminology(CO1)
5.
• To understandlinked list and the operations of linked list.
• To implement Linked list program using C
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 5
Topic Objective
6.
• Linked Listcan be defined as collection of objects called nodes that
are randomly stored in the memory.
• A node contains two fields i.e. data stored at that particular address
and the pointer which contains the address of the next node in the
memory.
• The last node of the list contains pointer to the null.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 6
Linked List
7.
• A linkedlist is a linear data structure.
• Nodes make up linked lists.
• Nodes are structures made up of data and a pointer to another
node.
• Usually the pointer is called next.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 7
Linked List
8.
Linked
List
• The elementsof a linked list are not stored in adjacent memory
locations as in arrays.
• It is a linear collection of data elements, called nodes, where the
linear order is implemented by means of pointers.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 8
Introduction to Linked List
9.
Linked
List
• In alinear or single-linked list, a node is connected to the next node by a
single link.
• A node in this type of linked list contains two types of fields
• data: which holds a list element
• next: which stores a link (i.e. pointer) to the next node in the list.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 9
Continued….
10.
• Linked listcan be visualized as a chain of nodes, where every node
points to the next node.
• As per the above illustration, following are the important points to
be considered.
– Linked List contains a link element called first.
– Each link carries a data field(s) and a link field called next.
– Each link is linked with its next link using its next link.
– Last link carries a link as null to mark the end of the list.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 10
Linked List Representation
11.
• The nodesin a linked list are not stored contiguously in the memory
• You don’t have to shift any element in the list
• Memory for each node can be allocated dynamically whenever the need
arises.
• The size of a linked list can grow or shrink dynamically
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 11
Properties of linked list
12.
• Following arethe basic operations supported by a list.
– Insertion − Adds an element at the beginning of the list.
– Deletion − Deletes an element at the beginning of the list.
– Display − Displays the complete list.
– Search − Searches an element using the given key.
– Delete − Deletes an element using the given key.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 12
Basic Operations on Linked List
13.
Arrays Linked list
Fixedsize: Resizing is expensive Dynamic size
Insertions and Deletions are inefficient:
Elements are usually shifted
Insertions and Deletions are efficient: No
shifting
Random access i.e., efficient indexing No random access
Not suitable for operations requiring accessing
elements by index such as sorting
No memory waste if the array is full or almost full;
otherwise may result in much memory waste.
Since memory is allocated dynamically(acc. to our need)
there is no waste of memory.
Sequential access is faster [Reason: Elements in
contiguous memory locations]
Sequential access is slow [Reason: Elements not in
contiguous memory locations]
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 13
Arrays & Linked list
14.
• Following arethe various types of linked list.
– Singly Linked List − Item navigation is forward only.
– Doubly Linked List − Items can be navigated forward and
backward.
– Circular Linked List − Last item contains link of the first element
as next
– Circular Doubly Linked List − Last item contains link of the first
element as next and the first element has a link to the last
element as previous. Items can be navigated forward and
backward.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 14
Types of Link List
15.
• A singlylinked list is a dynamic data structure which may grow or
shrink, and growing and shrinking depends on the operation made.
• In this type of linked list each node contains two fields one is data
field which is used to store the data items and another is next field
that is used to point the next node in the list.
5 3 8 null
next next next
data data data
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 15
Singly Linked list
16.
• There arethree possible positions where we can enter a new node
in a linked list –
– Insertion at beginning
– Insertion at end
– Insertion at given position
• Adding a new node in linked list is a more than one step activity.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 16
Insertion in a Single Linked List
17.
• Insertion atbeginning
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 17
Insertion in a Single Linked List (at beginning)
18.
• Insertion atend
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 18
Insertion in a Single Linked List (at end)
Temp
19.
• Insertion atgiven position
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 19
Insertion in a Single Linked List
(at given position)
20.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 20
Creating a node of linked list
Algorithm: Creating a Node of Linked List
1.Start
2.Create a structure NODE with two fields:
•INFO (to store data)
•LINK (to store address of next node)
3.Allocate memory for the new node.
4.Read the data item into INFO of new node.
5.Set LINK of new node := NULL.
6.If START = NULL, then
•Set START := new node.
Else
•Set PTR := START.
•Repeat while LINK[PTR] != NULL
•Set PTR := LINK[PTR].
•Set LINK[PTR] := new node.
7.Exit
21.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 21
Insertion at Beginning and End of Linked List
Algorithm: Insertion at Beginning of Linked List
1.Start
2.Create a new node NEW.
3.Read data into INFO[NEW].
4.Set LINK[NEW] := START.
5.Set START := NEW.
6.Exit
Algorithm: Insertion at End of Linked List
1.Start
2.Create a new node NEW.
3.Read data into INFO[NEW].
4.Set LINK[NEW] := NULL.
5.If START = NULL, then
•Set START := NEW.
•Exit
6.Else
•Set PTR := START.
•Repeat while LINK[PTR] != NULL
•Set PTR := LINK[PTR].
•Set LINK[PTR] := NEW.
7.Exit
OR
22.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 22
Insertion at a Given Position in a Singly Linked List
Algorithm: Insertion at a Given Position in a Singly Linked List
1.Start
2.Create a new node NEW.
3.Read data into INFO[NEW].
4.Read the position POS where the node is to be inserted.
5.If POS = 1, then
•Set LINK[NEW] := START.
•Set START := NEW.
•Exit
6.Else
OR
23.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 23
Insertion at a Given Position in a Singly Linked List
Explanation: Insertion at a Given Position in a Singly Linked List
1.Create a new node → A fresh node is made to hold the data and link.
2.Read data → Store the value to be inserted in the node’s INFO field.
3.Read position (POS) → The place in the list where the new node should go.
24.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 24
Insertion at a Given Position in a Singly Linked List
Case 1: Insert at Beginning (POS = 1)
•Make the new node point to the current first node (LINK[NEW] = START).
•Update START so that it points to the new node.
Case 2: Insert at Middle or End (POS > 1)
•Use a pointer PTR to traverse the list.
•Move PTR forward until it reaches the node just before the desired position.
•If the list ends before reaching that position → it means the position is invalid.
Linking the New Node
•Make the new node point to the node that comes after PTR (LINK[NEW] = LINK[PTR]).
•Make PTR point to the new node (LINK[PTR] = NEW).
Now the new node is inserted in the correct place.
25.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 25
Insertion at a Given Position in a Singly Linked List
Start
1.Create a new node NEW.
•Read data into NEW->INFO.
•Set NEW->LINK = NULL.
1. Insertion at Beginning
•Set NEW->LINK = START.
•Set START = NEW.
2. Insertion at End
•If START = NULL, then START = NEW.
•Else
•Set PTR = START.
•Move while PTR->LINK != NULL.
•Set PTR->LINK = NEW.
3. Insertion at Given Position (POS)
•If POS = 1, same as beginning case.
•Else
•Set PTR = START.
•Repeat until position – 1.
•Set NEW->LINK = PTR->LINK.
•Set PTR->LINK = NEW.
Stop
26.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 26
Creation and Traversal of single linked list
Algorithm: Traversal of a Singly Linked List
1.Start
2.If START = NULL, then
•Print “List is empty”
•Exit
3.Set PTR := START
4.Repeat while PTR != NULL
•Apply PROCESS(INFO[PTR]) (e.g., print
data)
•Set PTR := LINK[PTR]
5.Exit
Explanation
Start from the first node (START).
Move one node at a time using the link (PTR = PTR->next).
At each step, process the data (like printing).
Stop when the pointer becomes NULL (end of list).
Visit every node from START to end, processing data of
each node.
27.
• There arethree possible positions from where we can delete a node
in a linked list –
– Deletion at beginning
– Deletion at end
– Deletion from given position
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 27
Deletion in a Single Linked List
28.
• Deletion frombeginning
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 28
Deletion in Single Linked List (from beginning)
29.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 29
Deletion in Single Linked List (from beginning)
Algorithm: Deletion from Beginning of Singly Linked List
1.Start
2.If START = NULL, then
•Print “List is empty”
•Exit
3.Set PTR := START
4.Set START := LINK[PTR]
5.Free PTR (release the deleted node’s memory)
6.Exit
In short: Check if list empty → move START to next node → delete old first node.
30.
• Deletion fromend
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 30
Deletion in Single Linked List (from end)
31.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 31
Deletion in Single Linked List (from end)
Algorithm: Deletion from End of Singly Linked List
1.Start
2.If START = NULL, then
•Print “List is empty”
•Exit
3.If LINK[START] = NULL, then
•Free START
•Set START := NULL
•Exit
4.Set PTR := START
5.Repeat while LINK[PTR]->LINK != NULL
•Set PTR := LINK[PTR]
(Now PTR will point to the second-last node)
6.Set TEMP := LINK[PTR] (last node)
7.Set LINK[PTR] := NULL
8.Free TEMP (delete last node)
9.Exit
In short:
•If empty → nothing to delete.
•If only one node → delete it, set START = NULL.
•Else → move to second-last node, unlink the
last node, free it.
32.
• Deletion fromposition
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 32
Deletion in Single Linked List (from position)
33.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 33
Deletion in Single Linked List (from position)
Algorithm: Deletion at Given Position
1.Start
2.If list empty → Exit
3.Read position POS
4.If POS = 1 →
•Delete first node (START = START->next)
5.Else →
•Move pointer to node just before POS
•Adjust links to skip the node
•Delete that node
6.Exit
34.
• The circularlinked list is a linked list where all nodes are connected to
form a circle. In a circular linked list, the first node and the last node
are connected to each other which forms a circle. There is no NULL at
the end.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 34
Singly Circular Linked list
35.
• There arethree possible positions where we can enter a new node
in a Single Circular linked list –
– Insertion at beginning
– Insertion at end
– Insertion at given position
• Adding a new node in linked list is a more than one step activity.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 35
Insertion in a Single Circular Linked List
36.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 36
Insertion in a Single Circular Linked List
Start
1.Create a structure NODE with two fields:
•INFO → to store data
•LINK → to store address of next node
2.Allocate memory for the new node NEW.
3.Read the data item into INFO[NEW].
4.Set LINK[NEW] := NULL Case 1: Insertion at Beginning (POS = 1)
5.If (START = NULL) then
•Set START := NEW.
•Set LINK[NEW] := START.
6.Else
•Traverse to the last node using pointer PTR such that
LINK[PTR] = START.
•Set LINK[NEW] := START.
•Set LINK[PTR] := NEW.
•Set START := NEW.
37.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 37
Insertion in a Single Circular Linked List
Case 2: Insertion at End (POS = N+1)
7.If (START = NULL) then
•Set START := NEW.
•Set LINK[NEW] := START.
8.Else
•Traverse to the last node using pointer PTR
such that LINK[PTR] = START.
•Set LINK[PTR] := NEW.
•Set LINK[NEW] := START.
Case 3: Insertion at Given Position (1 < POS ≤
N)
9.Traverse to the node just before position POS
using pointer PTR.
10.Set LINK[NEW] := LINK[PTR].
11.Set LINK[PTR] := NEW.
38.
• There arethree possible positions where we can enter a new node
in a linked list –
– Deletion at beginning
– Deletion at end
– Deletion from given position
– Deletion_by_value
• Deleting new node in linked list is a more than one step activity.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 38
Deletion in a Single Circular Linked List
39.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 39
Deletion in Single Circular Linked List (by value)
Start
1.If START = NULL → print "List Empty" → Stop.
1. Deletion at Beginning
•Let PTR = START.
•If only one node (START->NEXT == START)
→ Free START, set START = NULL.
•Else
•Move LAST = START until LAST->NEXT == START.
•Set START = START->NEXT.
•Set LAST->NEXT = START.
•Free PTR.
Let PTR = START.
•A temporary pointer PTR is set to the first node.
If only one node (START NEXT == START)
→
•In a circular linked list, if there is only one node, then
its NEXT will point back to itself (because it is both the
first and last node).
•So the condition START NEXT == START means
→ only
one node exists in the list.
Free START, set START = NULL.
•If only one node is present, deleting that node makes
the list empty.
•So we release (free) that node and set START = NULL.
•LAST = START Initialize a pointer LAST to the
→
first node.
•Repeat: Move LAST = LAST NEXT (keep moving
→
forward).
•Stop when LAST NEXT == START
→ This
→
means you have reached the last node (because
the next of the last node always points back to
the first).
40.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 40
Deletion in Single Circular Linked List (by value)
2. Deletion at End
•If only one node → same as above (set START = NULL).
•Else
•Set PTR = START.
•Repeat until PTR->NEXT->NEXT == START (second last node).
•Set TEMP = PTR->NEXT (last node).
•Set PTR->NEXT = START.
•Free TEMP.
41.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 41
Deletion in Single Circular Linked List (from end)
3. Deletion at Given Position (POS)
•If POS = 1 → follow Deletion at Beginning.
•Else
•Set PTR = START.
•Repeat for i = 1 to POS-1:
→ PREV = PTR
→ PTR = PTR->NEXT
•If PTR == START → print "Invalid Position".
•Else
•PREV->NEXT = PTR->NEXT.
•Free PTR.
4. Deletion by Value (VAL)
•If START->INFO == VAL → follow Deletion at
Beginning.
•Else
•Set PTR = START.
•Repeat until PTR->NEXT == START and PTR-
>NEXT->INFO != VAL.
•If node not found → print "Value not found".
•Else
•Set TEMP = PTR->NEXT.
•PTR->NEXT = TEMP->NEXT.
•Free TEMP.
Stop
42.
• Doubly linkedlist is a complex type of linked list in which a node
contains a pointer to the previous as well as the next node in the
sequence.
• Therefore, in a doubly linked list, a node consists of three parts:
node data, pointer to the next node in sequence (next pointer) ,
pointer to the previous node (previous pointer).
• A sample node in a doubly linked list is shown in the figure.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 42
Doubly Linked List
43.
A doubly linkedlist containing three nodes is shown in the following
image.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 43
Doubly Linked List
44.
• Insertion atthe Beginning of Doubly Linked List
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 44
Insertion at the Beginning Linked List
45.
• Insertion atthe end of Doubly Linked List
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 45
Insertion at the end of Doubly Linked List
46.
• Insertion atgiven position in Doubly Linked List
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 46
Insertion in Doubly Linked List (at position)
47.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 47
Creating a Node of Doubly Linked List
In a DLL, insertion can happen at three places:
•At the beginning
•At the end
•At a given position
48.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 48
Creating a Doubly linked list with single node
Algorithm: Insertion in Doubly Linked
List
Step 1: Start
Step 2: Create a new node NEW with fields:
•INFO[NEW] ← data value
•LEFT[NEW] ← NULL
•RIGHT[NEW] ← NULL
Case 1: Insertion at Beginning
1.If START = NULL
→ Set START = NEW.
2.Else
→ Set RIGHT[NEW] = START
→ Set LEFT[START] = NEW
→ Set START = NEW
Notation used:
•START → Pointer to first node
•NEW → New node
•INFO → Data field of a node
•LEFT → Pointer to previous node
•RIGHT → Pointer to next node
•PTR → Temporary pointer
•POS → Position
49.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 49
Creation and Traversal of Doubly linked list
Case 2: Insertion at End
1.If START = NULL
→ Set START = NEW.
2.Else
→ Set PTR = START
→ Repeat while RIGHT[PTR] ≠ NULL
PTR = RIGHT[PTR]
→ Set RIGHT[PTR] = NEW
→ Set LEFT[NEW] = PTR
Case 3: Insertion at a Given Position (POS)
1.Read the position POS.
2.If POS = 1, perform insertion at beginning.
3.Else
•Set PTR = START
•Repeat POS - 1 times: PTR = RIGHT[PTR]
•Set RIGHT[NEW] = RIGHT[PTR]
•If RIGHT[PTR] ≠ NULL, then LEFT[RIGHT[PTR]] =
NEW
•Set LEFT[NEW] = PTR
•Set RIGHT[PTR] = NEW
50.
• Similar tosingle linked list there are three possible positions where
we can enter a new node in a doubly linked list –
– Deletion at beginning
– Deletion at end
– Deletion from given position
• Deleting new node in linked list is a more than one step activity.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 50
Deletion in a Doubly Linked List
51.
• Deletion frombeginning
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 51
Deletion in Doubly Linked List (from beginning)
52.
• Deletion fromend
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 52
Deletion in Doubly Linked List (from end)
53.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 53
Deletion in Doubly Linked List (from end)
• Deletion from given position
54.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 54
Deletion in Doubly Linked List (from position)
Step 1: START
Step 2: IF (START = NULL) THEN
PRINT "List is empty – No element to
delete"
EXIT
ENDIF
Case 1: Delete from Beginning
Step 3: IF (POS = 1) THEN
PTR ← START
START ← RIGHT[START]
IF (START ≠ NULL) THEN
LEFT[START] ← NULL
ENDIF
FREE PTR
Case 2: Delete from End
Step 4: ELSE IF (POS = LAST) THEN
PTR ← START
WHILE (RIGHT[PTR] ≠ NULL) DO
PTR ← RIGHT[PTR]
ENDWHILE
RIGHT[LEFT[PTR]] ← NULL
FREE PTR
55.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 55
Deletion in Doubly Linked List (from position)
Case 3: Delete from Given Position
Step 5: ELSE
PTR ← START
FOR i ← 1 TO POS-1 DO
PTR ← RIGHT[PTR]
ENDFOR
RIGHT[LEFT[PTR]] ← RIGHT[PTR]
IF (RIGHT[PTR] ≠ NULL) THEN
LEFT[RIGHT[PTR]] ← LEFT[PTR]
ENDIF
FREE PTR
56.
Linked Representation ofSparse Matrix
In linked list, each node has four fields. These four fields are defined as:
• Row: Index of row, where non-zero element is located
• Column: Index of column, where non-zero element is located
• Value: Value of the non zero element located at index – (row , column)
• Next node: Address of the next node
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 56
Introduction to Link List(CO1)
57.
Polynomials
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 57
Polynomial Representation
Polynomials are the algebraic expressions which consist of
exponents and coefficients.
Example -
10x2
+ 26x, here 10 and 26 are coefficients and 2, 1 is its exponential value.
Polynomial can be represented in the various ways. These are:
•By the use of arrays
•By the use of Linked List
58.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 58
Polynomial Representation
Polynomial can be represented
•By the use of arrays
•By the use of Linked List
•This is whyarrays aren’t good to
represent polynomials:
•p3(x) = 16x21 - 3x5 + 2x + 6
6 2 0 0 -3 0 ………… 0 16
WASTE OF
SPACE!
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 60
Polynomial (Array Representation)
61.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 61
Add Two Polynomials Using Arrays
Input: A[] = {5, 0, 10, 6} B[] = {1, 2, 4}
Output: sum[] = {6, 2, 14, 6}
The first input array represents "5 + 0x^1 + 10x^2 + 6x^3“
The second array represents "1 + 2x^1 + 4x^2"
And Output is "6 + 2x^1 + 14x^2 + 6x^3“
62.
• Advantages ofusing an Array:
• Only good for non-sparse polynomials.
• Ease of storage and retrieval.
• Disadvantages of using an Array:
• Have to allocate array size priorly.
• Huge array size required for sparse polynomials.
Waste of space and runtime.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 62
Polynomial (Array Representation)
63.
• A polynomialp(x) is the expression in variable x which is in the form
(axn
+ bxn-1
+ …. + jx+ k), where a, b, c …., k fall in the category of real
numbers and 'n' is non negative integer, which is called the degree of
polynomial.
• An essential characteristic of the polynomial is that each term in the
polynomial expression consists of two parts:
– one is the coefficient
– other is the exponent
• Example:
– 10x2
+ 26x,
• here 10 and 26 are coefficients and 2, 1 is its exponential value.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 63
Polynomial Representation (using Linked List)
64.
• Points tokeep in Mind while working with Polynomials:
• The sign of each coefficient and exponent is stored within the
coefficient and the exponent itself
• Additional terms having equal exponent is possible one
• The storage allocation for each term in the polynomial must be
done in ascending and descending order of their exponent
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 64
Polynomial Representation (using Linked List)
65.
• Addition ofpolynomial
1) Input: 1st number = 5x2
+ 4x1
+ 2x0
2nd number = -5x1
- 5x0
Output: 5x2
-1x1
-3x0
2) Input: 1st number = 5x3
+ 4x2
+ 2x0
2nd number = 5x^1 - 5x^0
Output: 5x3
+ 4x2
+ 5x1
- 3x0
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 65
Polynomial Representation (using Linked List)
66.
Subtraction of polynomial
Input:1st number = 5x2
+ 4x1
+ 2x0
2nd number = -5x1
- 5x0
Output: 5x2
+ 9x1
+ 7x0
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 66
Polynomial Representation (using Linked List)
• Which ofthe following is not a disadvantage to the usage of array?
a) Fixed size
b) There are chances of wastage of memory space if elements inserted in an
array are lesser than the allocated size
c) Insertion based on position
d) Accessing elements at specified positions
• What is the time complexity to count the number of elements in the
linked list?
a) O(1)
b) O(n)
c) O(logn)
d) O(n2)
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 68
Daily Quiz
69.
• What isthe space complexity for deleting a linked list?
a) O(1)
b) O(n)
c) Either O(1) or O(n)
d) O(logn)
• What differentiates a circular linked list from a normal linked list?
a) You cannot have the ‘next’ pointer point to null in a circular linked list
b) It is faster to traverse the circular linked list
c) You may or may not have the ‘next’ pointer point to null in a circular
linked list
d) Head node is known in circular linked list
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 69
Daily Quiz
70.
• Define datastructure and explain types of data structure with
suitable examples
• What are the primitive operations in any data structure
• Explain the asymptotic notations with suitable examples
• Differentiate between space and time complexity of an algorithm
• Write an algorithm for merging two already sorted arrays
• Write an algorithm/program for insert a node at between any
position of a linked list
• Write an algorithm/program to reverse a linked list
• Write an algorithm/program to sort two linked lists
• Write an algorithm/program to add two polynomials by using linked
list
• what are the applications of a single linked list, doubly linked list
and circular linked list
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 70
Weekly Assignment
71.
• Which ofthese best describes an array?
a) A data structure that shows a hierarchical behaviour
b) Container of objects of similar types
c) Arrays are immutable once initialised
d) Array is not a data structure
• How do you initialize an array in C?
a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 71
MCQ s
72.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 72
MCQ s
In the worst case, the number of comparisons needed to search a singly linked
list of length n for a given element is (GATE CS 2002)
A log 2 n
B n/2
C log 2 n – 1
D n
You are given pointers to first and last nodes of a singly linked list, which of the
following operations are dependent on the length of the linked list?
A Delete the first element
B Insert a new element as a first element
C Delete the last element of the list
D Add a new element at the end of the list
73.
• What arethe advantages of arrays?
a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type
• Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 73
MCQ s
74.
• In linkedlist each node contain minimum of two fields. One field is
data field to store the data second field is?
A. Pointer to character
B. Pointer to integer
C. Pointer to node
D. Node
• Linked list data structure offers considerable saving in
A. Computational Time
B. Space Utilization
C. Space Utilization and Computational Time
D. None of the mentioned
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 74
MCQ s
75.
Glossary Question
i. Linkedlist ii. Abstract Data type iii.Asymptotic Analysis iv. Linear
order
Answer the questions.
a. Another term for total order.
b. A process followed to solve a problem.
c. The specification of a data type with some language.
d. Dynamic allocation of link nodes to store the list of elements.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 75
• What isdoubly linked list? What are its applications? Explain how
an element can be deleted from doubly linked list using C program.
• What are the merits and demerits of array? Given two arrays of
integers in ascending order, develop an algorithm to merge these
arrays to form a third array sorted in ascending order.
• How can you represent a sparse matrix in memory?
• List the various operations on linked list.
• What do you understand by time and space trade off?
• Define the various asymptotic notations. Derive the O-notation for
linear search.
• Write a program in c to delete a specific element in single linked list.
Double linked list takes more space than single linked list for storing
one extra address. Under what condition, could a double linked list
more beneficial than single linked list.
09/03/2025 UNIT 1 DS Dr. Sarabjeet Kaur 82
Expected Questions for University Exam
83.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 83
Summary
We consider two fundamental data types for storing collections of
objects: the stack and the queue.
We implement each using either a singly-linked list or a resizing
array.
We introduce two advanced Java features—generics and iterators
—that simplify client code.
Finally, we consider various applications of stacks and queues
ranging from parsing arithmetic expressions to simulating
queueing systems.
84.
09/03/2025 UNIT 1DS Dr. Sarabjeet Kaur 84
References
• Aaron M. Tenenbaum, Yedidyah Langsam and Moshe J. Augenstein,
“Data Structures Using C and C++”, PHI Learning Private Limited,
Delhi India
• Horowitz and Sahani, “Fundamentals of Data Structures”, Galgotia
Publications Pvt Ltd Delhi India.
• Lipschutz, “Data Structures” Schaum’s Outline Series, Tata McGraw-
hill Education (India) Pvt. Ltd.
• Thareja, “Data Structure Using C” Oxford Higher Education.
• AK Sharma, “Data Structure Using C”, Pearson Education India.
• Michael T. Goodrich, Roberto Tamassia, David M. Mount “Data
Structures and Algorithms in C++”, Wiley India.
• . P. S. Deshpandey, “C and Data structure”, Wiley Dreamtech
Publication.