CoolFace
Apppublic

amh1k/daa-algorithm-visualizer

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

Design and Analysis of Algorithms - Project 2025

![C++](https://isocpp.org/) ![Next.js](https://nextjs.org/) ![React](https://reactjs.org/) ![TypeScript](https://www.typescriptlang.org/) ![License](LICENSE)

A comprehensive collection of divide-and-conquer algorithm implementations with professional web-based visualizations for the Design and Analysis of Algorithms course.

๐Ÿ‘ฅ Team Members

NameRoll Number
Huzaifa Abdul Rehman23k-0782
Abdul Moiz Hossain23k-0553
Ajay Kumar23K-0514

๐Ÿ“‹ Table of Contents


๐ŸŽฏ 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 -O2 compilation flags
  • โ€”Detailed Output including execution time and complexity analysis
  • โ€”Test Data Generation for comprehensive testing

๐Ÿ› ๏ธ Technologies Used

Backend

  • โ€”C++ C++11/14 - Algorithm implementation
  • โ€”STL - Data structures and algorithms
  • โ€”Chrono - High-precision time measurement

Frontend

  • โ€”Next.js Next.js 14.1 - React framework with App Router
  • โ€”React React 18.2 - UI library
  • โ€”TypeScript TypeScript 5.3 - Type safety
  • โ€”Tailwind CSS 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
cpp
// If b is even: a^b = (a^(b/2))^2
// If b is odd:  a^b = (a^(b/2))^2 ร— a
2. 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
bash
git clone https://github.com/amh1k/Daa-Project.git
cd Daa-Project
Step 2: Compile C++ Programs
bash
cd q2
g++ -O2 closest_pair.cpp -o closest_pair.exe
g++ -O2 integer_multiplication.cpp -o integer_multiplication.exe
Step 3: Install Dependencies
bash
cd ui
npm install
Step 4: Run Development Server
bash
npm run dev
Step 5: Open Browser

Navigate to: http://localhost:3000


Running Question 1 Algorithms

bash
# 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)

[image] Beautiful gradient animations with glassmorphism effects, featuring three main algorithm sections

๐ŸŒž Light Mode Support

[image] Professional light theme with optimal contrast and accessibility

๐Ÿ“ Closest Pair Visualization

[image] 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

[image] 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

[image] 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

[image] 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

AlgorithmProblemTime ComplexitySpace ComplexityLines of Code
Binary ExponentiationCompute a^bO(log b)O(log b)~30
Counting InversionsCount inversionsO(n log n)O(n)~50
Peak ElementFind peakO(log n)O(log n)~40
Max Stock ProfitMaximum profitO(n log n)O(n)~60
Median of ArraysFind medianO(log n)O(1)~70
Closest Pair2D point distanceO(n log n)O(n)247
Karatsuba MultiplyLarge integer multiplicationO(n^1.585)O(n)214

๐ŸŽ“ 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: -O2 optimization 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:

  1. 1.Fork the repository
  2. 2.Create feature branch: git checkout -b feature/improvement
  3. 3.Commit changes: git commit -m 'Add improvement'
  4. 4.Push to branch: git push origin feature/improvement
  5. 5.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