Session 1 (Introduction To Data Structure)
Session 1 (Introduction To Data Structure)
Ms Neetu Chauhan
Algorithm Preparation
Design for
and Interviews
Analysis and Careers
"A data structure is a systematic way of organizing and accessing data." - Clifford
A. Shaffer
"A data structure is a way to store and organize data in order to facilitate access
and modifications." - Cormen, Leiserson, Rivest, and Stein
"A data structure is a systematic way to organize and access data." - Robert
Sedgewick
"A data structure is a systematic way of organizing and accessing data." - Mark
Allen Weiss
Group Items: Data Items that have subordinate data items are
known as Group Items. For example, an employee's name can have
a first, middle, and last name.
Elementary Items: Data Items that are unable to divide into sub-
items are known as Elementary Items. For example, the ID of an
Employee.
Dr. Swati, Ms Suman & Ms Neetu 14
Classification of Data Structure
1. Bool-
-Represents logical value, either ‘true’ or ’false’.
-Fixed size of 1 byte.
2. Byte-
-Represents an 8-bit signed integer.
-use keyword ‘byte’ and size of 1 byte.
-Range of values from -128 to 127 (inclusive).
Syntax in C++:
3. Char-
-Represents single character.
-Example- a letter, a digit or symbol
-Fixed size of 2 bytes.
4. Int-
-Represents integer values.
-Store both negative and positive whole numbers.
-Fixed size of 4 bytes in memory.
5. Float-
-Represents floating-point numbers.
-Store real numbers (decimal values).
-Fixed size of 4 bytes in memory.
6. Double-
-Store larger decimal values with large precision.
-Fixed size of 8 bytes in memory.
1. Assignment Operations-
-Act of putting a value in a variable.
2. Arithmetic Operations-
-Mathematical calculations on numeric data type.
3. Comparison Operations-
-Compares two values and returns Boolean values.
4. Logical Operations-
-Perform Boolean operations on Boolean data types.
Limited size range: For example, an integer data type in Java can
store values between -2147483648 and 2147483647.
Array:
linear data structure
Collection of elements with same or different data types.
Exist in both single dimension and multiple dimensions.
Stack:
Linear data structure.
Follows a particular order to perform operations.
LIFO(Last In First Out) or FILO(First In Last Out).
Queue:
It is an ordered list.
Insertion operations from REAR end.
Deletion operations from FRONT end.
Queue:
Linked Lists:
Linear data structure
Collection of "nodes" connected via links i.e. pointers.
Linked lists nodes are not stored at a contiguous location.
They are linked using pointers to the different memory locations.
Linked Lists:
A node consists of :
-- a data value and
-- a pointer to the address of the next node.
Trees:
Hierarchical structure
Used to represent and organize data in a way so that easy to
navigate and search.
Collection of nodes connected by edges.
Graphs:
Collection of nodes connected by edges.
Used to represent relationships between different entities.
Example- used to find the shortest path or detecting cycles.
Types of Graphs:
Question: Given this scenario, which linear data structure would you
choose to manage the tickets in the help desk system? Explain your
choice and discuss its advantages and disadvantages in this context.
Additionally, outline the key operations you would need to support,
their time complexity, and how you would implement them.
Why Queue?
FIFO Structure: A queue operates on a First In, First Out (FIFO) principle, which is ideal
for managing tickets in the order they are received, ensuring that all customers are treated
fairly and in a timely manner.
Simplicity: Queues allow easy additions (enqueue) at the rear and removals (dequeue)
from the front, which aligns well with processing tickets from the oldest to the newest.
Advantages
Order Preservation: Ensures that tickets are handled in the exact order they are received.
Efficiency in Operations: Enqueue and dequeue operations are very efficient, typically
running in constant time, O(1).
Question:
Given this scenario, which data structures would you use to model the
transportation network and compute the shortest paths between stops? Explain your
choice and discuss its advantages and disadvantages in this context. Additionally,
outline the key operations and algorithms you would need to implement, their time
complexity, and how they would function within your chosen data structures.