7. Unit - I - DS
7. Unit - I - DS
4. Applications
5. Data Structure Operations:
❖Insertion
❖Deletion
❖Search
❖Traversal
Introduction to Data Structures
Definition:
❖ A data structure is a Specific way to store and organize data in a computer's memory so that these
data can be used efficiently.
❖ The data structure name indicates itself that organizing the data in memory.
❖ There are many ways of organizing the data in the memory as we have already seen one of the data
structures, i.e., array in C language.
❖ Array is a collection of memory elements in which data is stored sequentially, i.e., one after another.
❖ The data structure is a set of algorithms that we can use in any programming language to structure
the data in the memory.
Introduction to Data Structures
Data Type Data Structures
It tells about the type of data a variable can accept. It is a collection of data types
Data Types can only hold a particular value that is part Data Structure can have different kinds and types of
of the data data within one single object
Values can directly be assigned to the data type The data is assigned to the data structure object using
variables since data type already represents the type of some set of algorithms and operations like push, pop,
value that can be stored and so on.
For Data Types, there is no involvement of time Time complexity comes into play when working with
complexity since only type and nature of data is data structures as it mainly deals with manipulation
concern and execution of logic over stored data.
❖ Moreover, it also describes the possible operations allowed on those values. For example, the integer data
type can store an integer value. Possible operations on an integer include addition, subtraction,
multiplication, modulo.
❖ Abstract data type (ADT) is a concept or model of a data type. Because of ADT, a user doesn’t have to
bother about how that data type has been implemented.
❖ Moreover, ADT also takes care of the implementation of the functions on a data type. Here, the user will
have predefined functions on each data type ready to use for any operation.
❖ ADT only mentions what operations are to be performed but not how these operations will be
implemented.
❖ It does not specify how data will be organized in memory and what algorithms will be used for
implementing the operations. It is called “abstract” because it gives an implementation-independent view.
Introduction to Data Structures
• Static data structure: Static data structure has a fixed memory size. It is easier to access
the elements in a static data structure. An example of this data structure is an array.
• Dynamic data structure: In the dynamic data structure, the size is not fixed. It can be
randomly updated during the runtime which may be considered efficient concerning the
memory (space) complexity of the code. Examples of this data structure are queue, stack,
etc.
❖ Non-linear data structure: Data structures where data elements are not placed sequentially or
linearly are called non-linear data structures.
❖ In a non-linear data structure, we can’t traverse all the elements in a single run
only. Examples of non-linear data structures are trees and graphs.
Linear Data Structure
Characteristics of Linear Data Structure:
❖ Sequential Organization: In linear data structures, data elements are arranged
sequentially, one after the other.
❖ 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 or
removed, and the last element added will be the last one to be accessed or removed.
❖ 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.
Linear Data Structure
List of Linear Data Structures
Linked Lists collection of nodes, each containing an element and a reference to the
next node.
Common Features:
❖ Node: Each element in a linked list is
represented by a node, which contains two
components:
❖ Data: The actual data or value associated
with the element.
Circular Linked Lists:
❖ Next Pointer(or Link): A reference or pointer
to the next node in the linked list.
❖ The 'base' of the stack points to the first inserted ❖Pop: Remove an element from the top of a stack
element in the stack and the 'top' of the stack
points to the last inserted element.
❖IsEmpty: Check if the stack is empty
❖IsFull: Check if the stack is full
❖Peek: Get the value of the top element without
removing it
Linear Data Structure Example:-
❖ People waiting in line for a rail ticket form a queue
Queues:-
❖ Queue follows the First In First Out (FIFO) rule -
the item that goes in first is the item that comes
out first.
❖ A queue can be defined as an ordered list which
enables insert operations to be performed at one
end called REAR and delete operations to be
performed at another end called FRONT.
Characteristics:
Edge: An edge is a connection between two vertices in a Undirected Graph Directed Graph
graph.
Graph:-
❖ Social media analysis : Used to identify trends, sentiment, and key influencers
❖ Network monitoring : Graphs can be used to monitor network traffic in real-time
❖ IoT : Used to identify patterns, optimize performance
❖ Autonomous vehicles : allowing them to navigate safely and efficiently
❖ Web Graphs : Used to connect URLs on the internet
Operations on Data Structure
Insertion: It is the operation which we apply on all the data-structures. Insertion
means to add an element in the given data structure. The operation of insertion is
successful when the required element is added to the required data-structure.
Traversing: Traversing a Data Structure means to visit the element stored in it. It
visits data in a systematic manner. This can be done with any type of DS.