├── .github ├── code-of-conduct.md ├── contributing.md ├── issue-template.md └── pull-request-template.md ├── .gitignore ├── algorithms ├── data-structures │ └── LinkedList.rs ├── math │ ├── ackermann_peter.rs │ ├── collatz.rs │ ├── ducci.rs │ ├── extrema.rs │ ├── pascals_triangle.rs │ └── radix_fmt.rs ├── searches │ ├── BinarySearch.rs │ ├── ExponentialSearch.rs │ ├── FibonacciSearch.rs │ └── LinearSearch.rs └── sorting │ ├── BubbleSort.rs │ ├── HeapSort.rs │ ├── InsertionSort.rs │ ├── MergeSort.rs │ ├── QuickSort.rs │ └── SelectionSort.rs ├── license ├── readme.md └── src └── .gitkeep /.github/code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Attribution 36 | 37 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 38 | 39 | [homepage]: http://contributor-covenant.org 40 | [version]: http://contributor-covenant.org/version/1/4/ 41 | -------------------------------------------------------------------------------- /.github/contributing.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | > Please note that this project is released with a [Contributor Code of Conduct](code-of-conduct.md). By participating in this project you agree to abide by its terms. -------------------------------------------------------------------------------- /.github/issue-template.md: -------------------------------------------------------------------------------- 1 | I am creating an issue because... 2 | -------------------------------------------------------------------------------- /.github/pull-request-template.md: -------------------------------------------------------------------------------- 1 | I am creating a pull request for... 2 | 3 | - [ ] New algorithm 4 | - [ ] Update to an algorithm 5 | - [ ] Fix an error 6 | - [ ] Other - *Describe below* -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | outputs/ 2 | -------------------------------------------------------------------------------- /algorithms/data-structures/LinkedList.rs: -------------------------------------------------------------------------------- 1 | use List::{Item, Nil}; 2 | 3 | // Linked List implementation in rust 4 | 5 | fn main() { 6 | let mut list = List::new(); 7 | list = list.prepend(1); 8 | list = list.prepend(2); 9 | list = list.prepend(3); 10 | list = list.prepend(4); 11 | 12 | println!("len of final linked list {}", list.len()); 13 | println!("{}", list.stringify()); 14 | } 15 | 16 | enum List { 17 | Item(u32, Box), 18 | Nil, 19 | } 20 | 21 | impl List { 22 | fn new() -> List { 23 | Nil 24 | } 25 | fn prepend(self, elem: u32) -> List { 26 | Item(elem, Box::new(self)) 27 | } 28 | fn len(&self) -> u32 { 29 | match *self { 30 | Item(_, ref tail) => 1 + tail.len(), 31 | Nil => 0 32 | } 33 | } 34 | fn stringify(&self) -> String { 35 | match *self { 36 | Item(head, ref tail) => { 37 | format!("{}, {}", head, tail.stringify()) 38 | }, 39 | Nil => { 40 | format!("Nil") 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /algorithms/math/ackermann_peter.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("{}", ackermann(1, 1)); // 3 3 | println!("{}", ackermann(3, 4)); // 125 4 | } 5 | 6 | fn ackermann(m: u128, n: u128) -> u128 { 7 | if m == 0{ 8 | n + 1 9 | } else if m > 0 && n == 0 { 10 | ackermann(m - 1, 1) 11 | } else if m > 0 && n > 0 { 12 | ackermann(m - 1, ackermann(m, n - 1)) 13 | } else { 14 | 0u128 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /algorithms/math/collatz.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let count: u32 = 0; 3 | let n: u32 = 8; 4 | println!("{} took {} steps", n, collatz(n, count)); 5 | } 6 | 7 | 8 | fn collatz(n: u32, mut count: u32) -> u32 { 9 | if n == 1 { 10 | return count 11 | } else if n % 2 == 1 { 12 | count += 1; 13 | return collatz(3*n + 1, count) 14 | } else { 15 | count += 1; 16 | return collatz(n/2, count) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /algorithms/math/ducci.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // Usage: 3 | // ducci(a, b, c, d) 4 | ducci(123, 345, 456, 567); 5 | } 6 | 7 | fn ducci(a: i32, b: i32, c:i32, d:i32) { 8 | let mut n = (a, b, c, d); 9 | let mut counter = 2; 10 | loop { 11 | let old = n; 12 | n = ((n.0 - n.1).abs(), (n.2 - n.1).abs(), (n.3 - n.2).abs(), (n.0 - n.3).abs()); 13 | 14 | if n == (0, 0, 0, 0) { 15 | break println!("{:?}", n) 16 | } else if n == old { 17 | break 18 | } 19 | 20 | println!("{:?}", n); 21 | counter += 1 22 | } 23 | 24 | println!("{}", counter); 25 | } 26 | -------------------------------------------------------------------------------- /algorithms/math/extrema.rs: -------------------------------------------------------------------------------- 1 | mod extrema { 2 | pub fn min(array: &[i32]) -> i32 { 3 | if array.len() < 1 { 4 | return 0; 5 | } 6 | let mut minimum = array[0]; 7 | for number in array { 8 | if minimum > *number { 9 | minimum = *number; 10 | } 11 | } 12 | return minimum; 13 | } 14 | pub fn max(array: &[i32]) -> i32 { 15 | if array.len() < 1 { 16 | return 0; 17 | } 18 | let mut maximum = array[0]; 19 | for number in array { 20 | if maximum < *number { 21 | maximum = *number; 22 | } 23 | } 24 | return maximum; 25 | } 26 | } 27 | 28 | fn main() { 29 | let array = [1, 5, -3, 2, -1]; 30 | println!("The minimum of {:?} is {}", array, extrema::min(&array)); 31 | println!("The maximum of {:?} is {}", array, extrema::max(&array)); 32 | } -------------------------------------------------------------------------------- /algorithms/math/pascals_triangle.rs: -------------------------------------------------------------------------------- 1 | /* Pascals Triangle 2 | * 3 | * NerdyPepper - nerdypepper at tuta dot io - 2019 4 | * 5 | */ 6 | 7 | fn main() { 8 | println!("{}", pascal_triangle(10)); 9 | } 10 | 11 | fn binomial_coeff(n: u32, k: u32) -> u32 { 12 | // C(n, k) = (n)(n-1)(n-2)...(n-k+1) / (k)(k-1)(k-2)...1 13 | let mut coeff = 1u32; 14 | let mut r = k; 15 | if k > n - k { 16 | r = n - k; 17 | } 18 | for i in 0..r { 19 | coeff *= n - i; 20 | coeff /= i + 1; 21 | } 22 | coeff 23 | } 24 | 25 | fn pascal_triangle(n: u32) -> String { 26 | let mut triangle = String::new(); 27 | for i in 0..n { 28 | for _ in 0..(n - i - 1)/2 * 5 { 29 | triangle.push_str(" "); 30 | } 31 | for j in 0..i + 1 { 32 | triangle.push_str(&format!("{:4} ", binomial_coeff(i, j))); 33 | } 34 | triangle.push_str("\n"); 35 | } 36 | triangle 37 | } 38 | -------------------------------------------------------------------------------- /algorithms/math/radix_fmt.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("{}", radix_fmt(42.345, 16).unwrap()); // 2A.585 3 | println!("{}", radix_fmt(5.5, 2).unwrap()); // 101.1 4 | println!("{}", radix_fmt(13.245, 8).unwrap()); // 15.1753412172 5 | } 6 | 7 | fn radix_fmt>(number: T, obase: usize) -> Result { 8 | if obase > 36 && obase < 2 { 9 | return Err(format!("Base {} is not supported!", obase)); 10 | } 11 | let table: Vec = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect(); 12 | let number: f64 = number.into(); 13 | 14 | // format integral part of float 15 | let mut integral = number.trunc() as i64; 16 | let mut obase_int = String::new(); 17 | while integral >= obase as i64 { 18 | obase_int.push(table[(integral % obase as i64) as usize]); 19 | integral /= obase as i64; 20 | } 21 | obase_int.push(table[integral as usize]); 22 | if number.is_sign_negative() { 23 | obase_int.push('-'); 24 | } 25 | let obase_int = obase_int.chars().rev().collect::(); 26 | 27 | // format fractional part of float 28 | let mut fract = number.abs().fract(); 29 | let mut obase_fract = String::new(); 30 | let mut i = 0; 31 | loop { 32 | fract *= obase as f64; 33 | obase_fract.push(table[fract.trunc() as usize]); 34 | i += 1; 35 | if fract.fract() == 0. || i >= 15 { 36 | break; 37 | } 38 | fract = fract.fract(); 39 | } 40 | 41 | Ok(format!("{}.{}", obase_int, obase_fract)) 42 | } 43 | -------------------------------------------------------------------------------- /algorithms/searches/BinarySearch.rs: -------------------------------------------------------------------------------- 1 | pub fn binary_search(array: &[i32], item: i32) -> i32 { 2 | let mut high: i32 = array.len() as i32 - 1; 3 | let mut low: i32 = 0; 4 | let mut mid: i32; 5 | while low <= high { 6 | mid = ((high - low) / 2) + low; 7 | let val = array[mid as usize]; 8 | if val == item { 9 | return mid as i32; 10 | } 11 | if val > item { 12 | high = mid - 1; 13 | } 14 | if val < item { 15 | low = mid + 1; 16 | } 17 | } 18 | return -1; 19 | } 20 | 21 | fn main() { 22 | let arr = [ 1, 2, 5, 11, 12, 15, 21, 22, 25 ]; 23 | println!("{}",binary_search(&arr, 15)); 24 | } 25 | -------------------------------------------------------------------------------- /algorithms/searches/ExponentialSearch.rs: -------------------------------------------------------------------------------- 1 | mod search { 2 | pub fn exponential_search(array: &[i32], item: i32) -> i32 { 3 | if array.len() == 0 { 4 | return -1; 5 | } 6 | let mut i = 1; 7 | while i < array.len() { 8 | if array[i] < item { 9 | i *= 2; 10 | } else { 11 | break; 12 | } 13 | } 14 | if i >= array.len() { 15 | i = array.len() - 1; 16 | } 17 | let index = binary_search(&array[(i/2)..=i], item); 18 | if index != -1 { index + (i as i32 / 2) } else { -1 } 19 | } 20 | 21 | pub fn binary_search(array: &[i32], item: i32) -> i32 { 22 | let mut high: i32 = array.len() as i32 - 1; 23 | let mut low: i32 = 0; 24 | let mut mid: i32; 25 | while low <= high { 26 | mid = ((high - low) / 2) + low; 27 | let val = array[mid as usize]; 28 | if val == item { 29 | return mid as i32; 30 | } 31 | if val > item { 32 | high = mid - 1; 33 | } 34 | if val < item { 35 | low = mid + 1; 36 | } 37 | } 38 | -1 39 | } 40 | } 41 | 42 | fn main() { 43 | let arr = [ 1, 2, 5, 11, 12, 15, 21, 22, 25 ]; 44 | println!("{}", search::exponential_search(&arr, 1)); 45 | println!("{}", search::exponential_search(&arr, 5)); 46 | println!("{}", search::exponential_search(&arr, 15)); 47 | println!("{}", search::exponential_search(&arr, 22)); 48 | println!("{}", search::exponential_search(&arr, 25)); 49 | println!("{}", search::exponential_search(&arr, 45)); 50 | println!("{}", search::exponential_search(&arr, -45)); 51 | } 52 | -------------------------------------------------------------------------------- /algorithms/searches/FibonacciSearch.rs: -------------------------------------------------------------------------------- 1 | use std::cmp::min; 2 | 3 | pub fn fibonacci_search(array: &[i32], item: i32) -> i32 { 4 | let mut fb2 = 0; 5 | let mut fb1 = 1; 6 | let mut fb = fb2 + fb1; 7 | let mut offset: i32 = -1; 8 | while fb < array.len() { 9 | fb2 = fb1; 10 | fb1 = fb; 11 | fb = fb2 + fb1; 12 | } 13 | let mut i: i32; 14 | while fb > 1 { 15 | i = min(offset + fb2 as i32, array.len() as i32 - 1); 16 | if array[i as usize] < item { 17 | fb = fb1; 18 | fb1 = fb2; 19 | fb2 = fb - fb1; 20 | offset = i; 21 | } else if array[i as usize] > item { 22 | fb = fb2; 23 | fb1 = fb1 - fb2; 24 | fb2 = fb - fb1; 25 | } else { 26 | return i; 27 | } 28 | } 29 | if fb1 != 0 && array[offset as usize + 1] == item { 30 | return offset + 1; 31 | } 32 | -1 33 | } 34 | 35 | fn main() { 36 | let array = [1,2,3,4,5]; 37 | println!("{}", fibonacci_search(&array, 1)); 38 | println!("{}", fibonacci_search(&array, 2)); 39 | println!("{}", fibonacci_search(&array, 3)); 40 | println!("{}", fibonacci_search(&array, 4)); 41 | println!("{}", fibonacci_search(&array, 5)); 42 | } 43 | -------------------------------------------------------------------------------- /algorithms/searches/LinearSearch.rs: -------------------------------------------------------------------------------- 1 | pub fn linear_search(array: &[i32], item: i32) -> i32 { 2 | for i in 0..array.len() { 3 | if item == array[i] { 4 | return i as i32; 5 | } 6 | } 7 | return -1; 8 | } 9 | 10 | fn main() { 11 | let array = [1,2,3,4,5]; 12 | println!("{}", linear_search(&array, 3)); 13 | } -------------------------------------------------------------------------------- /algorithms/sorting/BubbleSort.rs: -------------------------------------------------------------------------------- 1 | mod sort { 2 | pub fn bubblesort(array: &mut [T]) { 3 | for i in 0..array.len() { 4 | println!("{:?}", array); 5 | let ending = array.len() - i; 6 | bubblesort_step(&mut array[..ending]); 7 | } 8 | } 9 | 10 | fn bubblesort_step(array: &mut [T]) { 11 | for i in 0..array.len() { 12 | if i == array.len() - 1 { 13 | return; 14 | } 15 | 16 | if array[i] > array[i + 1] { 17 | array.swap(i, i + 1); 18 | } 19 | } 20 | } 21 | } 22 | 23 | fn main() { 24 | let mut array = [9, 4, 1, 7, 3, 2, 8, 5, 6]; 25 | sort::bubblesort(&mut array); 26 | println!("{:?}", array); 27 | } 28 | -------------------------------------------------------------------------------- /algorithms/sorting/HeapSort.rs: -------------------------------------------------------------------------------- 1 | mod sort { 2 | pub fn heap_sort(array: &mut [T]) { 3 | println!("{:?}", array); 4 | let len = array.len(); 5 | for i in (0..(len / 2)).rev() { 6 | heapify(array, len, i); 7 | } 8 | println!("Max-heap:"); 9 | println!("{:?}", array); 10 | for i in (0..len).rev() { 11 | array.swap(0, i); 12 | heapify(array, i, 0); 13 | } 14 | println!("Result:"); 15 | println!("{:?}", array); 16 | } 17 | 18 | fn heapify(array: &mut [T], n: usize, i: usize) { 19 | let mut largest = i; 20 | let left = 2 * i + 1; 21 | let right = 2 * i + 2; 22 | 23 | if left < n && array[left] > array[largest] { 24 | largest = left; 25 | } 26 | if right < n && array[right] > array[largest] { 27 | largest = right; 28 | } 29 | 30 | if largest != i { 31 | array.swap(i, largest); 32 | heapify(array, n, largest); 33 | } 34 | } 35 | 36 | } 37 | 38 | fn main() { 39 | let mut array = [9, 4, 1, 7, 3, 2, 8, 5, 6]; 40 | // let mut array = [1, 12, 9, 5, 6, 10]; 41 | sort::heap_sort(&mut array); 42 | println!("{:?}", array); 43 | } 44 | -------------------------------------------------------------------------------- /algorithms/sorting/InsertionSort.rs: -------------------------------------------------------------------------------- 1 | mod sort { 2 | pub fn insertion_sort(array: &mut [T]) { 3 | let mut n; 4 | for i in 0..array.len() { 5 | println!("{:?}", array); 6 | n = i; 7 | while n > 0 && array[n] < array[n - 1] { 8 | array.swap(n, n - 1); 9 | n = n - 1; 10 | } 11 | } 12 | } 13 | } 14 | 15 | fn main() { 16 | let mut array = [9, 4, 1, 7, 3, 2, 8, 5, 6]; 17 | sort::insertion_sort(&mut array); 18 | println!("{:?}", array); 19 | } 20 | -------------------------------------------------------------------------------- /algorithms/sorting/MergeSort.rs: -------------------------------------------------------------------------------- 1 | mod sort { 2 | pub fn merge_sort(array: &mut [T]) { 3 | if array.len() < 2 { 4 | return; 5 | } 6 | let mid = (array.len() - 1) / 2; 7 | merge_sort(&mut array[0..=mid]); 8 | merge_sort(&mut array[(mid + 1)..]); 9 | merge(array, 0, mid, array.len() - 1); 10 | } 11 | 12 | fn merge(array: &mut [T], mut start1: usize, mut mid: usize, end: usize) { 13 | let mut start2 = mid + 1; 14 | if array[mid] <= array[start2] { 15 | return; 16 | } 17 | while start1 <= mid && start2 <= end { 18 | if array[start1] <= array[start2] { 19 | start1 += 1; 20 | } else { 21 | let val = array[start2]; 22 | let mut i = start2; 23 | while i != start1 { 24 | array[i] = array[i - 1]; 25 | i -= 1; 26 | } 27 | array[start1] = val; 28 | start1 += 1; 29 | start2 += 1; 30 | mid += 1; 31 | } 32 | } 33 | } 34 | } 35 | 36 | fn main() { 37 | let mut array = [9, 4, 1, 7, 3, 2, 8, 5, 6]; 38 | sort::merge_sort(&mut array); 39 | println!("{:?}", array); 40 | } 41 | -------------------------------------------------------------------------------- /algorithms/sorting/QuickSort.rs: -------------------------------------------------------------------------------- 1 | mod sort { 2 | 3 | pub fn quicksort(arr: &mut [T]) { 4 | let length = arr.len(); 5 | quicksort_step(arr, 0, (length as isize) - 1); 6 | } 7 | 8 | 9 | fn quicksort_step(arr: &mut [T], lo: isize, hi: isize) { 10 | if lo < hi { 11 | let pivot = lomuto_partiton(arr, lo, hi); 12 | quicksort_step(arr, lo, pivot - 1); 13 | quicksort_step(arr, pivot + 1, hi); 14 | } 15 | } 16 | 17 | fn lomuto_partiton(arr: &mut [T], lo: isize, hi: isize) -> isize { 18 | let mut i = lo - 1; 19 | let mut j = lo; 20 | 21 | while j < hi - 1 { 22 | if arr[j as usize] < arr[hi as usize] { 23 | i = i + 1; 24 | arr.swap(i as usize, j as usize); 25 | } 26 | j = j + 1; 27 | } 28 | 29 | if arr[hi as usize] < arr[(i + 1) as usize] { 30 | arr.swap(hi as usize, (i + 1) as usize); 31 | } 32 | 33 | return i + 1; 34 | } 35 | } 36 | 37 | fn main() { 38 | let mut arr = [3, 7, 8, 5, 2, 1, 9, 5, 4]; 39 | 40 | sort::quicksort(&mut arr); 41 | 42 | println!("{:?}", arr); 43 | } 44 | -------------------------------------------------------------------------------- /algorithms/sorting/SelectionSort.rs: -------------------------------------------------------------------------------- 1 | mod sort { 2 | pub fn selection_sort(array: &mut [T]) { 3 | for i in 0..array.len() { 4 | println!("{:?}", array); 5 | let min = search_min(&array[i..]) + i; 6 | if min != i { 7 | array.swap(i, min); 8 | } 9 | } 10 | } 11 | 12 | pub fn search_min(array: &[T]) -> usize { 13 | let mut min = 0; 14 | for i in 0..array.len() { 15 | if array[min] > array[i] { 16 | min = i; 17 | } 18 | } 19 | min 20 | } 21 | } 22 | 23 | fn main() { 24 | let mut array = [9, 4, 1, 7, 3, 2, 8, 5, 6]; 25 | sort::selection_sort(&mut array); 26 | println!("{:?}", array); 27 | } 28 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 All Algorithms and its contributors (allalgorithms.com) 4 | Copyright (c) 2018 Carlos Abraham (abranhe.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | We are accepting all pull requests. [Read More](https://github.com/AllAlgorithms/algorithms/issues/40) 2 | 3 |
4 |
5 |
6 |
7 |
8 | Algorithms Logo 9 |
10 |
11 |
12 |
13 |
14 |
15 | 16 |

17 | What is an algorithm?    18 | Contributing    19 | Stickers & T-Shirts 20 |

21 | 22 | 23 |

24 | 25 | Twitter 26 |     27 | 28 | Instagram 29 |     30 | 31 | Github 32 |     33 |

34 | 35 |
36 |

37 | Huge collection of All ▲lgorithms implemented in multiple languages 38 |

39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 |
47 | 48 | ## See 49 | 50 | - [What is an algorithm](#what-is-an-algorithm) 51 | - [Contributing](https://github.com/AllAlgorithms/algorithms/blob/master/.github/contributing.md) 52 | - [Code of Conduct](https://github.com/AllAlgorithms/algorithms/blob/master/.github/code-of-conduct.md) 53 | - [Stickers and T-Shirts](https://www.redbubble.com/people/abranhe/works/34285088) 54 | - [Twitter](https://twitter.com/AllAlgorithms) 55 | - [Instagram](https://instagram.com/AllAlgorithms) 56 | - [Algorithms Categories](#categories) 57 | - [Maintainers](#maintainers) 58 | - [License](#license) 59 | 60 | 61 | ## What is an algorithm? 62 | 63 | Informally, an algorithm is any well-defined computational procedure that takes 64 | some value, or set of values, as input and produces some value, or set of values, as 65 | output. An algorithm is thus a sequence of computational steps that transform the 66 | input into the output. 67 | 68 | An algorithm should have three important characteristics to be considered valid: 69 | 70 | - **It should be finite**: If your algorithm never ends trying to solve the problem 71 | it was designed to solve then it is useless 72 | - **It should have well defined instructions**: Each step of the algorithm has to 73 | be precisely defined; the instructions should be unambiguously specified for each case. 74 | - **It should be effective**: The algorithm should solve the problem it was designed 75 | to solve. And it should be possible to demonstrate that the algorithm converges with 76 | just a paper and pencil. 77 | 78 | ## Categories 79 | 80 | > Structure of The All ▲lgoritms project 81 | 82 | - [Artificial Intelligence](#artificial-intelligence) 83 | - [Backtracking](#backtracking) 84 | - [Bit Manipulation](#bit-manipulation) 85 | - [Cellular Automaton](#cellular-automaton) 86 | - [Ciphers](#ciphers) 87 | - [Computational Geometry](#computational-geometry) 88 | - [Cryptography](#cryptography) 89 | - [Data Structures](#data-structures) 90 | - [Divide and conquer](#divide-and-conquer) 91 | - [Dynamic Programming](#dynamic-programming) 92 | - [Gaming Theory](#gaming-theory) 93 | - [Graphs](#graphs) 94 | - [Greedy Algorithms](#greedy-algorithms) 95 | - [Math](#math) 96 | - [Networking](#networking) 97 | - [Numerical Analysis](#numerical-analysis) 98 | - [Operating system](#operating-system) 99 | - [Randomized Algorithms](#randomized-algorithms) 100 | - [Searches](#searches) 101 | - [Selections Algorithms](#selections-algorithms) 102 | - [Sorting](#sorting) 103 | - [Strings](#strings) 104 | - [Online Challenges](#online-challenges) 105 | - [Others](#others) 106 | 107 | ## [Artificial Intelligence](artificial-intelligence) 108 | 109 | - [Density-based spatial clustering of applications with noise (DBSCAN Clustering)](https://allalgorithms.com/docs/dbscan) 110 | - [Interactive Self-Organizing Data Analysis Technique yAy! (ISODATA Clustering)](https://allalgorithms.com/docs/isodata) 111 | - [Linear Regression](https://allalgorithms.com/docs/linear-regression) 112 | - [Logistic Regression](https://allalgorithms.com/docs/logistic-regression) 113 | - [Neutral Style Transfer](https://allalgorithms.com/docs/neutral-style-transfer) 114 | - [SATisfiable (SAT)](https://allalgorithms.com/docs/sat) 115 | - [Travelling salesman problem (TSP)](https://allalgorithms.com/docs/tsp) 116 | - [A* (A Star)](https://allalgorithms.com/docs/a-star) 117 | - [Artificial Neutral Network](https://allalgorithms.com/docs/artificial-neutral-network) 118 | - [Convolutional Neutral Network](https://allalgorithms.com/docs/convolutional-neutral-network) 119 | - [Decision Tree](https://allalgorithms.com/docs/decision-tree) 120 | - [Factorization Machines](https://allalgorithms.com/docs/factorization-machines) 121 | - [Gaussian Mixture Model](https://allalgorithms.com/docs/gaussian-mixtrue-model) 122 | - [Gradient Boosting Trees](https://allalgorithms.com/docs/gradient-boostring-trees) 123 | - [Hierachical Clustering](https://allalgorithms.com/docs/hierachical-clustering) 124 | - [Image Processing](https://allalgorithms.com/docs/image-processing) 125 | - [K Nearest Neighbors](https://allalgorithms.com/docs/k-nearest-neighbors) 126 | - [K Means](https://allalgorithms.com/docs/k-means) 127 | - [Minimax](https://allalgorithms.com/docs/minimax) 128 | - [Native Bayes](https://allalgorithms.com/docs/native-bayes) 129 | - [Nearest Sequence Memory](https://allalgorithms.com/docs/nearest-sequence-memory) 130 | - [Neutral Network](https://allalgorithms.com/docs/neutral-network) 131 | - [Perceptron](https://allalgorithms.com/docs/perceptron) 132 | - [Principal Component Analysis](https://allalgorithms.com/docs/principal-component-analysis) 133 | - [Q Learing](https://allalgorithms.com/docs/q-learning) 134 | - [Random Forests](https://allalgorithms.com/docs/random-forest) 135 | - [Restricted Boltzman Machine](https://allalgorithms.com/docs/restricted-boltzman-machine) 136 | 137 | ## [Backtracking](backtracking) 138 | 139 | - [Algorithm X](backtracking/algorithm-x) 140 | - [Crossword Puzzle](backtracking/crossword-Puzzle) 141 | - [Knight Tour](backtracking/knight-tour) 142 | - [M Coloring Problem](backtracking/m-coloring-problem) 143 | - [N Queen](backtracking/n-queen) 144 | - [Number of ways in Maze](backtracking/number-of-ways-in-maze) 145 | - [Partitions of set](backtracking/partitions-of-set) 146 | - [Permutation of Strings](backtracking/permutation-of-strings) 147 | - [Powerset](backtracking/powerset) 148 | - [Rat in maze](backtracking/rat-in-maze) 149 | - [Subset Sum](backtracking/subset-sum) 150 | - [Sudoku Solve](backtracking/sudoku-solve) 151 | 152 | ## [Bit Manipulation](bit-manipulation) 153 | 154 | - [Addition using bits](bit-manipulation/adding-using-bits) 155 | - [Bit divisor](bit-manipulation/bit-divisor) 156 | - [Byte swapper](bit-manipulation/byte-swapper) 157 | - [Convert numbers to binary](bit-manipulation/convert-numbers-to-binary) 158 | - [Count set bits](bit-manipulation/count-set-bits) 159 | - [Flip bits](bit-manipulation/flip-bits) 160 | - [Hamming distance](bit-manipulation/hamming-distace) 161 | - [Invert bit](bit-manipulation/invert-bit) 162 | - [Lonely integer](bit-manipulation/lonely-integer) 163 | - [Magic Number](bit-manipulation/magic-number) 164 | - [Maximum XOR Value](bit-manipulation/maximun-xor-value) 165 | - [Power of 2](bit-manipulation/power-of-2) 166 | - [Subset Generation](bit-manipulation/subset-generation) 167 | - [Sum binary numbers](bit-manipulation/sum-binary-numbers) 168 | - [Sum equals XOR](bit-manipulation/sum-equals-xor) 169 | - [Thrice unique number](bit-manipulation/thrice-unique-number) 170 | - [Twice unique number](bit-manipulation/twice-unique-number) 171 | - [XOR Swap](bit-manipulation/xor-swap) 172 | 173 | ## [Cellular Automaton](cellular-automaton) 174 | 175 | - [Brians Brain](cellular-automaton/brians-brain) 176 | - [Conways Game of life](cellular-automaton/conways-game-of-life) 177 | - [Elementary Cellular Automata](cellular-automaton/elementary-cellular-automata) 178 | - [Generic Algorithm](cellular-automaton/generic-algorithm) 179 | - [Langtons Ant](cellular-automaton/langtons-ant) 180 | - [Nobili Cellular Automata](cellular-automaton/nobili-cellular-automata) 181 | - [Von Neoumann Cellular Automata](cellular-automaton/von-neoumann-cellular-automata) 182 | 183 | ## [Computational Geometry](computational-geometry) 184 | 185 | - [2D Line intersection](computational-geometry/) 186 | - [2D Separating Axis test](computational-geometry/) 187 | - [Area of polygon](computational-geometry/) 188 | - [Area of triangle](computational-geometry/) 189 | - [Axis aligned bounding box collision](computational-geometry/) 190 | - [Bresenham Line](computational-geometry/) 191 | - [Chans Algorithm](computational-geometry/) 192 | - [Cohen Sutherland Lineclip](computational-geometry/) 193 | - [Distance between points](computational-geometry/) 194 | - [Graham Scan](computational-geometry/) 195 | - [Halfplane intersection](computational-geometry/) 196 | - [Jarvis March](computational-geometry/) 197 | - [Quickull](computational-geometry/) 198 | - [Sphere tetrahedron intersection](computational-geometry/) 199 | - [Sutherland Hodgeman clipping](computational-geometry/) 200 | 201 | ## [Cryptography](cryptography) 202 | 203 | - [Affine Cipher](cryptography/) 204 | - [Atbash Cipher](cryptography/) 205 | - [Autokey Cipher](cryptography/) 206 | - [Baconian Cipher](cryptography/) 207 | - [Caesar Cipher](cryptography/) 208 | - [Colummnar Cipher](cryptography/) 209 | - [Vigenere Cipher](cryptography/) 210 | 211 | ## [Data Structures](data-structures) 212 | 213 | - [Bag](data-structures/bag/) 214 | - [Hashes](data-structures/hashes/) 215 | - [Linked List](data-structures/linked-list/) 216 | - [List](data-structures/list/) 217 | - [Queue](data-structures/queue/) 218 | - [Stack](data-structures/stack/) 219 | - [Tree](data-structures/tree/) 220 | 221 | ## [Divide and conquer](divide-and-conquer) 222 | 223 | - [Strassen Matrix Manipulation](divide-and-conquer/) 224 | - [Closest Pair of Point](divide-and-conquer/) 225 | - [Inversion Count](divide-and-conquer/) 226 | - [Karatsuba Multiplication](divide-and-conquer/) 227 | - [Maximum Contiguous subsequence sum](divide-and-conquer/) 228 | - [Merge Sort using divide and conquer](divide-and-conquer/) 229 | - [Quick Sort using divide and conquer](divide-and-conquer/) 230 | - [Tournament Method to find min max](divide-and-conquer/) 231 | - [Warnock Algorithm](divide-and-conquer/) 232 | - [X Power Y](divide-and-conquer/) 233 | 234 | ## [Dynamic Programming](dynamic-programming) 235 | 236 | - [Array Median](dynamic-programming) 237 | - [Optima Binary Search Tree](dynamic-programming) 238 | - [Binomial Coefficient](dynamic-programming) 239 | 240 | ## [Gaming Theory](gaming-theory) 241 | 242 | - [Nim Next Best Move Game](gaming-theory/) 243 | - [Nim Win Loss Game](gaming-theory/) 244 | - [Grundy Numbers Kayle Game](gaming-theory/) 245 | 246 | ## [Graphs](graphs) 247 | 248 | - [Bipartite Check](graphs/) 249 | - [Adjacency Lists graphs representation](graphs/) 250 | - [A* (A Star)](https://allalgorithms.com/docs/a-star) 251 | 252 | ## [Greedy Algorithms](greedy-algorithms) 253 | 254 | - [Activity Selection](greedy-algorithms) 255 | - [Dijkstra Shortest Path](greedy-algorithms) 256 | - [Egyptian Fraction](greedy-algorithms) 257 | 258 | ## [Math](math) 259 | 260 | - [2 Sum](math/) 261 | - [Add Polynomials](math/) 262 | - [Amicable Numbers](math/) 263 | - [Armstrong Numbers](math/) 264 | - [Automorphic Numbers](math/) 265 | - [Average Stream Numbers](math/) 266 | - [Babylonian Method](math/) 267 | - [Binomial Coefficient](math/) 268 | - [Catalan Number](math/) 269 | - [Check is Square](math/) 270 | - [Convolution](math/) 271 | - [Coprime Numbers](math/) 272 | - [Count Digits](math/) 273 | - [Count Trailing Zeroes](math/) 274 | - [Decoding of String](math/) 275 | - [Delannoy Number](math/) 276 | - [Derangements](math/) 277 | - [DFA Division](math/) 278 | - [Diophantine](math/) 279 | - [Divided Differences](math/) 280 | - [Euler Totient](math/) 281 | - [Exponentiation Power](math/) 282 | - [Factorial](math/factorial) 283 | - [Fast Fourier transform](math/) 284 | - [Fast inverse (sqrt) Square Root](math/) 285 | 286 | ## [Networking](networking) 287 | 288 | - [Packet Sniffer](networking/) 289 | - [Determine Endianess](networking/) 290 | - [Validate IP](networking/) 291 | 292 | ## [Numerical Analysis](numerical-analysis) 293 | 294 | - [Integral](numerical-analysis/integral) 295 | - [Monte Carlo](numerical-analysis/monte-carlo) 296 | - [Runge Kutt](numerical-analysis/runge-kutt) 297 | 298 | ## [Operating system](operating-system) 299 | 300 | - [Currency](operating-system/) 301 | - [Deadlocks](operating-system/) 302 | - [Memory Management](operating-system/) 303 | - [Scheduling](operating-system/) 304 | - [Shell](operating-system/) 305 | 306 | ## [Randomized Algorithms](randomized-algorithms) 307 | 308 | - [Birthday Paradox](randomized-algorithms) 309 | - [Karger Minimum Cut Algorithm](randomized-algorithms) 310 | - [Kth Smallest Element Algorithm](randomized-algorithms) 311 | - [Random from Stream](randomized-algorithms) 312 | - [Random Node Linked list](randomized-algorithms) 313 | - [Randomized Quicksort](randomized-algorithms) 314 | - [Reservoir Sampling](randomized-algorithms) 315 | - [Shuffle an Array](randomized-algorithms) 316 | 317 | ## [Searches](searches) 318 | 319 | - [Binary Search](searches) 320 | - [Exponential Search](searches) 321 | - [Fibonacci Search](searches) 322 | - [Fuzzy Search](searches) 323 | - [Interpolation Search](searches) 324 | - [Jump Search](searches) 325 | - [Linear Search](searches) 326 | - [Ternay Search](searches) 327 | 328 | ## [Selections Algorithms](selections-algorithms) 329 | 330 | - [Median of Medians](selections-algorithms) 331 | - [Quick Select](selections-algorithms) 332 | 333 | ## [Sorting](sorting) 334 | 335 | - [Bead Sort](sorting/) 336 | - [Bogo Sort](sorting/) 337 | - [Bubble Sort](sorting/) 338 | - [Bucket Sort](sorting/) 339 | - [Circle Sort](sorting/) 340 | - [Comb Sort](sorting/) 341 | - [Counting Sort](sorting/) 342 | - [Cycle Sort](sorting/) 343 | - [Flash Sort](sorting/) 344 | - [Gnome Sort](sorting/) 345 | - [Heap Sort](sorting/) 346 | - [Insertion Sort](sorting/) 347 | - [Intro Sort](sorting/) 348 | - [Median Sort](sorting/) 349 | - [Merge Sort](sorting/) 350 | - [Pipeonhole Sort](sorting/) 351 | - [Quick Sort](sorting/) 352 | - [Radix Sort](sorting/) 353 | - [Selection Sort](sorting/) 354 | - [Shaker Sort](sorting/) 355 | - [Shell Sort](sorting/) 356 | - [Sleep Sort](sorting/) 357 | - [Stooge Sort](sorting/) 358 | - [Topological Sort](sorting/) 359 | - [Tree Sort](sorting/) 360 | 361 | ## [Strings](strings) 362 | 363 | - [Aho Corasick Algorithm](strings) 364 | - [Anagram Search](strings) 365 | - [Arithmetic on large numbers](strings) 366 | - [Boyer Moore Algorithm](strings) 367 | - [Finite Automata](strings) 368 | - [Kasai Algorithm](strings) 369 | - [Kmp Algorithm](strings) 370 | - [Levenshteing Distance](strings) 371 | - [Lipogram Checker](strings) 372 | 373 | ## [Online Challenges](online-challenges) 374 | 375 | - [Coderbyte](online-challenges/coderbyte) 376 | - [Code Chef](online-challenges/code-chef) 377 | - [Code Eval](online-challenges/code-eval) 378 | - [Hackerearth](online-challenges/hackerearth) 379 | - [Hackerrank](online-challenges/hackerrank) 380 | - [LeetCode](online-challenges/leetcode) 381 | - [Project Euler](online-challenges/project-euler) 382 | - [Rosalind](online-challenges/rosalind) 383 | - [SPOJ](online-challenges/spoj) 384 | - [Top Coder](online-challenges/top-coder)` 385 | 386 | ## [Others](others) 387 | 388 | - [Average](others/) 389 | - [Biggest of n numbers](others/) 390 | - [Biggest Suffix](others/) 391 | - [Fifteen Puzzle](others/) 392 | - [Jaccard Similarity](others/) 393 | - [Jose Phus Problem](others/) 394 | - [Lapindrom Checker](others/) 395 | - [Leap Year](others/) 396 | - [Magic Square](others/) 397 | - [Majority Element](others/) 398 | - [Minimum subarray size with degree](others/) 399 | - [No operator addition](others/) 400 | - [Paint fill](others/) 401 | - [Split list](others/) 402 | - [Tokenizer](others/) 403 | - [Unique number](others/) 404 | 405 | ## License 406 | 407 | This work is released under MIT License. 408 | 409 | To the extent possible under law, [Abraham Hernandez (@abranhe)](https://go.abranhe.com/github) has waived all copyright and related or neighboring rights to this work. 410 | 411 |
412 | 413 | 414 | 415 |
416 |
-------------------------------------------------------------------------------- /src/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AllAlgorithms/rust/b7588a5f784144ad2ce382fe466604b70affcc07/src/.gitkeep --------------------------------------------------------------------------------