0% found this document useful (0 votes)
30 views96 pages

Module 3 DSA 24

Uploaded by

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

Module 3 DSA 24

Uploaded by

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

Subject: Data Structure and Algorithms

LINEAR DATA STRUCTURE


by
Dr. Swapnil Gundewar
DEPARTMENT OF AIDS/AIML/CSD/CSME/CSE

FACULTY OF ENGINEERING
Course outcomes
Topic CO
Introduction to an Array, Representation of Arrays 1
Introduction to Stack, Stack-Definitions & Concepts 2
Operations On Stacks, Applications of Stacks 3
Polish Expression, Reverse Polish Expression And Their 3
Compilation
Recursion, Tower of Hanoi 3
Linked List 3
Applications of Linked List 4
SPECIFIC LEARNING OBJECTIVES
S/No Learning objectives Level

1 Understand the basic concepts of linear data structure Must know

2 Learn the types of arrays, stacks and queues Must know

Understand various operations performed on linear


3 data structure. Must know
Linear Data Structures

Linear Data Structures are a type of data structure in computer science


where data elements are arranged sequentially or linearly. Each element has
a previous and next adjacent, except for the first and last elements.
Characteristics of Linear Data Structure

• Sequential Organization: In linear data structures, data elements are arranged


sequentially, one after the other. Each element has a unique predecessor (except for
the first element) and a unique successor (except for the last element)

• Order Preservation: The order in which elements are added to the data structure is
preserved. This means that the first element added will be the first one to be
accessed.
• Fixed or Dynamic Size: Linear data structures can have either fixed or dynamic sizes.
Arrays typically have a fixed size when they are created, while other structures like
linked lists, stacks, and queues can dynamically grow or shrink as elements are added
or removed.

• Efficient Access: Accessing elements within a linear data structure is typically


efficient. For example, arrays offer constant-time access to elements using their
index.
Arrays

•An array is a collection of items stored at contiguous memory locations.

•The idea is to store multiple items of the same type together.

•This makes it easier to calculate the position of each element by simply


adding an offset to a base value, i.e., the memory location of the first element
of the array (generally denoted by the name of the array).
What Are Arrays in Data Structures?

An array is a linear data structure that collects elements of the same data type and
stores them in contiguous and adjacent memory locations. Arrays work on an index
system starting from 0 to (n-1), where n is the size of the array.
Why Do You Need an Array in Data Structures?

Let's suppose a class consists of ten students, and the class has to
publish their results. If you had declared all ten variables individually, it
would be challenging to manipulate and maintain the data.

If more students were to join, it would become more difficult to declare


all the variables and keep track of it. To overcome this problem, arrays
came into the picture.
What Are the Types of Arrays?

1D ARRAY

2D ARRAY

3D ARRAY
How Do You Declare an Array?

Arrays are typically defined with square brackets with the size of the arrays
as its argument.
Here is the syntax for arrays:
1D Arrays: int arr[n];
2D Arrays: int arr[m][n];
3D Arrays: int arr[m][n][o];
How Do You Initialize an Array?

•Method 1:
int a[6] = {2, 3, 5, 7, 11, 13};

• Method 2:
int arr[]= {2, 3, 5, 7, 11};

•Method 3:
int arr[5];
arr[0]=1;
arr[1]=2;
arr[2]=3;
arr[3]=4;
arr[4]=5;
How Can You Access Elements of Arrays in Data Structures?

You can access elements with the help of the index at which you stored them.

printf(“%d\n”,a[2]);
Basic Operations Performed with an Array
Operations in Array are like features of it, what an Array can do with the
elements inside it is the operation of arrays. Arrays have 5 basic operations:

•Traverse: Traversing literally means travelling through an area, and in terms of a


programming language it means running a loop in an array and performing the
required operation.
•Insertion: Adding an element inside an array on the given position(index) in the
array.
•Deletion: Removing any element from an array at a given position(index).
•Search: Searches an element of an array by the element index or the value.
•Sorting: Sort the elements
1. Traversing the Array

As we read above traversing means(literal) travelling through an area,


here we refer to traversing as travelling through the elements which are
present inside an array, could be an array of numbers (like number of
cocktails ordered)
Insertion
We can insert one or multiple elements in an array as per the requirement, of course, we can
add an element at the beginning of the array or at the end of the array.
We can add an element anywhere in the array by giving the index(position) on which the
element has to be added.

Insertion of an element can be done:


•At the beginning
•At the end and
•At any given index of an array.
Deletion

Deleting elements has the same scenario too. If the element has to be deleted from the beginning
or anywhere from the middle of the array, remaining elements will have to shift their index so it will
take n steps even if the index of element to be deleted is known, that means average or worst time
complexity, however if the element deleted is the last element of the array, best time complexity.
Searching for an Element
The method of searching for a specific value in an array is known
as searching.

There are two ways we can search


in an array, they are:
•Linear search
•Binary search
Sorting
Sorting in an array is the process in which it sorts elements in
a user-defined order.
Advantages of Arrays in Data Structures
⮚ Arrays store multiple elements of the same type with the same name.
⮚ You can randomly access elements in the array using an index number.
⮚ Array memory is predefined, so there is no extra memory loss.
⮚ Arrays avoid memory overflow.
⮚ 2D arrays can efficiently represent the tabular data.
Disadvantages of Arrays in Data Structures

⮚ The number of elements in an array should be predefined


⮚ An array is static. It cannot alter its size after declaration.
⮚ Insertion and deletion operation in an array is quite tricky as the array stores
elements in continuous form.
⮚ Allocating excess memory than required may lead to memory wastage.
Mapping 2D Array to 1D Array

2D arrays are actually there from the user point of view but the storage process
of 2D array is the same as one-dimensional arrays we have been using this
far. 2D arrays are created to give a tabular representation (in form of rows and
columns).
The size of a 2D array is equal to the multiplication of the number of rows and columns
of the array.
There are two major techniques of storing 2D arrays in memory,
giving us two formulas to map a 2D array into 1D or finding the
address of a random element in a 2D array.

Row Major Order: All the rows of the array are stored in the memory continuously.
2D array Index 0,0 0,1 0,2 0,3 1,0 1,1 1,2 1,3 2,0 2,1 2,2 2,3
2D array elements 1 2 3 4 5 6 7 8 9 10 11 12
Column Major Order: All the columns of the array are stored in the memory
continuously.
2D array Index
0,0 1,0 2,0 0,1 1,1 2,1 0,2 1,2 2,2 0,3 1,3 3,3
2D array elements
1 5 9 2 6 10 3 7 11 4 8 12
Sparse Matrix
What is a matrix?
A matrix can be defined as a two-dimensional array having 'm' rows and 'n'
columns. A matrix with m rows and n columns is called m × n matrix. It is a
set of numbers that are arranged in the horizontal or vertical lines of
entries.
What is a sparse matrix?

Sparse matrices are those matrices that have the majority of their
elements equal to zero. In other words, the sparse matrix can be defined
as the matrix that has a greater number of zero elements than the non-
zero elements.
Why is a sparse matrix required if we can use the simple
matrix to store elements?

Storage - We know that a sparse matrix contains lesser non-zero elements


than zero, so less memory can be used to store elements. It evaluates only
the non-zero elements.

Computing time: In the case of searching in sparse matrix, we need to


traverse only the non-zero elements rather than traversing all the sparse
matrix elements. It saves computing time by logically designing a data
structure traversing non-zero elements.
Representation of sparse matrix

The non-zero elements in the sparse matrix can be stored


using triplets that are rows, columns, and values. There are
two ways to represent the sparse matrix that are listed as
follows -

•Array representation
•Linked list representation
Array representation of the sparse matrix

• Representing a sparse matrix by a 2D array leads to the wastage of lots of memory.


This is because zeroes in the matrix are of no use, so storing zeroes with non-zero
elements is wastage of memory. To avoid such wastage, we can store only non-zero
elements. If we store only non-zero elements, it reduces the traversal time and the
storage space.
In 2D array representation of sparse matrix, there
are three fields used that are named as -

•Row - It is the index of a row where a non-zero element is


located in the matrix.
•Column - It is the index of the column where a non-zero
element is located in the matrix.
•Value - It is the value of the non-zero element that is
located at the index (row, column).
the array representation of sparse matrix with the help of
the example given below

In the above figure, we can observe a 5x4 sparse matrix containing 7


non-zero elements and 13 zero elements. The above matrix occupies
5x4 = 20 memory space. Increasing the size of matrix will increase the
wastage space.
Linked List representation of the sparse matrix

In a linked list representation, the linked list data structure is used to represent the sparse matrix. The
advantage of using a linked list to represent the sparse matrix is that the complexity of inserting or
deleting a node in a linked list is lesser than the array.
Unlike the array representation, a node in the linked list representation consists of four fields. The four
fields of the linked list are given as follows –

•Row - It represents the index of the row where the non-zero element is located.
•Column - It represents the index of the column where the non-zero element is located.
•Value - It is the value of the non-zero element that is located at the index (row, column).
•Next node - It stores the address of the next node.
In the above figure, we can observe a 4x4 sparse matrix containing 5 non-zero
elements and 11 zero elements. Above matrix occupies 4x4 = 16 memory space.
Increasing the size of matrix will increase the wastage space.
The linked list representation of the above matrix is given below -
Stack

• A stack is a linear data structure that follows the principle of


Last In First Out (LIFO). This means the last element inserted
inside the stack is removed first.

Stack data structures are useful when the order of actions is


important. They ensure that a system does not move onto a
new action before completing those before.
What is Stack in Data Structures?

By definition, a stack is an ordered list in which insertion and deletion are done at one end,
where the end is generally called the top. The last inserted element is available first and is the
first one to be deleted. Hence, it is known as Last In, First Out (LIFO) or First In, Last Out (FILO).
In a stack, the element at the top is known as the top element.
what is the difference between arrays and stacks?

Stacks differ from the arrays in a way that in arrays random access is possible; this means that we can
access any element just by using its index in the array. Whereas, in a stack only limited access is
possible and only the top element is directly available.

Consider an array, arr = [1, 2, 3, 4]. To access 2, we can simply write arr[1], where 1 is the index of the
array element, 2. But if the same is implemented using a stack, we can only access the topmost
element which is 4.
Features of Stack in Data Structure

⮚ Stacks are dynamic in nature; this means that they do not have a fixed size and
their size can be increased or decreased depending upon the number of elements.
⮚ In stacks, only one end is available to perform actions like insertion or deletion of
the elements
⮚ Stacks follow LIFO, which is Last In, First Out mechanism. Inserting an element is
known as push, and deleting an element is known as pop
Working of Stack in Data Structure
Initially, the stack is empty,
and we can add elements one
by one using the push
operation until the stack
becomes full. Let's say we
want to push the elements 1,
2, 3, 4, and 5 onto the stack.
We start by pushing 1 onto
the stack, which becomes the
top element. Then, we push 2,
3, 4, and 5 in the same way, as
shown
Stack Operations in Data Structure

1. push(x)

⮚ The process of inserting new data into a stack is known as push. The push (x)
operation takes the element to be added as a parameter
⮚ If we are implementing a stack using an array, it may have a pre-defined
capacity , which means that only a specific number of elements can be stored
in it.
⮚ In this case, if the stack is full, it results in a condition called stack overflow. It
indicates that we have utilized the entire capacity of the given stack, and there
is no space for any new element.
The steps involved in a push operation are –
1.Before inserting the element, check whether the stack is full.
2.If the stack is full, print “stack overflow” and terminate the program.
3.If the stack is not full, add data into the stack.
4.We can repeat the above steps until the maximum capacity of the stack is achieved.
Recall the above example of the elevator, the event of people walking into the elevator closely relates
to pushing the elements into a stack.
2. pop()

The process of deleting the topmost element from the stack is known as pop.
In stacks, if we try to pop or remove elements if the stack is empty, it results in a condition
known as underflow. It means that there is no element in the stack that can be removed.
The steps involved in a pop operation are –
1.Before removing the topmost element, check whether the stack is empty
2.If the stack is empty, print “Stack underflow” and terminate the program
3.If the stack is not empty, access the topmost element and let the top point to the element
just before it
4.We can repeat the above until all the elements from the stack are removed
3. topElement()/peek()

This operation on a stack returns the topmost element in a stack. This


operation is also known as the peek() operation on the stack.
4. isEmpty()
This operation is used to check if the given stack is empty. It returns a boolean
value; that is true when the stack is empty, otherwise false.

5. isFull()
This operation is used to check if the given stack is full. It returns a boolean
value; that is true when the stack is full, otherwise false.

6. size()
This operation determines the current size of the stack
Implementation of Stack in Data Structure

There are many ways to implement a stack, however,


two of the major ways in which a stack can be
implemented are –
1.Using a one-dimensional array
2.Using a single linked list
1. Using a one-dimensional array
2. Implementation of Stacks Using a Single Linked-list
Expression Parsing

The way to write arithmetic expression is known as a notation.


An arithmetic expression can be written in three different but
equivalent notations, i.e., without changing the essence or
output of an expression. These notations are −

•Infix Notation
•Prefix (Polish) Notation
•Postfix (Reverse-Polish) Notation
Infix Notation

We write expression in infix notation, e.g. a - b + c, where operators are


used in-between operands. It is easy for us humans to read, write, and
speak in infix notation but the same does not go well with computing
devices. An algorithm to process infix notation could be difficult and costly
in terms of time and space consumption.
Prefix Notation

In this notation, operator is prefixed to operands, i.e. operator is written


ahead of operands. For example, +ab. This is equivalent to its infix
notation a + b. Prefix notation is also known as Polish Notation.
Postfix Notation

• This notation style is known as Reversed Polish Notation. In this


notation style, the operator is postfixed to the operands i.e., the operator is
written after the operands. For example, ab+. This is equivalent to its
infix notation a + b.
Precedence

When an operand is in between two different operators,


which operator will take the operand first, is decided by
the precedence of an operator over others. For example −

As multiplication operation has precedence over addition,


b * c will be evaluated first. A table of operator
precedence is provided later.
Associativity

Associativity describes the rule where operators with the


same precedence appear in an expression. For example, in
expression a + b − c, both + and – have the same precedence,
then which part of the expression will be evaluated first, is
determined by associativity of those operators. Here, both +
and − are left associative, so the expression will be evaluated
as (a + b) − c.

Precedence and associativity determines the order of


evaluation of an expression. Following is an operator
precedence and associativity table (highest to lowest) −
The above table shows the default behavior of
operators. At any point of time in expression
evaluation, the order can be altered by using
parenthesis. For example −
In a + b*c, the expression part b*c will be evaluated
first, with multiplication as precedence over addition.
We here use parenthesis for a + b to be evaluated first,
like (a + b)*c.
Tower of Hanoi

Tower of Hanoi is a mathematical puzzle where we have three


rods (A, B, and C) and N disks. Initially, all the disks are stacked
in decreasing value of diameter i.e., the smallest disk is placed on
the top and they are on rod A. The objective of the puzzle is to
move the entire stack to another rod (here considered C), obeying
the following simple rules:
•Only one disk can be moved at a time.
•Each move consists of taking the upper disk from one of the stacks and placing it on
top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
•No disk may be placed on top of a smaller disk.
Queue

• A Queue is an abstract linear data structure serving as a collection of elements that are
inserted (enqueue operation) and removed (dequeue operation) according to the First
in First Out (FIFO) approach.
• Insertion happens at the rear end of the queue whereas deletion happens at the front
end of the queue. The front of the queue is returned using the peek operation.
What is Queue?

The Queue in data structure is an ordered, linear sequence of items. It is


a FIFO (First In First Out) data structure, which means that we can insert an
item to the rear end of the queue and remove from the front of the queue
only.
A Queue is a sequential data type, unlike an array, in an array, we can
access any of its elements using indexing, but we can only access the
element at the front of the queue at a time.
Queue operations

Enqueue
The Enqueue operation is used to add an element to the front of the queue.
•Steps of the algorithm:
•Check if the Queue is full.
•Set the front as 0 for the first element.
•Increase rear by 1.
•Add the new element at the rear index.
Dequeue
The Dequeue operation is used to remove an element from the rear of the queue.
•Steps of the algorithm:
•Check if the Queue is empty.
•Return the value at the front index.
•Increase front by 1.
•Set front and rear as -1 for the last element.
Peek
The Peek operation is used to return the front most element of the queue.
•Steps of the algorithm:
•Check if the Queue is empty.
•Return the value at the front index.
isFull
The isFull operation is used to check if the queue is full or not.
•Steps of the algorithm:
•Check if the number of elements in the queue (size) is equal to
the capacity, if yes, return True.
•Return False.
isEmpty
The isEmpty operation is used to check if the queue is empty or not.
•Steps of the algorithm:
•Check if the number of elements in the queue (size) is equal to 0, if yes,
return True.
•Return False.
Types of Queues

There are four different types of queues:


•Simple Queue
•Circular Queue
•Priority Queue
•Double Ended Queue
Simple Queue

In Linear Queue, an insertion takes place from one end while the deletion occurs
from another end. The end at which the insertion takes place is known as the rear
end, and the end at which the deletion takes place is known as front end. It strictly
follows the FIFO rule.

The major drawback of using a linear Queue is that insertion is done only from the
rear end. If the first three elements are deleted from the Queue, we cannot insert
more elements even though the space is available in a Linear Queue. In this case,
the linear Queue shows the overflow condition as the rear is pointing to the last
element of the Queue.
Circular Queue

In Circular Queue, all the nodes are represented as circular.


It is similar to the linear Queue except that the last element
of the queue is connected to the first element. It is also
known as Ring Buffer, as all the ends are connected to
another end. The representation of circular queue is shown in
the below image -

The drawback that occurs in a linear queue is overcome by


using the circular queue. If the empty space is available in a
circular queue, the new element can be added in an empty
space by simply incrementing the value of rear. The main
advantage of using the circular queue is better memory
utilization.
Priority Queue
It is a special type of queue in which the elements are arranged based on the priority.
It is a special type of queue data structure in which every element has a priority
associated with it. Suppose some elements occur with the same priority, they will be
arranged according to the FIFO principle. The representation of priority queue is
shown in the below image
-
There are two types of priority queue that are discussed as
follows -

• Ascending priority queue - In ascending priority queue, elements can be inserted in arbitrary order,
but only smallest can be deleted first. Suppose an array with elements 7, 5, and 3 in the same order,
so, insertion can be done with the same sequence, but the order of deleting the elements is 3, 5, 7.
• Descending priority queue - In descending priority queue, elements can be inserted in arbitrary order,
but only the largest element can be deleted first. Suppose an array with elements 7, 3, and 5 in the
same order, so, insertion can be done with the same sequence, but the order of deleting the elements
is 7, 5, 3.
Double Ended Queue
In Deque or Double Ended Queue, insertion and deletion can be done from both ends of the queue
either from the front or rear. It means that we can insert and delete elements from both front and rear
ends of the queue. Deque can be used as a palindrome checker means that if we read the string from
both ends, then the string would be the same.
Deque can be used both as stack and queue as it allows the insertion and deletion operations on both
ends. Deque can be considered as stack because stack follows the LIFO (Last In First Out) principle in
which insertion and deletion both can be performed only from one end. And in deque, it is possible to
perform both insertion and deletion from one end, and Deque does not follow the FIFO principle.
Input restricted deque - As the name implies, in input
restricted queue, insertion operation can be performed at only
one end, while deletion can be performed from both ends.
Output restricted deque - As the name implies, in output restricted queue,
deletion operation can be performed at only one end, while insertion can be
performed from both ends.
Linked List
A Linked List is a linear data structure consisting of connected nodes where
each node has corresponding data and a pointer to the address of the next
node. The first node of a linked list is called the Head, and it acts as an
access point.
Representation of linked list
Why use linked list over array?

Array contains following limitations:


•The size of array must be known in advance before using it in the program.
•Increasing size of the array is a time taking process. It is almost impossible to expand the size of the
array at run time.
•All the elements in the array need to be contiguously stored in the memory. Inserting any element in
the array needs shifting of all its predecessors.
Linked list is the data structure which can overcome all the limitations of an array.
•It allocates the memory dynamically. All the nodes of linked list are non-contiguously stored in the
memory and linked together with the help of pointers.
•Sizing is no longer a problem since we do not need to define its size at the time of declaration. List
grows as per the program's demand and limited to the available memory space.
Types of Linked List

• Singly linked lists


• Doubly linked lists
• Circular linked lists
• Circular doubly linked lists
Singly linked lists

• Singly linked list can be defined as the collection of ordered set of elements. The number of elements
may vary according to need of the program. A node in the singly linked list consist of two parts: data
part and link part. Data part of the node stores actual information that is to be represented by the
node while the link part of the node stores the address of its immediate successor.
• One way chain or singly linked list can be traversed only in one direction. In other words, we can say
that each node contains only next pointer, therefore we can not traverse the list in the reverse
direction.
Doubly Linked List
• Doubly linked list 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.
Circular Linked List

• In a circular Singly linked list, the last node of the list contains a pointer to the first node of the list. We
can have circular singly linked list as well as circular doubly linked list.
• We traverse a circular singly linked list until we reach the same node where we started. The circular
singly liked list has no beginning and no ending. There is no null value present in the next part of any
of the nodes.
Memory Representation of circular linked list:

• In the following image, memory representation of a circular linked list containing marks of a student in 4
subjects. However, the image shows a glimpse of how the circular list is being stored in the memory. The
start or head of the list is pointing to the element with the index 1 and containing 13 marks in the data
part and 4 in the next part. Which means that it is linked with the node that is being stored at 4th index
of the list.
• However, due to the fact that we are considering circular linked list in the memory therefore the last
node of the list contains the address of the first node of the list.
Circular Doubly Linked List

Circular doubly linked list is a more complexed type of data structure in which a node
contain pointers to its previous node as well as the next node. Circular doubly linked
list doesn't contain NULL in any of the node. The last node of the list contains the
address of the first node of the list. The first node of the list also contain address of the
last node in its previous pointer.
Memory Management of Circular Doubly linked list
Operations of Linked List
Travers
al
We can traverse the entire linked list starting from the head node. If there are n nodes then
the time complexity for traversal becomes O(n) as we hop through each and every node.
Insertion

There can be three cases that will occur when we are


inserting a node in a linked list.
•Insertion at the beginning
•Insertion at the end. (Append)
•Insertion after a given node
Insertion at the beginning
• Since there is no need to find the end of the list. If the list is empty, we make the new
node as the head of the list. Otherwise, we have to connect the new node to the
current head of the list and make the new node, the head of the list.
Insertion at end
• We will traverse the list until we find the last node. Then we insert the new node to
the end of the list. Note that we have to consider special cases such as list being
empty.
• In case of a list being empty, we will return the updated head of the linked list
because in this case, the inserted node is the first as well as the last node of the
linked list.
Insertion after a given node

• We are given the reference to a node, and the new node is inserted after the given node.
Deletion
To delete a node from a linked list, we need to do these steps
•Find the previous node of the node to be deleted.
•Change the next pointer of the previous node
•Free the memory of the deleted node.

In the deletion, there is a special case in which the first node is


deleted. In this, we need to update the head of the linked list.
Searching

• Given a particular key (data), we need to search for a node whose data
matches the key.
• In the best-case scenario, the head would be the node we are looking for,
whereas in the worst-case the required node would be the tail.
• In terms of time complexity the best case, the average case, and the worst
case of searching are denoted as Ω(1), Θ(n), and O(n) respectively.
Advantages of Linked List

• Dynamic in nature - Linked lists are dynamic in nature, and their size can be
adjusted according to our requirements.
• Ease of Insertion and Deletion - Insertion and deletion of a node in a linked list
remain efficient as the nodes are stored in random locations, and we only need to
update the next pointer of a constant number of nodes.
• Memory efficient - Memory consumption of a linked list is efficient as its size can
grow or shrink dynamically according to our requirements.
• Implementation - Various advanced data structures can be implemented using a
linked list vis-a-vis stack, queue, graph, hash maps, etc.
Disadvantages of Linked List

• Memory usage - A node in a linked list occupies more memory than an element in
an array as each node occupies at least two kinds of variables.
• Accessing a node - If you want to access a node in a linked list, you have to traverse
starting from the head. We cannot access any random nodes directly except for the
head itself, since nodes don't share a linear order in the physical memory and are
only referenced by pointers.
• Traversing in reverse order - Traversing in reverse order is difficult. Although a
doubly-linked list makes it easier but requires more memory to store those extra
'prev' pointers.
Applications of Linked List

• Linear data structures such as stack, queue, and non-linear data


structures such as hash maps, graphs can be implemented using
linked lists.
• Doubly linked lists are useful for building a forward-backward
navigation button in a web browser or undo-redo feature in an
editor.
• Circular Doubly linked lists can also be used for the implementation
of advanced data structures like Fibonacci Heap.
Summary
• Array
• Applications of Array
• Stacks
• Queues
• Polish Expressions
• Linked List
• Tower of Hanoi
Expected Questions

BAQ
1.Define linear data structure.
2.Enlist types of data structure.

SAQ
3.Illustrate the types of arrays.
4.Illustrate the concept of sparse matrix.

LAQ
5.Explain Polish Expression.
6.Explain various operations on stack.
7.Explain types of linked list
References

1. Data structure using C and C++-AM Tanenbaum, Y Langsam& MJ Augustein,Prentice Hall India.
2. Data structures & Program Design in C -Robert Kruse, Bruse Leung,Pearson Education.

You might also like