DS Unit1
DS Unit1
DATA STRUCTURE/BCS-301
Topic:
INTRODUCTION TO DATA STRUCTURE
INSTRUCTOR NAME
Definition:
• A data structure is a way of organizing and storing data in a computer so that it can be accessed
and used efficiently.
• Key Characteristics:
• Fixed Size
• Indexed Access
• Homogeneous Elements
Algorithm:
• An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain
predefined task.
• Every Algorithm must satisfy the following properties:
• Input- There should be 0 or more inputs supplied externally to the algorithm.
• Output- There should be at least 1 output obtained.
• Definiteness- Every step of the algorithm should be clear and well-defined.
• Finiteness- The algorithm should have a finite number of steps.
• Correctness- Every step of the algorithm must generate a correct output.
Algorithm:
• Key Characteristics of an Algorithm:
• Unambiguous − The algorithm should be unambiguous. Each of its steps (or phases), and
their inputs/outputs should be clear and must lead to only one meaning.
• Input − An algorithm should have 0 or more well-defined inputs.
• Output − An algorithm should have 1 or more well-defined outputs, and should match the
desired output.
• Finiteness − Algorithms must terminate after a finite number of steps.
• Independent − An algorithm should have step-by-step directions, which should be
independent of any programming code
Algorithm:
• Example:
} }
Algorithm:
• Efficiency of Algorithm:
• An algorithm is said to be efficient and fast if it takes less time to execute and
consumes less memory space
• To compare algorithms, we must have some criteria to measure the efficiency of
our algorithms
• The performance of an algorithm is measured based on the following properties :
• Time Complexity
• Space Complexity
Algorithm:
• Time complexity
• Time Complexity is a way to represent the amount of time required by the program to run
till its completion.
• It's generally a good practice to try to keep the time required minimum so that our
algorithm completes its execution in the minimum time possible.
• Space complexity
• It is the amount of memory space required by the algorithm, during the course of its
execution.
• An algorithm generally requires space for the following components
• Instruction Space
• Data Space
• Environment Space
Algorithm:
• Asymptotic Notations: Asymptotic notations are mathematical tools used to describe the
behavior of algorithms as the input size grows, specifically in terms of time and space
complexity. They provide a high-level understanding of an algorithm's efficiency.
Algorithm:
• Asymptotic Notations: Asymptotic notations are mathematical tools used to describe the
behavior of algorithms as the input size grows, specifically in terms of time and space
complexity. They provide a high-level understanding of an algorithm's efficiency.
Algorithm:
• Asymptotic Notations:
• Following are the commonly used asymptotic notations to calculate the running time
complexity of an algorithm:-
• Ο Notation (Big Oh Notation)
• Ω Notation (Omega Notation)
• θ Notation (Theta Notation)
Algorithm:
• Asymptotic Notations:
• Big O Notation (O): Represents the upper bound of an algorithm’s running time, providing
the worst-case scenario.
• k=n0
• For example, for a function f(n)
• Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. }
Algorithm:
• Asymptotic Notations:
• Omega Notation (Ω): Represents the lower bound of an algorithm’s running time,
providing the best-case scenario.
• k=n0
• For example, for a function f(n)
• Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n > n0. }
Algorithm:
• Asymptotic Notations:
• Theta Notation (Θ): The notation θ(n) is the formal way to express both the lower bound
and the upper bound of an algorithm's running time.
• k=n0
• For example, for a function f(n)
• θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n > n0. }
Algorithm:
• Asymptotic Notations:
• Common Asymptotic Notations:
Algorithm:
• Asymptotic Notations:
• Time-space trade-off :
• Most computers have a large amount of space, but not infinite space.
• Also, most people are willing to wait a little while for a big calculation, but not forever.
• So if some problem is taking a long time but not much memory, a space-time trade-off
would let you use more memory and solve the problem more quickly.
• Or, if it could be solved very quickly but requires more memory than you have, you can
try to spend more time solving the problem in the limited memory.
Array
• Array: An array is a collection of elements, all of the same data type, stored in contiguous
memory locations. Arrays allow efficient indexing and retrieval of data.
• Key Characteristics:
• Fixed Size
• Indexed Access
• Homogeneous Elements
• Types of Array:-
Array
• Single Dimensional Array:-
• The general form for declaring a single-dimension array is:
• datatype var_name[size];
• Here, datatype declares the base type of the array, which is the type of each
element in the array
• size defines how many elements the array will hold
• For Example:-
Array
• Multi Dimensional Array:-
• A multidimensional array is an array of arrays.
• It is useful when you want to store data as a tabular form, like a table with rows and
columns.
• For example:- float x[3][4];
• Here, x is a two-dimensional (2d) array. The array can hold 12 elements. You can think
the array as a table with 3 rows and each row has 4 columns as shown in figure.
Array
• Representation of Arrays:-
• A 2D array’s elements are stored in continuous memory locations.
• It can be represented in memory using any of the following two ways:
• Row-Major Order
• Column-Major Order
Array
• Representation of Arrays:-
• Row-Major Order:- Row Major Order is a method of representing a multi-dimension
array in sequential memory.
• In this method elements of an array are arranged sequentially row by row.
• Thus elements of the first row occupy the first set of memory locations reserved for
the array, elements of the second row occupy the next set of memory, and so on.
Array
• Representation of Arrays:-
• Row-Major Order:-
• Consider a Two Dimensional Array consisting of N rows and M columns. It can be
stored sequentially in memory row by row as shown below:
Array
• Representation of Arrays:-
• Row-Major Order:-
• Example: Consider the following example in which a two-dimensional array consisting
of two rows and four columns is stored sequentially in row-major order:
Array
• Representation of Arrays:-
• Row-Major Order:-
• The Location of element A[i, j] can be obtained by evaluating the expression:
• LOC (A [I, j]) = Base_Address + W [M (i-L1) + (j-L2)]
• Here,
• Base_Address is the address of the first element in the array.
• W is the word size. It means several bytes occupied by each element.
• N is the number of rows in an array.
• M is the number of columns in the array.
• L1 is the lower bound of the row.
• L2 is the lower bound of the column.
Array
• Representation of Arrays:-
• Row-Major Order:-
• Suppose we want to calculate the address of element A [1, 2].
• It can be calculated as follow:
• Here,
• Base_Address = 2000, W= 2, M=4, N=2, i=1, j=2
• LOC (A [i, j])=Base_Address + W [M (i-L1) + (j-L2)]
• LOC (A[1, 2])=2000 + 2 *[4*(1) + 2]
=2000 + 2 * [4 + 2]
=2000 + 2 * 6
=2000 + 12
=2012
Array
• Representation of Arrays:-
• Column-Major Order:- Column Major Order is a method of representing multidimensional
arrays in sequential memory.
• In this method elements of an array are arranged sequentially column by column.
• Thus elements of the first column occupy first set of memory locations reserved for the
array, elements of second column occupies the next set of memory, and so on.
• Consider a Two Dimensional Array consisting of N rows and M columns. It can be stored
sequentially in memory column by column as shown below:
Array
• Representation of Arrays:-
• Column-Major Order:-
• Example: Consider the following example in which a two-dimensional array consisting
of two rows and four columns is stored sequentially in Column Major Order:
Array
• Representation of Arrays:-
• Column-Major Order:-
• The Location of element A[i, j] can be obtained by evaluating the expression:
• LOC (A [i, j]) = Base_Address + W [N (j-L2) + (i-L1)]
• Here,
• Base_Address is the address of the first element in the array.
• W is the word size. It means the number of bytes occupied by each
element.
• N is the number of rows in an array.
• M is the number of columns in an array.
• L1 is the lower bound of the row.
• L2 is the lower bound of the column.
Array
• Representation of Arrays:-
• Column-Major Order:-
• Suppose we want to calculate the address of element A [1, 2].
• It can be calculated as follows:
• Here, Base_Address = 2000, W= 2, M=4, N=2, i=1, j=2
• LOC (A [i, j])=Base_Address + W [N (j-L2) + (i-L1)]
• LOC (A[1, 2])=2000 + 2 *[2*(2) + 1]
=2000 + 2 * [4 + 1]
=2000 + 2 * 5
=2000 + 10
=2010
Array
• Application of Arrays:-
• Arrays are used to store a List of values
• Arrays are used to Perform Matrix Operations
• Arrays are used to implement Search Algorithms
• Linear search
• Binary search
• Arrays are used to implement Sorting Algorithms
• Insertion sort
• Selection sort
• Quick sort
• Arrays are used to implement Data Structures
• Stack using an array
• Queue using an array
• Arrays are also used to implement CPU Scheduling Algorithms
CREATED BY K. VICTOR BABU
Introduction to Array
Array
• Sparse Matrix:- A matrix is a two-dimensional data object made of m rows and n columns,
therefore having total m x n values. If most of the elements of the matrix have a value 0, then it
is called a sparse matrix.
• Why use a sparse matrix instead of a simple matrix?
• Storage: There are lesser non-zero elements than zeros and thus lesser memory can be
used to store only those elements.
• Computing time: Computing time can be saved by logically designing a data structure
traversing only non-zero elements..
• Example
0 0 3 0 4
0 0 5 7 0
0 0 0 0 0
0 2 6 0 0
Array
• Sparse Matrix Representation:-
• Representing a sparse matrix by a 2D array leads to the wastage of lots of memory as
zeroes in the matrix are of no use in most of cases. So, instead of storing zeroes with non-
zero elements, we only store non-zero elements. This means storing non-zero elements
with triples- (Row, Column, value).
• Sparse matrix representations can be done in many ways.
• The following are two common representations:
• Array representation
• Linked list representation
Array
• Sparse Matrix Representation:-
• Method 1: Using Arrays
• 2D array is used to represent a sparse matrix in which there are three rows named as
• Row: Index of the row, where the non-zero element is located
• Column: Index of the column, where the non-zero element is located
• Value: Value of the non-zero element located at index – (row, column)
Array
• Sparse Matrix Representation:-
• Method 2: Using Linked Lists
• In the linked list, each node has four fields. These four fields are defined as:
• Row: Index of the row, where the non-zero element is located
• Column: Index of the column, where the non-zero element is located
• Value: Value of the non-zero element located at index – (row, column)
• Next node: Address of the next node
Linked List
• Linked List: A linked list is a linear data structure consisting of nodes, where each node
contains a data element and a reference (or pointer) to the next node in the sequence.
• Key Characteristics:
• Dynamic Size
• Non-Contiguous Memory
Linked List
• Application of Linked Lists:
• Implementing Stacks and Queues.
• Dynamic Memory Allocation.
• Browser History and Undo Functionality.
• Graph Adjacency Lists.
• Representation of Sparse Matrices.
• Music Playlists.
Linked List
• Type of Linked List:
Linked List
• Type of Linked List:
• Singly Linked List:
• The first and most simple type of linked list is a singly linked list.
• The singly-linked list consists of nodes.
• Each node of the singly linked list consists of a data value and a pointer to the next
node.
• The first node of the singly linked list is called the head of the linked list.
• The last node of the singly linked list is called the linked list’s tail and points to null,
which indicates the end of the linked list.
Linked List
• Type of Linked List:
• Singly Linked List:
• A singly linked list is traversed only in one direction i.e., only unidirectional
traversal is possible in the singly linked list from the head to the last node or the
tail.
• The below image clearly explains what the singly linked list looks like:
Linked List
• Type of Linked List:
• Singly Linked List:
• The structure defined for a single linked list is implemented as follows:
• Here, an integer type variable ‘data’ which holds the elements and
• Another type ‘node’, which has next, which stores the address of the next node in
the list.
Linked List
• Type of Linked List:
• Operations Performed on Singly Linked List:
• Creation:
• This operation is used to create a linked list
• Insertion / Deletion:
• At/From the beginning of the linked list
• At/From the end of the linked list
• At/From the specified position in a linked list
• Traversing:
• Traversing may be either forward or backward
• Searching:
• Finding an element in a linked list
• Concatenation:
• The process of appending the second list to the end of the first list
Linked List
• Type of Linked List:
• Creating a Singly Linked List:
• The above statement obtains memory to store a node and assigns its address to the
head which is a pointer variable.
Linked List
• Singly Linked List:
• Creating a Node:-
• To create a new node, we use the malloc function to dynamically allocate
memory for the new node.
• After creating the node, we can store the new item in the node using a pointer
to that node.
Linked List
• Singly Linked List:
• Inserting an Element:-
• While inserting an element or a node in a linked list, we have to do the following things:-
• Allocate a node
• Assign data to the info field of the node.
• Adjust a pointer
Linked List
• Singly Linked List:
• Insert A Node At The Beginning Of The Singly Linked List:-
Linked List
• Singly Linked List:
• An algorithm to insert a node at the beginning of the singly linked list:-
Linked List
• Singly Linked List:
• An algorithm to insert a node at the end of the singly linked list:-
Linked List
• Singly Linked List:
• An algorithm to insert a node at the end of the singly linked list:-
Linked List
• Singly Linked List:
• An example to insert a node at the end of the singly linked list:-
Linked List
• Singly Linked List:
• An algorithm to insert a node at the specified position in a linked list:-
Linked List
• Singly Linked List:
• Delete Node in Singly linked list:-
• A node may be deleted:
• From the beginning of the linked list
• From the end of the linked list
• From the specified position in a linked list
Linked List
• Singly Linked List:
• Delete Node in Singly linked list:-
Linked List
• Singly Linked List:
• Delete Node in Singly linked list:-
Linked List
• Singly Linked List:
• Delete Node in Singly linked list:-
Linked List
• Singly Linked List:
• Delete Node in Singly linked list:-
Linked List
• Singly Linked List:
• Delete Node in Singly linked list:-
Linked List
• Singly Linked List:
• Delete Node in Singly linked list:-
Linked List
• Singly Linked List:
• Delete Node in Singly linked list:-
Linked List
• Singly Linked List:
• Searching an item in a linked list:-
Linked List
• Singly Linked List:
• Searching an item in a linked list:-
Linked List
• Singly Linked List:
• Reverse of a linked list:-
Linked List
• Circular Linked List:
• Circular linked list is a variation of linked list in which the first elements points to the next
element and the last element points to the first element.
• Both singly and doubly linked list can be made into a circular linked list.
• Circular linked list can be used to help traverse the same list again and again if needed.
Linked List
• Circular Linked List:
• Circular linked list vs. Linear linked list
• A circularly linked list may be a natural option to represent arrays
• that are naturally circular, e.g. the corners of a polygon, a pool of buffers that are used
and released in FIFO order, or a set of processes that should be time-shared. In these
applications, a pointer to any node serves as a handle to the whole list.
• With a circular list, a pointer to the last node gives easy access also to the first node, by
following one Linked. Thus, in applications that require access to both ends of the list,
a circular structure allows one to handle the structure by a single pointer, instead of
two.
• The simplest representation for an empty circular list (when such a thing makes
sense) is a null pointer, indicating that the list has no nodes.
Linked List
• Circular Linked List:
• Types of circular linked list:-
• Singly: The last node points to the first node and there is only Linked between the nodes of
linked list.
• Doubly: The last node points to the first node and there are two links between the nodes of
linked list.
Linked List
• Circular Linked List:
• Advantages of Circular linked lists:-
• Efficient continuous traversal without resetting pointers.
• Memory-efficient as no NULL reference is needed.
• Ideal for queue implementations, especially circular buffers.
• Ensures all nodes are accessible from any other node.
• Simplified insertion and deletion at the head or end.
Linked List
• Circular Linked List:
• Disadvantages of Circular linked lists:-
• More complex implementation compared to singly linked lists.
• Difficult to detect the end of the list without additional checks.
• Increased risk of infinite loops if not carefully managed.
• Slightly higher memory overhead due to additional pointer management.
• Debugging and maintenance can be more challenging.
Linked List
• Operations on Circular Linked List:
• Traversal: Visit each node in the list starting from any node until returning to the starting
node.
• Insertion: Add a new node at the beginning, end, or at a specific position in the list.
• Deletion: Remove a node from the beginning, end, or a specific position in the list.
Linked List
• Insertion on Circular Linked List:
• Insertion can be of three types.
• Insert at first
• Insert at last
• Insert after constant
• Note: insertion after constant in circular and linear linked lists is exact the same.
Linked List
• Insertion at Beginning on Circular Linked List:
Linked List
• Insertion at Beginning on Circular Linked List:
Linked List
• Insertion at Last on Circular Linked List:
Linked List
• Insertion at Last on Circular Linked List:
Linked List
• Deletion on Circular Linked List:
• Deletion can be of three types.
• Delete from front
• Delete from last
• Deletion from mid
• Note: deletion from mid in circular and linear linked lists is the same.
Linked List
• Deletion at Front on Circular Linked List:
Linked List
• Deletion at Front on Circular Linked List:
Linked List
• Deletion at Front on Circular Linked List:
Linked List
• Deletion at Last on Circular Linked List:
Linked List
• Deletion at Last on Circular Linked List:
Linked List
• Traversal on Circular Linked List:
Linked List
• Traversal on Circular Linked List:
Linked List
• Doubly Linked List:
• A doubly linked list is a linear data structure consisting of nodes where each node contains
three fields: a data element, a reference to the next node, and a reference to the previous
node.
• Key Characteristics:
• Bi-Directional Traversal
• Dynamic Size
• Increased Memory Usage
Linked List
• Doubly Linked List:
Linked List
• Operation on Doubly Linked List:
• In a double-linked list, we perform the following operations...
• Insertion
• Deletion
• Traversal
Linked List
• Insertion on Doubly Linked List:
• In a double-linked list, the insertion operation can be performed in three ways as follows…
• Inserting at the beginning of the list
• Inserting at the end of the list
• Inserting a specific location in the list
Linked List
• Insertion at the Beginning on Doubly Linked List:
• We can use the following steps to insert a new node at the beginning of the
double-linked list…
• Step 1 – Create a newNode with a given value and newNode → previous as NULL.
• Step 2 – Check whether the list is Empty (head == NULL)
• Step 3 - If it is Empty then, assign NULL to newNode → next and newNode to head.
• Step 4 - If it is not Empty then, assign head to newNode → next and newNode to
head.
Linked List
• Insertion at End on Doubly Linked List:
• We can use the following steps to insert a new node at the end of the double-linked list…
• Step 1 – Create a newNode with a given value and newNode → next as NULL.
• Step 2 – Check whether the list is Empty (head == NULL)
• Step 3 - If it is Empty, then assign NULL to newNode → previous and newNode to head.
• Step 4 - If it is not Empty, then, define a node pointer temp and initialize with head.
• Step 5 - Keep moving the temp to its next node until it reaches the last node in the list
(until temp → next is equal to NULL).
• Step 6 - Assign newNode to temp → next and temp to newNode → previous.
Linked List
• Insertion at specific location on Doubly Linked List:
• We can use the following steps to insert a new node after a node in the double-linked list...
• Step 1 - Create a new Node with the given value.
• Step 2 – Check whether the list is Empty (head == NULL)
• Step 3 – If it is Empty then, assign NULL to both newNode → previous & newNode → next and set
newNode to head.
• Step 4 – If it is not Empty then, define two node pointers temp1 & temp2 and initialize temp1
with head.
• Step 5 – Keep moving the temp1 to its next node until it reaches to the node after which we want
to insert the newNode (until temp1 → data is equal to location, here location is the node value after
which we want to insert the newNode).
• Step 6 – Every time check whether temp1 is reached to the last node. If it is reached to the last
node then display ‘Given node is not found in the list!!! Insertion not possible!!!’ and terminate the
function. Otherwise, move the temp1 to the next node.
• Step 7 - Assign temp1 → next to temp2, newNode to temp1 → next, temp1 to newNode →
previous, temp2 to newNode → next and newNode to temp2 → previous.
CREATED BY K. VICTOR BABU
Introduction to Linked List
Linked List
• Deletion on Doubly Linked List:
• In a double-linked list, the deletion operation can be performed in three ways as follows…
• Deleting from the Beginning of the list
• Deleting from the End of the list
• Deleting a Specific Node
Linked List
• Deletion at Beginning on Doubly Linked List:
• We can use the following steps to delete a node from the beginning of the double-linked
list...
• Step 1 - Check whether the list is Empty (head == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!! Deletion is not possible and
terminates the function.
• Step 3 - If it is not Empty then, define a Node pointer 'temp' and initialize with head.
• Step 4 - Check whether the list has only one node (temp → previous is equal to temp →
next)
• Step 5 – If it is TRUE, then set head to NULL and delete temp (Setting Empty list
conditions)
• Step 6 – If it is FALSE, then assign temp → next to head, NULL to head → previous, and
delete temp.
Linked List
• Deletion at End on Doubly Linked List:
• We can use the following steps to delete a node from the beginning of the double-linked
list...
• Step 1 - Check whether the list is Empty (head == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!! Deletion is not possible and
terminates the function.
• Step 3 - If it is not Empty then, define a Node pointer 'temp' and initialize with head.
• Step 4 - Check whether the list has only one node (temp → previous is equal to temp →
next)
• Step 5 – If it is TRUE, then set head to NULL and delete temp (Setting Empty list
conditions)
• Step 6 – If it is FALSE, then assign temp → next to head, NULL to head → previous, and
delete temp.
Linked List
• Deletion at a Specific Location on the Doubly Linked List:
• We can use the following steps to delete a node from the beginning of the double-linked
list...
• Step 1 - Check whether the list is Empty (head == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!! Deletion is not possible and
terminates the function.
• Step 3 - If it is not Empty then, define a Node pointer 'temp' and initialize with head.
• Step 4 - Check whether the list has only one node (temp → previous is equal to temp →
next)
• Step 5 – If it is TRUE, then set head to NULL and delete temp (Setting Empty list
conditions)
• Step 6 – If it is FALSE, then assign temp → next to head, NULL to head → previous, and
delete temp.
Linked List
• Deletion at a Specific Location on the Doubly Linked List:
Step 7 - If the list has only one node and that is the node that is to be deleted then set head to
NULL and delete temp (free(temp)).
• Step 8 – If list contains multiple nodes, then check whether temp is the first node in the list
(temp == head).
• Step 9 – If the temp is the first node, then move the head to the next node (head = head →
next), set the head of previous to NULL (head → previous = NULL) and delete temp.
• Step 10 – If the temp is not the first node, then check whether it is the last node in the list
(temp → next == NULL).
• Step 11 – If the temp is the last node then set temp of previous of next to NULL (temp →
previous → next = NULL) and delete temp (free(temp)).
• Step 12 - If temp is not the first node and not the last node, then set temp of previous of
next to temp of next (temp → previous → next = temp → next), temp of next of previous to
temp of previous (temp → next → previous = temp → previous) and delete temp
(free(temp)).
CREATED BY K. VICTOR BABU
Introduction to Linked List
Linked List
• Traversing on the Doubly Linked List:
• We can use the following steps to display the elements of a double-linked list…
• Step 1 – Check whether the list is Empty (head == NULL)
• Step 2 - If it is Empty, then display 'List is Empty!!!' and terminate the function.
• Step 3 - If it is not Empty, then define a Node pointer 'temp' and initialize with head.
• Step 4 - Display 'NULL <--- '.
• Step 5 - Keep displaying temp → data with an arrow (<===>) until temp reaches to the
last node
• Step 6 - Finally, display temp → data with arrow pointing to NULL (temp → data --->
NULL).
Linked List
• Polynomials:
Linked List
• Polynomials:
Linked List
• Polynomials:
• Advantages of using an Array:
• Only good for non-sparse polynomials.
• Ease of storage and retrieval.
Linked List
• Polynomials:
Linked List
• Polynomials:
• Advantages of using a Linked list:
• Save space (don’t have to worry about sparse polynomials) and easy to maintain
• Don’t need to allocate list size and can declare nodes (terms) only as needed
• Disadvantages of using a Linked list :
• Can’t go backward through the list
• Can’t jump to the beginning of the list from the end.
Linked List
• Polynomials:
Linked List
• Adding polynomials using a Linked list representation:
• To do this, we have to break the process down to cases:
• Case 1: exponent of p1 > exponent of p2
Copy node of p1 to end of p3. [go to next node]
• Case 2: exponent of p1 < exponent of p2
Copy node of p2 to end of p3. [go to next node]
• Case 3: exponent of p1 = exponent of p2
Create a new node in p3 with the same exponent and with the sum of the coefficients
of p1 and p2.
Linked List
• Adding polynomials using a Linked list representation:
Linked List
• Adding polynomials using a Linked list representation:
Linked List
• Adding polynomials using a Linked list representation:
• Each data structure has strengths and weaknesses which affect performance depending on the
task.
• Arrays allow random access and require less memory per element (do not need space for
pointers) while lacking efficiency for insertion/deletion operations and memory allocation.
• On the contrary, linked lists are dynamic and have faster insertion/deletion time complexities.
• However, linked lists have a slower search time and pointers require additional memory per
element in the list.
1. Aaron M. Tenenbaum, Yedidyah Langsam and Moshe J. Augenstein, “Data Structures Using C
and C++”, PHI Learning Private Limited, Delhi India
2. Horowitz and Sahani, “Fundamentals of Data Structures”, Galgotia Publications Pvt Ltd Delhi
India.
3. Lipschutz, “Data Structures” Schaum’s Outline Series, Tata McGraw-hill Education (India) Pvt.
Ltd.
4. Thareja, “Data Structure Using C” Oxford Higher Education.
5. AK Sharma, “Data Structure Using C”, Pearson Education India.