amh1k/daa-algorithm-visualizer
Design and Analysis of Algorithms - Project 2025
    
A comprehensive collection of divide-and-conquer algorithm implementations with professional web-based visualizations for the Design and Analysis of Algorithms course.
๐ฅ Team Members
๐ Table of Contents
- About the Project
- Features
- Technologies Used
- Project Structure
- Problem Implementations
- Question 1: Basic Algorithms
- Question 2: Advanced Visualization
- How to Run
- Screenshots
- Time Complexity Analysis
- Contributing
๐ฏ About the Project
This project showcases 13 algorithmic implementations focusing on the Divide and Conquer paradigm, featuring:
- ๐ Interactive Web Visualizations - Step-by-step algorithm execution
- ๐จ Modern UI/UX - Dark mode, glassmorphism, smooth animations
- โก High Performance - Optimized C++ backend with Next.js frontend
- ๐ Comprehensive Testing - 40+ test cases with benchmark dashboard
- ๐ Educational Value - Clear explanations and visual learning
โจ Features
๐ Web Application (Question 2)
- Beautiful Landing Page with animated gradient backgrounds
- Interactive Visualizations:
- Closest Pair: Step-by-step divide-and-conquer animation
- Integer Multiplication: Recursive tree visualization
- Dark/Light Mode with system preference detection
- Multiple Input Methods: Predefined files, custom upload, manual entry
- Real-time Performance Metrics with benchmark dashboard
- Responsive Design - works on all screen sizes
- Professional UI Components using shadcn/ui and Radix UI
๐ข Algorithm Implementations (Question 1 & 2)
- 13 C++ Implementations covering classic divide-and-conquer problems
- Optimized Code with
-O2compilation flags - Detailed Output including execution time and complexity analysis
- Test Data Generation for comprehensive testing
๐ ๏ธ Technologies Used
Backend
C++11/14 - Algorithm implementation
- STL - Data structures and algorithms
- Chrono - High-precision time measurement
Frontend
Next.js 14.1 - React framework with App Router
React 18.2 - UI library
TypeScript 5.3 - Type safety
Tailwind CSS 3.4 - Utility-first styling
- Framer Motion - Smooth animations
- Recharts - Performance charts
- shadcn/ui - Modern UI components
๐ Project Structure
Daa-Project/
โ
โโโ README.md # Main documentation
โโโ GIT_CHEAT_SHEET.md # Git collaboration guide
โโโ INSTRUCTIONS.md # Quick setup guide
โโโ .gitignore # Git ignore rules
โ
โโโ q1/ # Question 1: Basic Algorithms
โ โโโ a.cpp # Algorithm A
โ โโโ b.cpp # Binary Exponentiation
โ โโโ c.cpp # Counting Inversions
โ โโโ e.cpp # Algorithm E
โ โโโ f.cpp # Peak Element Finder
โ โโโ g.cpp # Maximum Stock Profit
โ โโโ h_1.cpp # Median of Two Arrays (Method 1)
โ โโโ h_2.cpp # Median of Two Arrays (Method 2)
โ โโโ h_3.cpp # Median of Two Arrays (Method 3)
โ
โโโ q2/ # Question 2: Advanced Visualization
โโโ closest_pair.cpp # Closest Pair Algorithm (247 lines)
โโโ integer_multiplication.cpp # Karatsuba Multiplication (214 lines)
โ
โโโ test_data/ # Test Files (40+ files)
โ โโโ closest_pair/ # 10 point datasets (100-1000 points)
โ โโโ integer_multiplication/ # 10 digit datasets (100-1000 digits)
โ
โโโ ui/ # Next.js Web Application
โโโ app/ # Pages & API Routes
โ โโโ page.tsx # Landing page
โ โโโ closest-pair/ # Closest pair visualization page
โ โโโ integer-multiplication/ # Karatsuba visualization page
โ โโโ benchmark/ # Performance dashboard
โ โโโ api/ # API endpoints (5 routes)
โ
โโโ components/ # React Components (22 components)
โ โโโ closest-pair-step-visualization.tsx
โ โโโ recursive-tree.tsx
โ โโโ static-points-canvas.tsx
โ โโโ navigation.tsx
โ โโโ theme-provider.tsx
โ โโโ ui/ # shadcn/ui components
โ
โโโ lib/ # Utilities
โโโ public/ # Static assets
โโโ styles/ # Global styles๐ก Problem Implementations
Question 1: Basic Algorithms
1. Binary Exponentiation (b.cpp)
Problem: Compute a^b efficiently using divide and conquer.
- Time Complexity: O(log b)
- Space Complexity: O(log b) - recursion stack
- Approach: Exponentiation by squaring
// If b is even: a^b = (a^(b/2))^2
// If b is odd: a^b = (a^(b/2))^2 ร a2. Counting Inversions (c.cpp)
Problem: Count pairs (i, j) where i < j but arr[i] > arr[j].
- Time Complexity: O(n log n)
- Space Complexity: O(n)
- Approach: Modified merge sort
3. Peak Element Finder (f.cpp)
Problem: Find an element greater than or equal to its neighbors.
- Time Complexity: O(log n)
- Space Complexity: O(log n) - recursion stack
- Approach: Binary search on array
4. Maximum Stock Profit (g.cpp)
Problem: Find maximum profit from buying and selling stocks.
- Time Complexity: O(n log n)
- Space Complexity: O(n)
- Approach: Divide and conquer on difference array
5. Median of Two Sorted Arrays (h_1.cpp, h_2.cpp, h_3.cpp)
Problem: Find n-th smallest element from two sorted arrays.
- Time Complexity: O(log n)
- Space Complexity: O(1)
- Approach: Binary search on partitions
Question 2: Advanced Visualization
๐ฏ Algorithm 1: Closest Pair of Points
File: q2/closest_pair.cpp (247 lines)
Problem: Find the two closest points among n points in 2D space.
Algorithm: Divide and Conquer
- Time Complexity: O(n log n)
- Space Complexity: O(n)
Implementation Features:
- โ Sorts points by x and y coordinates
- โ Recursively divides plane into halves
- โ Checks strip area for cross-boundary pairs
- โ Generates JSON trace for visualization (n โค 50)
- โ Handles 100-1000 point datasets
Visualization Features:
- ๐จ Step-by-step animation with playback controls
- ๐ Divide line visualization (red dashed)
- ๐ฏ Active region highlighting (teal)
- ๐ฃ Strip area visualization (purple)
- โ Closest pair highlighting (green)
- โฏ๏ธ Play, pause, step forward/backward controls
- ๐ Progress tracking with step descriptions
๐ข Algorithm 2: Karatsuba Integer Multiplication
File: q2/integer_multiplication.cpp (214 lines)
Problem: Multiply arbitrarily large integers efficiently.
Algorithm: Karatsuba's Fast Multiplication
- Time Complexity: O(n^1.585) where n = number of digits
- Space Complexity: O(n)
Implementation Features:
- โ String-based arithmetic for large numbers
- โ Recursive three-way split (z2, z0, z1)
- โ Generates tree visualization (โค50 digits)
- โ Handles 100-1000+ digit multiplication
- โ Falls back to naive method for small numbers
Visualization Features:
- ๐ณ Interactive recursive tree display
- ๐จ Color-coded node types:
- ๐ฃ Purple - Root (original multiplication)
- ๐ต Blue - zโ (high digits: a ร c)
- ๐ข Green - zโ (low digits: b ร d)
- ๐ Orange - zโ (middle term)
- ๐ Zoom controls (30%-150%)
- ๐ฑ๏ธ Pan with left-click drag
- ๐ Smart number truncation for readability
- ๐ Depth and digit count tracking
๐ How to Run
Prerequisites
- Node.js v18 or higher
- npm or yarn package manager
- C++ Compiler (g++/MinGW/MSVC)
- Git (optional)
Quick Start (Question 2 - Web Application)
Step 1: Clone Repository
git clone https://github.com/amh1k/Daa-Project.git
cd Daa-ProjectStep 2: Compile C++ Programs
cd q2
g++ -O2 closest_pair.cpp -o closest_pair.exe
g++ -O2 integer_multiplication.cpp -o integer_multiplication.exeStep 3: Install Dependencies
cd ui
npm installStep 4: Run Development Server
npm run devStep 5: Open Browser
Navigate to: http://localhost:3000
Running Question 1 Algorithms
# Navigate to q1 directory
cd q1
# Compile and run any algorithm
g++ b.cpp -o b.exe
./b.exe
# Example: Binary Exponentiation
echo "2 10" | ./b.exe
# Output: 1024
# Example: Counting Inversions
./c.exe
# Output: The number of inversions are: 22๐ธ Screenshots
๐ Landing Page (Dark Mode)
Beautiful gradient animations with glassmorphism effects, featuring three main algorithm sections
๐ Light Mode Support
Professional light theme with optimal contrast and accessibility
๐ Closest Pair Visualization
Step-by-step divide-and-conquer animation with playback controls, divide line visualization, and active region highlighting
Features:
- Interactive canvas visualization
- Play, pause, step forward/backward controls
- Real-time algorithm step descriptions
- Multiple input methods (predefined, custom, manual)
- Compact footer legend with color coding
๐ข Integer Multiplication - Karatsuba Algorithm
Large number multiplication with result display and performance metrics
Features:
- Support for 100-1000+ digit numbers
- Instant calculation results
- Execution time tracking
- Clean result presentation
๐ณ Recursive Tree Visualization
Interactive tree showing Karatsuba's recursive breakdown with color-coded node types (zโ, zโ, zโ)
Features:
- Expand view with zoom controls (30%-150%)
- Pan with left-click drag
- Shrink button for compact view
- Color-coded nodes: Purple (Root), Blue (zโ), Green (zโ), Orange (zโ)
- Horizontal scrollbar for wide trees
- Smart number truncation for readability
๐ Benchmark Dashboard
Comprehensive performance testing with real-time progress tracking for all 20 test cases
Features:
- Batch execution of all test files
- Real-time progress indicators
- Side-by-side performance comparison
- Success/failure status for each test
- Execution time metrics
- Dataset size information
โฑ๏ธ Time Complexity Analysis
๐ Key Concepts Demonstrated
Algorithmic Techniques
- โ Divide and Conquer - Breaking problems into smaller subproblems
- โ Binary Search - Efficient searching in sorted/partially sorted data
- โ Merge Sort - Efficient sorting with additional applications
- โ Dynamic Problem Solving - Converting problems to known formats
- โ Optimization - Achieving logarithmic and linearithmic complexities
Software Engineering
- โ Full-Stack Development - C++ backend + React frontend
- โ API Design - RESTful endpoints with error handling
- โ Component Architecture - Reusable React components
- โ Type Safety - TypeScript for robust code
- โ Performance Optimization - Lazy loading, caching, GPU acceleration
- โ Responsive Design - Mobile-first approach
- โ Accessibility - WCAG-compliant UI
UI/UX Design
- โ Modern Design Patterns - Glassmorphism, gradients
- โ Smooth Animations - Framer Motion for professional feel
- โ Dark Mode - System preference detection
- โ Interactive Visualizations - Canvas & SVG rendering
- โ User Feedback - Loading states, progress bars, error messages
๐ Educational Value
For Students
- ๐ Step-by-step algorithm execution - Visual learning
- ๐ก Clear complexity explanations - Understand time/space trade-offs
- ๐งช Multiple test cases - Edge case handling
- ๐ Performance comparison - Benchmark different inputs
For Instructors
- โ Production-ready code - Demonstrates best practices
- โ Comprehensive documentation - Easy to understand and grade
- โ Interactive demos - Use in lectures
- โ Extensible architecture - Students can add more algorithms
๐ง Advanced Features
Performance Optimization
- C++ Backend:
-O2optimization flags - React Frontend: Code splitting, lazy loading
- Canvas Rendering: GPU-accelerated drawing
- Smart Caching: Webpack build optimization
Error Handling
- โ Executable validation
- โ Input file validation
- โ Parse error detection
- โ Timeout handling (30s limit)
- โ User-friendly error messages
Testing
- 40+ predefined test files
- Custom file upload support
- Manual input validation
- Edge case coverage
- Performance benchmarking
๐ค Contributing
This is an academic project. For improvements:
- Fork the repository
- Create feature branch:
git checkout -b feature/improvement - Commit changes:
git commit -m 'Add improvement' - Push to branch:
git push origin feature/improvement - Open Pull Request
๐ง Contact
For questions or discussions:
- Huzaifa Abdul Rehman - 23k-0782
- Abdul Moiz Hossain - 23k-0553
- Ajay Kumar - 23K-0514
๐ License
This project is created for educational purposes as part of the Design and Analysis of Algorithms course (CS302 - 5th Semester).
๐ Acknowledgments
References
- Introduction to Algorithms (CLRS) - Algorithm theory
- GeeksforGeeks & LeetCode - Problem-solving inspiration
- Next.js Documentation - Web framework guidance
- shadcn/ui - Component library
- Framer Motion - Animation library
Inspiration
- Algorithm visualization tools (VisuAlgo, Algorithm Visualizer)
- Professional web applications (Figma, VS Code)
- Academic research papers on divide-and-conquer
๐ Project Statistics
- Total Files: 2,800+ (including dependencies)
- Custom Code:
- 13 C++ algorithm implementations
- 22 React components
- 5 API routes
- 40+ test data files
- Lines of Code:
- C++: 600+ lines
- TypeScript/TSX: 3,000+ lines
- Test Coverage: 20 comprehensive test cases
- Supported Input Sizes:
- Closest Pair: 10-1000 points
- Integer Multiplication: 12-1000+ digits
๐ฏ Project Achievements
โ Complete implementation of 13 divide-and-conquer algorithms โ Professional web application with modern tech stack โ Interactive visualizations demonstrating algorithm internals โ Comprehensive test suite with 40+ test cases โ Beautiful UI design with dark mode support โ Performance benchmarking capabilities โ Educational documentation for learning โ Multiple input methods for flexibility โ Robust error handling and validation โ Production-ready deployment capability
๐ Future Enhancements
- [ ] Add more algorithms (Quick Sort, Heap Sort, etc.)
- [ ] Export visualization as GIF/Video
- [ ] Mobile app version
- [ ] Algorithm complexity calculator
- [ ] User accounts and saved visualizations
- [ ] Collaborative features
- [ ] Multi-language support
โญ If you find this repository helpful, please consider giving it a star!
Repository: https://github.com/amh1k/Daa-Project
