Student A: Nurdaulet Saparbekov
Pair Assignment: Pair 4 - Min and Max Heap Analysis
Data Structure: Min-Heap with decreaseKey and merge operations
This project implements a Min-Heap data structure in Java with support for:
- Standard heap operations (insert, extractMin, peekMin)
- decreaseKey: Update element value with O(log n) complexity
- merge: Combine two heaps efficiently in O(n) time
- Performance tracking and CSV export for empirical analysis
-
Complete Min-Heap Implementation
- Dynamic resizing with doubling strategy
- Handle-based element tracking for decreaseKey
- Bottom-up heap construction for merge
-
Performance Tracking
- Comparisons, swaps, array accesses, allocations
- Time measurements in nanoseconds/milliseconds
- CSV export for data analysis
-
Comprehensive Testing
- 30+ JUnit test cases
- Edge case coverage (empty, single element, large datasets)
- Stress tests and performance validation
-
Benchmarking Tools
- Interactive CLI benchmark runner
- JMH micro-benchmarks for accurate measurements
- Configurable input sizes
-
CI/CD Pipeline
- GitHub Actions for automated testing
- Maven build automation
DAA-assignment2/
├── src/
│ ├── main/
│ │ └── java/org/harryfloppa/
│ │ ├── algorithms/
│ │ │ ├── IHeap.java # Heap abstract class
│ │ │ ├── Heap.java # Heap abstract class
│ │ │ ├── MinHeap.java # Main implementation
│ │ ├── metrics/
│ │ │ └── PerformanceTracker.java # Metrics tracking
│ │ ├── cli/
│ │ └── BenchmarkRunner.java # CLI tool
│ │ ├── benchmarks/
│ │ └── MinHeapJMHBenchmark.java # Benchmark JMH
│ └── test/
│ └── java/org/harryfloppa/algorithms/
│ └── MinHeapTest.java # JUnit tests
├── .github/
│ └── workflows/
│ └── maven.yml # CI configuration
├── pom.xml # Maven dependencies
└── README.md
- Java 17 or higher
- Maven 3.6+
- Git
# Clone repository
git clone https://github.com/YOUR_USERNAME/DAA-assignment2.git
cd DAA-assignment2
# Build project
mvn clean install
# Run tests
mvn test# Run interactive benchmark tool
mvn exec:java -Dexec.mainClass="org.harryfloppa.BenchmarkRunner"Menu Options:
- Insert Benchmark
- ExtractMin Benchmark
- DecreaseKey Benchmark
- Merge Benchmark
- Run All Benchmarks
- Custom Size Testing
# Build benchmark JAR
mvn clean package
# Run JMH benchmarks
java -jar target/benchmarks.jar
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| insert | O(log n) | O(1) amortized |
| extractMin | O(log n) | O(1) |
| peekMin | O(1) | O(1) |
| decreaseKey | O(log n) | O(1) |
| merge | O(n₁ + n₂) | O(n₁ + n₂) |
- Best Case: O(1) - element inserted at bottom stays there
- Average Case: O(log n) - bubbles up partway
- Worst Case: O(log n) - bubbles to root
- Amortized O(1) for array resizing with doubling
- Always O(log n) - swap with last, remove, sift down
- Height of tree is ⌊log₂ n⌋
- O(1) handle lookup via HashMap
- O(log n) sift-up after value decrease
- Critical for Dijkstra's algorithm optimization
- O(n₁ + n₂) using Floyd's buildHeap algorithm
- Bottom-up construction is faster than n insertions
- No handle reuse to avoid conflicts
Run benchmarks to verify:
mvn exec:java -Dexec.mainClass="org.harryfloppa.BenchmarkRunner"
# Select option 5: Run All BenchmarksResults exported to benchmark-results.csv for analysis.
mvn test- Basic Operations: insert, extract, peek
- Advanced Operations: decreaseKey, merge
- Edge Cases:
- Empty heap
- Single element
- Duplicate values
- Large datasets (10,000+ elements)
- Integer limits (MIN_VALUE, MAX_VALUE)
- Performance Tests: Metrics validation and CSV export
Automated testing on every push/PR:
- Build with Maven
- Run all tests
- Generate test reportsView Status: Check "Actions" tab in your GitHub repository
Analysis:
- Time complexity matches O(n log n) for n insertions
- Comparisons scale as expected with heap height
- Memory allocations minimal due to doubling strategy
Made with ❤️ for Design and Analysis of Algorithms
