How sbktckp/design-and-analysis-of-algorithms works
1. Purpose and Execution Model
This is a C17 algorithms-lab repository: 36 independent command-line programs covering data structures, algorithm design paradigms, graph algorithms, amortization, and file handling. It is not a shared application/library; each numbered .c file is a standalone executable with its own main.
Primary entry points are the repository orchestrator run and root Makefile. ./run <question> selects and executes a full program; ./run compact/<question> selects its abbreviated counterpart.
2. Repository Organization: Full vs. Compact Implementations
Every lab/assignment directory is a self-contained unit with a local build, documentation, optional input data, full implementations, and a compact/ alternative. For example:
• Day 6 - Minimum Cost Spanning Tree/6.1_prim_mst.c
• Day 6 - Minimum Cost Spanning Tree/compact/6.1_prim_mst.c
• Day 6 - Minimum Cost Spanning Tree/Makefile
Full versions prioritize robust C practices, dynamic allocation, checked file operations, and appropriate data structures. Compact versions intentionally trade safety and asymptotic efficiency for short, record-book-ready code. They do not form a runtime dependency chain.
3. Build and Launch Boundary
The root build aggregates per-directory Makefiles:
• Makefile
• Day 3 - Divide and Conquer Method/Makefile
• Assignment 1 - File Handling/compact/Makefile
Each local Makefile compiles source files into that directory’s ignored bin/ output area. The launcher must execute binaries from their owning day directory because programs commonly resolve relative data/ paths. This working-directory convention is the key runtime boundary between otherwise independent exercises.
Runtime requirements are a POSIX-like shell plus gcc/make; the stated language target is standard C17. Development-container support is defined in .devcontainer/devcontainer.json. No network APIs, databases, or external application services are used.
4. Input, Output, and File-Handling Programs
Programs accept interactive input and/or positional arguments, with local test fixtures under per-topic data/ folders. File-oriented flows read relative files, transform or analyze content, then print or write results:
• Assignment 1 - File Handling/1.1_compare_files.c
• Assignment 1 - File Handling/1.2_uppercase_convert.c
• Assignment 1 - File Handling/data/test.txt
The launcher forwards arguments after a question identifier, enabling workflows such as source input path to generated output path. Generated files and binaries are excluded from source control.
5. Sequential, Recursive, and Sorting Stages
Early exercises operate over arrays and numeric inputs: traversal, prefix sums, duplicate detection, rotation, decimal conversion, and GCD. Divide-and-conquer implementations provide merge sort and quicksort, including behavior across ordered and random datasets:
• Day 1 - Revision of Data Structures/1.2_prefix_sum.c
• Day 2 - Fundamentals of Algorithmic Problem Solving/2.3_gcd_pairs.c
• Day 3 - Divide and Conquer Method/3.1_merge_sort.c
These are standalone algorithm pipelines: parse input, construct/work over in-memory arrays, emit results.
6. Data-Structure and Greedy Construction
Heap and greedy exercises construct explicit in-memory structures and repeatedly choose or reorder candidates:
• Day 4 - Heap/4.1_person_heap.c
• Day 5 - Greedy Techniques/5.1_fractional_knapsack.c
• Day 5 - Greedy Techniques/5.2_huffman_coding.c
Notably, full versions may use heaps/tree structures where compact versions use fixed arrays or linear selection. This distinction is pedagogical rather than an intermodule API boundary.
7. Graph and Dynamic-Programming Algorithms
Graph programs ingest adjacency matrices or edge lists, then execute canonical optimization flows: Prim/Kruskal produce MSTs, Dijkstra relaxes from one source, and Floyd–Warshall updates all-pairs distances by intermediary vertex. DP programs fill tables bottom-up and reconstruct solutions where applicable:
• Day 6 - Minimum Cost Spanning Tree/6.2_kruskal_mst.c
• Day 7 - Single Source Shortest Path/7.1_dijkstra_shortest_path.c
• Day 9 - All Pair Shortest Path/9.1_floyd_warshall.c
Representative graph-input boundaries are local fixtures such as Day 6 - Minimum Cost Spanning Tree/data/inEdgeList.dat and Day 7 - Single Source Shortest Path/data/inDiAdjMat1.dat.
Main entry points: Day 3 - Divide and Conquer Method/Makefile Directory Makefiles · run run launcher · inEdgeList.dat Local data fixtures · Makefile Root Makefile
Components 19
Build & Launch
- POSIX shell, gcc & make · C17 build and execution environment.
- Root Makefile · Aggregates directory-local builds.
Makefile - run launcher · Selects a full or compact question and forwards arguments.
run - Directory Makefiles · Compile each self-contained exercise into its local bin directory.
Day 3 - Divide and Conquer Method/Makefile - Local bin executables · Ignored outputs owned by each exercise directory.
- Development container
.devcontainer/devcontainer.json
Full Standalone Programs
- File handling · Reads, transforms, compares, or writes local files.
Assignment 1 - File Handling/1.2_uppercase_convert.c - Array & numeric algorithms · Parses input, processes in-memory arrays, and prints results.
Day 1 - Revision of Data Structures/1.2_prefix_sum.c - GCD pair analysis
Day 2 - Fundamentals of Algorithmic Problem Solving/2.3_gcd_pairs.c - Divide-and-conquer sorting
Day 3 - Divide and Conquer Method/3.1_merge_sort.c - Heap & greedy algorithms · Full variants use dynamic structures where appropriate.
Day 4 - Heap/4.1_person_heap.c - Graph optimization · Consumes matrices or edge lists for MST and shortest-path algorithms.
Day 6 - Minimum Cost Spanning Tree/6.2_kruskal_mst.c - All-pairs shortest path · Updates a distance matrix by intermediary vertex.
Day 9 - All Pair Shortest Path/9.1_floyd_warshall.c
Compact Alternatives
- Compact program variants · Short alternatives with simplified safety and data-structure choices.
Day 6 - Minimum Cost Spanning Tree/compact/6.1_prim_mst.c - Compact build rules
Assignment 1 - File Handling/compact/Makefile
Local Runtime I/O
- Owning exercise directory · Programs run here so relative data paths resolve correctly.
- Local data fixtures · Per-topic files used by file and graph exercises.
Day 6 - Minimum Cost Spanning Tree/data/inEdgeList.dat - Interactive input & arguments
- Printed or generated results · Generated files are not source-controlled.
Connections 22
- Development container → POSIX shell, gcc & make: provides
- POSIX shell, gcc & make → Root Makefile: runs
- POSIX shell, gcc & make → run launcher: runs
- Root Makefile → Directory Makefiles: aggregates
- Directory Makefiles → Local bin executables: builds full programs
- Compact build rules → Local bin executables: builds compact programs
- File handling → Directory Makefiles: compiled by
- Array & numeric algorithms → Directory Makefiles: compiled by
- GCD pair analysis → Directory Makefiles: compiled by
- Divide-and-conquer sorting → Directory Makefiles: compiled by
- Heap & greedy algorithms → Directory Makefiles: compiled by
- Graph optimization → Directory Makefiles: compiled by
- All-pairs shortest path → Directory Makefiles: compiled by
- Compact program variants → Compact build rules: compiled by
- run launcher → Local bin executables: selects and executes
- run launcher → Owning exercise directory: sets
- Owning exercise directory → Local data fixtures: resolves relative paths
- Interactive input & arguments → run launcher: question and forwarded args
- Interactive input & arguments → Local bin executables: interactive input
- Local data fixtures → File handling: read or transformed
- Local data fixtures → Graph optimization: graph input
- Local bin executables → Printed or generated results: prints or writes