Data Structures with Python - Unit 1 to 3 Notes
UNIT 1: INTRODUCTION TO DATA STRUCTURES
1. Introduction to Data Structures:
Data Structure is a way to store and organize data so that it can be used efficiently. It helps in
processing data logically and in an optimized manner.
2. Operations on Data Structures:
- Traversing
- Insertion
- Deletion
- Searching
- Sorting
- Merging
3. Classification of Data Structures:
- Primitive Data Structures: int, float, char, bool (e.g., a = 10)
- Non-Primitive Data Structures:
a. Linear: Arrays, Lists, Stacks, Queues
b. Non-Linear: Trees, Graphs
4. Characteristics of Data Structures:
- Correctness
- Time Complexity
- Space Complexity
- Reusability
- Abstraction
5. Primitive and Non-Primitive Types with Examples:
- Primitive: int, float, char
- Non-Primitive: list, tuple, dict, set in Python
6. Linear and Non-Linear Data Structures:
- Linear: Arranged in sequence (e.g., list, stack)
- Non-Linear: Not arranged sequentially (e.g., tree, graph)
7. Abstract Data Type (ADT):
- Abstraction hides implementation.
- ADT Examples: Student, Date, Employee (define fields and methods)
- Using ADT: Create functions to work on ADT.
- Implementing ADT: Define classes and functions in Python.
8. Python Program to Use Basic Data Structures:
Example:
arr = [1, 2, 3]
stack = []
stack.append(10)
stack.pop()
9. Implement an ADT with all operations:
Example: Class-based implementation of Stack with push, pop, display, etc.
10. Algorithm Analysis:
- Space Complexity: Amount of memory used.
- Time Complexity: Time taken by algorithm as input grows.
11. Runtime Analysis:
- Evaluating the efficiency of an algorithm based on input size and steps.
12. Asymptotic Notations:
- Big-O: Worst-case
- Omega: Best-case
- Theta: Average-case
------------------------------------------------------------
UNIT 2: ALGORITHM DESIGN STRATEGIES
1. Brute Force:
- Bubble Sort
- Selection Sort
- Linear Search
2. Decrease and Conquer:
- Insertion Sort
3. Divide and Conquer:
- Merge Sort: Divide list, sort each part, merge.
- Quick Sort: Use pivot, divide list, recursively sort.
- Binary Search: Search in sorted list by halving.
Python Examples for All Above Provided
------------------------------------------------------------
UNIT 3: DYNAMIC PROGRAMMING
1. Dynamic Programming (DP):
- Solve overlapping subproblems.
- Store results to avoid recalculation.
2. Fibonacci Example:
- Recursive (O(2^n))
- Memoization (Top-Down DP) (O(n))
- Tabulation (Bottom-Up DP) (O(n))
- Optimized DP (O(n), O(1) space)
Python code for all versions of Fibonacci included.