DATA STRUCTURE & ALGORITHM
DATA STRUCTURE
DEFINITION
Afrah Ahamed Musthafa
III BSc IT
Data Structure and Algo 2
rithm
DEFINITION
A data structure is a specialized format for organizing,
managing, and storing data in a computer so that it
can be accessed and modified efficiently. In computer
science, the choice of data structure impacts both the
performance and complexity of algorithms, as well as
the organization of the data in memory. Data
structures form the foundation for many important
algorithms, and different data structures are suited for
different kinds of tasks.
Data Structure and Algo 3
rithm
WHAT IS A DATA STRUCTURE?
A data structure is a way of storing and organizing data in a computer so that it can be used efficiently. It defines:
• How data is stored: Whether data is stored in contiguous memory locations (like in an array) or as linked
objects (like in linked lists).
• How data can be accessed: Some data structures are designed to allow fast access to any data element
(random access), while others only allow sequential access.
• How data is modified: Operations such as insertion, deletion, and searching must be supported by the data
structure, and the efficiency of these operations can vary depending on the data structure used.
Data Structure and Algo 4
rithm
Data structures can be broadly classified
TYPES OF DATA into two categories:
STRUCTURES a. Primitive Data Structures
•These are the basic types of data structures that are directly operated
upon by machine-level instructions.
•They typically involve fundamental data types like integers, floating-
point numbers, characters, and pointers.
•These types have a predefined size and structure that the computer
can interpret directly. Examples include:
•int
•float
•char
•boolean
Data Structure and
5
Algorithm
Data structures can be broadly classified
TYPES OF DATA into two categories:
STRUCTURES
b. Non-Primitive Data Structures
• These are more complex data structures
that are built upon primitive data types.
• Non-primitive data structures can be
linear or non-linear, depending on how
data elements are organized.
Data Structure and Algo 6
rithm
LINEAR DATA STRUCTURES
Linear means that elements are arranged in a sequence, one after the other.
Examples include:
1. Arrays: A collection of elements, each identified by an index or key.
2. Linked Lists: A linear data structure where each element points to the next,
forming a sequence.
3. Stacks: A collection of elements that follows the Last In First Out (LIFO) principle.
4. Queues: A collection of elements that follows the First In First Out (FIFO)
principle.
Data Structure and Algo 7
rithm
NON-LINEAR DATA STRUCTURES
Non-linear data structures don’t store data elements in a linear sequence. Instead, they organize data
in a hierarchical manner.
1. Trees: A tree is a hierarchical structure consisting of nodes, where each node has a value and
pointers to child nodes.
2. Graphs: A graph is a set of nodes connected by edges, which can be directed or undirected.
3. Heaps: A type of tree-based structure that satisfies the heap property (either max-heap or min-
heap).
4. Hash Tables: A data structure that maps keys to values using a hash function for efficient access.
Data Structure and Algo 8
rithm
OPERATIONS ON DATA
STRUCTURES
The functionality of data structures comes from the operations that can
be performed on them. These include:
•Insertion: Adding an element to the data structure
•Deletion: Removing an element from the data structure.
•Traversal: Accessing and processing each element of the data structure.
•Searching: Finding the location of a particular element within the data structure.
•Sorting: Rearranging elements in a specific order (ascending or descending).
Data Structure and Algo 9
rithm
The choice of data structure depends
CHOOSING THE RIGHT on the nature of the problem and the
operations needed. Factors to
DATA STRUCTURE consider include:
•Speed requirements: How fast do you need operations
like search, insertion, and deletion.
•Memory constraints: How much memory can you
allocate.
•Complexity of the problem: Does the problem involve
linear or hierarchical relationships.
•Operations needed: Are frequent insertions and deletions
required, or is random access more important.
Data Structure and Algo 10
rithm
a data structure is an organized
way of storing and managing
data to enable efficient access
and modification. Understanding
the properties, operations, and
time complexities of different
SUMMARY
data structures is critical for
designing efficient algorithms
and solving computational
problems effectively.
THANK YOU
Afrah Ahamed Mushafa
III BSc IT