DSA in Python - Detailed Notes (Exam +
Placement)
1. Time Complexity
Time complexity measures the efficiency of an algorithm.
Common complexities: O(1), O(log n), O(n), O(n log n), O(n^2)
# Example: Linear Time O(n)
for i in range(n):
print(i)
2. Arrays (Lists in Python)
Arrays store elements in contiguous memory.
arr = [1,2,3]
[Link](4)
print(arr[0])
3. Linked List
A linked list is a collection of nodes connected by pointers.
class Node:
def __init__(self, data):
[Link] = data
[Link] = None
4. Stack
Stack follows LIFO principle.
stack = []
[Link](10)
[Link]()
5. Queue
Queue follows FIFO principle.
from collections import deque
q = deque()
[Link](10)
[Link]()
6. Binary Search Tree
BST maintains sorted order: left < root < right.
class Node:
def __init__(self, data):
[Link] = data
[Link] = None
[Link] = None
7. Sorting Algorithms
Sorting arranges elements in order.
# Bubble Sort
def bubble_sort(arr):
for i in range(len(arr)):
for j in range(len(arr)-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
Practice Notes Section 1
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 2
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 3
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 4
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 5
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 6
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 7
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 8
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 9
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 10
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 11
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 12
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 13
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 14
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 15
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 16
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 17
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 18
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 19
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"
Practice Notes Section 20
Explain concepts, solve problems, and revise regularly. Practice is key to mastering DSA.
# Example Practice
def example():
return "Practice makes perfect"