Team Ai
Apppublic

amh1k/daa-algorithm-visualizer

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
README.md543 linesDownload Raw Back to root
1---2title: DAA Algorithm Visualizer3emoji: ๐Ÿ“Š4colorFrom: blue5colorTo: green6sdk: docker7app_port: 78608pinned: false9---10 11# Design and Analysis of Algorithms - Project 202512 13[![C++](https://img.shields.io/badge/C++-11%2B-blue.svg)](https://isocpp.org/)14[![Next.js](https://img.shields.io/badge/Next.js-14.1-black.svg)](https://nextjs.org/)15[![React](https://img.shields.io/badge/React-18.2-61dafb.svg)](https://reactjs.org/)16[![TypeScript](https://img.shields.io/badge/TypeScript-5.3-blue.svg)](https://www.typescriptlang.org/)17[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)18 19A comprehensive collection of divide-and-conquer algorithm implementations with **professional web-based visualizations** for the Design and Analysis of Algorithms course.20 21## ๐Ÿ‘ฅ Team Members22 23| Name | Roll Number |24|------|-------------|25| **Huzaifa Abdul Rehman** | 23k-0782 |26| **Abdul Moiz Hossain** | 23k-0553 |27| **Ajay Kumar** | 23K-0514 |28 29---30 31## ๐Ÿ“‹ Table of Contents32 33- [About the Project](#about-the-project)34- [Features](#features)35- [Technologies Used](#technologies-used)36- [Project Structure](#project-structure)37- [Problem Implementations](#problem-implementations)38  - [Question 1: Basic Algorithms](#question-1-basic-algorithms)39  - [Question 2: Advanced Visualization](#question-2-advanced-visualization)40- [How to Run](#how-to-run)41- [Screenshots](#screenshots)42- [Time Complexity Analysis](#time-complexity-analysis)43- [Contributing](#contributing)44 45---46 47## ๐ŸŽฏ About the Project48 49This project showcases **13 algorithmic implementations** focusing on the **Divide and Conquer** paradigm, featuring:50 51- ๐Ÿ“Š **Interactive Web Visualizations** - Step-by-step algorithm execution52- ๐ŸŽจ **Modern UI/UX** - Dark mode, glassmorphism, smooth animations53- โšก **High Performance** - Optimized C++ backend with Next.js frontend54- ๐Ÿ“ˆ **Comprehensive Testing** - 40+ test cases with benchmark dashboard55- ๐ŸŽ“ **Educational Value** - Clear explanations and visual learning56 57---58 59## โœจ Features60 61### ๐ŸŒ Web Application (Question 2)62- **Beautiful Landing Page** with animated gradient backgrounds63- **Interactive Visualizations**:64  - Closest Pair: Step-by-step divide-and-conquer animation65  - Integer Multiplication: Recursive tree visualization66- **Dark/Light Mode** with system preference detection67- **Multiple Input Methods**: Predefined files, custom upload, manual entry68- **Real-time Performance Metrics** with benchmark dashboard69- **Responsive Design** - works on all screen sizes70- **Professional UI Components** using shadcn/ui and Radix UI71 72### ๐Ÿ”ข Algorithm Implementations (Question 1 & 2)73- **13 C++ Implementations** covering classic divide-and-conquer problems74- **Optimized Code** with `-O2` compilation flags75- **Detailed Output** including execution time and complexity analysis76- **Test Data Generation** for comprehensive testing77 78---79 80## ๐Ÿ› ๏ธ Technologies Used81 82### Backend83- ![C++](https://img.shields.io/badge/C++-00599C?style=flat&logo=c%2B%2B&logoColor=white) **C++11/14** - Algorithm implementation84- **STL** - Data structures and algorithms85- **Chrono** - High-precision time measurement86 87### Frontend88- ![Next.js](https://img.shields.io/badge/Next.js-000000?style=flat&logo=next.js&logoColor=white) **Next.js 14.1** - React framework with App Router89- ![React](https://img.shields.io/badge/React-61DAFB?style=flat&logo=react&logoColor=black) **React 18.2** - UI library90- ![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?style=flat&logo=typescript&logoColor=white) **TypeScript 5.3** - Type safety91- ![Tailwind CSS](https://img.shields.io/badge/Tailwind-38B2AC?style=flat&logo=tailwind-css&logoColor=white) **Tailwind CSS 3.4** - Utility-first styling92- **Framer Motion** - Smooth animations93- **Recharts** - Performance charts94- **shadcn/ui** - Modern UI components95 96---97 98## ๐Ÿ“ Project Structure99 100```101Daa-Project/102โ”‚103โ”œโ”€โ”€ README.md                    # Main documentation104โ”œโ”€โ”€ GIT_CHEAT_SHEET.md          # Git collaboration guide105โ”œโ”€โ”€ INSTRUCTIONS.md              # Quick setup guide106โ”œโ”€โ”€ .gitignore                  # Git ignore rules107โ”‚108โ”œโ”€โ”€ q1/                         # Question 1: Basic Algorithms109โ”‚   โ”œโ”€โ”€ a.cpp                   # Algorithm A110โ”‚   โ”œโ”€โ”€ b.cpp                   # Binary Exponentiation111โ”‚   โ”œโ”€โ”€ c.cpp                   # Counting Inversions112โ”‚   โ”œโ”€โ”€ e.cpp                   # Algorithm E113โ”‚   โ”œโ”€โ”€ f.cpp                   # Peak Element Finder114โ”‚   โ”œโ”€โ”€ g.cpp                   # Maximum Stock Profit115โ”‚   โ”œโ”€โ”€ h_1.cpp                 # Median of Two Arrays (Method 1)116โ”‚   โ”œโ”€โ”€ h_2.cpp                 # Median of Two Arrays (Method 2)117โ”‚   โ””โ”€โ”€ h_3.cpp                 # Median of Two Arrays (Method 3)118โ”‚119โ””โ”€โ”€ q2/                         # Question 2: Advanced Visualization120    โ”œโ”€โ”€ closest_pair.cpp        # Closest Pair Algorithm (247 lines)121    โ”œโ”€โ”€ integer_multiplication.cpp # Karatsuba Multiplication (214 lines)122    โ”‚123    โ”œโ”€โ”€ test_data/              # Test Files (40+ files)124    โ”‚   โ”œโ”€โ”€ closest_pair/       # 10 point datasets (100-1000 points)125    โ”‚   โ””โ”€โ”€ integer_multiplication/ # 10 digit datasets (100-1000 digits)126    โ”‚127    โ””โ”€โ”€ ui/                     # Next.js Web Application128        โ”œโ”€โ”€ app/                # Pages & API Routes129        โ”‚   โ”œโ”€โ”€ page.tsx        # Landing page130        โ”‚   โ”œโ”€โ”€ closest-pair/   # Closest pair visualization page131        โ”‚   โ”œโ”€โ”€ integer-multiplication/ # Karatsuba visualization page132        โ”‚   โ”œโ”€โ”€ benchmark/      # Performance dashboard133        โ”‚   โ””โ”€โ”€ api/            # API endpoints (5 routes)134        โ”‚135        โ”œโ”€โ”€ components/         # React Components (22 components)136        โ”‚   โ”œโ”€โ”€ closest-pair-step-visualization.tsx137        โ”‚   โ”œโ”€โ”€ recursive-tree.tsx138        โ”‚   โ”œโ”€โ”€ static-points-canvas.tsx139        โ”‚   โ”œโ”€โ”€ navigation.tsx140        โ”‚   โ”œโ”€โ”€ theme-provider.tsx141        โ”‚   โ””โ”€โ”€ ui/             # shadcn/ui components142        โ”‚143        โ”œโ”€โ”€ lib/                # Utilities144        โ”œโ”€โ”€ public/             # Static assets145        โ””โ”€โ”€ styles/             # Global styles146```147 148---149 150## ๐Ÿ’ก Problem Implementations151 152### Question 1: Basic Algorithms153 154#### 1. Binary Exponentiation (`b.cpp`)155**Problem**: Compute `a^b` efficiently using divide and conquer.156- **Time Complexity**: O(log b)157- **Space Complexity**: O(log b) - recursion stack158- **Approach**: Exponentiation by squaring159```cpp160// If b is even: a^b = (a^(b/2))^2161// If b is odd:  a^b = (a^(b/2))^2 ร— a162```163 164#### 2. Counting Inversions (`c.cpp`)165**Problem**: Count pairs (i, j) where i < j but arr[i] > arr[j].166- **Time Complexity**: O(n log n)167- **Space Complexity**: O(n)168- **Approach**: Modified merge sort169 170#### 3. Peak Element Finder (`f.cpp`)171**Problem**: Find an element greater than or equal to its neighbors.172- **Time Complexity**: O(log n)173- **Space Complexity**: O(log n) - recursion stack174- **Approach**: Binary search on array175 176#### 4. Maximum Stock Profit (`g.cpp`)177**Problem**: Find maximum profit from buying and selling stocks.178- **Time Complexity**: O(n log n)179- **Space Complexity**: O(n)180- **Approach**: Divide and conquer on difference array181 182#### 5. Median of Two Sorted Arrays (`h_1.cpp`, `h_2.cpp`, `h_3.cpp`)183**Problem**: Find n-th smallest element from two sorted arrays.184- **Time Complexity**: O(log n)185- **Space Complexity**: O(1)186- **Approach**: Binary search on partitions187 188---189 190### Question 2: Advanced Visualization191 192#### ๐ŸŽฏ Algorithm 1: Closest Pair of Points193 194**File**: `q2/closest_pair.cpp` (247 lines)195 196**Problem**: Find the two closest points among n points in 2D space.197 198**Algorithm**: Divide and Conquer199- **Time Complexity**: O(n log n)200- **Space Complexity**: O(n)201 202**Implementation Features**:203- โœ… Sorts points by x and y coordinates204- โœ… Recursively divides plane into halves205- โœ… Checks strip area for cross-boundary pairs206- โœ… Generates JSON trace for visualization (n โ‰ค 50)207- โœ… Handles 100-1000 point datasets208 209**Visualization Features**:210- ๐ŸŽจ Step-by-step animation with playback controls211- ๐Ÿ“ Divide line visualization (red dashed)212- ๐ŸŽฏ Active region highlighting (teal)213- ๐ŸŸฃ Strip area visualization (purple)214- โœ… Closest pair highlighting (green)215- โฏ๏ธ Play, pause, step forward/backward controls216- ๐Ÿ“Š Progress tracking with step descriptions217 218---219 220#### ๐Ÿ”ข Algorithm 2: Karatsuba Integer Multiplication221 222**File**: `q2/integer_multiplication.cpp` (214 lines)223 224**Problem**: Multiply arbitrarily large integers efficiently.225 226**Algorithm**: Karatsuba's Fast Multiplication227- **Time Complexity**: O(n^1.585) where n = number of digits228- **Space Complexity**: O(n)229 230**Implementation Features**:231- โœ… String-based arithmetic for large numbers232- โœ… Recursive three-way split (z2, z0, z1)233- โœ… Generates tree visualization (โ‰ค50 digits)234- โœ… Handles 100-1000+ digit multiplication235- โœ… Falls back to naive method for small numbers236 237**Visualization Features**:238- ๐ŸŒณ Interactive recursive tree display239- ๐ŸŽจ Color-coded node types:240  - ๐ŸŸฃ Purple - Root (original multiplication)241  - ๐Ÿ”ต Blue - zโ‚‚ (high digits: a ร— c)242  - ๐ŸŸข Green - zโ‚€ (low digits: b ร— d)243  - ๐ŸŸ  Orange - zโ‚ (middle term)244- ๐Ÿ” Zoom controls (30%-150%)245- ๐Ÿ–ฑ๏ธ Pan with left-click drag246- ๐Ÿ“ Smart number truncation for readability247- ๐Ÿ“Š Depth and digit count tracking248 249---250 251## ๐Ÿš€ How to Run252 253### Prerequisites254- **Node.js** v18 or higher255- **npm** or **yarn** package manager256- **C++ Compiler** (g++/MinGW/MSVC)257- **Git** (optional)258 259### Quick Start (Question 2 - Web Application)260 261#### Step 1: Clone Repository262```bash263git clone https://github.com/amh1k/Daa-Project.git264cd Daa-Project265```266 267#### Step 2: Compile C++ Programs268```bash269cd q2270g++ -O2 closest_pair.cpp -o closest_pair.exe271g++ -O2 integer_multiplication.cpp -o integer_multiplication.exe272```273 274#### Step 3: Install Dependencies275```bash276cd ui277npm install278```279 280#### Step 4: Run Development Server281```bash282npm run dev283```284 285#### Step 5: Open Browser286Navigate to: **http://localhost:3000**287 288---289 290### Running Question 1 Algorithms291 292```bash293# Navigate to q1 directory294cd q1295 296# Compile and run any algorithm297g++ b.cpp -o b.exe298./b.exe299 300# Example: Binary Exponentiation301echo "2 10" | ./b.exe302# Output: 1024303 304# Example: Counting Inversions305./c.exe306# Output: The number of inversions are: 22307```308 309---310 311## ๐Ÿ“ธ Screenshots312 313### ๐Ÿ  Landing Page (Dark Mode)314![Home Page](q2/screenshots/Home_Page.png)315*Beautiful gradient animations with glassmorphism effects, featuring three main algorithm sections*316 317### ๐ŸŒž Light Mode Support318![Light Mode](q2/screenshots/Light_Mode.png)319*Professional light theme with optimal contrast and accessibility*320 321### ๐Ÿ“ Closest Pair Visualization322![Closest Pair Algorithm](q2/screenshots/Closest_Pair.png)323*Step-by-step divide-and-conquer animation with playback controls, divide line visualization, and active region highlighting*324 325**Features:**326- Interactive canvas visualization327- Play, pause, step forward/backward controls328- Real-time algorithm step descriptions329- Multiple input methods (predefined, custom, manual)330- Compact footer legend with color coding331 332### ๐Ÿ”ข Integer Multiplication - Karatsuba Algorithm333![Integer Multiplication](q2/screenshots/Integer_Multiplication.png)334*Large number multiplication with result display and performance metrics*335 336**Features:**337- Support for 100-1000+ digit numbers338- Instant calculation results339- Execution time tracking340- Clean result presentation341 342### ๐ŸŒณ Recursive Tree Visualization343![Recursive Tree](q2/screenshots/Integer_Multiplication_Recursive_Tree.png)344*Interactive tree showing Karatsuba's recursive breakdown with color-coded node types (zโ‚€, zโ‚, zโ‚‚)*345 346**Features:**347- Expand view with zoom controls (30%-150%)348- Pan with left-click drag349- Shrink button for compact view350- Color-coded nodes: Purple (Root), Blue (zโ‚‚), Green (zโ‚€), Orange (zโ‚)351- Horizontal scrollbar for wide trees352- Smart number truncation for readability353 354### ๐Ÿ“Š Benchmark Dashboard355![Benchmark Dashboard](q2/screenshots/Bench_Mark.png)356*Comprehensive performance testing with real-time progress tracking for all 20 test cases*357 358**Features:**359- Batch execution of all test files360- Real-time progress indicators361- Side-by-side performance comparison362- Success/failure status for each test363- Execution time metrics364- Dataset size information365 366---367 368## โฑ๏ธ Time Complexity Analysis369 370| Algorithm | Problem | Time Complexity | Space Complexity | Lines of Code |371|-----------|---------|-----------------|------------------|---------------|372| **Binary Exponentiation** | Compute a^b | O(log b) | O(log b) | ~30 |373| **Counting Inversions** | Count inversions | O(n log n) | O(n) | ~50 |374| **Peak Element** | Find peak | O(log n) | O(log n) | ~40 |375| **Max Stock Profit** | Maximum profit | O(n log n) | O(n) | ~60 |376| **Median of Arrays** | Find median | O(log n) | O(1) | ~70 |377| **Closest Pair** | 2D point distance | O(n log n) | O(n) | 247 |378| **Karatsuba Multiply** | Large integer multiplication | O(n^1.585) | O(n) | 214 |379 380---381 382## ๐ŸŽ“ Key Concepts Demonstrated383 384### Algorithmic Techniques385- โœ… **Divide and Conquer** - Breaking problems into smaller subproblems386- โœ… **Binary Search** - Efficient searching in sorted/partially sorted data387- โœ… **Merge Sort** - Efficient sorting with additional applications388- โœ… **Dynamic Problem Solving** - Converting problems to known formats389- โœ… **Optimization** - Achieving logarithmic and linearithmic complexities390 391### Software Engineering392- โœ… **Full-Stack Development** - C++ backend + React frontend393- โœ… **API Design** - RESTful endpoints with error handling394- โœ… **Component Architecture** - Reusable React components395- โœ… **Type Safety** - TypeScript for robust code396- โœ… **Performance Optimization** - Lazy loading, caching, GPU acceleration397- โœ… **Responsive Design** - Mobile-first approach398- โœ… **Accessibility** - WCAG-compliant UI399 400### UI/UX Design401- โœ… **Modern Design Patterns** - Glassmorphism, gradients402- โœ… **Smooth Animations** - Framer Motion for professional feel403- โœ… **Dark Mode** - System preference detection404- โœ… **Interactive Visualizations** - Canvas & SVG rendering405- โœ… **User Feedback** - Loading states, progress bars, error messages406 407---408 409## ๐Ÿ“š Educational Value410 411### For Students412- ๐Ÿ“– **Step-by-step algorithm execution** - Visual learning413- ๐Ÿ’ก **Clear complexity explanations** - Understand time/space trade-offs414- ๐Ÿงช **Multiple test cases** - Edge case handling415- ๐Ÿ“Š **Performance comparison** - Benchmark different inputs416 417### For Instructors418- โœ… **Production-ready code** - Demonstrates best practices419- โœ… **Comprehensive documentation** - Easy to understand and grade420- โœ… **Interactive demos** - Use in lectures421- โœ… **Extensible architecture** - Students can add more algorithms422 423---424 425## ๐Ÿ”ง Advanced Features426 427### Performance Optimization428- **C++ Backend**: `-O2` optimization flags429- **React Frontend**: Code splitting, lazy loading430- **Canvas Rendering**: GPU-accelerated drawing431- **Smart Caching**: Webpack build optimization432 433### Error Handling434- โœ… Executable validation435- โœ… Input file validation436- โœ… Parse error detection437- โœ… Timeout handling (30s limit)438- โœ… User-friendly error messages439 440### Testing441- 40+ predefined test files442- Custom file upload support443- Manual input validation444- Edge case coverage445- Performance benchmarking446 447---448 449## ๐Ÿค Contributing450 451This is an academic project. For improvements:452 4531. Fork the repository4542. Create feature branch: `git checkout -b feature/improvement`4553. Commit changes: `git commit -m 'Add improvement'`4564. Push to branch: `git push origin feature/improvement`4575. Open Pull Request458 459---460 461## ๐Ÿ“ง Contact462 463For questions or discussions:464 465- **Huzaifa Abdul Rehman** - 23k-0782466- **Abdul Moiz Hossain** - 23k-0553467- **Ajay Kumar** - 23K-0514468 469---470 471## ๐Ÿ“„ License472 473This project is created for educational purposes as part of the Design and Analysis of Algorithms course (CS302 - 5th Semester).474 475---476 477## ๐Ÿ™ Acknowledgments478 479### References480- **Introduction to Algorithms (CLRS)** - Algorithm theory481- **GeeksforGeeks & LeetCode** - Problem-solving inspiration482- **Next.js Documentation** - Web framework guidance483- **shadcn/ui** - Component library484- **Framer Motion** - Animation library485 486### Inspiration487- Algorithm visualization tools (VisuAlgo, Algorithm Visualizer)488- Professional web applications (Figma, VS Code)489- Academic research papers on divide-and-conquer490 491---492 493## ๐Ÿ“Š Project Statistics494 495- **Total Files**: 2,800+ (including dependencies)496- **Custom Code**:497  - 13 C++ algorithm implementations498  - 22 React components499  - 5 API routes500  - 40+ test data files501- **Lines of Code**:502  - C++: 600+ lines503  - TypeScript/TSX: 3,000+ lines504- **Test Coverage**: 20 comprehensive test cases505- **Supported Input Sizes**:506  - Closest Pair: 10-1000 points507  - Integer Multiplication: 12-1000+ digits508 509---510 511## ๐ŸŽฏ Project Achievements512 513โœ… Complete implementation of 13 divide-and-conquer algorithms514โœ… Professional web application with modern tech stack515โœ… Interactive visualizations demonstrating algorithm internals516โœ… Comprehensive test suite with 40+ test cases517โœ… Beautiful UI design with dark mode support518โœ… Performance benchmarking capabilities519โœ… Educational documentation for learning520โœ… Multiple input methods for flexibility521โœ… Robust error handling and validation522โœ… Production-ready deployment capability523 524---525 526## ๐Ÿš€ Future Enhancements527 528- [ ] Add more algorithms (Quick Sort, Heap Sort, etc.)529- [ ] Export visualization as GIF/Video530- [ ] Mobile app version531- [ ] Algorithm complexity calculator532- [ ] User accounts and saved visualizations533- [ ] Collaborative features534- [ ] Multi-language support535 536---537 538**โญ If you find this repository helpful, please consider giving it a star!**539 540---541 542**Repository**: https://github.com/amh1k/Daa-Project543