Skip to content

Commit acc2a49

Browse files
authored
Merge branch 'master' into new-branch
2 parents 14cccbe + 04db59a commit acc2a49

File tree

7 files changed

+74
-15
lines changed

7 files changed

+74
-15
lines changed

en/Ciphers/caesar_cipher.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ Let us say we are sending a secret message to a friend.
3838

3939
## Implementation
4040

41+
* [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/ciphers/caesar_cipher.cpp)
42+
* [JavaScript](https://github.com/TheAlgorithms/JavaScript/blob/master/Ciphers/CaesarCipher.js)
43+
* [PHP](https://github.com/TheAlgorithms/PHP/blob/master/Ciphers/CaesarCipher.php)
4144
* [Python](https://github.com/TheAlgorithms/Python/blob/master/ciphers/caesar_cipher.py)
45+

en/Ciphers/vigenere_cipher.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,9 @@ Decryption is similar to encryption (except for the subtraction operation).
6565
## Implementations
6666

6767
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/ciphers/vigenere_cipher.cpp)
68-
- [Python](https://github.com/TheAlgorithms/Python/blob/master/ciphers/vigenere_cipher.py)
68+
- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Encoders/VigenereEncoder.cs)
69+
- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/Vigenere.java)
6970
- [JavaScript](https://github.com/TheAlgorithms/JavaScript/blob/master/Ciphers/VigenereCipher.js)
71+
- [Julia](https://github.com/TheAlgorithms/Julia/blob/main/src/cipher/vigenere.jl)
72+
- [Python](https://github.com/TheAlgorithms/Python/blob/master/ciphers/vigenere_cipher.py)
73+
- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/vigenere.rs)

en/Dynamic Programming/Coin Change.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ Let's say we have 3 coin types `[1,2,3]` and we want to change for `7` cents. So
4949
So the final answer is **8**. 8 ways to make change of 7 cents using all coin types. `{{1,1,1,1,1,1,1}, {1,1,1,1,1,2}, {1,1,1,2,2}, {1,2,2,2}, {1,1,1,1,3}, {1,3,3}, {2,2,3}, {1,1,2,3}}`
5050

5151
#### Code Implementation Link
52-
[Python](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/coin_change.py)
52+
- [JavaScript](https://github.com/TheAlgorithms/JavaScript/blob/master/Dynamic-Programming/CoinChange.js)
53+
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/coin_change.cpp)
54+
- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/greedyalgorithms/CoinChange.java)
55+
- [Go](https://github.com/TheAlgorithms/Go/blob/master/dynamic/coinchange.go)
56+
- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/coin_change.rs)
57+
- [Dart](https://github.com/TheAlgorithms/Dart/blob/master/dynamic_programming/coin_change.dart)
58+
- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/dynamic_programming/coin_change.rb)
59+
- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/DynamicProgramming/CoinChange.scala)
60+
- [Julia](https://github.com/TheAlgorithms/Julia/blob/main/src/dynamic_programming/coin_change.jl)
61+
- [Lua](https://github.com/TheAlgorithms/Lua/blob/main/src/misc/coin_change.lua)
62+
- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Problems/DynamicProgramming/CoinChange/DynamicCoinChangeSolver.cs)
5363

5464
#### Video Explanation
5565
[Total Unique Ways To Make Change by Back To Back SWE](https://www.youtube.com/watch?v=DJ4a7cmjZY0)
Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,77 @@
1-
# Floyd Cycle Detection Algorithm to find duplicate number in an array
1+
# Floyd Cycle Detection Algorithm to find duplicate numbers in an array
22

33
## Problem Statement
44

55
Given an array of integers containing `n + 1` integers, where each integer is in the range `[1, n]` inclusive. If there is only one duplicate number in the input array, this algorithm returns the duplicate number without modifying the original array, otherwise, it returns -1.
66

77
## Approach
8+
- We can imagine the array `arr` as a directed graph where each element is a node. `arr[i]` is the index of the node to which the i-th node points.
9+
- For example, given the `arr = [1, 3, 4, 2, 3]`, we can represent `arr` as the following <br></br>
10+
![image](images/graph_1.png)
811

9-
- Use the function `f(x) = arr[x]` to construct the sequence:
10-
`arr[0]`, `arr[arr[0]]`, `arr[arr[arr[0]]]`, `arr[arr[arr[arr[0]]]]`, etc....
11-
- Each new element in the sequence is an element in `arr[]` at the index of the previous element.
12-
- Starting from `x = arr[0]`, it will produce a linked list with a cycle.
13-
- The cycle appears because `arr[]` contains duplicate elements(at least one). The duplicate value is an entrance to the cycle.
12+
- Since there are duplicates in `arr`, a cycle exists in the directed graph as there is a path from node 3 to itself, `3 -> 2 -> 4 -> 3`.
13+
- The problem now becomes finding the entrance node to the cycle (3 in this case).
14+
- We can use the Floyd Cycle Detection Algorithm (also known as the "Hare and Tortoise algorithm") to detect the entrance of the cycle.
15+
- The idea of the algorithm is to maintain two pointers, `hare` and `tortoise` that iterate the array at different "speeds" (just like the fable). The details are as follows:
1416

17+
### The procedure
18+
- Using two pointers `hare` and `tortoise`.
19+
- Initiate `hare = tortoise = arr[0]`.
20+
- For every next step until `hare == tortoise` again, assign `hare = arr[arr[hare]]` and `tortoise = arr[tortoise]` (`hare` "jumps" 2 steps while `tortoise` "jumps" one step).
21+
- At this point, `hare == tortoise`, reset `tortoise = arr[0]` while keeping the value of `hare` in the above procedure.
22+
- For every next step until `hare == tortoise` again, assign `hare = arr[hare]` and `tortoise = arr[tortoise]` (this time `hare` only "jumps" one step).
23+
- When `tortoise == hare`, the entrance of the cycle is found, hence `hare` and `tortoise` represent the value of the duplicated element.
24+
- Return `tortoise` (also possible to return `hare`)
25+
1526
## Time Complexity
1627

17-
O(n)
28+
`O(n)`
1829

1930
## Space Complexity
2031

21-
O(1)
32+
`O(1)`, since we only use two extra variables as pointers.
2233

23-
## Example
34+
## Example with step-by-step explanation
35+
![image](images/graph_2.png)
2436

2537
```
26-
arr = [3, 4, 8, 5, 9, 1, 2, 6, 7, 4]
38+
arr = [3, 4, 8, 5, 9, 1, 2, 6, 7, 4]
2739
28-
return value = 4
40+
hare = tortoise = arr[0] = 3
41+
42+
1st step:
43+
- hare = arr[arr[3]] = arr[5] = 1
44+
- tortoise = arr[3] = 5
45+
2nd step:
46+
- hare = arr[arr[1]] = arr[4] = 9
47+
- tortoise = arr[5] = 1
48+
3rd step:
49+
- hare = arr[arr[9]] = arr[4] = 9
50+
- tortoise = arr[1] = 4
51+
4th step:
52+
- hare = arr[arr[9]] = 9
53+
- tortoise = arr[4] = 9
54+
55+
tortoise = arr[0] = 3
56+
57+
1st step:
58+
- hare = arr[9] = 4
59+
- tortoise = arr[3] = 5
60+
2nd step:
61+
- hare = arr[4] = 9
62+
- tortoise = arr[5] = 1
63+
3rd step:
64+
- hare = arr[9] = 4
65+
- tortoise = arr[1] = 4
66+
67+
return tortoise = 4
2968
```
3069

3170
## Code Implementation Links
3271

3372
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/floyd_cycle_detection_algo.cpp)
3473
- [C](https://github.com/TheAlgorithms/C/blob/master/searching/floyd_cycle_detection_algorithm.c)
35-
3674
#### Video Explanation
3775

38-
[YouTube video explaining the Floyd Cycle Detection algorithm](https://www.youtube.com/watch?v=B6smdk7pZ14)
76+
- [YouTube video explaining the Floyd Cycle Detection algorithm](https://www.youtube.com/watch?v=B6smdk7pZ14)
77+
- [Another Youtube video](https://www.youtube.com/watch?v=PvrxZaH_eZ4&t=1s)
15.5 KB
Loading
27.1 KB
Loading

en/Sorting Algorithms/Radix Sort.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ takes extra space to sort numbers.
5151
- [Assembly](https://github.com/TheAlgorithms/AArch64_Assembly/blob/main/sorters/radix_sort.s)
5252
- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/radix_sort.c)
5353
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/radix_sort.cpp)
54+
- [C#](https://github.com/TheAlgorithms/C-Sharp/tree/master/Algorithms/Sorters/Integer/RadixSorter.cs)
5455
- [Dart](https://github.com/TheAlgorithms/Dart/blob/master/sort/radix_sort.dart)
5556
- [Go](https://github.com/TheAlgorithms/Go/blob/master/sort/radixsort.go)
5657
- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/RadixSort.java)
@@ -61,6 +62,7 @@ takes extra space to sort numbers.
6162
- [R](https://github.com/TheAlgorithms/R/blob/master/sorting_algorithms/radix_sort.r)
6263
- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/radix_sort.rb)
6364
- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/radix_sort.rs)
65+
- [Zig](https://github.com/TheAlgorithms/Zig/blob/main/sort/radixSort.zig)
6466

6567
#### Video Explanation
6668

0 commit comments

Comments
 (0)