CS502 Midterm Study Guide
CS502 Midterm Study Guide
Chapter 1: Introduction
Common Complexities
Merge Sort
Steps:
1. Divide: Split array into halves.
2. Conquer: Recursively sort subarrays.
3. Combine: Merge sorted halves.
Example: Sorting [3, 1, 4, 2] -> Divide into [3, 1] and [4, 2], sort, then merge.
Complexity: Θ(n log n).
Examples:
- Bubble Sort: Repeatedly swap adjacent elements if they are in the wrong order.
- Selection Sort: Select the smallest unsorted element and place it in order.
Complexity: Θ(n²).
Efficient Sorting
Non-Comparison-Based Sorting
Fibonacci Sequence
Given items with weights and values, maximize the total value without exceeding the weight
limit.
Algorithm: DP table to track maximum values for weight limits.