Skip to content

Add ShellSort implementation in Java#398

Merged
Pradeepsingh61 merged 1 commit into
Pradeepsingh61:mainfrom
Pasan11504:feature/shell-sort
Oct 4, 2025
Merged

Add ShellSort implementation in Java#398
Pradeepsingh61 merged 1 commit into
Pradeepsingh61:mainfrom
Pasan11504:feature/shell-sort

Conversation

@Pasan11504
Copy link
Copy Markdown
Contributor

📋 Pull Request Description

What does this PR add?

  • New algorithm implementation

Algorithm Details

  • Name: Shell Sort
  • Language: Java
  • Category: Sorting
  • Time Complexity: O(n^3/2) worst case, O(n log n) average case
  • Space Complexity: O(1) - in-place sorting

Unique Features

  • Dual gap sequence implementations - Knuth's and Shell's original
  • Performance comparison between gap sequences included
  • Advanced insertion sort with gap-based optimization
  • Adaptive algorithm - excels on nearly sorted data
  • Educational value - demonstrates gap sequence effects
  • Comprehensive documentation with complexity analysis
  • Professional testing - 8 test scenarios + performance benchmarks

Gap Sequences Implemented

  1. Knuth's Sequence: h = 3h + 1 (1, 4, 13, 40, 121, ...)
  2. Shell's Original: n/2, n/4, n/8, ..., 1

Performance & Testing

  • Code compiles without errors or warnings
  • All test cases pass (basic, edge cases, performance)
  • Large array performance tested (10K elements in ~3.6ms)
  • Nearly sorted data optimization verified
  • Gap sequence comparison benchmarked
  • Exception handling validated
  • Memory efficiency confirmed (in-place sorting)

Code Quality

  • 15+ meaningful comments explaining gap logic
  • Complete JavaDoc for all methods
  • Two complete implementations for educational comparison
  • Clean, readable, professional code structure
  • Optimal space complexity (O(1))

Files Added

  • Java/algorithms/sorting/ShellSort.java - Complete ShellSort with dual gap sequences

Algorithm Advantages

  • vs Simple Sorts: Much better performance O(n^3/2) vs O(n²)
  • vs Complex Sorts: In-place, simple implementation, adaptive
  • Educational: Perfect example of gap sequence optimization
  • Practical: Excellent for medium-sized datasets

Contributes to Hacktoberfest 2025 🎃

Additional Notes

This implementation showcases Shell sort's evolution from simple insertion sort to an efficient algorithm through gap sequences. The dual implementation allows developers to understand and compare different gap sequence strategies, making it both practical and educational.

- Implements advanced insertion sort with gap sequences for improved performance
- Time Complexity: O(n^3/2) worst case, O(n log n) average case
- Space Complexity: O(1) - in-place sorting algorithm
- Features two gap sequence implementations: Knuth's and Shell's original
- Knuth's sequence: h = 3h + 1 (1, 4, 13, 40, 121, ...)
- Shell's sequence: n/2, n/4, n/8, ..., 1
- Comprehensive test cases including performance comparison
- Handles edge cases: null arrays, negatives, duplicates, large numbers
- Excellent performance on nearly sorted data (adaptive algorithm)
- Follows repository coding standards and Java conventions
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 4, 2025

🎉 Welcome to Hacktoberfest 2025, @Pasan11504! 🎃

Thank you for your first contribution to our DSA repository! Here's what happens next:

🔍 Automatic Checks

  • Code Validation: Passed
  • 🧪 Compilation Tests: Passed

📋 Next Steps

🎯 Great job! Your code compiled successfully. Maintainers @Karanjot786 and @Pradeepsingh61 will review your PR soon.

🎁 What You Get

  • 🏆 Hacktoberfest Credit: This PR counts toward your 6 PR goal for exclusive T-shirt + Tree!
  • 🌟 Hall of Fame: You'll be featured in our contributors list
  • 📚 Learning: Code review feedback from experienced developers

💡 Tips for Success

  • Follow our Contributing Guidelines
  • Add comments explaining your algorithm
  • Include time/space complexity analysis
  • Test your code before submitting

Welcome to the community! 🚀

@github-actions github-actions Bot requested a review from Karanjot786 October 4, 2025 08:25
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 4, 2025

🤖 Automated PR Status

🔍 Code Validation

Passed - File naming and structure look good!

🧪 Compilation Tests

Passed - All code compiles successfully!

📋 Overall Status

🎉 Ready for Review - Your PR has passed all automated checks!
👥 Maintainers have been notified for review.


This comment was generated automatically. Checks will re-run when you push new commits.

@Pradeepsingh61 Pradeepsingh61 merged commit 3443cf2 into Pradeepsingh61:main Oct 4, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants