


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Data Structures & Algorithms – Complete Study Notes
1. Introduction Data Structures : Organized ways to store and manage data for efficient access and modification. Algorithm : A step-by-step procedure to solve a problem. Importance : Optimizes memory usage Reduces computation time Forms the foundation of software development 2. Types of Data Structures 2.1 Linear Data Structures Elements stored sequentially Examples: 1. Array – Fixed-size collection of elements arr = [1, 2, 3, 4] print(arr[2]) # Output: 3 2. Linked List – Nodes connected via pointers 3. Stack – Last In First Out (LIFO) 4. Queue – First In First Out (FIFO) 2.2 Non-linear Data Structures Elements not in sequence Examples: 1. Tree – Hierarchical structure Binary Tree, Binary Search Tree (BST) 2. Graph – Nodes connected by edges Directed / Undirected Weighted / Unweighted 3. Algorithms Basics Definition: A set of rules or steps to solve a problem. Complexity:
Time Complexity – How fast an algorithm runs Space Complexity – How much memory it uses Big O Notation: Complex ity Example O(1) Accessing array element O(n) Linear search O(log n) Binary search O(n^2) Bubble sort
4. Sorting Algorithms Algorithm Time Complexity Best Use Case Bubble Sort O(n^2) Small arrays Insertion Sort O(n^2) Almost sorted data Merge Sort O(n log n) Large datasets Quick Sort O(n log n) General- purpose Python Example – Bubble Sort def bubble_sort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] return arr print(bubble_sort([5, 2, 9, 1])) # Output: [1, 2, 5, 9] 5. Searching Algorithms 1. Linear Search def linear_search(arr, x): for i in range(len(arr)): if arr[i] == x: