Convert Figma logo to code with AI

EvgenyKarkan logoEKAlgorithms

EKAlgorithms contains some well known CS algorithms & data structures.

2,423
363
2,423
6

Top Related Projects

183,979

All Algorithms implemented in Python

Minimal examples of data structures and algorithms in Python

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.

:fireworks:Interactive Online Platform that Visualizes Algorithms from Code

Algorithms and data structures in Swift, with explanations!

Quick Overview

EKAlgorithms is a GitHub repository containing a collection of common computer science algorithms and data structures implemented in Objective-C. It serves as a learning resource and reference for developers interested in understanding and implementing various algorithms in Objective-C.

Pros

  • Comprehensive collection of algorithms and data structures
  • Well-organized and easy to navigate repository structure
  • Includes unit tests for most implementations
  • Provides a valuable resource for Objective-C developers and algorithm enthusiasts

Cons

  • Limited to Objective-C implementations, which may not be as relevant for modern iOS development
  • Some implementations may lack detailed explanations or comments
  • Not actively maintained, with the last update being several years ago
  • May not include the most recent or optimized versions of some algorithms

Code Examples

  1. Binary Search implementation:
+ (NSInteger)binarySearchForValue:(NSInteger)value inSortedArray:(NSArray *)array
{
    NSInteger left = 0;
    NSInteger right = [array count] - 1;
    
    while (left <= right) {
        NSInteger middle = (left + right) / 2;
        NSInteger middleValue = [[array objectAtIndex:middle] integerValue];
        
        if (middleValue == value) {
            return middle;
        }
        else if (middleValue > value) {
            right = middle - 1;
        }
        else {
            left = middle + 1;
        }
    }
    
    return -1;
}
  1. Bubble Sort implementation:
+ (NSArray *)bubbleSortArray:(NSArray *)unsortedArray
{
    NSMutableArray *mutableArray = [unsortedArray mutableCopy];
    
    for (NSInteger i = 0; i < [mutableArray count]; i++) {
        for (NSInteger j = 0; j < [mutableArray count] - 1 - i; j++) {
            if ([mutableArray[j] compare:mutableArray[j + 1]] == NSOrderedDescending) {
                [mutableArray exchangeObjectAtIndex:j withObjectAtIndex:j + 1];
            }
        }
    }
    
    return [mutableArray copy];
}
  1. Linked List implementation:
@interface EKLinkedListNode : NSObject

@property (nonatomic, strong) id value;
@property (nonatomic, strong) EKLinkedListNode *next;

@end

@interface EKLinkedList : NSObject

@property (nonatomic, strong) EKLinkedListNode *head;

- (void)addValue:(id)value;
- (void)removeValue:(id)value;
- (BOOL)containsValue:(id)value;

@end

Getting Started

To use EKAlgorithms in your Objective-C project:

  1. Clone the repository: git clone https://github.com/EvgenyKarkan/EKAlgorithms.git
  2. Copy the desired algorithm files into your project
  3. Import the header files in your code: #import "EKAlgorithm.h"
  4. Use the algorithms in your code:
NSArray *unsortedArray = @[@5, @2, @8, @1, @9];
NSArray *sortedArray = [EKSort bubbleSortArray:unsortedArray];
NSLog(@"Sorted array: %@", sortedArray);

Note: As the project is not actively maintained, it's recommended to review and test the implementations before using them in production code.

Competitor Comparisons

183,979

All Algorithms implemented in Python

Pros of Python

  • Larger community and more contributors, leading to more diverse algorithms and implementations
  • Better organized structure with clear categorization of algorithms
  • More comprehensive documentation and explanations for each algorithm

Cons of Python

  • Primarily focused on Python, limiting language diversity
  • May include some redundant or less optimized implementations due to multiple contributors

Code Comparison

EKAlgorithms (Objective-C):

+ (NSArray *)quicksortArray:(NSArray *)unsortedArray {
    if ([unsortedArray count] <= 1) {
        return unsortedArray;
    }
    // ... (rest of the implementation)
}

Python:

def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    return quick_sort(left) + middle + quick_sort(right)

The Python implementation is more concise and readable, utilizing list comprehensions for partitioning. The EKAlgorithms version, while in Objective-C, follows a similar logic but with more verbose syntax due to the language's nature.

Minimal examples of data structures and algorithms in Python

Pros of algorithms

  • More comprehensive coverage of algorithms and data structures
  • Better organized with clear categorization of topics
  • More active development and community engagement

Cons of algorithms

  • Primarily Python-focused, limiting language diversity
  • Less emphasis on detailed explanations within the code

Code comparison

EKAlgorithms (Objective-C):

+ (NSArray *)intersectionOfSortedArrays:(NSArray *)firstArray andArray:(NSArray *)secondArray {
    NSMutableArray *result = [NSMutableArray array];
    NSUInteger i = 0, j = 0;
    while (i < firstArray.count && j < secondArray.count) {
        // ... (implementation details)
    }
    return result;
}

algorithms (Python):

def intersection(a, b):
    i, j = 0, 0
    result = []
    while i < len(a) and j < len(b):
        if a[i] == b[j]:
            result.append(a[i])
            i += 1
            j += 1
        elif a[i] < b[j]:
            i += 1
        else:
            j += 1
    return result

Summary

algorithms offers a more extensive collection of algorithms and data structures, with better organization and community support. However, it primarily focuses on Python implementations. EKAlgorithms provides implementations in Objective-C, offering language diversity but with a smaller scope and less active development. The code comparison shows similar logical approaches but highlights the language differences between the two repositories.

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

Pros of javascript-algorithms

  • More comprehensive coverage of algorithms and data structures
  • Better documentation with explanations and complexity analysis
  • Active maintenance and regular updates

Cons of javascript-algorithms

  • Larger codebase, potentially overwhelming for beginners
  • Focused solely on JavaScript, limiting language diversity

Code Comparison

EKAlgorithms (Objective-C):

+ (NSArray *)bubbleSortArray:(NSArray *)unsortedArray {
    NSMutableArray *mutableArray = [unsortedArray mutableCopy];
    for (NSInteger i = [mutableArray count] - 1; i > 0; i--) {
        for (NSInteger j = 0; j < i; j++) {
            if ([mutableArray[j] compare:mutableArray[j + 1]] == NSOrderedDescending) {
                [mutableArray exchangeObjectAtIndex:j withObjectAtIndex:j + 1];
            }
        }
    }
    return [mutableArray copy];
}

javascript-algorithms (JavaScript):

export const bubbleSort = (originalArray) => {
  const array = [...originalArray];
  for (let i = 1; i < array.length; i += 1) {
    for (let j = 0; j < array.length - i; j += 1) {
      if (array[j] > array[j + 1]) {
        [array[j], array[j + 1]] = [array[j + 1], array[j]];
      }
    }
  }
  return array;
};

Both implementations showcase the bubble sort algorithm, but javascript-algorithms offers a more modern approach with ES6+ syntax and improved readability.

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.

Pros of interactive-coding-challenges

  • More comprehensive coverage of data structures and algorithms
  • Includes interactive Jupyter notebooks for hands-on learning
  • Provides test cases and solutions for each challenge

Cons of interactive-coding-challenges

  • Larger repository size, potentially overwhelming for beginners
  • Less focus on specific language implementations (primarily Python)

Code Comparison

EKAlgorithms (Objective-C):

+ (NSArray *)quicksortArray:(NSArray *)unsortedArray {
    if ([unsortedArray count] <= 1) {
        return unsortedArray;
    }
    // ... (implementation continues)
}

interactive-coding-challenges (Python):

class Solution(object):
    def quick_sort(self, data):
        if data is None or len(data) < 2:
            return data
        # ... (implementation continues)

Both repositories offer implementations of common algorithms, but interactive-coding-challenges provides a more structured learning approach with interactive notebooks and test cases. EKAlgorithms focuses on Objective-C implementations, making it more suitable for iOS developers. The code comparison shows similar approaches to implementing quicksort, with EKAlgorithms using Objective-C's NSArray and interactive-coding-challenges using Python's list data structure.

:fireworks:Interactive Online Platform that Visualizes Algorithms from Code

Pros of Algorithm Visualizer

  • Interactive visualization of algorithms, enhancing understanding
  • Supports multiple programming languages
  • Collaborative platform allowing users to contribute and share algorithms

Cons of Algorithm Visualizer

  • More complex setup and usage compared to EKAlgorithms
  • Requires web-based environment, not suitable for offline use
  • May have a steeper learning curve for beginners

Code Comparison

EKAlgorithms (Objective-C):

+ (NSInteger)binarySearchForValue:(NSInteger)value inArray:(NSArray *)array
{
    NSInteger low = 0;
    NSInteger high = [array count] - 1;
    while (low <= high) {
        NSInteger mid = (low + high) / 2;

Algorithm Visualizer (JavaScript):

function binarySearch(array, element) {
  let low = 0;
  let high = array.length - 1;
  while (low <= high) {
    let mid = Math.floor((low + high) / 2);

Algorithm Visualizer offers a more interactive and visual approach to learning algorithms, supporting multiple languages and collaborative contributions. However, it requires a web-based environment and may be more complex to set up and use compared to EKAlgorithms.

EKAlgorithms, on the other hand, provides a simpler, offline-friendly implementation in Objective-C, which may be more suitable for iOS developers or those looking for a straightforward reference. The code comparison shows similar implementations of binary search in both repositories, with Algorithm Visualizer using JavaScript and EKAlgorithms using Objective-C.

Algorithms and data structures in Swift, with explanations!

Pros of swift-algorithm-club

  • More comprehensive collection of algorithms and data structures
  • Better organized with clear explanations and visualizations
  • Active community with regular updates and contributions

Cons of swift-algorithm-club

  • Focused solely on Swift, limiting its usefulness for other languages
  • May be overwhelming for beginners due to its extensive content
  • Lacks some optimization techniques found in EKAlgorithms

Code Comparison

EKAlgorithms (Objective-C):

+ (NSArray *)intersectionOfArray:(NSArray *)firstArray withArray:(NSArray *)secondArray
{
    NSMutableSet *firstSet = [NSMutableSet setWithArray:firstArray];
    NSMutableSet *secondSet = [NSMutableSet setWithArray:secondArray];
    [firstSet intersectSet:secondSet];
    return [firstSet allObjects];
}

swift-algorithm-club (Swift):

func intersection<T: Hashable>(_ arrays: [[T]]) -> Set<T> {
    guard let firstArray = arrays.first else { return [] }
    let initialSet = Set(firstArray)
    return arrays.dropFirst().reduce(initialSet) { $0.intersection($1) }
}

The swift-algorithm-club implementation is more concise and supports multiple arrays, while EKAlgorithms focuses on two arrays. The Swift version also uses generics, making it more flexible for different data types.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Build Status

EKAlgorithms

EKAlgorithms is a set of computer exercises implemented in Objective-C. Data structures, well known algorithms, CS curiosities, you name it!

Don't forget to watch the repository; Its content will be expanded and updated frequently.

Arrays and Lists

  1. Index of maximum element in array.
  2. Indexes of maximum and minimum elements simultaneously.
  3. Find longest string in array of strings.
  4. Find shortest string in array of strings.
  5. Array reverse.
  6. Intersection of two arrays.
  7. Union of two arrays (with remove duplicates).
  8. Union of two arrays (with remove duplicates) for some key.
  9. Find duplicates.
  10. Array with N unique/not unique random objects.
  11. Check if array is sorted.
  12. Array shuffle (Fisher-Yates).
  13. Sum of array elements.
  14. N of occurences of each element in array.

Search Algorithms

  1. Linear search.
  2. Binary search.

Sorting Algorithms

  1. Bubble sort.
  2. Shell sort.
  3. Merge sort.
  4. Quick sort.
  5. Insertion sort.
  6. Selection sort.
  7. Radix Sort.
  8. Partial selection sort.
  9. Heap sort.

Selection Algorithms

  1. Quickselect.

Strings

  1. Palindrome or not.
  2. String reverse.
  3. Words count.
  4. Permutations of string.
  5. Occurrences of each character (a - z).
  6. Count "needles" in a "haystack".
  7. Random string.
  8. Concatenation of two strings.
  9. Find 1st occurrence of "needle" in a "haystack".
  10. Last occurrence of "needle" in a "haystack".
  11. Longest common subsequence.
  12. Levenshtein distance.
  13. KMP (Knuth–Morris–Pratt).
  14. Boyer–Moore string search algorithm.

Numeric Algorithms

  1. Sieve of Eratosthenes.
  2. Great common divisor (GCD).
  3. Least common multiple (LCM).
  4. Factorial.
  5. Fibonacci numbers (5 algos).
  6. Sum of digits.
  7. Binary to decimal conversion.
  8. Decimal to binary conversion.
  9. Fast exponentiation.
  10. Number reverse.
  11. Even/odd check.
  12. Leap year check.
  13. Armstrong number check.
  14. Prime number check.
  15. Find Nth prime.
  16. Swap the value of two NSInteger pointers.
  17. Square root using Newton-Raphson method.
  18. Convert integer to another numeral system (2, 8, 12, 16).
  19. Fast inverse square root.

Data Structures

  1. Stack (LIFO).
  2. Queue (FIFO).
  3. Deque.
  4. Linked list.
  5. Graph:
    • DFS (depth-first search);
    • BFS (breadth-first search);
    • MST (minimum spanning tree - Prim's algorithm);
    • MST (minimum spanning tree - Kruskal's algorithm);
    • Shortest path (Dijkstra's algorithm);
    • Topsort.
  6. Tree.
  7. Binary tree:
    • Pre-order traversal;
    • In-order traversal;
    • Post-order traversal.
  8. Binary search tree (BST).
  9. AVL tree.
  10. Binary heap.

Problems

  1. Josephus Problem.
  2. Modulo bias.

Geometry

  1. Array of sorted locations according to a distance to a given location.
  2. Cartesian quadrant selection algorithms

Recursion

  1. Tower of Hanoi.

Contributions

Pull requests are welcome! But if you want to do a contribution, open an issue first.

Originally, the compiled exercises are for educational purposes only and have no intention of being the ultimate solution complexity-wise, but they do intend to be used by you as a starting point of a deeper study on algorithms and their optimization.

Important Note

The Foundation framework already includes tools and methods for most of the exercises contained here. Kudos to Apple on that! But... this. is. SPARTA! So lets get our hands dirty and try to implement cool CS stuff with minimal use of existing APIs.

Thanks!

Similar repositories

algorithms playground for common questions (Ruby language)

Examples of commonly used data structures and algorithms in Swift. (Swift)

Algorithms and data structures in Swift, with explanations!

Contributors

Special thanks to these guys for their contributions to the project's development: