Data Structure Module 1
Data Structure Module 1
1. Static Data Structures: The data structures having a fixed size are
known as Static Data Structures. The memory for these data
structures is allocated at the compiler time, and their size cannot be
changed by the user after being compiled; however, the data stored
in them can be altered. The Array is the best example of the Static
Data Structure as they have a fixed size, and its data can be modified
later.
2. Dynamic Data Structures: The data structures having a dynamic
size are known as Dynamic Data Structures. The memory of these
data structures is allocated at the run time, and their size varies
during the run time of the code. Moreover, the user can change the
size as well as the data elements stored in these data structures at the
run time of the code Linked Lists, Stacks, and Queues are common
examples of dynamic data structures
The following is the list of Linear Data Structures that we generally use:
1. Arrays
a. We can store a list of data elements belonging to the same data type.
b. Array acts as an auxiliary storage for other data structures.
c. The array also helps store data elements of a binary tree of the fixed
count.
d. Array also acts as a storage of matrices.
2. Linked Lists
a. Singly Linked List: A Singly Linked List is the most common type of
Linked List. Each node has data and a pointer field containing an address to
the next node.
b. Doubly Linked List: A Doubly Linked List consists of an information
field and two pointer fields. The information field contains the data.
The first pointer field contains an address of the previous node,
whereas another pointer field contains a reference to the next node.
Thus, we can go in both directions (backward as well as forward).
c. Circular Linked List: The Circular Linked List is similar to the Singly
Linked List. The only key difference is that the last node contains the
address of the first node, forming a circular loop in the Circular
Linked List.
a. The Linked Lists help us implement stacks, queues, binary trees, and
graphs of predefined size.
b. We can also implement Operating System's function for dynamic
memory management.
c. Linked Lists also allow polynomial implementation for mathematical
operations.
d. We can use Circular Linked List to implement Operating Systems or
application functions that Round Robin execution of tasks.
e. Circular Linked List is also helpful in a Slide Show where a user
requires to go back to the first slide after the last slide is presented.
f. Doubly Linked List is utilized to implement forward and backward
buttons in a browser to move forward and backward in the opened
pages of a website.
3. Stacks
A Stack is a Linear Data Structure that follows the LIFO (Last In, First Out)
principle that allows operations like insertion and deletion from one end of
the Stack, i.e., Top. Stacks can be implemented with the help of contiguous
memory, an Array, and non-contiguous memory, a Linked List. Real-life
examples of Stacks are piles of books, a deck of cards, piles of money, and
many more.
The above figure represents the real-life example of a Stack where the
operations are performed from one end only, like the insertion and
removal of new books from the top of the Stack. It implies that the insertion
and deletion in the Stack can be done only from the top of the Stack. We can
access only the Stack's tops at any given time.
4. Queues
The above image is a real-life illustration of a movie ticket counter that can
help us understand the Queue where the customer who comes first is
always served first. The customer arriving last will undoubtedly be served
last. Both ends of the Queue are open and can execute different operations.
Another example is a food court line where the customer is inserted from
the rear end while the customer is removed at the front end after providing
the service they asked for.
1. Trees
The Tree data structure is a specialized method to arrange and collect data
in the computer to be utilized more effectively. It contains a central node,
structural nodes, and sub-nodes connected via edges. We can also say that
the tree data structure consists of roots, branches, and leaves connected.
a. Binary Tree: A Tree data structure where each parent node can have
at most two children is termed a Binary Tree.
b. Binary Search Tree: A Binary Search Tree is a Tree data structure
where we can easily maintain a sorted list of numbers.
c. AVL Tree: An AVL Tree is a self-balancing Binary Search Tree where
each node maintains extra information known as a Balance Factor
whose value is either -1, 0, or +1.
d. B-Tree: A B-Tree is a special type of self-balancing Binary Search
Tree where each node consists of multiple keys and can have more
than two children.
2. Graphs
G = (V,E)
Depending upon the position of the vertices and edges, the Graphs can
be classified into different types:
The user of data type does not need to know how that data type is
implemented, for example, we have been using Primitive values like
int, float, char data types only with the knowledge that these data
type can operate and be performed on without any idea of how they
are implemented.
So a user only needs to know what a data type can do, but not how it
will be implemented. Think of ADT as a black box which hides the
inner structure and design of the data type. Now we’ll define three
ADTs namely List ADT, Stack ADT, Queue ADT.
1. List ADT
Vies of list
2. Stack ADT
View of stack
3. Queue ADT
View of Queue
The queue abstract data type (ADT) follows the basic design of
the stack abstract data type.
Each node contains a void pointer to the data and the link
pointer to the next element in the queue. The program’s
responsibility is to allocate memory for storing the data.
The Queue ADT Functions is given below:
Advantages:
Disadvantages: