A collection of Python implementations for common algorithmic problems and mathematical functions.
Located in algorithm_practice/
-
Kadane's Algorithm (
kadane_algorithm.py
)- Finds the contiguous subarray with the maximum sum
- Returns both the maximum sum and the start/end indices
- Time Complexity: O(n)
-
Longest Common Prefix (
longest_common_prefix.py
)- Finds the longest common prefix shared by all strings in an array
- Returns empty string if no common prefix exists
- Time Complexity: O(S) where S is the sum of all characters in all strings
-
First Repeated Character (
repetitive_first_character.py
)- Finds the first repeating character in a string
- Returns None if no character repeats
- Time Complexity: O(n²)
-
Second Largest Element (
second_largest_element.py
)- Finds the second largest element in an array of integers
- Handles edge cases like empty arrays or arrays with less than 2 elements
- Time Complexity: O(n)
-
Longest Substring Without Repeat (
long_subs_without_repeat.py
)- Finds the length of the longest substring without repeating characters
- Returns the substring and its length
- Time Complexity: O(n)
-
Reverse String (
reverse_string.py
)- Reverses the order of words in a given string
- Preserves word order while reversing the overall string
- Time Complexity: O(n)
Located in math_functions/
-
Fibonacci Sequence (
fibonacci.py
)- Implements the Fibonacci sequence generator
- F(n) = F(n-1) + F(n-2), where F(0)=0, F(1)=1
- Time Complexity: O(n)
-
Primality Test (
primality_test.py
)- Checks if a given number is prime
- Uses optimized square root method
- Time Complexity: O(√n)
-
Euclidean Algorithm (
euclidean_algorithm.py
)- Finds the Greatest Common Divisor (GCD) of two numbers
- Uses the Euclidean algorithm method
- Time Complexity: O(log min(a,b))
Located in oop_practice/
- Exercise (
exercise.dart
)- Contains Dart implementations of OOP concepts
- Includes various class and object examples
Each algorithm is implemented in its own file. To use any algorithm:
- Import the specific file
- Call the corresponding function with appropriate parameters
- Python 3.x (for Python files)
- Dart SDK (for Dart files)
Each file includes example test cases and print statements demonstrating usage.
python_function/
├── algorithm_practice/
│ ├── kadane_algorithm.py
│ ├── longest_common_prefix.py
│ ├── repetitive_first_character.py
│ ├── second_largest_element.py
│ ├── long_subs_without_repeat.py
│ └── reverse_string.py
├── math_functions/
│ ├── fibonacci.py
│ ├── primality_test.py
│ └── euclidean_algorithm.py
└── oop_practice/
└── exercise.dart