├── Cache └── .keep ├── Graph └── .keep ├── Hashes └── .keep ├── Misc ├── .keep └── Sattolos │ └── shell │ └── main.sh ├── Classical ├── .keep ├── data-structures │ ├── .keep │ ├── heap │ │ └── .keep │ ├── queue │ │ ├── .keep │ │ └── shell │ │ │ └── queue.sh │ ├── stack │ │ ├── .keep │ │ └── shell │ │ │ └── main.sh │ ├── binary-tree │ │ └── .keep │ ├── dequeue │ │ ├── .keep │ │ └── shell │ │ │ └── dequeue.sh │ ├── linked-list │ │ └── .keep │ └── binary-search-tree │ │ └── .keep └── sorting │ ├── insertion-sort │ └── shell │ │ └── insertion-sort.sh │ ├── bubble-sort │ └── shell │ │ └── bubble_sort.sh │ ├── selection-sort │ └── shell │ │ └── selection-sort.sh │ └── shell-sort │ └── shell │ └── shell-sort.sh ├── Cryptography └── .keep ├── HackerRank ├── .keep ├── Warmup │ ├── Staircase │ │ └── shell │ │ │ └── staircase.sh │ ├── SolveMeFirst │ │ └── golang │ │ │ └── SolveMeFirst.go │ ├── TimeConversion │ │ └── shell │ │ │ └── time_conversion.sh │ ├── VeryBigSum │ │ └── golang │ │ │ └── VeryBigSum.go │ ├── SimpleArraySum │ │ └── golang │ │ │ └── SimpleArraySum.go │ ├── DiagonalDiference │ │ └── golang │ │ │ └── DiagonalDiference.go │ └── PlusMinus │ │ └── golang │ │ └── PlusMinus.go └── Implementation │ └── TheGridSearch │ └── shell │ └── the_grid_search.sh ├── Sequence └── .keep ├── Statistics └── .keep ├── Language theory └── .keep ├── Distributed systems └── .keep ├── Advanced Algorithms and Data Structures └── .keep ├── LICENSE └── README.md /Cache/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Graph/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Hashes/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Misc/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Cryptography/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /HackerRank/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Sequence/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Statistics/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Language theory/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Distributed systems/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/data-structures/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/data-structures/heap/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/data-structures/queue/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/data-structures/stack/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/data-structures/binary-tree/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/data-structures/dequeue/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/data-structures/linked-list/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Advanced Algorithms and Data Structures/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Classical/data-structures/binary-search-tree/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Misc/Sattolos/shell/main.sh: -------------------------------------------------------------------------------- 1 | #!bin/bash -x 2 | 3 | ITEMS=("$@") 4 | LEN=${#ITEMS[@]} 5 | 6 | while [[ $LEN -gt 1 ]]; do 7 | LEN=$((LEN-1)) 8 | R=$(( $RANDOM % $LEN )); 9 | SWP=${ITEMS[R]} 10 | ITEMS[$R]=${ITEMS[LEN]} 11 | ITEMS[$LEN]=$SWP 12 | done 13 | 14 | echo ${ITEMS[@]} 15 | -------------------------------------------------------------------------------- /HackerRank/Warmup/Staircase/shell/staircase.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -r N 4 | 5 | for ((i=0; i 0 ; i-- )); do 7 | for (( j = 0; j < i; j++ )); do 8 | if (( items[j] > items[$(( j + 1 ))])); then 9 | temp=${items[j]} 10 | items[$j]=${items[$((j + 1))]} 11 | items[$(( j + 1 ))]=${temp} 12 | fi 13 | done 14 | done 15 | 16 | echo "${items[@]}" 17 | -------------------------------------------------------------------------------- /Classical/sorting/selection-sort/shell/selection-sort.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | items=("$@") 4 | len=${#items[@]} 5 | for (( i=0; i < $((len - 1)); i+=1)); do 6 | min_index=$i 7 | for (( j=i+1; j < len; j+=1)); do 8 | if (( items[j] < items[min_index])); then 9 | min_index=$j 10 | fi 11 | done 12 | 13 | temp=${items[i]} 14 | items[$i]=${items[min_index]} 15 | items[min_index]=$temp 16 | done 17 | 18 | echo "${items[@]}" 19 | -------------------------------------------------------------------------------- /HackerRank/Warmup/VeryBigSum/golang/VeryBigSum.go: -------------------------------------------------------------------------------- 1 | Vpackage main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | func main() { 12 | var N string 13 | fmt.Scanln(&N) 14 | bytes, _ := ioutil.ReadAll(os.Stdin) 15 | 16 | var sum int64 = 0 17 | for _, value := range strings.Split(string(bytes), " ") { 18 | parse, _ := strconv.ParseInt(value, 10, 64) 19 | sum += parse 20 | } 21 | 22 | fmt.Println(sum) 23 | } 24 | -------------------------------------------------------------------------------- /HackerRank/Warmup/SimpleArraySum/golang/SimpleArraySum.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "io/ioutil" 7 | "strings" 8 | "strconv" 9 | ) 10 | 11 | func main() { 12 | var N string 13 | fmt.Scanln(&N) 14 | bytes, _:= ioutil.ReadAll(os.Stdin) 15 | 16 | var sum int64 = 0 17 | for _, value := range strings.Split(string(bytes), " ") { 18 | parse, _ := strconv.ParseInt(value, 10, 64) 19 | sum += parse 20 | } 21 | 22 | 23 | fmt.Println(sum) 24 | } 25 | -------------------------------------------------------------------------------- /Classical/data-structures/dequeue/shell/dequeue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | items=() 4 | while true ; do 5 | printf "> " 6 | read -r line 7 | args=($line) 8 | case ${args[0]} in 9 | "FADD") 10 | arg_list=(${args[1]}) 11 | arg_list+=(${items[@]}) 12 | items=(${arg_list[@]}) 13 | ;; 14 | "RADD") 15 | items+=(${args[1]}) 16 | ;; 17 | "FPOP") 18 | echo "${items[0]}" 19 | items=(${items[@]:1}) 20 | ;; 21 | "RPOP") 22 | echo "${items[(( ${#items[@]} - 1))]}" 23 | items=(${items[@]:0:$((${#items[@]} - 1))}) 24 | ;; 25 | esac 26 | 27 | done 28 | -------------------------------------------------------------------------------- /HackerRank/Implementation/TheGridSearch/shell/the_grid_search.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "> Insert T"; read T 4 | for (( i=0; i < T ; i=$i+1 )); do 5 | echo "> Insert R and C" 6 | read RC 7 | R=($RC)[0] 8 | C=($RC)[1] 9 | 10 | G=() 11 | 12 | echo "Insert the Grid" 13 | 14 | for (( k = 0; k < R; k++ )); do 15 | read line 16 | G=(${G[@]} ${line}) 17 | done 18 | 19 | P=() 20 | echo "Insert the pattern" 21 | 22 | for (( k = 0; k < count; k++ )); do 23 | read line 24 | P=(${G[@]} ${line}) 25 | done 26 | 27 | 28 | done 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /HackerRank/Warmup/DiagonalDiference/golang/DiagonalDiference.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | func stringsToInts(strs []string) []int { 12 | var ints []int 13 | ints = make([]int, len(strs)) 14 | for i := 0; i < len(strs); i++ { 15 | ints[i], _ = strconv.Atoi(strs[i]) 16 | } 17 | return ints 18 | } 19 | 20 | func main() { 21 | s := bufio.NewScanner(os.Stdin) 22 | s.Scan() 23 | N, _ := strconv.Atoi(s.Text()) 24 | 25 | mx := make([][]int, N) 26 | for i := 0; i < N; i++ { 27 | s.Scan() 28 | mx[i] = stringsToInts(strings.Split(s.Text(), " ")) 29 | } 30 | 31 | firstD := 0 32 | secD := 0 33 | for j := 0; j < N; j++ { 34 | firstD += mx[j][j] 35 | secD += mx[j][(N-1)-j] 36 | } 37 | 38 | res := firstD - secD 39 | if res < 0 { 40 | res *= -1 41 | } 42 | 43 | fmt.Println(res) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Classical/sorting/shell-sort/shell/shell-sort.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | items=("$@") 4 | length=${#items[@]} 5 | 6 | major_step_index=$(( length / 2 )) 7 | 8 | echo "Major $major_step_index" 9 | while (( major_step_index > 0 )); do 10 | for i in $( seq 0 $major_step_index); do 11 | 12 | for j in $( seq $(( i + major_step_index)) $length $major_step_index ); do 13 | current=${items[$j]} 14 | inner_step_index=$j 15 | 16 | while (( inner_step_index >= major_step_index && items[$(( inner_step_index - major_step_index ))] > current )); do 17 | items[$inner_step_index]=${items[$(( inner_step_index - manjor_step_index ))]} 18 | inner_step_index=$(( inner_step_index - major_step_index )) 19 | done 20 | 21 | items[$inner_step_index]=$current 22 | done 23 | 24 | major_slice_index=$(( major_step_index / 2)) 25 | done 26 | done 27 | 28 | 29 | echo "${items[@]}" 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Vitor Barbosa de Freitas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /HackerRank/Warmup/PlusMinus/golang/PlusMinus.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | func stringsToInts(strs []string) []int { 12 | var ints []int 13 | ints = make([]int, len(strs)) 14 | for i := 0; i < len(strs); i++ { 15 | ints[i], _ = strconv.Atoi(strs[i]) 16 | } 17 | return ints 18 | } 19 | 20 | func filter(ints []int, filter func(int) bool) []int { 21 | var intsf []int 22 | for _, v := range ints { 23 | if filter(v) { 24 | intsf = append(intsf, v) 25 | } 26 | } 27 | return intsf 28 | } 29 | 30 | func main() { 31 | s := bufio.NewScanner(os.Stdin) 32 | s.Scan() 33 | N, _ := strconv.Atoi(s.Text()) 34 | 35 | s.Scan() 36 | ints := stringsToInts(strings.Split(s.Text(), " ")) 37 | positives := filter(ints, func(v int) bool { 38 | return v > 0 39 | }) 40 | 41 | negatives := filter(ints, func(v int) bool { 42 | return v < 0 43 | }) 44 | 45 | zeros := filter(ints, func(v int) bool { 46 | return v == 0 47 | }) 48 | 49 | fmt.Println(float64(len(positives)) / float64(N)) 50 | fmt.Println(float64(len(negatives)) / float64(N)) 51 | fmt.Println(float64(len(zeros)) / float64(N)) 52 | 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algorithms 2 | My personal collection of algorithms and data structures :) 3 | 4 | ## Categories 5 | 6 | - Classical 7 | - Advanced Algorithms and Data Structures 8 | - Graph 9 | - Sequence 10 | - Statistics 11 | - Cryptography 12 | - Language theory 13 | - Cache 14 | - Hashes 15 | - Distributed systems 16 | - HackerRank 17 | - Misc 18 | 19 | ## References 20 | This repository is inspired in the work of: 21 | 22 | ### Repos 23 | 24 | - [felipernb/algorithms.js](https://github.com/felipernb/algorithms.js) 25 | - [prakhar1989/Algorithms](https://github.com/prakhar1989/Algorithms) 26 | - [arnauddri/algorithms](https://github.com/arnauddri/algorithms) 27 | - [sagivo/algorithms](https://github.com/sagivo/algorithms) 28 | - [tayllan/awesome-algorithms](https://github.com/tayllan/awesome-algorithms) 29 | - [braydie/HowToBeAProgrammer](https://github.com/braydie/HowToBeAProgrammer) 30 | - [nzakas/computer-science-in-javascript](https://github.com/nzakas/computer-science-in-javascript) 31 | - [donnemartin/interactive-coding-challenges](https://github.com/donnemartin/interactive-coding-challenges) 32 | - [EvgenyKarkan/EKAlgorithms](https://github.com/EvgenyKarkan/EKAlgorithms) 33 | - [mgechev/javascript-algorithms](https://github.com/mgechev/javascript-algorithms) 34 | - [kennyledet/Algorithm-Implementations](https://github.com/kennyledet/Algorithm-Implementations) 35 | - [jbrownlee/CleverAlgorithms](https://github.com/jbrownlee/CleverAlgorithms) 36 | - [arnauddri/algorithms](https://github.com/arnauddri/algorithms) 37 | - [ivan-vasilev/neuralnetworks](https://github.com/ivan-vasilev/neuralnetworks) 38 | - [phishman3579/java-algorithms-implementation](https://github.com/phishman3579/java-algorithms-implementation) 39 | - [lintool/MapReduceAlgorithms](https://github.com/lintool/MapReduceAlgorithms) 40 | - [DEAP/deap](https://github.com/DEAP/deap) 41 | 42 | ### Books 43 | - [Programming Pearls](http://www.amazon.com/Programming-Pearls-2nd-Edition-Bentley/dp/0201657880) 44 | - [Algorithms, 4th Edition](http://algs4.cs.princeton.edu/home/) 45 | - [Introduction to Algorithms](https://mitpress.mit.edu/books/introduction-algorithms) 46 | - [Introduction to Distributed Algorithms](http://www.amazon.com/Introduction-Distributed-Algorithms-Gerard-Tel/dp/0521794838) 47 | - [150 Programming Questions and Solutions by Gayle Laakmann](http://www.amazon.com.br/Cracking-Coding-Interview-Programming-Questions/dp/098478280X) 48 | - [Algorithm in Nutshell](http://www.amazon.com/Algorithms-Nutshell-In-OReilly/dp/059651624X) 49 | - [The Art of Computer Programming](http://www-cs-faculty.stanford.edu/~uno/taocp.html) 50 | - [Distributed systems for fun and profit](http://book.mixu.net/distsys/single-page.html) 51 | - [Advanced Data Structures and Algorithms](https://books.google.com.br/books/about/Advanced_Data_Structures_and_Algorithms.html?id=9mBJ0CpKXdkC&redir_esc=y) 52 | --------------------------------------------------------------------------------