Project Overview
This capstone project focuses on algorithm implementation and visualization. You will work with test datasets containing arrays of various sizes (100 to 10,000 elements) with different initial orderings (random, sorted, reverse-sorted, nearly-sorted). Your goal is to build a professional sorting visualizer that animates each algorithm step-by-step in the console, tracks comparisons and swaps, measures execution time, and allows users to compare algorithm performance.
Algorithms
Implement 6 classic sorting algorithms with analysis
Visualization
ASCII-based animation showing each step
Performance
Track comparisons, swaps, and execution time
CLI Interface
Menu-driven command-line user interface
Learning Objectives
Technical Skills
- Implement and understand sorting algorithm complexity
- Use function pointers for algorithm selection
- Measure execution time with clock() and time()
- Manipulate console output for animation effects
- Build modular programs with header files
Professional Skills
- Analyze algorithm performance empirically
- Create intuitive visual representations
- Build user-friendly command-line interfaces
- Write maintainable and well-documented code
- Compare theoretical vs actual performance
Project Scenario
CodeAcademy Learning Platform
You have been hired as a Software Developer at CodeAcademy, an online learning platform that teaches programming to beginners. The curriculum team wants to add an interactive tool that helps students understand how different sorting algorithms work by visualizing each step of the sorting process.
"Students often struggle to understand sorting algorithms from just reading pseudocode. We need a visual tool that shows exactly how Bubble Sort, Quick Sort, and others rearrange elements step by step. Can you build a console-based visualizer that makes algorithms come alive?"
System Requirements from the Client
- Bubble Sort with optimization flag
- Selection Sort
- Insertion Sort
- Merge Sort (recursive)
- Quick Sort (with pivot selection)
- Heap Sort
- Bar chart display using ASCII characters
- Highlight current elements being compared
- Show swap operations with color
- Adjustable animation speed
- Step-by-step or continuous mode
- Count total comparisons
- Count total swaps/moves
- Measure execution time (milliseconds)
- Display complexity notation
- Compare multiple algorithms side-by-side
- Generate random arrays of any size
- Load arrays from test files
- Create sorted, reverse, nearly-sorted data
- Allow custom array input
- Save results to file
The Dataset
You will work with random number arrays specifically designed for sorting algorithm testing and performance analysis. The Kaggle dataset contains CSV files with different sizes to benchmark algorithm performance at various scales:
Sample Dataset Download
Download random number files for testing your sorting implementations (same format as Kaggle).
Random Numbers CSV Files:
Full Dataset from Kaggle
This project uses the Random Numbers dataset from Kaggle -
CSV files with random numbers generated using np.random.rand() for algorithm benchmarking:
random_numbers_1000.csv- 1,000 numbersrandom_numbers_10000.csv- 10,000 numbersrandom_numbers_100000.csv- 100,000 numbers
random_numbers_1000000.csv- 1 million numbersrandom_numbers_10000000.csv- 10 million numbers
Dataset Schema
| File | Records | Use Case |
|---|---|---|
random_numbers_1000.csv | 1,000 numbers | Quick testing |
random_numbers_10000.csv | 10,000 numbers | Small benchmarks |
random_numbers_100000.csv | 100,000 numbers | Medium benchmarks |
random_numbers_1000000.csv | 1,000,000 numbers | Large benchmarks |
random_numbers_10000000.csv | 10,000,000 numbers | Stress testing |
fscanf(file, "%lf", &arr[i]) for doubles.
Compare algorithm performance across different array sizes to analyze time complexity.
Key Concepts
Before diving into the implementation, understand these fundamental concepts that power your sorting visualizer. These concepts are essential for building an efficient and educational algorithm visualization tool.
- Bubble Sort: O(n^2) - Compare adjacent pairs, swap if out of order
- Selection Sort: O(n^2) - Find minimum, place at beginning
- Insertion Sort: O(n^2) - Build sorted portion one element at a time
- Merge Sort: O(n log n) - Divide, sort halves, merge back
- Quick Sort: O(n log n) avg - Partition around pivot recursively
- Heap Sort: O(n log n) - Build max-heap, extract maximum
- Bar Chart: Use ASCII characters to draw bars proportional to values
- Color Coding: ANSI escape codes for highlighting comparisons/swaps
- Animation: Clear screen and redraw to create motion effect
- Speed Control: Use usleep() or Sleep() to control delay
- Step Mode: Wait for keypress between each operation
- Legend Display: Show current operation and metrics
- Comparisons: Count each time two elements are compared
- Swaps/Moves: Count each time elements change position
- Time: Use clock() to measure CPU time in milliseconds
- Memory: Track auxiliary space for algorithms like Merge Sort
- Iterations: Count outer loop passes for iterative algorithms
- Recursion Depth: Track maximum stack depth for recursive algorithms
- Sort Function Type: Define typedef for sort function signature
- Algorithm Array: Store all algorithms in function pointer array
- Generic Visualizer: Pass algorithm as parameter to visualize()
- Benchmark Runner: Loop through all algorithms using pointers
- Callback System: Notify visualizer on each comparison/swap
- Clean Interface: Single function handles all algorithm types
Project Structure
include/
- sorting.h - Algorithm declarations
- visualizer.h - Display functions
- metrics.h - Performance tracking
- utils.h - Helper functions
- menu.h - Menu interface
src/
- bubble.c - Bubble sort
- selection.c - Selection sort
- insertion.c - Insertion sort
- merge.c - Merge sort
- quick.c - Quick sort
- heap.c - Heap sort
- visualizer.c - Display logic
- metrics.c - Performance tracking
- menu.c - User interface
- main.c - Entry point
Other Files
- data/ - Test arrays
- tests/ - Unit test files
- Makefile - Build config
- README.md - Documentation
Project Requirements
Complete all components below to build a fully functional sorting visualizer. Each step builds upon the previous one, taking you from basic algorithms to an interactive educational tool.
Basic Sorting Algorithms
Implement O(n^2) Algorithms:
- Bubble Sort with early termination optimization
- Selection Sort finding minimum each pass
- Insertion Sort building sorted portion
- Each algorithm counts comparisons and swaps
Advanced Sorting Algorithms
Implement O(n log n) Algorithms:
- Merge Sort with auxiliary array allocation
- Quick Sort with median-of-three pivot selection
- Heap Sort with heapify operations
- Track recursion depth for recursive algorithms
Visualization Engine
ASCII Bar Chart Display (visualizer.c):
- Draw horizontal or vertical bars for each element
- Highlight elements being compared (different color)
- Highlight elements being swapped (another color)
- Show current operation description
- Display running metrics (comparisons, swaps, time)
Performance Metrics
Metrics Tracking (metrics.c):
- Metrics structure with comparisons, swaps, time, memory
- Timer functions using clock() for CPU time
- Reset and accumulate functions for benchmarking
- Format and print metrics in table format
Menu Interface
Main Menu (menu.c):
- Select sorting algorithm from list
- Choose data source (file, random, custom)
- Set visualization speed (fast, medium, slow, step)
- Run single algorithm or compare all
- View benchmark results table
Benchmark Comparison
Algorithm Comparison:
- Run all algorithms on same input data
- Display side-by-side metrics table
- Rank algorithms by each metric
- Test with different input patterns
- Export results to CSV file
Example Usage
Your sorting visualizer should provide a clear, menu-driven interface. Below are the expected features and sample workflows for each major operation.
- Visualize Sorting Algorithm
- Run Single Algorithm (no visual)
- Compare All Algorithms
- Generate Random Array
- Load Array from File
- Enter Custom Array
- Set Visualization Speed
- View Algorithm Info
- Export Results to CSV
- Exit
Choose from 6 sorting algorithms:
- Bubble Sort - Simple, O(n^2), stable
- Selection Sort - Simple, O(n^2), unstable
- Insertion Sort - Adaptive, O(n^2), stable
- Merge Sort - Divide and conquer, O(n log n), stable
- Quick Sort - Partition-based, O(n log n) avg, unstable
- Heap Sort - Heap-based, O(n log n), unstable
- Bar Chart: ASCII bars showing element values
- Compare Highlight: Yellow for elements being compared
- Swap Highlight: Green for elements being swapped
- Sorted Highlight: Cyan for elements in final position
- Speed Control: Instant, Fast (10ms), Medium (50ms), Slow (200ms), Step
- Algorithm Name: Name of sorting algorithm
- Comparisons: Total number of comparisons
- Swaps: Total number of swaps/moves
- Time (ms): Execution time in milliseconds
- Complexity: Time and space complexity notation
Test Cases for Validation
| Test Case | Input | Expected Result |
|---|---|---|
| Small Random | 10 random elements | All algorithms sort correctly |
| Already Sorted | 1,2,3,4,5,6,7,8,9,10 | Bubble/Insertion detect early, minimal work |
| Reverse Sorted | 10,9,8,7,6,5,4,3,2,1 | Maximum comparisons for Bubble/Selection |
| Duplicates | 5,3,8,3,9,3,1,3 | All algorithms handle duplicates correctly |
| Single Element | 42 | Return immediately, no operations |
| Empty Array | (empty) | Handle gracefully, no crash |
| Large Random | 1000 random elements | O(n^2) noticeably slower than O(n log n) |
| Negative Numbers | -5,3,-8,0,9,-1 | Sort correctly including negatives |
Submission Requirements
Create a public GitHub repository with the exact name shown below:
Required Repository Name
c-sorting-visualizer
Required Project Structure
include/
- sorting.h
- visualizer.h
- metrics.h
- utils.h
- menu.h
src/
- bubble.c, selection.c, insertion.c
- merge.c, quick.c, heap.c
- visualizer.c
- metrics.c
- menu.c, main.c
Other
- data/ (test arrays)
- tests/ (test files)
- Makefile
- README.md
README.md Required Sections
1. Project Header
- Project title and description
- Your full name and submission date
- Course and project number
2. Features
- List of all sorting algorithms
- Visualization capabilities
- Performance metrics tracked
3. Build Instructions
- Prerequisites (GCC, make)
- How to compile with make
- How to run the program
4. Usage Examples
- Menu navigation guide
- Sample visualization output
- Screenshots or GIFs of animation
5. Algorithm Details
- Brief description of each algorithm
- Time and space complexity
- Best/worst case scenarios
6. Benchmark Results
- Performance comparison table
- Analysis of results
- Observations about complexity
7. Challenges and Solutions
- Difficulties encountered
- How you solved them
- What you learned
8. Contact
- GitHub profile link
- LinkedIn (optional)
- Email (optional)
Do Include
- All source files (.c) and headers (.h)
- Working Makefile with all targets
- Test data files for validation
- Test file with unit tests
- Screenshots/GIFs showing visualization
- Complete README with all sections
Do Not Include
- Compiled binaries or object files (*.o, *.exe)
- IDE-specific files (.vscode/, .idea/)
- Temporary or backup files
- Plagiarized code from online sources
gcc -Wall -Wextra and all
sorting algorithms produce correctly sorted output.
Enter your GitHub username - we will verify your repository automatically
Grading Rubric
Your project will be graded on the following criteria. Total: 400 points.
| Criteria | Points | Description |
|---|---|---|
| Basic Algorithms | 60 | Bubble, Selection, Insertion sort correctly implemented |
| Advanced Algorithms | 90 | Merge, Quick, Heap sort correctly implemented |
| Visualization | 80 | Clear ASCII display with highlighting and animation |
| Performance Metrics | 50 | Accurate tracking of comparisons, swaps, time |
| User Interface | 40 | Menu system, input validation, user-friendly messages |
| Benchmark Comparison | 40 | Side-by-side algorithm comparison with analysis |
| Code Quality | 20 | Modular design, comments, function pointers |
| Documentation | 20 | README quality, screenshots, complexity analysis |
| Total | 400 |
Grading Levels
Excellent
Exceeds all requirements with exceptional quality
Good
Meets all requirements with good quality
Satisfactory
Meets minimum requirements
Needs Work
Missing key requirements
Ready to Submit?
Make sure you have completed all requirements and reviewed the grading rubric above.
Submit Your ProjectPre-Submission Checklist
Use this checklist to verify you have completed all requirements before submitting your project.
Sorting Algorithms
Visualization
Metrics and Comparison
Repository Requirements
Common Issues and Solutions
Encountering problems? Here are the most common issues students face and how to resolve them quickly.
Quick Sort Stack Overflow
Program crashes on large or already-sorted arrays
Use median-of-three pivot selection instead of always picking first or last element. This prevents worst-case O(n^2) behavior on sorted input.
Screen Flicker During Animation
Visualization flickers annoyingly during animation
Use ANSI escape codes to move cursor to top of screen instead of clearing. Use printf("\033[H") to move to home position.
Merge Sort Memory Leak
Memory usage grows with each sort operation
Allocate a single auxiliary array once before sorting and pass it to the recursive function. Free it after sorting completes.
Inaccurate Time Measurement
Time shows 0ms for small arrays
Use clock() instead of time() for CPU time measurement. Calculate: (double)(end - start) / CLOCKS_PER_SEC * 1000.0 for milliseconds.
Still Having Issues?
Check the course discussion forum or reach out for help