📘 PAPER 4 – DESIGN & ANALYSIS OF ALGORITHMS (UNIT 1 – INTRODUCTION & SORTING TECHNIQUES ) university of allahabad
cx
📘 PAPER 4 – DESIGN & ANALYSIS OF ALGORITHMS
🔴 UNIT 1 – INTRODUCTION & SORTING TECHNIQUES
1️⃣ Introduction to Algorithms
✅ What is an Algorithm?
An algorithm is a finite set of well-defined steps used to solve a problem.
✅ Characteristics of Algorithm
✔ Input
✔ Output
✔ Finiteness
✔ Definiteness
✔ Effectiveness
2️⃣ Analysis of Algorithms
Algorithm analysis means measuring performance in terms of:
🔹 Time Complexity
Time taken by an algorithm to run.
🔹 Space Complexity
Memory used by the algorithm.
3️⃣ Growth of Functions
Used to compare algorithm efficiency.
Common Growth Rates:
| Notation | Name |
|---|---|
| O(1) | Constant |
| O(log n) | Logarithmic |
| O(n) | Linear |
| O(n log n) | Linear-log |
| O(n²) | Quadratic |
| O(2ⁿ) | Exponential |
4️⃣ Asymptotic Notations
🔹 Big-O Notation – Worst Case
🔹 Omega (Ω) – Best Case
🔹 Theta (Θ) – Average Case
5️⃣ Recurrence Relations
A recurrence relation defines a function in terms of itself.
Example:
Solution Methods:
✔ Substitution method
✔ Recursion tree
✔ Master theorem
6️⃣ Sorting Algorithms
🔹 1. Shell Sort
Idea:
Improvement over insertion sort by comparing distant elements.
Steps:
-
Choose gap
-
Compare elements
-
Reduce gap
-
Repeat
Time Complexity:
-
Best: O(n log n)
-
Worst: O(n²)
🔹 2. Quick Sort
Concept:
Divide and conquer algorithm.
Steps:
-
Choose pivot
-
Partition array
-
Recursively sort subarrays
Time Complexity:
| Case | Time |
|---|---|
| Best | O(n log n) |
| Average | O(n log n) |
| Worst | O(n²) |
🔹 3. Merge Sort
Concept:
Divide array → Sort → Merge
Steps:
-
Divide array into halves
-
Recursively sort
-
Merge sorted parts
Time Complexity:
Advantage:
✔ Stable
✔ Predictable time
🔹 4. Heap Sort
Based on:
Steps:
-
Build heap
-
Extract max/min
-
Reheapify
Time Complexity:
🔹 5. Counting Sort (Linear Sorting)
Used when:
-
Elements are in limited range
Time Complexity:
7️⃣ Comparison of Sorting Algorithms
📌 EXAM IMPORTANT QUESTIONS (UNIT 1)
✔ Define algorithm
✔ Explain asymptotic notations
✔ Explain quick sort with example
✔ Compare merge sort and quick sort
✔ Explain recurrence relation
Comments
Post a Comment