An open API service indexing awesome lists of open source software.

https://github.com/endygamedev/rust_algorithms

:gear: Some algorithms written in Rust.
https://github.com/endygamedev/rust_algorithms

algorithms rust rust-lang structures

Last synced: 4 months ago
JSON representation

:gear: Some algorithms written in Rust.

Awesome Lists containing this project

README

          

:gear: Algorithms on Rust GitHub Workflow Status Travis CI

:crab: Content



  1. Algebra

  2. Seach

  3. Sorting

  4. Dynamic programming


:crab: Algebra


1. Euclidean algorithm

Short description

Euclidean algorithm is an efficient method for computing the greatest common divisor (GCD) of two integers, the largest number that divides them both without a remainder.


View full on Wiki

2. Minimum of an
array

3. Maximum of an array


:crab: Search


1. Binary search


Short description

Binary search is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the search ends with the remaining half being empty, the target is not in the array.


Performance


  • Average: O(log n)

  • Worst-case: O(log n)

  • Best-case: O(1)


View full on Wiki

2. Linear search


Short description

A linear search sequentially checks each element of the list until it finds an element that matches the target value. If the algorithm reaches the end of the list, the search terminates unsuccessfully.


Performance


  • Average: O(n/2)

  • Worst-case: O(n)

  • Best-case: O(1)


View full on Wiki


:crab: Sorting


1. Bubble sort


Short description

Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list.


Performance


  • Average: O(n2)

  • Worst-case: O(n2)

  • Best-case: O(1)


View full on Wiki

2. Insertion sort


Short description

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. Sorting is typically done in-place, by iterating up the array, growing the sorted list behind it. At each array-position, it checks the value there against the largest value in the sorted list (which happens to be next to it, in the previous array-position checked). If larger, it leaves the element in place and moves to the next. If smaller, it finds the correct position within the sorted list, shifts all the larger values up to make a space, and inserts into that correct position.


Performance


  • Average: O(n2)

  • Worst-case: O(n2)

  • Best-case: O(1)


View full on Wiki

3. Selection sort


Short description

Selection sort is an in-place comparison sorting algorithm. The algorithm divides the input list into two parts: a sorted sublist of items which is built up from left to right at the front (left) of the list and a sublist of the remaining unsorted items that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.


Performance


  • Average: O(n2)

  • Worst-case: O(n2)

  • Best-case: O(1)


View full on Wiki

4. Quicksort


Short description

Quicksort is a divide and conquer algorithm. It first divides the input array into two smaller sub-arrays: the low elements and the high elements. It then recursively sorts the sub-arrays. The steps for in-place Quicksort are:


  1. Pick an element, called a pivot, from the array.

  2. Partitioning: reorder the array so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.

  3. Recursively apply the above steps to the sub-array of elements with smaller values and separately to the sub-array of elements with greater values.



Performance


  • Average: O(n log n)

  • Worst-case: O(n2)

  • Best-case: O(n log n)


View full on Wiki

5. Merge sort


Short description

Merge sort is a divide and conquer algorithm. Conceptually, a merge sort works as follows:


  1. Divide the unsorted list into n sublists, each containing one element (a list of one element is considered sorted).

  2. Repeatedly merge sublists to produce new sorted sublists until there is only one sublist remaining. This will be the sorted list.



Performance


  • Average: O(n log n)

  • Worst-case: O(n log n)

  • Best-case: O(n log n)


View full on Wiki

6. Shell sort


Short description

Shell sort is an in-place comparison sort. It can be seen as either a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort). The method starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared. By starting with far apart elements, it can move some out-of-place elements into position faster than a simple nearest neighbor exchange.


Performance


  • Average: depends on gap sequence

  • Worst-case: O(n2)

  • Best-case: O(n log n)


View full on Wiki

7. Cocktail shaker sort


Short description

Cocktail shaker sort is a slight variation of bubble sort. It differs in that instead of repeatedly passing through the list from bottom to top, it passes alternately from bottom to top and then from top to bottom. It can achieve slightly better performance than a standard bubble sort. The reason for this is that bubble sort only passes through the list in one direction and therefore can only move items backward one step each iteration.


Performance


  • Average: O(n2)

  • Worst-case: O(n2)

  • Best-case: O(n)


View full on Wiki


:crab: Dynamic programming


1. 0-1 Knapsack problem


Short description

The knapsack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items. The problem often arises in resource allocation where the decision makers have to choose from a set of non-divisible projects or tasks under a fixed budget or time constraint, respectively.


Performance


  • Complexity: O(NW) , where `N` is number of items in knapsack and `W` is knapsack capacity


View full on Wiki




:arrow_up: Back to top :arrow_up:




| :man_technologist: endygamedev |