Final compliant solution for two tasks:
- Task 1: Bus Allocation under distance and capacity constraints
- Task 2: Music Pattern Analysis (transposition-invariant contiguous patterns)
- No dictionaries or sets used anywhere
- No external graph libraries (e.g., networkx)
- From-scratch algorithms and list-based data structures
- Graph: adjacency list from
(u, v, w)undirected roads - Distances: Dijkstra implemented from scratch (manual binary heap)
- Allocation: Backtracking CSP to assign exactly
Tstudents - Constraints: Each bus must carry between
minandmax; students only board buses within distanceD
- Distances:
O(B * (R log L)) - Mapping students to buses:
O(S * B) - Backtracking guided by capacity checks (effective for given sizes)
python3 assignment_solution.py
# choose Task 1 and follow prompts
Input formats:
- roads:
(0,1,3), (0,2,5), ... - students:
4,10,8,... - buses:
(0,3,5), (6,5,10), ...
- Normalization: interval differences (key-invariant)
- Preprocessing: substrings per sequence; manual duplicate removal (no sets)
- Query:
getFrequentPattern(K)returns the most frequent normalized pattern of lengthK
python3 assignment_solution.py
# choose Task 2 and follow prompts
assignment_solution.py— main solution (both tasks + CLI)test_both_tasks.py— optional test harness
MIT