Welcome to the DSA Code Repository! We're excited to have you contribute to this comprehensive collection of algorithms and data structures. This guide will help you make meaningful contributions for Hacktoberfest 2025 and beyond.
- Getting Started
- Repository Structure
- Contribution Guidelines
- Code Standards
- Pull Request Process
- Community Guidelines
- Git installed on your machine
- Basic knowledge of at least one programming language (C, C++, Java, Python)
- GitHub account
- Text editor or IDE of your choice
-
Fork the Repository
# Click the "Fork" button on GitHub # This creates your personal copy of the repository
-
Clone Your Fork
git clone https://github.com/YOUR_USERNAME/DSA_Code.git cd DSA_Code -
Set Up Remote
git remote add upstream https://github.com/ORIGINAL_OWNER/DSA_Code.git git remote -v # Verify remotes -
Stay Updated
git fetch upstream git checkout main git merge upstream/main
Our repository follows a Language β Topic β Implementation structure:
DSA_Code/
βββ C/ # C Language Implementations
β βββ algorithms/
β β βββ searching/ # Search algorithms
β β βββ sorting/ # Sort algorithms
β β βββ mathematical/ # Math algorithms
β βββ data_structures/ # Core data structures
β βββ dynamic_programming/ # DP solutions
βββ CPP/ # C++ Language Implementations
β βββ algorithms/ # Algorithm categories
β βββ data_structures/ # Data structure implementations
β βββ dynamic_programming/ # DP solutions
β βββ object_oriented_programming/ # OOP concepts
βββ Java/ # Java Language Implementations
β βββ algorithms/ # Enterprise algorithm patterns
β βββ data_structures/ # Collection framework usage
β βββ dynamic_programming/ # DP with Java features
β βββ projects/ # Complete Java applications
βββ Python/ # Python Language Implementations
βββ algorithms/ # Clean, readable algorithms
βββ data_structures/ # Pythonic implementations
βββ dynamic_programming/ # DP with Python features
βββ projects/ # Complete Python projects
- Missing Algorithms: Implement algorithms not yet in the repository
- New Data Structures: Add data structure implementations
- New Programming Languages: Add support for JavaScript, Go, Rust, Kotlin, Swift, etc.
- Complete Projects: Full applications demonstrating algorithms
- Optimization: Improve existing code performance
- Documentation: Add comprehensive comments and examples
- Test Cases: Add unit tests for existing implementations
- Bug Fixes: Fix issues in current code
- Code Refactoring: Improve code quality and readability
- Cross-Language Ports: Port algorithms between languages
- Language-Specific READMEs: Setup guides for new languages
- README Improvements: Enhance documentation
- Comments: Add explanatory comments to existing code
- Examples: Provide usage examples for algorithms
- Documentation: Fix typos and improve clarity
- Simple Algorithms: Implement basic algorithms
C/
βββ algorithms/searching/ β binary_search.c
βββ algorithms/sorting/ β quick_sort.c
βββ algorithms/mathematical/ β prime_check.c
βββ data_structures/stacks/ β stack_array.c
βββ dynamic_programming/ β fibonacci_dp.c
CPP/
βββ algorithms/sorting/ β merge_sort.cpp
βββ data_structures/trees/ β binary_search_tree.cpp
βββ object_oriented_programming/ β polymorphism_example.cpp
βββ dynamic_programming/ β longest_common_subsequence.cpp
βββ projects/ β complete_application.cpp
Java/
βββ algorithms/graph_algorithms/ β DijkstraAlgorithm.java
βββ data_structures/trees/ β AVLTree.java
βββ dynamic_programming/ β CoinChange.java
βββ projects/games/ β TicTacToe.java
Python/
βββ algorithms/machine_learning/ β linear_regression.py
βββ data_structures/graphs/ β graph_adjacency_list.py
βββ projects/games/ β snake_game.py
βββ dynamic_programming/ β edit_distance.py
We welcome contributions in ANY programming language! Here's how to add a new language:
YourLanguage/ # e.g., JavaScript/, Go/, Rust/, Kotlin/
βββ README.md # Language-specific guide
βββ algorithms/
β βββ searching/ β binary_search.ext
β βββ sorting/ β merge_sort.ext
β βββ graph_algorithms/ β dijkstra.ext
β βββ arrays/ β array_operations.ext
β βββ strings/ β string_algorithms.ext
β βββ mathematical/ β math_algorithms.ext
βββ data_structures/
β βββ trees/ β binary_tree.ext
β βββ stacks/ β stack.ext
β βββ queues/ β queue.ext
β βββ graphs/ β graph.ext
β βββ heaps/ β heap.ext
β βββ linked_lists/ β linked_list.ext
βββ dynamic_programming/ β dp_solutions.ext
βββ projects/ # Optional: Complete applications
βββ games/
βββ data_analysis/
βββ web_development/
Your YourLanguage/README.md should include:
# YourLanguage Implementations
## π Getting Started
### Prerequisites
- YourLanguage version X.X or higher
- Package manager (if applicable)
- Any specific dependencies
### Running the Code
```bash
# Instructions to run/compile code
your-language filename.ext- Use language-specific naming:
camelCase,snake_case, etc. - File extensions:
.js,.go,.rs,.kt, etc.
- How to run tests
- Testing framework used
- Example test commands
- Any special considerations
- Performance notes
- Best practices for this language
##### **Step 3: Follow Code Standards**
- **Naming**: Use language-specific conventions
- **Documentation**: Include comprehensive comments
- **Testing**: Add test cases where applicable
- **Dependencies**: Keep external dependencies minimal
- **Performance**: Write efficient, idiomatic code
##### **Step 4: Popular Languages to Add**
Here are some highly requested languages:
| Language | Extension | Use Cases | Difficulty |
|----------|-----------|-----------|------------|
| **JavaScript** | `.js` | Web algorithms, Node.js | ββ |
| **TypeScript** | `.ts` | Type-safe web development | βββ |
| **Go** | `.go` | Concurrent algorithms, systems | βββ |
| **Rust** | `.rs` | Memory-safe, high-performance | ββββ |
| **Kotlin** | `.kt` | Android, JVM algorithms | βββ |
| **Swift** | `.swift` | iOS, macOS development | βββ |
| **PHP** | `.php` | Web backend algorithms | ββ |
| **Ruby** | `.rb` | Dynamic, expressive code | ββ |
| **C#** | `.cs` | .NET framework algorithms | βββ |
| **Dart** | `.dart` | Flutter development | ββ |
| **Scala** | `.scala` | Functional programming | ββββ |
| **R** | `.r` | Statistical algorithms | βββ |
##### **Step 5: Example Implementation Template**
```language
/*
* Algorithm: [Algorithm Name]
* Language: [Your Language]
* Description: [Brief description]
* Time Complexity: O(?)
* Space Complexity: O(?)
* Author: [Your Name]
* Date: [Date]
*/
// Your implementation here
function/method algorithmName(parameters) {
// Input validation
// Algorithm implementation
// Return result
}
// Test cases
function/method testAlgorithm() {
// Test case 1
// Test case 2
// Edge cases
}
// Main function (if applicable)
- C:
snake_case.cβbinary_search.c - C++:
snake_case.cppβquick_sort.cpp - Java:
PascalCase.javaβBinarySearchTree.java - Python:
snake_case.pyβbubble_sort.py
Every file must include:
"""
Algorithm: [Algorithm Name]
Description: [Brief description of what the algorithm does]
Time Complexity: O(?)
Space Complexity: O(?)
Author: [Your Name]
Date: [Date]
"""def algorithm_name(parameters):
"""
Brief description of the function.
Args:
param1 (type): Description of parameter 1
param2 (type): Description of parameter 2
Returns:
return_type: Description of return value
Examples:
>>> algorithm_name(example_input)
expected_output
Raises:
ErrorType: Description of when this error occurs
"""/*
* Algorithm: Binary Search
* Description: Search for target in sorted array
* Time Complexity: O(log n)
* Space Complexity: O(1)
*/
#include <stdio.h>
#include <stdlib.h>
/**
* Performs binary search on sorted array
* @param arr: Sorted array to search in
* @param size: Size of the array
* @param target: Value to search for
* @return: Index if found, -1 otherwise
*/
int binary_search(int arr[], int size, int target) {
// Input validation
if (arr == NULL || size <= 0) {
return -1;
}
// Implementation here
// ...
}
// Test function
void test_binary_search() {
int arr[] = {1, 3, 5, 7, 9};
int size = sizeof(arr) / sizeof(arr[0]);
printf("Testing binary search...\n");
// Test cases
}
int main() {
test_binary_search();
return 0;
}/*
* Algorithm: Quick Sort
* Description: Efficient divide-and-conquer sorting algorithm
* Time Complexity: O(n log n) average, O(nΒ²) worst
* Space Complexity: O(log n)
*/
#include <iostream>
#include <vector>
#include <algorithm>
/**
* Quick sort implementation using modern C++
* @param arr Vector to be sorted
* @param low Starting index
* @param high Ending index
*/
template<typename T>
void quickSort(std::vector<T>& arr, int low, int high) {
if (low < high) {
int pivot = partition(arr, low, high);
quickSort(arr, low, pivot - 1);
quickSort(arr, pivot + 1, high);
}
}
// Test function with modern C++ features
void testQuickSort() {
std::vector<int> test_data = {64, 34, 25, 12, 22, 11, 90};
std::cout << "Original array: ";
for (const auto& elem : test_data) {
std::cout << elem << " ";
}
quickSort(test_data, 0, test_data.size() - 1);
std::cout << "\nSorted array: ";
for (const auto& elem : test_data) {
std::cout << elem << " ";
}
std::cout << std::endl;
}/**
* Algorithm: Merge Sort
* Description: Stable divide-and-conquer sorting algorithm
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* @author Your Name
* @version 1.0
* @since 2025-01-01
*/
import java.util.*;
public class MergeSort {
/**
* Sorts an array using merge sort algorithm.
*
* @param arr the array to be sorted
* @throws IllegalArgumentException if array is null
*/
public static void mergeSort(int[] arr) {
if (arr == null) {
throw new IllegalArgumentException("Array cannot be null");
}
if (arr.length <= 1) {
return; // Already sorted
}
mergeSort(arr, 0, arr.length - 1);
}
private static void mergeSort(int[] arr, int left, int right) {
if (left < right) {
int mid = left + (right - left) / 2;
mergeSort(arr, left, mid);
mergeSort(arr, mid + 1, right);
merge(arr, left, mid, right);
}
}
/**
* Test the merge sort implementation.
*/
public static void main(String[] args) {
int[] testArray = {64, 34, 25, 12, 22, 11, 90};
System.out.println("Original array: " + Arrays.toString(testArray));
mergeSort(testArray);
System.out.println("Sorted array: " + Arrays.toString(testArray));
// Additional test cases
testEdgeCases();
}
private static void testEdgeCases() {
// Test empty array
int[] emptyArray = {};
mergeSort(emptyArray);
assert emptyArray.length == 0;
// Test single element
int[] singleElement = {42};
mergeSort(singleElement);
assert singleElement[0] == 42;
System.out.println("All tests passed!");
}
}"""
Algorithm: Heap Sort
Description: Efficient in-place comparison-based sorting algorithm
Time Complexity: O(n log n)
Space Complexity: O(1)
Author: Your Name
Date: 2025-01-01
"""
from typing import List
def heap_sort(arr: List[int]) -> List[int]:
"""
Sort an array using heap sort algorithm.
Args:
arr: List of integers to be sorted
Returns:
List[int]: Sorted array in ascending order
Raises:
TypeError: If input is not a list
ValueError: If array contains non-integer values
Examples:
>>> heap_sort([64, 34, 25, 12, 22, 11, 90])
[11, 12, 22, 25, 34, 64, 90]
>>> heap_sort([])
[]
>>> heap_sort([42])
[42]
"""
# Input validation
if not isinstance(arr, list):
raise TypeError("Input must be a list")
if not arr:
return []
if not all(isinstance(x, int) for x in arr):
raise ValueError("Array must contain only integers")
# Create a copy to avoid modifying original
result = arr.copy()
# Implementation here
# ...
return result
def _heapify(arr: List[int], n: int, i: int) -> None:
"""Helper function to maintain heap property."""
# Implementation
pass
def main():
"""Test the heap sort implementation."""
# Test cases
test_cases = [
[64, 34, 25, 12, 22, 11, 90],
[1],
[],
[5, 5, 5, 5],
[9, 8, 7, 6, 5, 4, 3, 2, 1]
]
for i, test_case in enumerate(test_cases, 1):
print(f"Test case {i}:")
print(f" Input: {test_case}")
sorted_array = heap_sort(test_case)
print(f" Output: {sorted_array}")
print(f" Correct: {sorted_array == sorted(test_case)}")
print()
if __name__ == "__main__":
main()We have automated workflows that will check your PR for quality and help you improve your contributions!
Our Duplicate Detection workflow automatically checks if similar implementations already exist:
- What it checks: Compares your file names with existing files to find potential duplicates
- When it runs: Automatically on every PR
- What happens: If a potential duplicate is found, you'll receive a friendly comment explaining:
- Which files appear similar
- How to verify if it's truly a duplicate
- Options to either improve existing code or explain why yours is different
π‘ Pro Tip: Always search the repository before adding a new algorithm to avoid duplicates!
Our Quality Checks workflow ensures all contributions meet our standards:
-
β Algorithm Description (Required)
- Your code must explain what the algorithm does
- Include the purpose and approach
-
β Complexity Analysis (Required)
- Time complexity (e.g.,
O(n log n)) - Space complexity (e.g.,
O(n)) - Brief explanation of why
- Time complexity (e.g.,
-
β Comments (Recommended)
- Single file PRs: Minimum 3 comments
- Multiple file PRs: Minimum 5 comments per file
- Explain complex logic and key steps
-
β Test Cases/Examples (Recommended)
- Demonstrate your code works
- Show different input scenarios
- Include edge cases
Single File Contributions (More Lenient):
- Only 3 comments required (vs 5)
- Minimum 15 lines (vs 20)
- Won't receive warnings for minor issues
- Focus on critical requirements (description + complexity)
Multiple File Contributions (Stricter):
- All quality checks apply
- Higher standards for documentation
- Ensures consistency across files
If your PR needs improvements, you'll get a helpful comment with:
- β What's missing or needs improvement
- π Why each requirement is important
- π‘ Example template showing best practices
- π§ Exactly how to fix the issues
Note: Quality checks are educational, not blocking - they help you improve, but won't fail your PR!
If any workflow fails, you'll receive a friendly explanation with:
- π What went wrong: Clear explanation of the error
- π§ How to fix it: Step-by-step instructions
- π‘ Common causes: Why this error typically happens
- π Resources: Links to documentation and examples
All automated workflows update existing comments instead of spamming:
- β One comment per workflow type
- β Updates when you push new commits
- β Always shows current status
- β Clean, non-spammy PR discussions
-
Search for Duplicates
# Search the repository for similar implementations # Check the language folder to see what already exists ls CPP/algorithms/sorting/ # Example for C++ sorting algorithms
-
Test Your Code
# For Python python your_algorithm.py # For Java javac YourAlgorithm.java && java YourAlgorithm # For C++ g++ -o algorithm your_algorithm.cpp && ./algorithm # For C gcc -o algorithm your_algorithm.c && ./algorithm
-
Check Code Quality
- β No compilation errors
- β No runtime errors on test cases
- β Algorithm description included
- β Time & space complexity documented
- β Meaningful comments (3+ for single file, 5+ for multiple)
- β Test cases or examples included
- β Proper input validation
- β Clear variable names
-
Update Documentation
- Add algorithm to appropriate README
- Include complexity analysis
- Provide usage examples
-
Create Feature Branch
git checkout -b feature/algorithm-name git add . git commit -m "Add [algorithm name] implementation in [language]" git push origin feature/algorithm-name
-
Pull Request Template
## π Pull Request Description ### What does this PR add? - [ ] New algorithm implementation - [ ] Data structure implementation - [ ] New programming language support - [ ] Language-specific README - [ ] Bug fix - [ ] Documentation improvement - [ ] Test cases ### Algorithm/Feature Details - **Name**: [Algorithm Name] - **Language**: [Programming Language] - **Category**: [e.g., Sorting, Searching, Graph, etc.] - **Time Complexity**: O(?) - **Space Complexity**: O(?) ### Testing - [ ] Code compiles without errors - [ ] All test cases pass - [ ] Edge cases handled - [ ] Documentation updated ### Screenshots (if applicable) [Add screenshots of output] ### Additional Notes [Any additional information about the implementation]
-
PR Checklist
- Code follows language-specific style guidelines
- File is in the correct directory
- File name follows naming conventions
- Algorithm is well-documented
- Test cases are included
- No duplicate implementations
- Code is original work (if adapted, cite source)
- Use welcoming and inclusive language
- Respect different viewpoints and experiences
- Accept constructive criticism gracefully
- Focus on what's best for the community
- Aim for meaningful contributions
- Test your code thoroughly
- Write clear, readable code
- Include comprehensive documentation
- Ask questions if you're unsure
- Help review others' pull requests
- Share knowledge and learn from others
- Be patient with newcomers
- Make sure your PRs are meaningful, not spam
- Quality contributions are valued over quantity
- Help maintain the repository's standards
- Engage positively with the community
π οΈ Co-Admin & Maintainer:
- Twitter/X: @Karanjotdulay
- GitHub: @Karanjot786
- Direct Contact: Reach out to @Karanjotdulay on Twitter/X for quick questions
- GitHub Issues: For bugs, feature requests, or general questions
- Pull Request Comments: For specific code review questions
- Discussions: For broader community discussions
Solution: Check the Repository Structure section and choose the appropriate language and category.
Solution: Check the Code Standards section for language-specific requirements.
Solution: Check open issues labeled "good first issue" or "help wanted".
Solution: Read the feedback, make necessary changes, and resubmit. Don't take it personally!
Contributors will be recognized through:
- README Hall of Fame: Top contributors featured in README
- Monthly Highlights: Featured contributors each month
- Hacktoberfest Completion: Special recognition for Hacktoberfest participants
By participating in this project, you agree to abide by our Code of Conduct:
- Be respectful and inclusive
- No harassment, discrimination, or offensive behavior
- Focus on constructive feedback
- Help create a welcoming environment for all
Thank you for contributing to the DSA Code Repository! Your contributions help make this a valuable resource for developers worldwide. π
Happy Coding and Happy Hacktoberfest 2025! β¨