CIT 203
Introduction to Data Structures and
Algorithms (DSA)
1. Why Study Data Structures and Algorithms?
Modern computing is all about data — storing it, processing it, and making sense of it
efficiently. Whether we’re building:
A social network that must handle billions of profiles and friendships,
A search engine that scans trillions of web pages,
Or a GPS system that computes the fastest path in seconds,
we need two things:
👉 Data Structures (ways to store and organize data)
👉 Algorithms (step-by-step methods to process and manipulate that data)
Core idea:
Data structures are about organization (how we put data in memory).
Algorithms are about manipulation (how we get useful results from that data).
Together, they make software fast, efficient, and scalable.
2. What is a Data Structure?
Definition
A data structure is a way to store, organize, and manage data so that it can be accessed and
modified efficiently.
Analogy
Imagine a library:
If books are just piled randomly → it’s hard to find the one you want.
If books are organized alphabetically or by genre → finding is fast.
Similarly, in computing:
Unstructured data → slow and inefficient.
Well-structured data → fast and manageable.
Example: Family Tree (non-computer analogy)
Suppose you want to keep track of your relatives.
Writing names in a long list won’t help you easily find your grandmother’s mother.
Instead, you use a family tree: a hierarchical structure with links (parent ↔ child).
With this structure, it becomes trivial to trace relationships across generations.
This shows:
Different problems require different structures.
Choosing the right data structure makes problem-solving easier.
Types of Data Structures
1. Primitive Data Structures (basic building blocks)
o Directly provided by programming languages.
o Examples: int, float, char, bool.
2. Abstract Data Structures (built using primitives)
o Designed to solve specific problems.
o Examples:
Array: stores elements in contiguous memory.
Linked List: nodes connected via pointers.
Stack: LIFO (Last In First Out).
Queue: FIFO (First In First Out).
Tree: hierarchical (parent-child).
Graph: network of nodes and edges.
3. What is an Algorithm?
Definition
An algorithm is a finite sequence of well-defined steps that solve a particular problem.
Input → Algorithm → Output
Example: Recipe for making French fries (Pommes Frites).
o Input: potatoes, oil, salt.
o Steps: peel, slice, fry, season.
o Output: delicious fries 🍟.
NB In computing, instead of ingredients, we use data; instead of cooking steps, we use
instructions in a programming language.
Algorithm Characteristics
1. Finiteness → Must end after a finite number of steps.
2. Definiteness → Steps are precise and unambiguous.
3. Input → Takes zero or more values as input.
4. Output → Produces at least one result.
5. Effectiveness → Steps must be basic enough to be executed in practice.
Algorithm Examples
GPS → Find shortest route.
Search engines → Find relevant documents.
Sorting → Arrange movies by rating.
Databases → Efficient lookup of millions of records.
4. Data Structures + Algorithms = Power
👉 A data structure without an algorithm is just a storage box.
👉 An algorithm without a data structure is like a plan with no materials.
They must work together. For example:
Bubble Sort algorithm works on an array.
DFS (Depth First Search) works on a graph.
Binary Search works only on a sorted array/list.
Thus, choosing the right combination is critical.
5. Where is DSA Needed?
DSA underlies nearly all modern computing:
Operating Systems: scheduling processes, memory management.
Database Systems: indexing, query optimization.
Networking: routing packets, congestion control.
Machine Learning: handling large datasets, optimizing training.
Cybersecurity: encryption, hashing.
Video Games: pathfinding, collision detection.
Web Applications: load balancing, caching.
In short: If you want to be a good programmer, you must master DSA.
6. Core Theory & Terminology
Term Explanation
Algorithm A set of instructions to solve a problem.
Data Structure A way of organizing data for efficient use.
Time Complexity How the execution time grows with input size (n).
Space Complexity How much memory the algorithm uses.
Mathematical tool to describe worst-case time complexity (O(n), O(log n),
Big-O Notation
etc.).
Recursion Function calling itself to solve subproblems.
Divide & Conquer Strategy: break problem → solve subproblems → combine solutions.
Brute Force Try all possible solutions (often slow but simple).
7. Extended Examples (to show students why DSA matters)
Example 1: Searching in a Phone Book
If unsorted: must scan one by one → O(n).
If sorted: use binary search → O(log n).
With hashing: find instantly in O(1) average time.
Lesson: The data structure (array vs hash table) + algorithm (linear vs binary search) drastically
affects efficiency.
Example 2: Social Media
Facebook has billions of users.
Data structure: Graph (users = nodes, friendships = edges).
Algorithm: BFS to suggest “friends of friends”.
Example 3: Maps / GPS
Data structure: Graph (cities = nodes, roads = edges).
Algorithm: Dijkstra’s shortest path → finds fastest route.
8. C Illustration (Very Simple Examples)
Array (Primitive)
#include <stdio.h>
int main() {
int arr[5] = {10, 20, 30, 40, 50};
for (int i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
Simple Algorithm (Find Maximum)
#include <stdio.h>
int main() {
int arr[5] = {10, 50, 30, 20, 40};
int max = arr[0];
for (int i = 1; i < 5; i++)
if (arr[i] > max) max = arr[i];
printf("Max: %d\n", max);
return 0;
}