data_structures_algorithms
data_structures_algorithms
Introduction
These notes cover fundamental concepts in Data Structures and Algorithms, essential for computer
science students. Topics include linked lists, time complexity, and sorting algorithms, with examples
and exercises.
1. Linked Lists
A linked list is a linear data structure where elements are stored in nodes. Each node contains data and
a reference to the next node.
1.1 Structure
A node in a singly linked list can be represented as:
class Node:
def __init__(self, data):
self.data = data
self.next = None
1.2 Diagram
Text-based representation of a linked list (Head -> Node1 -> Node2 -> None):
[Head] --> [Node1 | data: 5 | next] --> [Node2 | data: 10 | next] --> [None]
2. Time Complexity
Time complexity measures the efficiency of an algorithm as the input size grows. Common notations
include O(1), O(n), O(n²).
3.1 Pseudocode
procedure bubbleSort(arr):
n = length(arr) --
for i from 0 to n-1:
for j from 0 to n-i-1:
if arr[j] > arr[j+1]:
swap(arr[j], arr[j+1])
Time Complexity: O(n²)