Data Structures & Algorithms
Introduction — Lecture Notes
1. What is a Data Structure?
A data structure is a way of organizing and storing data in a computer's main memory so that it can
be used efficiently. In simple words, it is not just about storing data — it is about storing it in a way
that makes access, search, and modification fast and easy.
Real-Life Analogy: The Library
Think of a big library. A library has different sections for different subjects — for example a Computer
Science section, a Law section, and a Commerce section. Inside each section there are several
racks, and inside each rack there are shelves arranged in a proper order.
This layered organization — section → rack → shelf — is exactly what a data structure does with
data. It groups related data together and arranges it in a defined structure, just like books are grouped
and arranged in a library.
Because of this organization, when you need a specific book, you don't search the entire library —
you go straight to the correct section, then the correct rack, then the correct shelf. This is the real
benefit of a data structure: it lets you find a specific piece of data quickly because you already know
which "section" it belongs to, instead of scanning everything from scratch.
Extra Example: Contacts App on Your Phone
Your phone's contact list is another everyday data structure. Contacts are stored alphabetically (A, B,
C...), so when you want to find "Rahul", your phone doesn't check every single contact — it jumps
directly near the "R" section. That's efficient data organization in action.
Extra Example: A Wardrobe
A wardrobe with separate sections for shirts, trousers, and accessories is also a data structure in
everyday life. If clothes were dumped randomly, finding one shirt would take forever. Proper sections
= faster access, exactly like data structures in programming.
2. Programs, Data, and Data Structures
What is a Program?
A program is a set of instructions that tells a computer what to do. It manipulates data to achieve a
specific task — for example, a calculator program takes numbers (data) and performs operations on
them.
Data and Programs
Programs operate on data. The way data is organized — i.e. the data structure used — significantly
impacts how efficient the program is. The same task can run fast or slow purely based on which data
structure was chosen to hold the data.
Where Data and Data Structures Actually Live
This is an important distinction to understand clearly:
• Data (permanent storage): Raw data is generally stored permanently on the hard drive /
secondary storage (e.g., a file, a database). This data stays even after the computer is
switched off.
• Data Structures (while the program runs): When a program runs, it loads the required data
from the hard drive into the computer's main memory (RAM), and arranges it using a specific
data structure (array, linked list, tree, etc.) so the CPU can access and process it quickly. This
arrangement in RAM is temporary — it exists only while the program is running.
In short: data rests on the hard drive; data structures organize that data inside main memory so the
running program can work with it efficiently.
Data Structures in Programs
Choosing the right data structure is crucial for writing efficient and effective programs. It makes
programs more readable, maintainable, and scalable.
3. Why Organize Data?
Efficiency Management
Organized data allows for faster searching, It simplifies data management, making it
sorting, and retrieval. easier to update, insert, and delete records.
Storage
Good data structures optimize storage space, reducing memory usage — so the program doesn't
waste RAM holding data in an inefficient shape.
Extra example: Imagine sorting 10,000 unsorted names to find one — you'd have to check almost all
of them (slow). But if the names are already organized (e.g., sorted, or stored in a hash table), you
can jump almost directly to the answer. That's exactly why we organize data.
4. What is an Algorithm?
An algorithm is a step-by-step procedure or a set of rules to solve a specific problem or perform a
computation. It is a finite sequence of steps/instructions to solve a specific problem.
Example: Making Tea
The process of making tea is a perfect everyday algorithm. Steps include: boil water, add tea leaves,
add milk/sugar, let it boil, strain, and serve. Each step happens in a fixed order, and following these
steps always produces the same result — that's exactly what an algorithm is in programming too.
Extra Example: Following a GPS Route
When Google Maps gives you turn-by-turn directions to reach a destination, that sequence of turns is
an algorithm — a finite, ordered set of steps that reliably gets you from point A to point B.
Extra Example: A Cooking Recipe / Sorting Playing Cards
Sorting a deck of playing cards by picking the smallest card and placing it first, then the next smallest,
and so on, is essentially the Selection Sort algorithm performed by hand.
5. Properties of Algorithms
1. Finiteness
An algorithm must always terminate after a finite number of steps. It cannot run forever.
2. Definiteness
Each step must be precisely defined, clear, and unambiguous — there should be no confusion about
what to do next.
3. Input
An algorithm has zero or more well-defined inputs.
4. Output
An algorithm must produce one or more well-defined outputs.
5. Generality
The algorithm should be applicable to a wide range of inputs, not just one specific case.
6. Importance of Data Structures and Algorithms
Efficient Data Storage & Access
DSA allows programs to run faster and more efficiently.
Scalability
DSA enables programs to handle larger datasets and more users.
Organization
DSA helps organize data and programs in a structured manner and in a memory-efficient way.
Problem Solving
DSA provides tools for solving complex computational problems.
Essentials for CP & Interviews
A strong grip on DSA is essential for competitive programming and cracking technical interviews.
Two More Everyday Examples of DSA's Importance
• Food delivery apps (like Zomato/Swiggy): They use graphs and shortest-path algorithms to
find the fastest route from the restaurant to your home among thousands of possible roads.
• Autocomplete on Google/YouTube search: Uses a data structure called a Trie to instantly
suggest words as you type, instead of scanning every possible word in the dictionary each
time.
7. The Impact of Efficient Algorithms
Faster Processing
Efficient algorithms reduce the time it takes to execute, leading to a better user experience — for
example, a well-written search algorithm returns results almost instantly.
Resource Optimization
Efficient algorithms minimize the use of computational resources such as processing power and
memory, which matters a lot when an app is used by millions of people at once.
8. Data Structures and Real-World Applications
Social Networks
Graphs are used to model relationships between users (e.g., friends, followers).
Search Engines
Hash tables are used to index and retrieve web pages quickly.
Databases
Trees (like B-Trees) are used for indexing and organizing data for fast lookup.
Extra example: Ride-hailing apps like Uber use graphs and priority queues to match you with the
nearest available driver in real time.
End of Introduction notes. Next up: Arrays and Linked Lists — their definitions, operations,
advantages, and complexities.