
Lecture 3: Introduction to Data Structures & Algorithms
After understanding the basics of computing and programming, the next step in Computer Science Engineering is mastering Data Structures and Algorithms. These two concepts form the foundation of efficient problem-solving in computer science.
1. What are Data Structures?
A Data Structure is a way of organizing and storing data in a computer so that it can be accessed and modified efficiently. Just like books are arranged in a library for easy retrieval, data structures arrange information for fast and effective operations.
Examples of Data Structures:
- Array – Stores elements in a fixed-size sequence.
- Linked List – Stores elements connected by pointers.
- Stack – Follows LIFO (Last In, First Out).
- Queue – Follows FIFO (First In, First Out).
- Tree – Represents hierarchical data (like a family tree).
- Graph – Represents relationships (like social networks).
- Hash Table – Provides fast lookups using keys.
2. What are Algorithms?
An Algorithm is a step-by-step method for solving a problem. It is like a recipe in cooking—clearly defined steps that must be followed to achieve the desired result.
Properties of a Good Algorithm:
- Correctness – It must solve the intended problem.
- Efficiency – It should use minimal time and memory.
- Clarity – Steps must be clear and unambiguous.
- Finiteness – It must terminate after a finite number of steps.
- Generality – It should solve all instances of a problem, not just one.
3. Relationship Between Data Structures & Algorithms
Data structures and algorithms are like the two sides of a coin:
- Data structures provide efficient storage and access to data.
- Algorithms provide efficient ways to manipulate and process that data.
- Together, they determine the performance of software systems.
Example: If data is stored in a queue, then the algorithm must follow FIFO principles to insert and remove elements correctly.
4. Examples of Common Algorithms
- Searching Algorithms
- Linear Search – Check elements one by one.
- Binary Search – Divide and conquer (works only on sorted data).
- Sorting Algorithms
- Bubble Sort – Compare and swap repeatedly.
- Selection Sort – Select the smallest/largest and place it correctly.
- Merge Sort – Divide and merge sorted halves.
- Quick Sort – Partition and recursively sort.
- Graph Algorithms
- Breadth-First Search (BFS) – Explore level by level.
- Depth-First Search (DFS) – Explore as deep as possible before backtracking.
- Dijkstra’s Algorithm – Find the shortest path in a weighted graph.
5. Example: Linear Search Algorithm
# Example: Linear Search in Python
def linear_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i # Return index of the target
return -1 # Return -1 if not found
# Test
numbers = [10, 20, 30, 40, 50]
print(linear_search(numbers, 30)) # Output: 2
In the above program, the algorithm checks each element one by one until the target is found or the list ends.
6. Importance of Studying DSA
Mastery of Data Structures & Algorithms (DSA) is crucial because it:
- Improves problem-solving skills.
- Forms the basis of competitive programming and coding interviews.
- Enables optimization of software performance.
- Provides industry relevance – most tech companies test DSA knowledge in hiring.
“Data Structures are about how you organize data. Algorithms are about how you use that data. Together, they are the language of efficiency in computer science.”
7. Summary of Key Points
- Data Structures = ways to organize and store data.
- Algorithms = step-by-step instructions to solve problems.
- Both together determine efficiency of programs and systems.
- Common algorithms include searching, sorting, and graph traversal.
- DSA knowledge is a core requirement for computer science engineers.
✦ Lecture 3 prepared under the authority of English Master Institute (EMI) Worldwide ✦