Chapter One - DS Introduction
Chapter One - DS Introduction
• With the help of Data Structures, we can easily traverse the data items.
• Basic data types like Integer, Float, Character, and Boolean come under the
Primitive Data Structures.
• These data types are also called Simple data types, as they contain characters
that can't be divided further
Non-Primitive Data Structures
• Non-Primitive Data Structures are those data structures derived from
Primitive Data Structures.
• These data structures can't be manipulated or operated directly by
machine-level instructions.
• The focus of these data structures is on forming a set of data elements
that is either homogeneous (same data type)
or heterogeneous (different data types).
• Based on the structure and arrangement of data, we can divide these
data structures into two sub-categories -
• Linear Data Structures
• Non-Linear Data Structures
Linear Data Structures
• A data structure that preserves a linear connection among its data elements is known as a
Linear Data Structure. The arrangement of the data is done linearly, where each element
consists of the successors and predecessors except the first and the last data element.
• Based on memory allocation, the Linear Data Structures are further classified into two types:
• 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.
• 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
Types of Linear Data Structures
3. 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.
Some Applications of Linked Lists:
1.The Linked Lists help us implement stacks, queues, binary trees, and graphs of
predefined size.
2. We can also implement Operating System's function for dynamic memory
management.
3. Linked Lists also allow polynomial implementation for mathematical operations.
4. We can use Circular Linked List to implement Operating Systems or application
functions that Round Robin execution of tasks.
5. 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.
6. 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.
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 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.
Stacks (cont …)
• The primary operations in the
Stack are as follows:
• Push: Operation to insert a new
element in the Stack is termed
as Push Operation.
• Pop: Operation to remove or
delete elements from the Stack
is termed as Pop Operation.
Some Applications of Stacks:
• The Stack is used as a Temporary Storage Structure for recursive operations.
• Stacks are also utilized to evaluate the arithmetic expressions in different
programming languages.
• Stacks are also helpful in converting infix expressions to postfix expressions.
• We can match parenthesis using Stacks.
• Stacks can be used to reverse a String.
• Stacks are helpful in solving problems based on backtracking.
• We can use Stacks in depth-first search in graph and tree traversal.
• Stacks are also used in Operating System functions.
• Stacks are also used in UNDO and REDO functions in an edit.
4. Queues
• A Queue is a linear data structure similar to a Stack with some
limitations on the insertion and deletion of the elements.
• The insertion of an element in a Queue is done at one end, and the
removal is done at another or opposite end.
• Thus, we can conclude that the Queue data structure follows FIFO
(First In, First Out) principle to manipulate the data elements.
Implementation of Queues can be done using Arrays, Linked Lists, or
Stacks.
• Some real-life examples of Queues are a line at the ticket counter, an
escalator, a car wash, and many more.
Operations of the Queue
• Enqueue: The insertion or Addition of some data elements to the
Queue is called Enqueue. The element insertion is always done with
the help of the rear pointer.
• Dequeue: Deleting or removing data elements from the Queue is
termed Dequeue. The deletion of the element is always done with the
help of the front pointer.
Some Applications of Queues:
• Queues are generally used in the breadth search operation in Graphs.
• Queues are also used in Job Scheduler Operations of Operating Systems,
like a keyboard buffer queue to store the keys pressed by users and a print
buffer queue to store the documents printed by the printer.
• Queues are responsible for CPU scheduling, Job scheduling, and Disk
Scheduling.
• Priority Queues are utilized in file-downloading operations in a browser.
• Queues are also used to transfer data between peripheral devices and the
CPU.
• Queues are also responsible for handling interrupts generated by the User
Applications for the CPU.
Non-Linear Data Structures
• Trivial Graph: A Graph having only one vertex is termed a Trivial Graph.
• Simple Graph: A Graph with neither self-loops nor multiple edges is known as a Simple Graph.
• Directed Graph: A Graph consisting of the directed edges between the vertices is known as a Directed
Graph.
• Connected Graph: A Graph with at least a single path between every pair of vertices is termed a
Connected Graph.
• Disconnected Graph: A Graph where there does not exist any path between at least one pair of vertices is
termed a Disconnected Graph.
• etc
Some Applications of graph
• Graphs help us represent routes and networks in transportation, travel, and communication
applications.
• Graphs are used to display routes in GPS.
• Graphs also help us represent the interconnections in social networks and other network-
based applications.
• Graphs are utilized in mapping applications.
• Graphs are responsible for the representation of user preference in e-commerce applications.
• Graphs are also used in Utility networks in order to identify the problems posed to local or
municipal corporations.
• Graphs also help to manage the utilization and availability of resources in an organization.
• Graphs are also used to make document link maps of the websites in order to display the
connectivity between the pages through hyperlinks.
• Graphs are also used in robotic motions and neural networks.
Basic Operations of Data Structures
1. Traversal: Traversing a data structure means accessing each data element exactly once so it
can be administered. For example, traversing is required while printing the names of all the
employees in a department.
2. Search: Search is another data structure operation which means to find the location of one
or more data elements that meet certain constraints. Such a data element may or may not be
present in the given set of data elements. For example, we can use the search operation to
find the names of all the employees who have the experience of more than 5 years.
3. Insertion: Insertion means inserting or adding new data elements to the collection. For
example, we can use the insertion operation to add the details of a new employee the
company has recently hired.
4. Deletion: Deletion means to remove or delete a specific data element from the given list of
data elements. For example, we can use the deleting operation to delete the name of an
employee who has left the job.
5. Sorting: Sorting means to arrange the data elements in either Ascending or Descending order
depending on the type of application.
• For example, we can use the sorting operation to arrange the names of employees in a department in
alphabetical order or estimate the top three performers of the month by arranging the performance of
the employees in descending order and extracting the details of the top three.
Basic Operations of Data Structures
6. Merge: Merge means to combine data elements of two sorted lists in order to
form a single list of sorted data elements.
7. Create: Create is an operation used to reserve memory for the data elements
of the program. The creation of data structure can take place either during
compile-time and Run-time.
For example, the malloc() function is used in C Language to create data
structure.
8. Selection: Selection means selecting a particular data from the available data.
We can select any particular data by specifying conditions inside the loop.
9. Update: The Update operation allows us to update or modify the data in the
data structure. We can also update any particular data by specifying some
conditions inside the loop, like the Selection operation.
10. Splitting: The Splitting operation allows us to divide data into various subparts
decreasing the overall process completion time.
Understanding the Abstract Data Type
• As per the National Institute of Standards and Technology (NIST), a
data structure is an arrangement of information, generally in the
memory, for better algorithm efficiency.
• From the definition, we can conclude that the operations in data
structure include:
• A high level of abstractions like addition or deletion of an item from a list.
• Searching and sorting an item in a list.
• Accessing the highest priority item in a list.
• Whenever the data structure does such operations, it is known as
an Abstract Data Type (ADT).
Abstract data type
• It can be defined as a set of data elements along with the operations
on the data.
• The term "abstract" refers to the fact that the data and the
fundamental operations defined on it are being studied
independently of their implementation.
• It includes what we can do with the data, not how we can do it.
• All the data structures, like an array, linked list, queue, stack, etc., are
examples of ADT.