diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6a5baae5..22dfbfc7 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -7,4 +7,4 @@ # Order is important. The last matching pattern has the most precedence. -* @vbrazo @Panquesito7 @AnupKumarPanwar @ashwek @appgurueu +* @vbrazo @Panquesito7 @appgurueu diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..54904a21 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,31 @@ +### Description + + + + +Closes #{ISSUE_ID} + +### Checklist + +- [ ] A description of the changes in this PR is mentioned above. +- [ ] All the new and existing checks pass. +- [ ] No plagiarized, duplicated, or repetitive documentation that has been directly copied from another source. +- [ ] If it's a new explanation, it contains solid, understandable, and accessible information. +- [ ] I have read the whole [contributing guidelines](https://github.com/TheAlgorithms/Algorithms-Explanation/blob/master/CONTRIBUTING.md) and agree to the [Code of Conduct](https://github.com/TheAlgorithms/.github/blob/master/CODE_OF_CONDUCT.md). + +### Screenshots (if any) + + + +### Note to reviewers + + diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 93befa6c..bda5bfac 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -9,9 +9,9 @@ jobs: - uses: actions/stale@v4 with: stale-issue-message: 'This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.' - close-issue-message: 'Please ping one of the maintainers once you add more information and updates here. If this is not the case and you need some help, feel free to ask for help in our [Gitter](https://gitter.im/TheAlgorithms) channel. Thank you for your contributions!' + close-issue-message: 'Please ping one of the maintainers once you add more information and updates here. If this is not the case and you need some help, feel free to ask for help in our [Gitter](https://gitter.im/TheAlgorithms/community) channel. Thank you for your contributions!' stale-pr-message: 'This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.' - close-pr-message: 'Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our [Gitter](https://gitter.im/TheAlgorithms) channel. Thank you for your contributions!' + close-pr-message: 'Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our [Gitter](https://gitter.im/TheAlgorithms/community) channel. Thank you for your contributions!' exempt-issue-labels: 'dont-close,approved' exempt-pr-labels: 'dont-close,approved' days-before-stale: 30 diff --git a/.github/workflows/url_check.yml b/.github/workflows/url_check.yml new file mode 100644 index 00000000..6533f676 --- /dev/null +++ b/.github/workflows/url_check.yml @@ -0,0 +1,28 @@ +--- +name: url_check + +'on': + workflow_dispatch: + push: + branches: + - master + pull_request: + schedule: + - cron: '43 5 * * TUE' + +jobs: + run_lychee: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check links + uses: lycheeverse/lychee-action@v1.9.3 + with: + args: > + --no-progress + * + fail: true +... diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..c48f48a8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,64 @@ +# Contributing Guidelines + +## Legal + +Contributions must be all your own work; plagiarism is not allowed. +By submitting a pull request, you agree to license your contribution +under the [license of this repository](./LICENSE.txt). + +## Translations + +Translations go in the appropriate folder named by the locale code. + +Do not change the structure or formatting of the original (English) explanation when translating or updating translations. +You may change number formatting to fit the locale +(`42.33` may be formatted as `42,33` in a german translation for instance) +as long as it doesn't create ambiguities +(e.g. `[42,33, 13]` in an array would be disallowed and should either remain `[42.33, 13]` or use a different delimiter `[42,33; 13]`). + +## Writing Explanations + +See the [explanation of the Euclidean Algorithm](en/Basic%20Math/Euclidean%20algorithm.md) +for an example of how a good explanation may look like. + +### Structure + +You should structure your explanations using headings. +The top-level heading should be the name of the algorithm or data structure to be explained + +Subsequent sub-headings *may* be: + +1. Problem solved by the algorithm +2. Design/approach of the algorithm +3. Detailed (yet not too technical) description of the algorithm, usually including (pseudo)-code +4. Analysis (proof of correctness, best/worst/average cases, time & space complexity) +5. Walkthrough(s) of how the algorithm processes example input(s) +6. Application(s) of the algorithm +7. Further resources such as reference implementations, videos or other explanations. *If possible, link to The Algorithms' website as well (example: ).* + +### Capitalization + +- Use *Title Case* for headings. +- Start new sentences with a capital letter. + +### Typographical Conventions + +- Leave a space after punctuation such as `.`, `!`, `?`, `,`, `;` or `:`. +- Add a space before and after `-`. **Do not add a space before punctuation.** +- Add a space before an opening parenthesis `(`. Do not add a space before the closing parenthesis `)`. +- Add spaces around (but not inside) quotes. Use single quotes for quotes within quotes. + +### Markdown Conventions + +[GitHub-flavored Markdown is used](https://github.github.com/gfm/). Explanations should render well when viewed from GitHub. + +- **Do not add redundant formatting.** Formatting should always be meaningful. + If you apply a certain formatting to all elements of a certain kind (e.g. adding emphasis around all headings), you're doing something wrong. +- Use ATX-style "hashtag" headings: `#`, `##`, `###`, `####`, `#####`, `######` rather than Setext-style "underline" headings. + Leave blank lines around headings. The first heading should always be `# Title`. Subheadings must be exactly one level deeper than their parents. +- Indent lists by two blanks. Prefer `-` over `*` for bulleted lists. Enumerate numbered lists correctly, starting at `1`. +- Use fenced code blocks (and specify the correct language) rather than using indented code blocks. + Format code inside fenced code blocks properly (prefer pseudocode over code though). Leave blank lines around fenced code blocks. +- Use named links `[name](link)` rather than relying on automatic link detection or using `<>`-links. + There are rarely good reasons to not give a link a descriptive name. +- Use HTML only if necessary (rarely - if ever - the case). Do not use HTML for unnecessary formatting. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index fba99dd0..00000000 --- a/LICENSE.md +++ /dev/null @@ -1,9 +0,0 @@ -The MIT License (MIT) - -Copyright © 2020-2021 The Algorithms - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..34466e2a --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2020-2024 The Algorithms and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index e1c8e5ab..f9520d85 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Algorithms explanation -[![Gitter chat](https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square)](https://gitter.im/TheAlgorithms)  +[![Gitter chat](https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square)](https://gitter.im/TheAlgorithms/community)  [![contributions welcome](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square)](https://github.com/TheAlgorithms/Ruby/blob/master/CONTRIBUTING.md)  ![Repository size](https://img.shields.io/github/repo-size/TheAlgorithms/Algorithms-Explanation.svg?label=Repo%20size&style=flat-square)  [![Discord chat](https://img.shields.io/discord/808045925556682782.svg?logo=discord&colorB=5865F2&style=flat-square)](https://discord.gg/c7MnfGFGa6) diff --git a/en/Basic Math/Aliquot_Sum.md b/en/Basic Math/Aliquot_Sum.md index 88e8c998..2f282440 100644 --- a/en/Basic Math/Aliquot_Sum.md +++ b/en/Basic Math/Aliquot_Sum.md @@ -34,12 +34,8 @@ The reason we take the upper bound as $[\frac{n} 2]$ is that, the largest possib The sum which we obtain is the aliquot sum of the number ## Implementations -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Numeric/AliquotSumCalculator.cs) -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AliquotSum.java) -- [JavaScript](https://github.com/TheAlgorithms/JavaScript/blob/master/Maths/AliquotSum.js) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/aliquot_sum.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/maths/aliquot_sum.rb) +- [TheAlgorithms](https://the-algorithms.com/algorithm/aliquot-sum) ## Sources - [Wikipedia](https://en.wikipedia.org/wiki/Aliquot_sum) -- [GeeksForGeeks](https://www.geeksforgeeks.org/aliquot-sum/) \ No newline at end of file +- [GeeksForGeeks](https://www.geeksforgeeks.org/aliquot-sum/) diff --git a/en/Basic Math/Average_Mean.md b/en/Basic Math/Average_Mean.md index be5f191b..5eacce57 100644 --- a/en/Basic Math/Average_Mean.md +++ b/en/Basic Math/Average_Mean.md @@ -57,14 +57,9 @@ If we properly consider significant digits: `sum / count = 23` Return the value of 22.857142 or `23`. -## Implementation - -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/average_mean.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/maths/average_mean.rb) - ## Video URL -- [Mean on Khan Academy](https://www.khanacademy.org/math/ap-statistics/summarizing-quantitative-data-ap/measuring-center-quantitative/v/mean-median-and-mode) +- [Mean on Khan Academy](https://www.khanacademy.org/math/cc-sixth-grade-math/cc-6th-data-statistics/mean-and-median/v/mean-median-and-mode) ## Others diff --git a/en/Basic Math/Euclidean algorithm.md b/en/Basic Math/Euclidean algorithm.md new file mode 100644 index 00000000..d104998a --- /dev/null +++ b/en/Basic Math/Euclidean algorithm.md @@ -0,0 +1,92 @@ +# Euclidean algorithm + +## Problem + +Find the Greatest Common Divisor (GCD) of two positive integers $a$ and $b$, which is defined as the largest number $g = gcd(a, b)$ such that $g$ divides both $a$ and $b$ without remainder. + +## Idea + +The Euclidean algorithm is based on the simple observation that the GCD of two numbers doesn't change if the smaller number is subtracted from the larger number: + +Let $a > b$. Let $g$ be the GCD of $a$ and $b$. +Then $g$ divides $a$ and $b$. Thus $g$ also divides $a - b$. + +Let $g'$ be the GCD of $b$ and $a - b$. + +Proof by contradiction that $g' = g$: + +Assume $g' < g$ or $g' > g$. + +If $g' < g$, $g'$ would not be the *greatest* common divisor, +since $g$ is also a common divisor of $a - b$ and $b$. + +If $g' > g$, $g'$ divides $b$ and $a - b$ - +that is, there exist integers $n, m$ +such that $g'n = b$ and $g'm = a - b$. +Thus $g'm = a - g'n \iff g'm + g'n = a \iff g'(m + n) = a$. +This imples that $g' > g$ also divides $a$, +which contradicts the initial assumption that $g$ is the GCD of $a$ and $b$. + +## Implementation + +To speed matters up in practice, modulo division is used instead of repeated subtractions: +$b$ can be subtracted from $a$ as long as $a >= b$. +After these subtractions only the remainder of $a$ when divided by $b$ remains. + +A straightforward Lua implementation might look as follows: + +```lua +function gcd(a, b) + while b ~= 0 do + a, b = b, a % b + end + return a +end +``` + +note that `%` is the modulo/remainder operator; +`a` is assigned to the previous value of `b`, +and `b` is assigned to the previous value of `a` +modulo the previous value of `b` in each step. + +## Analysis + +### Space Complexity + +The space complexity can trivially be seen to be constant: +Only two numbers (of assumed constant size), $a$ and $b$, need to be stored. + +### Time Complexity + +Each iteration of the while loop runs in constant time and at least halves $b$. +Thus $O(log_2(n))$ is an upper bound for the runtime. + +## Walkthrough + +Finding the GCD of $a = 42$ and $b = 12$: + +1. $42 \mod 12 = 6$ +2. $12 \mod 6 = 0$ + +The result is $gcd(42, 12) = 6$. + +Finding the GCD of $a = 633$ and $b = 142$ using the Euclidean algorithm: + +1. $633 \mod 142 = 65$ +2. $142 \mod 65 = 12$ +3. $65 \mod 12 = 5$ +4. $12 \mod 5 = 2$ +5. $5 \mod 2 = 1$ +6. $2 \mod 1 = 0$ + +The result is $gcd(633, 142) = 1$: $a$ and $b$ are co-prime. + +## Applications + +* Shortening fractions +* Finding the Least Common Multiple (LCM) +* Efficiently checking whether two numbers are co-prime (needed e.g. for the RSA cryptosystem) + +## Resources + +* [Wikipedia Article](https://en.wikipedia.org/wiki/Euclidean_algorithm) diff --git a/en/Basic Math/Fibonacci_Numbers.md b/en/Basic Math/Fibonacci_Numbers.md index 01e8df48..eb8fac3f 100644 --- a/en/Basic Math/Fibonacci_Numbers.md +++ b/en/Basic Math/Fibonacci_Numbers.md @@ -55,24 +55,6 @@ Calculate matrix^8 ### Step 5 F(8)=21 -## Implementation - -- [C](https://github.com/TheAlgorithms/C/blob/master/misc/fibonacci.c) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fibonacci.cpp) -- [Elixir](https://github.com/TheAlgorithms/Elixir/blob/master/lib/dynamic_programming/fibonacci.ex) -- [F#](https://github.com/TheAlgorithms/F-Sharp/blob/main/Algorithms/Math/Fibonacci.fs) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/dynamic/fibonacci.go) -- [Haskell](https://github.com/TheAlgorithms/Haskell/blob/master/src/Maths/Fibonacci.hs) -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciNumber.java) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Fibonacci.js) -- [PHP](https://github.com/TheAlgorithms/PHP/blob/master/Maths/Fibonacci.php) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/fibonacci.py) -- [R](https://github.com/TheAlgorithms/R/blob/master/Mathematics/Fibonacci.R) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) -- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/fibonacci.rs) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Mathematics/Fibonacci.scala) -- [Swift](https://github.com/TheAlgorithms/Swift/blob/master/recursion/fibonacci.swift) - ## Video URL - [Youtube](https://www.youtube.com/watch?v=EEb6JP3NXBI) diff --git a/en/Basic Math/Find the maximum number.md b/en/Basic Math/Find the maximum number.md index 1e7cf5f0..6579ad98 100644 --- a/en/Basic Math/Find the maximum number.md +++ b/en/Basic Math/Find the maximum number.md @@ -98,10 +98,6 @@ Get the last value out of the list by using predefined last method. Return the value 70. -## Implementation - -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) - # Source - [GeeksForGeeks](https://www.geeksforgeeks.org/c-program-find-largest-element-array/) diff --git a/en/Basic Math/Geometric Pogression.md b/en/Basic Math/Geometric Pogression.md index 3943a575..73c1f6ca 100644 --- a/en/Basic Math/Geometric Pogression.md +++ b/en/Basic Math/Geometric Pogression.md @@ -51,4 +51,3 @@ nth term of a GP = `a*rn-1`. # YouTube - [Video URL for concept](https://youtu.be/gua96ju_FBk) -- [Video for understanding GP Dynamic Programming in C++](https://youtu.be/92ZldzuGUHs) diff --git a/en/Basic Math/magic_square.md b/en/Basic Math/magic_square.md index 73e71d81..4edce04a 100644 --- a/en/Basic Math/magic_square.md +++ b/en/Basic Math/magic_square.md @@ -15,7 +15,7 @@ A magic square puzzle of the `n` order is an organization of `n²` numbers, usua As mentioned above, the formula of the magic square sum is n(n² + 1)/2.\ For a magic square of order 3, we need to substitute n = 3 to know the magic sum so that we can easily form the magic square 3×3. -When `n = 3`, the sum = 3(3*3 + 1) = 3(9 + 1)/2 = (3 × 10)/2 = 15\ +When `n = 3`, the sum = 3(3\*3 + 1)/2 = 3(9 + 1)/2 = (3 × 10)/2 = 15\ Now, we have to place the numbers in the respective places so that the sum of numbers in each row, column and diagonal is equal to 15. ## Magic Square Trick for order 3 @@ -35,7 +35,6 @@ The cell above x is taken as y – 1 as given below: ![magic-square-1](https://user-images.githubusercontent.com/106215707/192823521-c992c61b-055a-4af8-b697-71fb0ed22566.png) ![magic-square-2](https://user-images.githubusercontent.com/106215707/192823583-8a375043-21d7-4a74-b2d8-119a6ca727eb.png) - Let us make the complementary magic square of the above square. `(n² + 1) = 32 + 1 = 9 + 1 = 10` @@ -43,28 +42,31 @@ Let us make the complementary magic square of the above square. Now, subtract each number from (n² + 1), i.e. from 10. - First row numbers: - - 10 – 4 = 6 - - 10 – 3 = 7 + + - 10 – 4 = 6 + - 10 – 3 = 7 - 10 – 8 = 2 - Second row numbers: - - 10 – 9 = 1 , - - 10 – 5 = 5 , + + - 10 – 9 = 1 , + - 10 – 5 = 5 , - 10 – 1 = 9 - Third row numbers: - - 10 – 2 = 8 , - - 10 – 7 = 3 , + - 10 – 2 = 8 , + - 10 – 7 = 3 , - 10 – 6 = 4 - ![magic-square-3](https://user-images.githubusercontent.com/106215707/192823650-21655cfe-0b8f-4bcb-b7d0-76280770c615.png) +# REFERENCE - -# REFERENCE ## website:- + - [Byjus](https://byjus.com/maths/magic-square/) - [geeksforgeeks](https://www.geeksforgeeks.org/magic-square/) + ## Youtube:- + - [video](https://www.bing.com/videos/search?q=magic+square&&view=detail&mid=26BE595B719B8B532E5126BE595B719B8B532E51&&FORM=VRDGAR&ru=%2Fvideos%2Fsearch%3Fq%3Dmagic%2Bsquare%26FORM%3DHDRSC3) diff --git a/en/Ciphers/caesar_cipher.md b/en/Ciphers/caesar_cipher.md index f002d77a..592b0374 100644 --- a/en/Ciphers/caesar_cipher.md +++ b/en/Ciphers/caesar_cipher.md @@ -35,7 +35,3 @@ Let us say we are sending a secret message to a friend. * The second letter is `h`. The letter 6 letters away is `n`. Our message is now `Zn` * We continue like that until the end. Our final message is: `Znk Igkygx iovnkx oy g lat yahyzozazout iovnkx.` * Decryption is the same way, except instead of going to the right in the alphabet, we go backwards. - -## Implementation - -* [Python](https://github.com/TheAlgorithms/Python/blob/master/ciphers/caesar_cipher.py) diff --git a/en/Ciphers/hill_cipher.md b/en/Ciphers/hill_cipher.md index cb906838..775e0ecb 100644 --- a/en/Ciphers/hill_cipher.md +++ b/en/Ciphers/hill_cipher.md @@ -17,7 +17,7 @@ key:`GYBNQKURP` 1. We have to write key as an `n × n` matrix as ``` - [6 24 1] + [6 24 1] [13 16 10] [20 17 15] ``` @@ -31,7 +31,7 @@ key:`GYBNQKURP` 3. Now, we need to encipher the vector by just multiplying these two matrices ``` - [6 24 1] [0] [67] [15] + [6 24 1] [0] [67] [15] [13 16 10] * [2] = [222] ≈ [4] (mod 26) [20 17 15] [19] [319] [7] ``` @@ -42,22 +42,18 @@ So we will get the encrypted text as **POH**. 1. We need to first inverse our key matrix ``` -1 - [6 24 1] [8 5 10] + [6 24 1] [8 5 10] [13 16 10] ≈ [21 8 21] (mod 26) [20 17 15] [21 12 8] ``` 2. For the previous Cipher Text **POH** ``` - [8 5 10] [15] [260] [0] + [8 5 10] [15] [260] [0] [21 8 21] * [14] ≈ [574] ≈ [2] (mod 26) ≈ ACT [21 12 8] [7] [539] [19] ``` -## Implementations - -[**Python**](https://github.com/TheAlgorithms/Python/blob/master/ciphers/hill_cipher.py) - ## Video Explanation [Video explanation of the Hill Cipher](https://www.youtube.com/watch?v=6T46sgty4Mk) diff --git a/en/Ciphers/playfair-cipher.md b/en/Ciphers/playfair-cipher.md index 83095afd..158a4a92 100644 --- a/en/Ciphers/playfair-cipher.md +++ b/en/Ciphers/playfair-cipher.md @@ -53,21 +53,21 @@ The rules above are used for Encryption. Can be applied vice-versa for Decryptio ``` [m o n a r] [c h y b d] - [e f g k i] + [e f g i k] [l p q s t] [u v w x z] ``` -2. Split the plaintext in digraphs(pair of two). If there is an odd number of letters, a Z is added to the last letter. Pair cannot be made with same letter. Break the letter in single and add a bogus letter to the previous letter. +2. Split the plaintext in digraphs(pair of two). If there is an odd number of letters, an X is added to the last letter. Pairs cannot be made with same letter. If this occurs, split the pair by adding an X between the duplicate letters. ``` - 'in' 'st' 'ru' 'me' 'nt' 'sz' + 'in' 'st' 'ru' 'me' 'nt' 'sx' ``` 3. Now, we need to follow the rules for encrypting and do as follows: ``` - Plain Text: instrumentsz + Plain Text: instrumentsx key: monarchy Encryption: i -> g @@ -80,10 +80,10 @@ The rules above are used for Encryption. Can be applied vice-versa for Decryptio e -> l n -> r t -> q - s -> t - z -> x + s -> x + x -> a ``` -So we will get the encrypted text as **gatlmzclrqtx**. +So we will get the encrypted text as **gatlmzclrqxa**. ### Decryption @@ -92,17 +92,17 @@ So we will get the encrypted text as **gatlmzclrqtx**. ``` [m o n a r] [c h y b d] - [e f g k i] + [e f g i k] [l p q s t] [u v w x z] ``` 2. We need to split the ciphertext as done for plaintext while encrypting ``` - 'ga' 'tl' 'mz' 'cl' 'rq' 'tx' + 'ga' 'tl' 'mz' 'cl' 'rq' 'xa' ``` -3. For the previous Cipher Text **gatlmzclrqtx**, by following the rules we get: +3. For the previous Cipher Text **gatlmzclrqxa**, by following the rules we get: ``` Plain Text: gatlmzclrqtx @@ -113,13 +113,9 @@ So we will get the encrypted text as **gatlmzclrqtx**. mz -> ru cl -> me rq -> nt - tx -> sz + xa -> sx ``` -So we will get the encrypted text as **instrumentsz**. - -## Implementations - -- [**Python**](https://github.com/TheAlgorithms/Python/blob/master/ciphers/playfair_cipher.py) +So we will get the encrypted text as **instrumentsx**. ## Video Explanation diff --git a/en/Ciphers/rsa_cipher.md b/en/Ciphers/rsa_cipher.md index 97649cec..3cae166d 100644 --- a/en/Ciphers/rsa_cipher.md +++ b/en/Ciphers/rsa_cipher.md @@ -153,10 +153,3 @@ Enter your Private Key: 23 PlainText: 51 ``` - -## Implementations - -- [Python](https://github.com/TheAlgorithms/Python/blob/master/ciphers/rsa_cipher.py) -- [GoLang](https://github.com/TheAlgorithms/Go/blob/master/cipher/rsa/rsa.go) -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/RSA.java) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/ciphers/rsa.rb) \ No newline at end of file diff --git a/en/Ciphers/vigenere_cipher.md b/en/Ciphers/vigenere_cipher.md new file mode 100644 index 00000000..94bf5749 --- /dev/null +++ b/en/Ciphers/vigenere_cipher.md @@ -0,0 +1,63 @@ +# Vigenere Cipher + +The Vigenere cipher is a famous toy cipher. It was invented in 1553 by the Italian cryptographer Giovan Battista Bellaso but for centuries was attributed to the 16th-century French cryptographer Blaise de Vigenère, who devised a similar cipher in 1586. + +It is easy to encrypt and decrypt but at the same time, it is easy to intercept and crack this cipher. It is a polyalphabetic substitution cipher, meaning that the same letter of the alphabet can be replaced by different letters depending on the key. The key is a word or phrase that is repeated to match the length of the message. Then the letters of the key are used to shift the letters of the message. + +## Improvement over Caesar cipher + +The Vigenere cipher is an improvement over the Caesar cipher. The Caesar cipher uses a single character as the key to shift the message. In contrast, the Vigenere cipher uses a word or a phrase as the key. This means that the same character occurring at different positions in the message will be shifted by different amounts. This makes it harder to crack the cipher. + +## Setup + +1. Choose the message space you are going to use. In our case, we will use all lowercase letters of the English language. But we can use ASCII characters as well. Let us denote the size of the message space as $n$. In our case, $n = 26$. +2. Assign a numerical value to each letter of the message space. For example, $a=1, b=2, c=3$ and so on. +3. Choose a key. + +## Encryption + +1. Repeat the key to match the length of the message. For example, if the message is `checktheking` and the key is `chess`, the key is repeated to match the length of the message. The key is now `chesschessch`. +2. Now, the letters of the key are used to shift the letters of the message. Let $a$ be $1$, $b$ be $2$ and so on. Then, the message is encrypted using the following formula: $C_i = (V(M_i) + V(K_i)) \mod n$ where $C_i$ is the encrypted letter at position $i$, $V(M_i)$ is the numerical value of the letter at position $i$ and $V(K_i)$ is the numerical value of the letter at position $i$, and $n$ is the size of the message space. + +| Message | c | h | e | c | k | t | h | e | k | i | n | g | +|---------|---|---|---|---|---|---|---|---|---|---|---|---| +| Value | 3 | 8 | 5 | 3 | 11| 20| 8 | 5 | 11| 9 | 14| 7 | +| Key | c | h | e | s | s | c | h | e | s | s | c | h | +| Shift | 3 | 8 | 5 | 19| 19| 3 | 8 | 5 | 19| 19| 3 | 8 | +| Cipher | f | p | j | q | z | w | p | j | z | z | c | p | + +So the encrypted message is `fpjqzwjpzzcp`. + +## Decryption + +Decryption is the inverse of encryption. It is is done by subtracting the shift value from the cipher value. The formula is $M_i = L((C_i - V(K_i)) \mod n)$ where everything is defined as above and $L$ is additionally defined as a function which converts a numerical value back to a letter. + +| Cipher | f | p | j | q | z | w | p | j | z | z | c | p | +|---------|---|---|---|---|---|---|---|---|---|---|---|---| +| Key | c | h | e | s | s | c | h | e | s | s | c | h | +| Shift | 3 | 8 | 5 | 19| 19| 3 | 8 | 5 | 19| 19| 3 | 8 | +| Value | 3 | 8 | 5 | 3 | 11| 20| 8 | 5 | 11| 9 | 14| 7 | +| Message | c | h | e | c | k | t | h | e | k | i | n | g | + +So the decrypted message is `checktheking`, as expected. + +## Complexity Analysis + +### Encryption + +The encryption is done by adding the shift value to the message value. So the **time complexity is $O(n)$** where $n$ is the length of the message. +We use a linear data structure such as an array to store the message and the key. So the **space complexity is $O(n)$**. + +### Decryption + +Decryption is similar to encryption (except for the subtraction operation). +**So time and space complexity are the same as for encryption - $O(n)$**. + +## Cryptanalysis and caution + +1. **It is a toy cipher. It is easy to crack. It is not secure.** +2. There are several key (length) finding methods such as + - [Kasiski examination](https://en.wikipedia.org/wiki/Kasiski_examination) + - [Index of coincidence](https://en.wikipedia.org/wiki/Index_of_coincidence) +3. Once the key length is found, [frequency analysis](https://en.wikipedia.org/wiki/Frequency_analysis) can be used to find the key and hence crack the cipher. +4. Therefore, this cipher should not be used to encrypt any important data. diff --git a/en/Data Structures/Graph/Bellman-Ford.md b/en/Data Structures/Graph/Bellman-Ford.md index ee30886e..49b1e59c 100644 --- a/en/Data Structures/Graph/Bellman-Ford.md +++ b/en/Data Structures/Graph/Bellman-Ford.md @@ -88,13 +88,6 @@ O(V^2) E 1 A->B->E = -1 + 2 ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/bellman_ford.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/graphs/bellman_ford.py) -- [C](https://github.com/TheAlgorithms/C/blob/master/data_structures/graphs/bellman_ford.c) - #### Video Explanation [A video explaining the Bellman-Ford Algorithm](https://www.youtube.com/watch?v=hxMWBBCpR6A) diff --git a/en/Data Structures/Linked Lists/Circular Linked List.md b/en/Data Structures/Linked Lists/Circular Linked List.md index d75322c3..ab86a80e 100644 --- a/en/Data Structures/Linked Lists/Circular Linked List.md +++ b/en/Data Structures/Linked Lists/Circular Linked List.md @@ -37,7 +37,7 @@ The Linked List has a ```pointer``` to the adjacent elements but the last node i ### SLL v.s. CLL -![image](https://i0.wp.com/algorithms.tutorialhorizon.com/files/2016/03/Circular-Linked-List.png) +![image](https://tutorialhorizon.com/static/media/algorithms/2016/03/Circular-Linked-List.png) ### Example @@ -64,12 +64,6 @@ public void insertHead(int data) } ``` -## Code Implementation Links - -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Linked-List/SingleCircularLinkedList.js.js) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/cll/cll.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/circular_linked_list.py) - ## Video Explanation [Video explanation on YouTube](https://youtu.be/HMkdlu5sP4A) diff --git a/en/Data Structures/Linked Lists/Doubly Linked List.md b/en/Data Structures/Linked Lists/Doubly Linked List.md index e4cbb791..65fb7692 100644 --- a/en/Data Structures/Linked Lists/Doubly Linked List.md +++ b/en/Data Structures/Linked Lists/Doubly Linked List.md @@ -100,14 +100,6 @@ class LinkedList { ![Tracing of algorithm](https://www.geeksforgeeks.org/wp-content/uploads/gq/2014/03/DLL_add_middle1.png) -## Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/doubly_linked_list.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/doubly_linked_list.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/data-structures/linked-list/double-linkedlist.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/double_list.rb) - ## Video Explanation [A CS50 video explaining the Doubly Linked List Data Structure](https://www.youtube.com/watch?v=FHMPswJDCvU) diff --git a/en/Data Structures/Linked Lists/Singly Linked List.md b/en/Data Structures/Linked Lists/Singly Linked List.md index 27ccc46a..4b7e5823 100644 --- a/en/Data Structures/Linked Lists/Singly Linked List.md +++ b/en/Data Structures/Linked Lists/Singly Linked List.md @@ -37,13 +37,6 @@ class LinkedList { } ``` -## Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/linked_list.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/singly_linked_list.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/single_list.rb) - ## Video Explanation [A CS50 video explaining the Linked List Data Structure](https://www.youtube.com/watch?v=5nsKtQuT6E8) diff --git a/en/Data Structures/Probablistic/BloomFilter.md b/en/Data Structures/Probablistic/BloomFilter.md index b1752d9b..3fc5a19a 100644 --- a/en/Data Structures/Probablistic/BloomFilter.md +++ b/en/Data Structures/Probablistic/BloomFilter.md @@ -117,12 +117,6 @@ Notice that this does not match either the result of `foo` or `bar`, however bec The probability of false positives increases with the probability of hash collisions within the filter. However, you can optimize the number of collisions if you have some sense of the cardinality of your set ahead of time. You can do this by optimizing `k` and `M`, `M` should be ~ 8-10 bits per expected item, and `k` should be `(M/n) * ln2`. -## Examples - -Implementations of the Bloom Filter are available for: - -* [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/DataStructures/Probabilistic/BloomFilter.cs) - ## Video Explainer [Video Explainer by Narendra L](https://www.youtube.com/watch?v=Bay3X9PAX5k) \ No newline at end of file diff --git a/en/Data Structures/Queues/queue.md b/en/Data Structures/Queues/queue.md new file mode 100644 index 00000000..93d83066 --- /dev/null +++ b/en/Data Structures/Queues/queue.md @@ -0,0 +1,35 @@ +# Queue + +## Description + +A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle. It is often compared to a real-world queue of people waiting in line. The element that is added first is the one that gets removed first. Queues are commonly used for various applications, such as task scheduling, managing requests, and more. + +## Queue Operations + +1) Enqueue (Push): This operation is used to add an item to the back or end of the queue. It's equivalent to "pushing" an item onto the queue. When you enqueue an item, it becomes the last item in the queue. + +2) Dequeue (Pop): Dequeue is the operation used to remove and return the front item from the queue. The item that has been in the queue the longest (the front item) is the one removed. After dequeuing an item, the next item in the queue becomes the new front. + +3) Peek (Front): This operation is used to view the front item in the queue without removing it. It provides a way to examine the item at the front of the queue without actually dequeuing it. + +4) isEmpty: This operation checks whether the queue is empty. If the queue contains no items, it returns true; otherwise, it returns false. + +## Source + +- [Queue Data Structure](https://www.geeksforgeeks.org/queue-data-structure/) + +## Video URL + +- [Queue in Data Structure](https://www.youtube.com/watch?v=zp6pBNbUB2U) +- [Implementation of Queue using Arrays](https://www.youtube.com/watch?v=YqrFeU90Coo) +- [Queue Implementation using Linked List in C](https://www.youtube.com/watch?v=RN1wzY_tnYU) + +## Implementation + +1) Queue Implementation Using Lists (Arrays) + +In this approach, you can use a list (or array) to represent a queue. You will maintain two pointers, one pointing to the front of the queue and another pointing to the back. The front pointer keeps track of the element to be dequeued, and the back pointer keeps track of where new elements should be enqueued. + +2) Queue Implementation Using a Linked List + +In this approach, you can use a linked list to implement a queue. You maintain two pointers, one pointing to the front (head) of the queue and another pointing to the back (tail). Enqueueing involves adding a new node at the tail, and dequeueing involves removing the node at the head. diff --git a/en/Data Structures/Tries/trie.md b/en/Data Structures/Tries/trie.md new file mode 100644 index 00000000..0be94fce --- /dev/null +++ b/en/Data Structures/Tries/trie.md @@ -0,0 +1,158 @@ +# Trie + +A trie (also called a prefix tree) is a tree data structure that shows order, linking parents to children. It is an efficient way of storing objects that have commonalities. A good example would be in storing phone numbers, or strings in general + +For the strings example, supposing we have a list of strings to store in our data store + +1. egg +2. eat +3. ear +4. end + +And one of the methods we are to support is a search operation for any of the words, we can approach it the basic way - select each word, and do a string comparison, matching letter to letter. The algorithm would be as follows: + + +``` +## searching for ear in data store + +data_store = ["egg", "eat", "ear", "end"] +to_find = "ear" + +## pick each word +## do a string match letter by letter +## when you find a mismatch, move to the next string +## continue this process +## if at the end of an iteration, index has been increased to +## the length of the word to find, we have found a match + +for word in data_store: + index = 0 + while index < len(word): + if to_find[index] != word[index]: + break + index += 1 + if index == len(to_find): + print("a match has been found") + +``` + +Without a doubt, this strategy will work, but the time complexity of doing this is *O(num of words x len of longest word)* which is quite expensive. +However, if we represent the storage of numbers in a tree such that each letter appears only once in a particular level in the tree, we can achieve a much better search time. Take, for example, the tree below + +``` + e + / | \ + a n g + / \ | | + r t d g + +``` + +You can see from the above representation, that all the words are in the tree, starting from the letter e, which is found at the beginning of all the words, then a, n, and g coming in the next level and so on... +The above representation is called a trie. + +# Standard Trie Operations + +1) insert(): inserts the string into the trie. +2) search(): searches for the string within the trie. + +# Building a Trie + +## Defining a node class for the elements of the trie + +To start building a trie, you first need to define a node with the revelant attributes needed for any trie. + +``` +class Node: + def __init__(self, is_word: bool=False): + self.is_word = is_word + self.children = {} +``` + +Here, you can see that the class `Node` has three instance attributes: +1. is_word: *bool* = to mark whether that node in the trie marks the completion of a word +2. children: *Dict* = to hold pointers to other children nodes + +Then the trie gets built by creating a node for each letter and adding it as a child to the node before it + +## Building the trie itself + +Start by initializing an empty node + +``` +class Trie: + def __init__(self): + self.node = Node() +``` + +For the insert operation, fetch the starting node, then for every letter in the word, add it to the children of the letter before it. The final node has its `is_word` attribute marked as **True** because we want to be aware of where the word ends + +``` +def insert(self, word: str) -> None: + node = self.node + for ltr in word: + if ltr not in node.children: + node.children[ltr] = Node() + node = node.children[ltr] + node.is_word=True +``` + +*In the code above, the `node` variable starts by holding a reference to the null node, while the `ltr` iterating variable starts by holding the first letter in `word`. This would ensure that `node` is one level ahead of `ltr`. As they are both moved forward in the iterations, `node` will always remain one level ahead of `ltr`* + +For the search operation, fetch the starting node, then for every letter in the word, check if it is present in the `children` attribute of the current node. As long as it is present, repeat for the next letter and next node. If during the search process, we find a letter that is not present, then the word does not exist in the trie. If we successfully get to the end of the iteration, then we have found what we are looking for. It is time to return a value + +Take a look at the code + +``` +def search(self, word: str) -> bool: + node = self.node + for ltr in word: + if ltr not in node.children: + return False + node = node.children[ltr] + return node.is_word +``` + +For the return value, there are two cases: +1. we are searching for a word -> return `node.is_word` because we want to be sure it is actually a word, and not a prefix +2. we are searching for a prefix -> return **True** because whether it is a word or not, it is prefix that exists in the trie + +Now here is the full code + +``` +class Node: + def __init__(self, is_word: bool=False): + self.is_word = is_word + self.children = {} + +class Trie: + + def __init__(self): + self.node = Node() + + + def insert(self, word: str) -> None: + node = self.node + for ltr in word: + if ltr not in node.children: + node.children[ltr] = Node() + node = node.children[ltr] + node.is_word=True + + + def search(self, word: str) -> bool: + node = self.node + for ltr in word: + if ltr not in node.children: + return False + node = node.children[ltr] + return node.is_word +``` + +# Helpful links + +1) [Trie Data Structure - GeeksForGeeks](https://www.geeksforgeeks.org/trie-insert-and-search/) + +# Video Playlist + +- [Trie Data Structure](https://www.youtube.com/watch?v=zIjfhVPRZCg) \ No newline at end of file diff --git a/en/Dynamic Programming/Coin Change.md b/en/Dynamic Programming/Coin Change.md index 6801cace..187f0dc0 100644 --- a/en/Dynamic Programming/Coin Change.md +++ b/en/Dynamic Programming/Coin Change.md @@ -48,8 +48,5 @@ Let's say we have 3 coin types `[1,2,3]` and we want to change for `7` cents. So ``` 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}}` -#### Code Implementation Link -[Python](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/coin_change.py) - #### Video Explanation [Total Unique Ways To Make Change by Back To Back SWE](https://www.youtube.com/watch?v=DJ4a7cmjZY0) diff --git a/en/Dynamic Programming/Kadane's Algorithm.md b/en/Dynamic Programming/Kadane's Algorithm.md index 6e53f07f..6d6c89f0 100644 --- a/en/Dynamic Programming/Kadane's Algorithm.md +++ b/en/Dynamic Programming/Kadane's Algorithm.md @@ -106,8 +106,6 @@ largest_sum = max(5, 6) = 6 ```Hence the output will be 6``` +### Video Explanation Link - -### Code Implementation Links - -- [Python](https://github.com/TheAlgorithms/Python/blob/252df0a149502143a14e7283424d40b785dd451c/maths/kadanes.py) +- [Kadane's Algorithm to Maximum Sum Subarray Problem](https://www.youtube.com/watch?v=86CQq3pKSUw) diff --git a/en/Dynamic Programming/Longest Common Subsequence.md b/en/Dynamic Programming/Longest Common Subsequence.md index 2dc8f1ed..d613f807 100644 --- a/en/Dynamic Programming/Longest Common Subsequence.md +++ b/en/Dynamic Programming/Longest Common Subsequence.md @@ -69,12 +69,6 @@ B 0 0 1 2 3 ``` So the length of LCS is `dp[4][4] = 3`. -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/longest_common_subsequence.py) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Dynamic%20Programming/Longest%20Common%20Subsequence.cpp) - #### Video Explanation [Video explanation by Tushar Roy](https://youtu.be/NnD96abizww) diff --git a/en/Greedy Algorithms/Fractional Knapsack.md b/en/Greedy Algorithms/Fractional Knapsack.md index cc9eb8c8..fb49dab1 100644 --- a/en/Greedy Algorithms/Fractional Knapsack.md +++ b/en/Greedy Algorithms/Fractional Knapsack.md @@ -35,12 +35,6 @@ We won't be able to make more money by combining diverse things. ``` -#### Code Implementation Links - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/greedy_algorithms/knapsack.cpp) -- [Python](https://github.com/TheAlgorithms/Python/tree/master/knapsack) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/tree/master/Algorithms/Knapsack) - #### Video Explanation [A CS50 video explaining the Greedy Algorithm](https://www.youtube.com/watch?v=Ou9OA0yQCYA) diff --git a/en/Image Processing/Harris Detector.md b/en/Image Processing/Harris Detector.md index a0b7388e..16b5f3ed 100644 --- a/en/Image Processing/Harris Detector.md +++ b/en/Image Processing/Harris Detector.md @@ -13,10 +13,6 @@ Given image $I$, $n\times n$ size Gaussian Kernel $G_{n\times n}$, 3. Compute the response function $R$, where $R=AB-C^2-k(A+B)$ 4. Classify all points in $R​$. -## Code Implementation Links - -- [Python](https://github.com/TheAlgorithms/Python/blob/master/computer_vision/harriscorner.py) - ## Reference C. Harris and M. Stephens, “A Combined Corner and Edge Detector,” in *Proceedings of the Alvey Vision Conference 1988*, Manchester, 1988, pp. 23.1-23.6. diff --git a/en/Search Algorithms/Binary Search.md b/en/Search Algorithms/Binary Search.md index 3f18817e..ff704de5 100644 --- a/en/Search Algorithms/Binary Search.md +++ b/en/Search Algorithms/Binary Search.md @@ -38,14 +38,6 @@ target = 9 A simple Binary Search implementation may return -1 as 9 is not present in the array. A more complex one would return the index at which 9 would have to be inserted, which would be `-8` (last position in the array (7) plus one (7+1), negated)`. ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/BinarySearch.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/binary_search.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/binary_search.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Search/BinarySearcher.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/binary_search.c) - #### Video Explanation [A CS50 video explaining the Binary Search Algorithm](https://www.youtube.com/watch?v=5xlIPT1FRcA) diff --git a/en/Search Algorithms/Exponential Search.md b/en/Search Algorithms/Exponential Search.md index 8c363cc2..3530b2c5 100644 --- a/en/Search Algorithms/Exponential Search.md +++ b/en/Search Algorithms/Exponential Search.md @@ -2,7 +2,7 @@ #### Prerequisites -- [Binary Search algorithm](https://github.com/faridevnz/Algorithms-Explanation/blob/master/en/Search%20Algorithms/Binary%20Search.md) +- [Binary Search algorithm](Binary%20Search.md) #### Problem Statement @@ -39,7 +39,7 @@ Now we can apply the binary search on the subarray from 512 and 1_000. #### Complexity Explanation - The complexity of the first part of the algorithm is **O( log *i* )** because if *i* is the position of the target in the array, after doubling the search *index* `⌈log(i)⌉` times, the algorithm will be at a search index that is greater than or equal to *i*. We can write `2^⌈log(i)⌉ >= i` -- The complexity of the second part of the algorithm also is **O ( log *i* )** because that is a simple Binary Search. The Binary Search complexity ( as explained [here](https://github.com/faridevnz/Algorithms-Explanation/blob/master/en/Search%20Algorithms/Binary%20Search.md) ) is O( *n* ) where *n* is the length of the array. In the Exponential Search, the length of the array on which the algorithm is applied is `2^i - 2^(i-1)`, put into words it means '( the length of the array from start to *i* ) - ( the part of array skipped until the previous iteration )'. Is simple verify that `2^i - 2^(i-1) = 2^(i-1) ` +- The complexity of the second part of the algorithm also is **O ( log *i* )** because that is a simple Binary Search. The Binary Search complexity ( as explained [here](Binary%20Search.md) ) is O( *n* ) where *n* is the length of the array. In the Exponential Search, the length of the array on which the algorithm is applied is `2^i - 2^(i-1)`, put into words it means '( the length of the array from start to *i* ) - ( the part of array skipped until the previous iteration )'. Is simple verify that `2^i - 2^(i-1) = 2^(i-1) ` After this detailed explanation we can say that the the complexity of the Exponential Search is: @@ -53,9 +53,3 @@ Let's take a look at this comparison with a less theoretical example. Imagine we - The Binary Search start from the middle of the array and arrive to the 4th position after many iterations - The Exponential Search arrive at the 4th index after only 2 iterations - -#### Code Implementation Links - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/exponential_search.cpp) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/exponential_search.c) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Search/ExponentialSearch.js) diff --git a/en/Search Algorithms/Floyd Cycle Detection Algorithm to Find Duplicate Number.md b/en/Search Algorithms/Floyd Cycle Detection Algorithm to Find Duplicate Number.md index 320541aa..a431d58d 100644 --- a/en/Search Algorithms/Floyd Cycle Detection Algorithm to Find Duplicate Number.md +++ b/en/Search Algorithms/Floyd Cycle Detection Algorithm to Find Duplicate Number.md @@ -1,38 +1,73 @@ -# Floyd Cycle Detection Algorithm to find duplicate number in an array +# Floyd Cycle Detection Algorithm to find duplicate numbers in an array ## Problem Statement 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. ## Approach +- 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. +- For example, given the `arr = [1, 3, 4, 2, 3]`, we can represent `arr` as the following

+![image](images/graph_1.png) -- Use the function `f(x) = arr[x]` to construct the sequence: -`arr[0]`, `arr[arr[0]]`, `arr[arr[arr[0]]]`, `arr[arr[arr[arr[0]]]]`, etc.... -- Each new element in the sequence is an element in `arr[]` at the index of the previous element. -- Starting from `x = arr[0]`, it will produce a linked list with a cycle. -- The cycle appears because `arr[]` contains duplicate elements(at least one). The duplicate value is an entrance to the cycle. +- 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`. +- The problem now becomes finding the entrance node to the cycle (3 in this case). +- We can use the Floyd Cycle Detection Algorithm (also known as the "Hare and Tortoise algorithm") to detect the entrance of the cycle. +- 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: +### The procedure +- Using two pointers `hare` and `tortoise`. +- Initiate `hare = tortoise = arr[0]`. +- 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). +- At this point, `hare == tortoise`, reset `tortoise = arr[0]` while keeping the value of `hare` in the above procedure. +- For every next step until `hare == tortoise` again, assign `hare = arr[hare]` and `tortoise = arr[tortoise]` (this time `hare` only "jumps" one step). +- When `tortoise == hare`, the entrance of the cycle is found, hence `hare` and `tortoise` represent the value of the duplicated element. +- Return `tortoise` (also possible to return `hare`) + ## Time Complexity -O(n) +`O(n)` ## Space Complexity -O(1) +`O(1)`, since we only use two extra variables as pointers. -## Example +## Example with step-by-step explanation +![image](images/graph_2.png) ``` -arr = [3, 4, 8, 5, 9, 1, 2, 6, 7, 4] +arr = [3, 4, 8, 5, 9, 1, 2, 6, 7, 4] -return value = 4 -``` +hare = tortoise = arr[0] = 3 + +1st step: + - hare = arr[arr[3]] = arr[5] = 1 + - tortoise = arr[3] = 5 +2nd step: + - hare = arr[arr[1]] = arr[4] = 9 + - tortoise = arr[5] = 1 +3rd step: + - hare = arr[arr[9]] = arr[4] = 9 + - tortoise = arr[1] = 4 +4th step: + - hare = arr[arr[9]] = 9 + - tortoise = arr[4] = 9 -## Code Implementation Links +tortoise = arr[0] = 3 -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/floyd_cycle_detection_algo.cpp) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/floyd_cycle_detection_algorithm.c) +1st step: + - hare = arr[9] = 4 + - tortoise = arr[3] = 5 +2nd step: + - hare = arr[4] = 9 + - tortoise = arr[5] = 1 +3rd step: + - hare = arr[9] = 4 + - tortoise = arr[1] = 4 + +return tortoise = 4 +``` #### Video Explanation -[YouTube video explaining the Floyd Cycle Detection algorithm](https://www.youtube.com/watch?v=B6smdk7pZ14) +- [YouTube video explaining the Floyd Cycle Detection algorithm](https://www.youtube.com/watch?v=B6smdk7pZ14) +- [Another Youtube video](https://www.youtube.com/watch?v=PvrxZaH_eZ4&t=1s) diff --git a/en/Search Algorithms/Linear Search.md b/en/Search Algorithms/Linear Search.md index eb6f90bf..4da70e54 100644 --- a/en/Search Algorithms/Linear Search.md +++ b/en/Search Algorithms/Linear Search.md @@ -33,13 +33,6 @@ target = 6 Linear Search should return -1 as 6 is not present in the array ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LinearSearch.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/linear_search.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/linear_search.py) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/linear_search.c) - #### Video Explanation [A CS50 video explaining the Linear Search Algorithm](https://www.youtube.com/watch?v=CX2CYIJLwfg) diff --git a/en/Search Algorithms/images/graph_1.png b/en/Search Algorithms/images/graph_1.png new file mode 100644 index 00000000..2a45b595 Binary files /dev/null and b/en/Search Algorithms/images/graph_1.png differ diff --git a/en/Search Algorithms/images/graph_2.png b/en/Search Algorithms/images/graph_2.png new file mode 100644 index 00000000..d51e9516 Binary files /dev/null and b/en/Search Algorithms/images/graph_2.png differ diff --git a/en/Selection Algorithms/Find Second Largest Element.md b/en/Selection Algorithms/Find Second Largest Element.md new file mode 100644 index 00000000..14971faa --- /dev/null +++ b/en/Selection Algorithms/Find Second Largest Element.md @@ -0,0 +1,70 @@ +# Find Second Largest Element + +#### Problem statement + +Given an unsorted array, write a function to find the second largest element in the array. + +#### Approach + +- Find the largest element in the array by traversing through the array using a loop and store the value in a variable (for ex: a ) +- Assign a variable to store the negative infinite value, which stores the least value (for ex: b ) +- Run a loop from zero to the size of the array. +- Now check whether the current element is greater than variable "b" and also not equal to variable "a", which is the largest number in the array. +- if the above condition is true, then the variable b stores the current element. + +#### Time Complexity + +- Best case: `O(n)` +- Average case: `O(n)` +- Worst case: `O(n)` + +#### Space Complexity + +Worst case: `O(1)` + +#### Example + +```txt +arr = [2, 5, 3, 9, 12, 34, 25] +Indexes: 0 1 2 3 4 5 6 +a = max(arr) +(a = 34) +b = float("-inf") + +Traverse elements from i = 0 to i = 6 +i = 0 +Check if b < arr[i] (arr[0]) and arr[0] != a +True : b = arr[0] (b = 2) + +i = 1 +Check if b < arr[i] (arr[1]) and arr[1] != a +True : b = arr[0] (b = 5) + +i = 2 +Check if b < arr[i] (arr[2]) and arr[2] != a +False : As b = 5 is greater than the current element arr[2] = 3 +continues with the loop + +i = 3 +Check if b < arr[i] (arr[3]) and arr[3] != a +True : b = arr[3] (b = 9) + +i = 4 +Check if b < arr[i] (arr[4]) and arr[4] != a +True : b = arr[4] (b = 12) + +i = 5 +Check if b < arr[i] (arr[5]) and arr[5] != a +False: As current element is equal to the variable "a" which stores the highest value in the array +continues with the loop + +i = 6 +Check if b < arr[i] (arr[6]) and arr[6] != a +True : b = arr[6] (b = 25) + +Now we get the value 25 in the variable "b", which is the second highest value in the array. +``` + +#### Video Explanation + +[Video explaining 2 approaches](https://www.youtube.com/watch?v=Mv8jhYQEbkA) diff --git a/en/Selection Algorithms/Quick Select.md b/en/Selection Algorithms/Quick Select.md index 706dcb97..cc915e4e 100644 --- a/en/Selection Algorithms/Quick Select.md +++ b/en/Selection Algorithms/Quick Select.md @@ -41,13 +41,6 @@ Let's say k = 4. ie. We have to find 4th smallest element. 4. As position of '7' is 4th (ie. k). Thus we will simply return 7 ``` -### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/QuickSelect.java) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/quick_select.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/search/selectk.go) -- [JavaScript](https://github.com/TheAlgorithms/JavaScript/blob/master/Data-Structures/Array/QuickSelect.js) - ### Helpful Video Links [Video explaining how to find the Kth smallest/largest element in varying complexities](https://youtu.be/hGK_5n81drs) diff --git a/en/Sorting Algorithms/Bubble Sort.md b/en/Sorting Algorithms/Bubble Sort.md index bed31654..3ce99615 100644 --- a/en/Sorting Algorithms/Bubble Sort.md +++ b/en/Sorting Algorithms/Bubble Sort.md @@ -79,18 +79,6 @@ Indexes: 0 1 2 3 Since there are no swaps in above steps, it means the array is sorted and we can stop here. ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bubble_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/bubble_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/BubbleSorter.cs) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubblesort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/bubble_sort.c) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/BubbleSort.scala) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/BubbleSort.js) - #### Video Explanation [A video explaining the Bubble Sort Algorithm](https://www.youtube.com/watch?v=Jdtq5uKz-w4) diff --git a/en/Sorting Algorithms/Counting Sort.md b/en/Sorting Algorithms/Counting Sort.md index 3e1f30d2..984d28bc 100644 --- a/en/Sorting Algorithms/Counting Sort.md +++ b/en/Sorting Algorithms/Counting Sort.md @@ -41,15 +41,6 @@ countingSort(array, size) decrease count of each element restored by 1 ``` -#### Code Implementation Links - -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/counting_sort.c) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/counting_sort.cpp) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/CountingSort.js) -- [Matlab](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/counting_sort.m) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/counting_sort.py) -- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/counting_sort.rs) - #### Video Explanation [A video explaining the Counting Sort Algorithm](https://www.youtube.com/watch?v=7zuGmKfUt7s) diff --git a/en/Sorting Algorithms/Cycle Sort.md b/en/Sorting Algorithms/Cycle Sort.md new file mode 100644 index 00000000..840aab13 --- /dev/null +++ b/en/Sorting Algorithms/Cycle Sort.md @@ -0,0 +1,69 @@ +# Cycle Sort + +#### Problem Statement + +Given an unsorted array of n elements, write a function to sort the array + +#### Approach + +- If the element is already at its correct position do nothing +- Otherwise, find the correct position of a by counting the total number of elements that are less than current element +- Insert current element into its correct position +- Set replaced element as new current element and find its correct position +- Continue process until array is sorted + +#### Time Complexity + +`O(n^2)` Worst case performance + +`O(n^2)` Best-case performance + +`O(n^2)` Average performance + +#### Space Complexity + +`O(n)` Worst case + +#### Application of algorithm + +- Cycle sort algorithm is useful for situations where memory write or element swap operations are costly. + +#### Example + +A single cycle of sorting array | b | d | e | a | c | + +``` +1. Select element for which the cycle is run, i.e. "b". + +|b|d|e|a|c| + +b - current element + +2. Find correct location for current element and update current element. + +|b|b|e|a|c| + +d - current element + +3. One more time, find correct location for current element and update current element. + +|b|b|e|d|c| + +a - current element + +4. Current element is inserted into position of initial element "b" which ends the cycle. + +|a|b|e|d|c| + +a - current element + +5. New cycle should be started for next element. +``` + +#### Video Explanation + +[A video explaining the Cycle Sort Algorithm](https://www.youtube.com/watch?v=gZNOM_yMdSQ) + +#### The Algorithms Page + +[Cycle Sort](https://the-algorithms.com/algorithm/cycle-sort) diff --git a/en/Sorting Algorithms/Heap Sort.md b/en/Sorting Algorithms/Heap Sort.md index 455fe239..7b545351 100644 --- a/en/Sorting Algorithms/Heap Sort.md +++ b/en/Sorting Algorithms/Heap Sort.md @@ -55,17 +55,6 @@ in top down manner. ![heap-image](https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif "Heap Sort") -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/HeapSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/heap_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/heap_sort.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/heapsort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/heap_sort.rb) -- [C-sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/HeapSorter.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/heap_sort.c) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/HeapSort.js) - #### Video Explanation [A video explaining the Heap Sort Algorithm](https://www.youtube.com/watch?v=MtQL_ll5KhQ) diff --git a/en/Sorting Algorithms/Insertion Sort.md b/en/Sorting Algorithms/Insertion Sort.md index 4c7c997f..d1253151 100644 --- a/en/Sorting Algorithms/Insertion Sort.md +++ b/en/Sorting Algorithms/Insertion Sort.md @@ -48,16 +48,6 @@ and elements from 11 to 13 will move one position ahead of their current positio 5, 6, 11, 12, 13 -- sorted array ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/InsertionSort.java) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/insertion_sort.c) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/insertion_sort.cpp) -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/InsertionSorter.cs) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/InsertionSort.scala) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/insertion_sort.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/insertion_sort.rb) - #### Video Explanation [A CS50 video explaining the Insertion Search Algorithm](https://www.youtube.com/watch?v=DFG-XuyPYUQ) diff --git a/en/Sorting Algorithms/Merge Sort.md b/en/Sorting Algorithms/Merge Sort.md index 25c16f97..d26b6275 100644 --- a/en/Sorting Algorithms/Merge Sort.md +++ b/en/Sorting Algorithms/Merge Sort.md @@ -59,15 +59,6 @@ Similarly [3, 7] and [4, 6] will be merged and made [3, 4, 6, 7]. At the next stack level [1, 2, 5, 9] and [3, 4, 6, 7] will be merged and we will get the final sorted array as [1, 2, 3, 4, 5, 6, 7, 9]. ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/MergeSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/merge_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/MergeSorter.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/merge_sort.c) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/merge_sort.rb) - #### Video Explanation [A CS50 video explaining the Merge Sort Algorithm](https://www.youtube.com/watch?v=EeQ8pwjQxTM) diff --git a/en/Sorting Algorithms/Quick Sort.md b/en/Sorting Algorithms/Quick Sort.md index a08711e4..666e0c46 100644 --- a/en/Sorting Algorithms/Quick Sort.md +++ b/en/Sorting Algorithms/Quick Sort.md @@ -66,14 +66,6 @@ Now 70 is at its correct place. All elements smaller than it. ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/QuickSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/quick_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/quick_sort.py) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/quick_sort.c) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/quicksort.rb) - #### Video Explanation [A video explaining the Quick Sort Algorithm](https://www.youtube.com/watch?v=COk73cpQbFQ) diff --git a/en/Sorting Algorithms/Radix Sort.md b/en/Sorting Algorithms/Radix Sort.md index 2db36da8..0e474d06 100644 --- a/en/Sorting Algorithms/Radix Sort.md +++ b/en/Sorting Algorithms/Radix Sort.md @@ -46,4 +46,6 @@ If we have `log2n` bits for every digit, the running time of Radix appears to be asymptotic notation are higher for Radix Sort and Quick-Sort uses hardware caches more effectively. Also, Radix sort uses counting sort as a subroutine and counting sort takes extra space to sort numbers. +#### Video Explanation + Video reference: https://youtu.be/nu4gDuFabIM diff --git a/en/Sorting Algorithms/Recursive Versions/Recursive Bubble Sort.md b/en/Sorting Algorithms/Recursive Versions/Recursive Bubble Sort.md index ef0b1972..0c66b6b6 100644 --- a/en/Sorting Algorithms/Recursive Versions/Recursive Bubble Sort.md +++ b/en/Sorting Algorithms/Recursive Versions/Recursive Bubble Sort.md @@ -63,11 +63,6 @@ void bubbleSort(arr[], n) bubbleSort(arr, n-1) ``` -## Implementations - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSortRecursion.java) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/bubble_sort_recursion.c) - ## Video Explanation [A video explaining iterative as well as recursive bubble sort](https://www.youtube.com/watch?v=gDMDVLBfCI0) diff --git a/en/Sorting Algorithms/Selection Sort.md b/en/Sorting Algorithms/Selection Sort.md index c3f4b285..713b2d41 100644 --- a/en/Sorting Algorithms/Selection Sort.md +++ b/en/Sorting Algorithms/Selection Sort.md @@ -49,19 +49,6 @@ Indexes: 0 1 2 3 The array is now sorted. ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SelectionSort.java) -- [C++ Iterative](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/selection_sort_iterative.cpp) -- [C++ Recursive](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/selection_sort_recursive.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/selection_sort.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/selection_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/selection_sort.rb) -- [C iterative](https://github.com/TheAlgorithms/C/blob/master/sorting/selection_sort.c) -- [C recursive](https://github.com/TheAlgorithms/C/blob/master/sorting/selection_sort_recursive.c) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/SelectionSort.scala) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/selectionSort.js) - #### Video Explanation [A video explaining the Selection Sort Algorithm](https://www.youtube.com/watch?v=f8hXR_Hvybo) diff --git a/en/Sorting Algorithms/Shell Sort.md b/en/Sorting Algorithms/Shell Sort.md index 48c6be16..94b94060 100644 --- a/en/Sorting Algorithms/Shell Sort.md +++ b/en/Sorting Algorithms/Shell Sort.md @@ -54,17 +54,6 @@ Initial Gap: 4 12. Divide the gap by 2 and repeat until gap = 1 ``` -#### Code Implementation Links - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/ShellSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/shell_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/shell_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/ShellSorter.cs) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/shell_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/shell_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/shell_sort.c) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/shellSort.js) - #### Video Explanation [A video explaining the Shell Sort Algorithm](https://www.youtube.com/watch?v=H8NiFkGu2PY) diff --git a/es/Algoritmos de Ordenamiento/Ordenamiento Burbuja.md b/es/Algoritmos de Ordenamiento/Ordenamiento Burbuja.md index 6b81c545..2e1b0be4 100644 --- a/es/Algoritmos de Ordenamiento/Ordenamiento Burbuja.md +++ b/es/Algoritmos de Ordenamiento/Ordenamiento Burbuja.md @@ -79,18 +79,6 @@ Indices: 0 1 2 3 Como no hay intercambios en los pasos de arriba, el arreglo ya se ha ordenado y nos podemos detener. ``` -#### Enlaces a implementaciones de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Bubble%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/bubble_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/BubbleSorter.cs) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubble_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/bubble_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/BubbleSort.c) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/BubbleSort.scala) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/bubblesort.js) - #### Explicación en video [Un video explicando el Algoritmo de Ordenamiento Burbuja](https://www.youtube.com/watch?v=EQMGabLO_M0) diff --git a/es/Algoritmos de Ordenamiento/Ordenamiento Shell.md b/es/Algoritmos de Ordenamiento/Ordenamiento Shell.md index a50edf27..3c4aa1e7 100644 --- a/es/Algoritmos de Ordenamiento/Ordenamiento Shell.md +++ b/es/Algoritmos de Ordenamiento/Ordenamiento Shell.md @@ -55,17 +55,6 @@ Brecha inicial: 4 12. Divida la brecha por 2 y repita hasta la brecha = 1 ``` -#### Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/ShellSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Shell%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/shell_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/ShellSorter.cs) -- [Ir](https://github.com/TheAlgorithms/Go/blob/master/sorts/shell_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/shell_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/shellSort.c) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/shellSort.js) - #### Explicación de vídeo [Un vídeo explicando el algoritmo del ordenamiento de Shell](https://www.youtube.com/watch?v=H8NiFkGu2PY) diff --git "a/es/Algoritmos de Ordenamiento/Ordenamiento de fusi\303\263n.md" "b/es/Algoritmos de Ordenamiento/Ordenamiento de fusi\303\263n.md" index ef2b24d8..02df6850 100644 --- "a/es/Algoritmos de Ordenamiento/Ordenamiento de fusi\303\263n.md" +++ "b/es/Algoritmos de Ordenamiento/Ordenamiento de fusi\303\263n.md" @@ -31,15 +31,6 @@ Vuelva a llamar a la función de ordenación de combinación de llamadas para es Ahora combine ambas mitades para obtener la matriz ordenada [0, 1, 2, 3, 5, 9] ``` -#### Enlaces de la implementación del código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/MergeSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/merge_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/MergeSorter.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/merge_sort.c) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/merge_sort.rb) - #### Explicación de vídeo [Un vídeo CS50 que explica el algoritmo de ordemaniento de fusión](https://www.youtube.com/watch?v=EeQ8pwjQxTM) diff --git "a/es/Algoritmos de Ordenamiento/Ordenamiento de inserci\303\263n.md" "b/es/Algoritmos de Ordenamiento/Ordenamiento de inserci\303\263n.md" index 013e7089..20a9d11d 100644 --- "a/es/Algoritmos de Ordenamiento/Ordenamiento de inserci\303\263n.md" +++ "b/es/Algoritmos de Ordenamiento/Ordenamiento de inserci\303\263n.md" @@ -47,16 +47,6 @@ y los elementos del 11 al 13 se moverán una posición por delante de su posici 5, 6, 11, 12, 13 -- matriz ordenada ``` -#### Enlaces de implementación del código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/InsertionSort.java) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/insertion_sort.c) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/insertion_sort.cpp) -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/InsertionSorter.cs) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/InsertionSort.scala) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/insertion_sort.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/insertion_sort.rb) - #### Explicación de vídeo [Un vídeo CS50 que explica el algoritmo de Ordenamiento de inserción](https://www.youtube.com/watch?v=DFG-XuyPYUQ) diff --git "a/es/Algoritmos de Ordenamiento/Ordenamiento de mont\303\263n (heap sort).md" "b/es/Algoritmos de Ordenamiento/Ordenamiento de mont\303\263n (heap sort).md" index 862cdd81..2732ff73 100644 --- "a/es/Algoritmos de Ordenamiento/Ordenamiento de mont\303\263n (heap sort).md" +++ "b/es/Algoritmos de Ordenamiento/Ordenamiento de mont\303\263n (heap sort).md" @@ -55,17 +55,6 @@ El procedimiento de amontonar se llama a sí mismo recursivamente para construir ![imagen del montón](https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif "Heap sort") -#### Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/HeapSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/heap_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/heap_sort.py) -- [Ir](https://github.com/TheAlgorithms/Go/blob/master/sorts/heapsort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/heap_sort.rb) -- [C-sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/HeapSorter.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/heap_sort.c) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/HeapSort.js) - #### Explicación de vídeo [Un vídeo explicando el algoritmo de ordenamiento de montón (heap sort)](https://www.youtube.com/watch?v=MtQL_ll5KhQ) diff --git "a/es/Algoritmos de Ordenamiento/Ordenamiento de selecci\303\263n.md" "b/es/Algoritmos de Ordenamiento/Ordenamiento de selecci\303\263n.md" index 9fd0dc28..8aaa49cb 100644 --- "a/es/Algoritmos de Ordenamiento/Ordenamiento de selecci\303\263n.md" +++ "b/es/Algoritmos de Ordenamiento/Ordenamiento de selecci\303\263n.md" @@ -49,17 +49,6 @@ arr[] = {80, 10, 40, 30} La matriz ahora está ordenada. ``` -#### Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SelectionSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Selection%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/selection_sort.py) -- [Ir](https://github.com/TheAlgorithms/Go/blob/master/sorts/selection_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/selection_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/SelectionSort.c) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/SelectionSort.scala) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/selectionSort.js) - #### Explicación de vídeo [Un vídeo explicando el algoritmo de Ordenamiento de selección](https://www.youtube.com/watch?v=f8hXR_Hvybo) diff --git "a/es/Algoritmos de Ordenamiento/Ordenamiento r\303\241pido.md" "b/es/Algoritmos de Ordenamiento/Ordenamiento r\303\241pido.md" index 837997b5..62c9dfd9 100644 --- "a/es/Algoritmos de Ordenamiento/Ordenamiento r\303\241pido.md" +++ "b/es/Algoritmos de Ordenamiento/Ordenamiento r\303\241pido.md" @@ -67,13 +67,6 @@ Ahora 70 está en su lugar correcto. Todos los elementos más pequeños que eso. ``` -#### Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/QuickSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Quick%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/quick_sort.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/quicksort.rb) - #### Explicación de vídeo [Un vídeo explicando el algoritmo de ordenamiento rápido](https://www.youtube.com/watch?v=COk73cpQbFQ) diff --git "a/es/Algoritmos de b\303\272squeda/B\303\272squeda binaria.md" "b/es/Algoritmos de b\303\272squeda/B\303\272squeda binaria.md" index d18d0bdd..089c1566 100644 --- "a/es/Algoritmos de b\303\272squeda/B\303\272squeda binaria.md" +++ "b/es/Algoritmos de b\303\272squeda/B\303\272squeda binaria.md" @@ -38,24 +38,6 @@ target = 9 Búsqueda binaria debe devolver -1 dado que 9 no está presente en la matriz ``` -#### Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/BinarySearch.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Search/Binary%20Search.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/binary_search.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Search/BinarySearcher.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/Binary_Search.c) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Search/BinarySearch.js) -- [Haskell](https://github.com/TheAlgorithms/Haskell/blob/master/src/Misc/BinarySearch.hs) -- [F-Sharp](https://github.com/TheAlgorithms/F-Sharp/blob/main/Algorithms/Search/BinarySearch.fs) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/searches/binarysearch.go) -- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/searching/binary_search.rs) -- [Dart](https://github.com/TheAlgorithms/Dart/blob/master/search/binary_Search.dart) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/binary_search.rb) -- [PHP](https://github.com/TheAlgorithms/PHP/blob/master/searches/binary_search.php) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Search/BinarySearch.scala) -- [MATLAB-Octave](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/binary_search.m) - #### Explicación en vídeo de YouTube [Un vídeo CS50 explicando el algoritmo de búsqueda binaria](https://www.youtube.com/watch?v=5xlIPT1FRcA) diff --git "a/es/Algoritmos de b\303\272squeda/B\303\272squeda exponencial.md" "b/es/Algoritmos de b\303\272squeda/B\303\272squeda exponencial.md" index fbb2c658..dbddf8c1 100644 --- "a/es/Algoritmos de b\303\272squeda/B\303\272squeda exponencial.md" +++ "b/es/Algoritmos de b\303\272squeda/B\303\272squeda exponencial.md" @@ -2,7 +2,7 @@ #### Requisitos previos -- [Algoritmo de búsqueda binaria](https://github.com/faridevnz/Algorithms-Explicación/blob/master/en/Search%20Algorithms/Binary%20Search.md) +- [Algoritmo de búsqueda binaria](Búsqueda%20binaria.md) #### Declaración de problema @@ -39,7 +39,7 @@ Ahora podemos aplicar la búsqueda binaria en el subarray de 512 y 1_000. #### Explicación de complejidad - La complejidad de la primera parte del algoritmo es **`O( log *i* )`** porque si *i* es la posición del destino en la matriz, después de duplicar la búsqueda *index* `⌈log(i)⌉` veces, el algoritmo estará en un índice de búsqueda que es mayor o igual que *i*. Podemos escribir `2^⌈log(i)⌉ >= i` -- La complejidad de la segunda parte del algoritmo también es **`O ( log *i* )`** porque se trata de una simple búsqueda binaria. La complejidad de búsqueda binaria ( como se explica [aquí](https://github.com/faridevnz/Algorithms-Explicación/blob/master/en/Search%20Algorithms/Binary%20Search.md) ) es `O(*n*)` donde *n* es la longitud de la matriz. En la búsqueda exponencial, la longitud de la matriz en la que se aplica el algoritmo es `2^i - 2^(i-1)`, en palabras significa `(la longitud de la matriz de principio a *i* ) - (la parte de matriz omitida hasta la iteración anterior)`. Es simple verificar que `2^i - 2^(i-1) = 2^(i-1)`. +- La complejidad de la segunda parte del algoritmo también es **`O ( log *i* )`** porque se trata de una simple búsqueda binaria. La complejidad de búsqueda binaria ( como se explica [aquí](Búsqueda%20binaria.md) ) es `O(*n*)` donde *n* es la longitud de la matriz. En la búsqueda exponencial, la longitud de la matriz en la que se aplica el algoritmo es `2^i - 2^(i-1)`, en palabras significa `(la longitud de la matriz de principio a *i* ) - (la parte de matriz omitida hasta la iteración anterior)`. Es simple verificar que `2^i - 2^(i-1) = 2^(i-1)`. Después de esta explicación detallada, podemos decir que la complejidad de la búsqueda exponencial es: @@ -53,8 +53,3 @@ Echemos un vistazo a esta comparación con un ejemplo menos teórico. Imagine qu - La búsqueda binaria comienza desde el centro de la matriz y llega a la 4ª posición después de muchas iteraciones - La búsqueda exponencial llega al 4º índice después de sólo 2 iteraciones - -#### Enlaces de implementación de código - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/exponential_search.cpp) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Search/ExponentialSearch.js) diff --git "a/es/Algoritmos de b\303\272squeda/B\303\272squeda lineal.md" "b/es/Algoritmos de b\303\272squeda/B\303\272squeda lineal.md" index 48c97a5d..1e86ff63 100644 --- "a/es/Algoritmos de b\303\272squeda/B\303\272squeda lineal.md" +++ "b/es/Algoritmos de b\303\272squeda/B\303\272squeda lineal.md" @@ -33,24 +33,6 @@ target = 6 La búsqueda lineal debe devolver -1 ya que 6 no está presente en la matriz ``` -#### Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LinearSearch.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Search/Linear%20Search.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/linear_search.py) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Search/LinearSearch.js) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Search/LinearSearcher.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/linear_search.c) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/searches/linearsearch.go) -- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/searching/linear_search.rs) -- [Dart](https://github.com/TheAlgorithms/Dart/blob/master/search/linear_Search.dart) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/linear_search.rb) -- [PHP](https://github.com/TheAlgorithms/PHP/blob/master/searches/linear_search.php) -- [Kotlin](https://github.com/TheAlgorithms/Kotlin/blob/master/src/main/kotlin/search/LinearSearch.kt) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Search/LinearSearch.scala) -- [OCaml](https://github.com/TheAlgorithms/OCaml/blob/master/searches/linear_search.ml) -- [MATLAB-Octave](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/linear_search.m) - #### Explicación en YouTube [Un vídeo CS50 que explica el algoritmo de búsqueda lineal](https://www.youtube.com/watch?v=CX2CYIJLwfg) diff --git "a/es/Algoritmos de selecci\303\263n/Selecci\303\263n R\303\241pida.md" "b/es/Algoritmos de selecci\303\263n/Selecci\303\263n R\303\241pida.md" index 8d40f9fa..d15428ee 100644 --- "a/es/Algoritmos de selecci\303\263n/Selecci\303\263n R\303\241pida.md" +++ "b/es/Algoritmos de selecci\303\263n/Selecci\303\263n R\303\241pida.md" @@ -39,11 +39,6 @@ Digamos que k = 4 y tenemos que encontrar el cuarto elemento menor: 4. Como la posición de '7' es la cuarta, simplemente devolveremos el valor 7. ``` -## Enlaces de implementaciones de código - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/selecting/quickSelect.cpp) -- [Python](https://programmerclick.com/article/92711720579/) - ## Enlaces de explicación en vídeo [Programación en C++, Ordenamiento por Selección](https://www.youtube.com/watch?v=HVa2_UtXkCI) diff --git a/es/Cifrado/Cifrado Cesar.md b/es/Cifrado/Cifrado Cesar.md index 5f62140a..daf35af8 100644 --- a/es/Cifrado/Cifrado Cesar.md +++ b/es/Cifrado/Cifrado Cesar.md @@ -38,9 +38,3 @@ Digamos que estamos enviando un mensaje secreto a un amigo. * La segunda letra es `h`. La letra a 6 letras de distancia es `n`. Nuestro mensaje ahora es `Zn` * Seguimos así hasta el final. Nuestro mensaje final es: `Znk Igkygx iovnkx oy g lat yahyzozazout iovnkx.` * El descifrado es de la misma manera, excepto que en lugar de ir a la derecha en el alfabeto, vamos hacia atrás. - -## Implementación - -* [Python](https://github.com/TheAlgorithms/Python/blob/master/ciphers/caesar_cipher.py) -* [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/ciphers/caesar_cipher.cpp) -* [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/caesar.rs) diff --git "a/es/Estructuras de datos/Gr\303\241fico/Bellman Ford.md" "b/es/Estructuras de datos/Gr\303\241fico/Bellman Ford.md" index 1e32bba7..d3908206 100644 --- "a/es/Estructuras de datos/Gr\303\241fico/Bellman Ford.md" +++ "b/es/Estructuras de datos/Gr\303\241fico/Bellman Ford.md" @@ -86,13 +86,6 @@ D -2 A->B->E->D = -1 + 2 + -3 E 1 A->B->E = -1 + 2 ``` -#### Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Dynamic%20Programming/Bellman-Ford.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/graph/bellman_ford.py) -- [C](https://github.com/TheAlgorithms/C/blob/master/data_structures/graphs/Bellman-Ford.c) - #### Explicación de vídeo [Un video explicando el algoritmo Bellman Ford](https://www.youtube.com/watch?v=hxMWBBCpR6A) diff --git a/es/Estructuras de datos/Listas vinculadas/Doble lista vinculada.md b/es/Estructuras de datos/Listas vinculadas/Doble lista vinculada.md index e4492ee7..6cd9548a 100644 --- a/es/Estructuras de datos/Listas vinculadas/Doble lista vinculada.md +++ b/es/Estructuras de datos/Listas vinculadas/Doble lista vinculada.md @@ -102,14 +102,6 @@ class LinkedList { ![Seguimiento del algoritmo](https://www.geeksforgeeks.org/wp-content/uploads/gq/2014/03/DLL_add_middle1.png) -## Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Data%20Structure/Doubly%20Linked%20List.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/doubly_linked_list.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/data-structures/linked-list/double-linkedlist.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/double_list.rb) - ## Explicación de vídeo [Un vídeo CS50 explicando la Estructura de Datos de la Lista Doblemente Vinculada](https://www.youtube.com/watch?v=FHMPswJDCvU) diff --git a/es/Estructuras de datos/Listas vinculadas/Lista singular vinculada.md b/es/Estructuras de datos/Listas vinculadas/Lista singular vinculada.md index 4ac01ed3..8be7ca58 100644 --- a/es/Estructuras de datos/Listas vinculadas/Lista singular vinculada.md +++ b/es/Estructuras de datos/Listas vinculadas/Lista singular vinculada.md @@ -37,12 +37,6 @@ class LinkedList { } ``` -## Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Data%20Structure/Linked%20List.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/singly_linked_list.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/single_list.rb) ## Explicación de vídeo diff --git "a/es/Matematicas B\303\241sico/Numeros_Fibonacci.md" "b/es/Matematicas B\303\241sico/Numeros_Fibonacci.md" index 121518ee..23778eed 100644 --- "a/es/Matematicas B\303\241sico/Numeros_Fibonacci.md" +++ "b/es/Matematicas B\303\241sico/Numeros_Fibonacci.md" @@ -65,13 +65,6 @@ Calcular matriz^8 F(8)=21 -## Implementación - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fibonacci.cpp) -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciNumber.java) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/80c2dc85d714f73783f133964d6acd9b5625ddd9/Maths/Fibonacci.js) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/fibonacci.py) - ## Video en YouTube - [YouTube](https://www.youtube.com/watch?v=EEb6JP3NXBI) diff --git "a/es/Matematicas B\303\241sico/Promedio.md" "b/es/Matematicas B\303\241sico/Promedio.md" index ee2ca0ef..02d3801f 100644 --- "a/es/Matematicas B\303\241sico/Promedio.md" +++ "b/es/Matematicas B\303\241sico/Promedio.md" @@ -58,13 +58,9 @@ Si consideramos correctamente dígitos significativos: `suma / recuento = 23` Devuelva el valor de 22. 857142 o `23`. -## Implementación - -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/average_mean.py) - ## Video en YouTube -- [Media en Khan Academy](https://www.khanacademy.org/math/ap-statistics/summarizing-quantitative-data-ap/measuring-center-quantitative/v/mean-media-and-mode) +- [Media en Khan Academy](https://www.khanacademy.org/math/cc-sixth-grade-math/cc-6th-data-statistics/mean-and-median/v/mean-median-and-mode) ## Otros diff --git a/es/Procesamiento de imagenes/Detector de Harris.md b/es/Procesamiento de imagenes/Detector de Harris.md index 6046196b..b171a86f 100644 --- a/es/Procesamiento de imagenes/Detector de Harris.md +++ b/es/Procesamiento de imagenes/Detector de Harris.md @@ -13,10 +13,6 @@ Dada la imagen `$I$`, $ntimes n$ tamaño Gaussian Kernel `$G_{ntimes n}$`, 3. Calcule la función de respuesta `$R$`, donde `$R=AB-C^2-k(A+B)$` 4. Clasifique todos los puntos en `$R$`. -## Enlaces de implementación de código - -- [Python](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/feature_detectors/harris.py) - ## Referencia C. Harris y M. Stephens, "A Combined Corner and Edge Detector", en *Procedings of the Alvey Vision Conference 1988*, Manchester, 1988, págs. 23.1-23.6. diff --git "a/es/Programaci\303\263n dinamica/Cambio de monedas.md" "b/es/Programaci\303\263n dinamica/Cambio de monedas.md" index 92bd4425..7e1228a4 100644 --- "a/es/Programaci\303\263n dinamica/Cambio de monedas.md" +++ "b/es/Programaci\303\263n dinamica/Cambio de monedas.md" @@ -58,15 +58,6 @@ Digamos que tenemos 3 tipos de monedas `[1,2,3]`, y queremos cambiarlas por 7 ce Así que la respuesta final es **8**. 8 maneras de hacer un cambio de 7 centavos usando todos los tipos de monedas. `{{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}}` -#### Enlace de implementación de código - -* [Python](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/coin_change.py) -* [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/coin_change.cpp) -* [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java) -* [Dart](https://github.com/TheAlgorithms/Dart/blob/master/dynamic_programming/coin_change.dart) -* [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/dynamic_programming/coin_change.rb) -* [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/DynamicProgramming/CoinChange.scala) - #### Vídeo de explicación [Formas únicas totales de hacer el cambio de espaldas a espaldas SWE](https://www.youtube.com/watch?v=DJ4a7cmjZY0) diff --git "a/es/Programaci\303\263n dinamica/Subsecuencia com\303\272n m\303\241s larga.md" "b/es/Programaci\303\263n dinamica/Subsecuencia com\303\272n m\303\241s larga.md" index 1c8eb62e..d51e4f55 100644 --- "a/es/Programaci\303\263n dinamica/Subsecuencia com\303\272n m\303\241s larga.md" +++ "b/es/Programaci\303\263n dinamica/Subsecuencia com\303\272n m\303\241s larga.md" @@ -75,15 +75,6 @@ B 0 0 1 2 3 Así que la longitud de LCS es `dp[4] [4] = 3`. -#### Enlaces de implementación de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/longest_common_subsequence.py) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Dynamic%20Programming/Longest%20Common%20Subsequence.cpp) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/LongestCommonSubsequence.js) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/dynamicprogramming/longestCommonSubsequence.go) -- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/longest_common_subsequence.rs) - #### Explicación en YouTube [Explicación en YouTube de Tushar Roy](https://youtu.be/NnD96abizww) diff --git a/fr/filtres_audio/filtre_butterworth.md b/fr/filtres_audio/filtre_butterworth.md index 85b5d226..b02fc4ba 100644 --- a/fr/filtres_audio/filtre_butterworth.md +++ b/fr/filtres_audio/filtre_butterworth.md @@ -27,7 +27,3 @@ $$\tag{avec $p_k=\omega_ce^{\frac{j(2k+n-1)\pi}{2n}}$}H(p) = \frac{G_0}{\prod^n_ * On commence par calculer les différents coefficients pour le filtre. * On applique ces coefficients à un filtre IIR. - -## Implementation - -* [Python](https://github.com/TheAlgorithms/Python/audio_filters/butterworth_filter.py) diff --git a/fr/math/Determinant.md b/fr/math/Determinant.md index 57feedd4..717bdb0c 100644 --- a/fr/math/Determinant.md +++ b/fr/math/Determinant.md @@ -34,7 +34,3 @@ Calculons le déterminant de la matrice $\begin{bmatrix}1&2&3\\4&5&6\\7&8&9\end{ ### Conclusion Le déterminant de $\begin{bmatrix}1&2&3\\4&5&6\\7&8&9\end{bmatrix}$ est $0$. - -## Implémentation - -* [Python](https://github.com/TheAlgorithms/Python/blob/master/linear_algebra/src/lib.py) diff --git a/fr/math/Suite_de_Fibonacci.md b/fr/math/Suite_de_Fibonacci.md index c52ad099..b6ce3d60 100644 --- a/fr/math/Suite_de_Fibonacci.md +++ b/fr/math/Suite_de_Fibonacci.md @@ -40,7 +40,3 @@ Dans notre exemple nous cherchons à calculer F(6), le 7ème terme de la suite. ### Conclusion On a donc $F(6) = 8$ - -## Implémentation - -* [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/fibonacci.py) diff --git "a/fr/math/Suite_de_Fibonacci_r\303\251cursive.md" "b/fr/math/Suite_de_Fibonacci_r\303\251cursive.md" index e4549d03..12506035 100644 --- "a/fr/math/Suite_de_Fibonacci_r\303\251cursive.md" +++ "b/fr/math/Suite_de_Fibonacci_r\303\251cursive.md" @@ -41,7 +41,3 @@ Dans notre exemple nous cherchons à calculer $F(4)$, le 5ème terme de la suite ### Conclusion On a donc $F(4) = 3$ - -## Implémentation - -* [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/fibonacci_sequence_recursion.py) diff --git a/fr/tri/Tri_fusion.md b/fr/tri/Tri_fusion.md new file mode 100644 index 00000000..b2b12e4c --- /dev/null +++ b/fr/tri/Tri_fusion.md @@ -0,0 +1,48 @@ +# Tri Fusion + +## Description + +### Principe +Le tri fusion, aussi appelé "tri dichotomique" est un Algorithme de tri Stable, qui est basé sur la technique "diviser pour régner". + +### Complexités + +#### Complexités spatiale + +La complexité spatiale de l'algorithme est de `O(n)` + +#### Complexités temporelle + +- meilleur cas : `O(n log n)` +- cas moyens : `O(n log n)` +- pire cas : `O(n log n)` + +## Étapes + +- Trouvez le milieu du tableau et divisez le en deux moitiés en fonction du milieu. +- Appeler récursivement la fonction de tri fusion pour les deux moitiés +- Fusionnez les deux moitiés triées pour obtenir le tableau trié. + +## Exemple + +```txt +tab = [1, 9, 2, 5, 7, 3, 6, 4] + +Divisez le tableau en deux moitiés [1, 9, 2, 5] et [7, 3, 6, 4] + +Les deux moitiés ci-dessus ne sont pas encore triées, donc nous devons les diviser à nouveau en deux moitiés. + +Cette fois, nous obtenons quatre tableaux : [1, 9], [2, 5], [7, 3] et [6, 4]. + +les deux derniers tableaux ne sont toujours pas triés, donc nous les divisons à nouveau en deux moitiés et nous obtenons [7], [3], [6], and [4]. + +Puisqu'un tableau d'un seul élément est trié, nous avons maintenant tous les tableaux triés, il ne nous reste plus qu'à les fusionner de manière appropriée. + +D'abord, les tableaux d'un seul élément seront fusionnés vu qu'ils ont été divisés en dernier, et sont au sommet de la pile de récursion, donc nous obtenons [3,7] et [4,6]. + +Puis la fusion va se produire conformément à la pile de récurrence, [1, 9] et [2, 5] seront fusionnés et donneront [1, 2, 5, 9]. + +De même, [3, 7] et [4, 6] seront fusionnés et donneront [3, 4, 6, 7]. + +Au niveau suivant de la pile, [1, 2, 5, 9] et [3, 4, 6, 7] seront fusionnés et nous obtiendrons le tableau trié final comme [1, 2, 3, 4, 5, 6, 7, 9]. +``` diff --git a/fr/tri/Tri_par_insertion.md b/fr/tri/Tri_par_insertion.md index 7ac6b5aa..b03c5b02 100644 --- a/fr/tri/Tri_par_insertion.md +++ b/fr/tri/Tri_par_insertion.md @@ -44,10 +44,6 @@ Tri par insertion dans le : * [meilleur cas](../Exemples/tri/TriInsertionMeilleur.mp4) * [pire cas](../Exemples/tri/TriInsertionPire.mp4) -## Implémentation - -* [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/insertion_sort.py) - ## Pour aller plus loin * Dans le meilleur cas, nous n'effectuons qu'une unique comparaison. En effet, le terme comparé et plus grand que le terme juste avant, donc aucune modification n'est à effectuer. (ce qui correspond bien à $n$ opérations) diff --git a/fr/tri/Tri_par_selection.md b/fr/tri/Tri_par_selection.md new file mode 100644 index 00000000..e7f04bb6 --- /dev/null +++ b/fr/tri/Tri_par_selection.md @@ -0,0 +1,50 @@ +# Tri par Selection + +## Description + +### Principe + +Le tri par sélection est un algorithme de tri par comparaison, qui malgres sa simplicité est en generale considerer comme ineficasse de fait de sa complexité. + +### Complexités + +#### Complexités spatiale + +- `O(1)` + +#### Complexité temporelle + +- Pire, moyens et meilleur cas : `O(n^2)` + +## Étapes + +- Sélectionner le plus petit élément du tableau +- Le permuter avec le premier élément du tableau +- Puis sélectionner le plus petit élément du tableau dans la liste non triée restante +- Le permuter avec le premier élément du tableau dans la liste non triée restante +- Continuez à faire cela pour chaque élément du tableau + +## Exemple + +```txt + +tab[] = {80, 10, 40, 30} +Indexes : 0 1 2 3 + +1. Index = 0 + Sélectionnez le nombre minimum dans le tableau et son index (index entre 0-3), (la plus petite valeur est 10, et l'index est 1) +2. Permuter les indexe 1 et 0 (valeurs 10 et 80) +3. La nouvelle valeur du tableau est : {10, 80, 40, 30} + +4. Index = 1 + Sélectionnez le nombre minimum dans le tableau et son index (index entre 1-3), (la plus petite valeur est 30, et l'index est 3) +5. Permuter les indexe 3 et 1 (valeurs 30 et 80) +6. La nouvelle valeur du tableau est : {10, 30, 40, 80} + +7. Index = 2 + Sélectionnez le nombre minimum dans le tableau et son index (index entre 2-3), (la plus petite valeur est 40, et l'index est 2) +8. Permuter les indexe 2 et 2 (valeurs 40 et 40) +9. La nouvelle valeur du tableau est : {10, 30, 40, 80} + +Le Tableau est maintenant trié. +``` diff --git "a/fr/tri/Tri_\303\240_bulles.md" "b/fr/tri/Tri_\303\240_bulles.md" new file mode 100644 index 00000000..1d460c17 --- /dev/null +++ "b/fr/tri/Tri_\303\240_bulles.md" @@ -0,0 +1,75 @@ +# Tri à bulles + +## Description + +### Principe + +Le principe du tri à bulles est de comparer répétitivement les éléments consécutifs d'un tableau deux à deux, et de les permuter lorsque ces derniers sont mal trié. + +### Complexités + +#### Complexités temporelle + +- Dans le pire des cas, lorsque le plus petit élément est à la fin du tableau, la complexité est de `O(n^2)` +- Dans le meilleur cas, lorsque le tableau est déjà trié, la complexité est de `O(n)` (on n'effectue qu’une seule itération de l'algorithme) +- En moyenne, la complexité est de `O(n^2)` + + +## Étapes + +- Sélectionner le premier élément du tableau +- Le comparer avec l'élément suivant + - Si la valeur du premier élément est plus grande que celle du deuxième, permuter ces derniers. + - Sinon, ne rien faire +- Continuez à faire cela pour chaque index du tableau. +- Répétez les étapes précédentes n fois. + +## Exemple + +```txt +tab[] = {10, 80, 40, 30} +Indexes: 0 1 2 3 + +1. Index = 0, Valeur = 10 +2. 10 < 80, ne rien faire et continuer + +3. Index = 1, Valeur = 80 +4. 80 > 40, permuter 80 et 40 +5. Les nouvelles valeurs du tableau sont : {10, 40, 80, 30} + +6. Index = 2, Valeur = 80 +7. 80 > 30, permuter 80 et 30 +8. Les nouvelles valeurs du tableau sont : {10, 40, 30, 80} + +Répétez les étapes précédentes + +tab[] = {10, 40, 30, 80} +Indexes: 0 1 2 3 + +1. Index = 0, Valeur = 10 +2. 10 < 40, ne rien faire et continuer + +3. Index = 1, Valeur = 40 +4. 40 > 30, permuter 40 et 30 +5. Les nouvelles valeurs du tableau sont : {10, 30, 40, 80} + +6. Index = 2, Valeur = 40 +7. 40 < 80, ne rien faire +8. Les nouvelles valeurs du tableau sont : {10, 30, 40, 80} + +Répétez les étapes précédentes + +tab[] = {10, 30, 40, 80} +Indexes: 0 1 2 3 + +1. Index = 0, Valeur = 10 +2. 10 < 30, ne rien faire et continuer + +3. Index = 1, Valeur = 30 +4. 30 < 40, ne rien faire et continuer + +5. Index = 2, Valeur = 40 +6. 40 < 80, ne rien faire + +Puisqu'il n'y a pas de permutations dans les étapes précédentes, cela signifie que le tableau est trié et que nous pouvons nous arrêter ici. +``` diff --git "a/he/\327\236\327\252\327\236\327\230\327\231\327\247\327\224 \327\221\327\241\327\231\327\241\327\231\327\252/\327\236\327\241\327\244\327\250\327\231 \327\244\327\231\327\221\327\225\327\240\327\220\327\246'\327\231.md" "b/he/\327\236\327\252\327\236\327\230\327\231\327\247\327\224 \327\221\327\241\327\231\327\241\327\231\327\252/\327\236\327\241\327\244\327\250\327\231 \327\244\327\231\327\221\327\225\327\240\327\220\327\246'\327\231.md" index 6881e908..52411f28 100644 --- "a/he/\327\236\327\252\327\236\327\230\327\231\327\247\327\224 \327\221\327\241\327\231\327\241\327\231\327\252/\327\236\327\241\327\244\327\250\327\231 \327\244\327\231\327\221\327\225\327\240\327\220\327\246'\327\231.md" +++ "b/he/\327\236\327\252\327\236\327\230\327\231\327\247\327\224 \327\221\327\241\327\231\327\241\327\231\327\252/\327\236\327\241\327\244\327\250\327\231 \327\244\327\231\327\221\327\225\327\240\327\220\327\246'\327\231.md" @@ -79,13 +79,6 @@ F(8)=21 ``` -

יישום סדרת פיבונאצ'י בשפות תכנות שונות

- -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fibonacci.cpp) -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciNumber.java) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/80c2dc85d714f73783f133964d6acd9b5625ddd9/Maths/Fibonacci.js) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/fibonacci.py) -

קישור לסרטון הסבר

- [Youtube](https://www.youtube.com/watch?v=EEb6JP3NXBI) diff --git "a/ko/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/\353\266\204\355\225\240 \352\260\200\353\212\245\355\225\234 \353\260\260\353\202\255 \353\254\270\354\240\234.md" "b/ko/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/\353\266\204\355\225\240 \352\260\200\353\212\245\355\225\234 \353\260\260\353\202\255 \353\254\270\354\240\234.md" new file mode 100644 index 00000000..02885f8c --- /dev/null +++ "b/ko/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/\353\266\204\355\225\240 \352\260\200\353\212\245\355\225\234 \353\260\260\353\202\255 \353\254\270\354\240\234.md" @@ -0,0 +1,38 @@ +# 배낭 문제 (그리디 알고리즘) + +#### 문제 + +무게와 가치가 정해진 항목들의 집합이 주어졌을 때, 주어진 최대 무게 내에서 가치가 최대가 되도록 하는 항목의 수를 찾아라. + +##### 그리디 알고리즘은 분할 가능한 배낭 문제에서 항상 최적해를 제공한다. + +#### 시간 복잡도 + +최악: $O(nlog n)$ + +#### 예시 + +``` +배낭의 최대 무게 W = 60 +value = [280, 100, 120, 120] +weight = [40, 10, 20, 24] + +Ratio(V/W) = 7,10,6,5 +각 항목을 A,B,C,D라 하자. + +먼저 항목들을 가치와 무게의 비율을 기준으로 내림차순으로 정렬한다. +B는 배낭의 용량보다 작기 때문에 첫 번째로 선택된다. 다음으로, 남은 용량이 A의 무게보다 크기 때문에 A가 선택된다. +배낭의 남은 용량이 C의 무게보다 작기 때문에 C는 전체 항목을 선택할 수 없다. +따라서 C는 (60-50)/20의 비율만큼 일부만 선택된다. +이제 배낭의 용량은 지정된 항목들의 무게와 동일해서 더 이상 항목을 선택할 수 없다. + +선택된 물건들의 총 무게는 10+40+20*(10/20) = 60이다. + +총 이익은 100+280+120*(10/20) = 380+60 = 440이다. + +이것이 가장 적합한 선택이다. 다른 항목을 조합하여 더 많은 돈을 버는 것은 불가능하다. +``` + +#### 영상 URL + +[A CS50 video explaining the Greedy Algorithm](https://www.youtube.com/watch?v=Ou9OA0yQCYA) diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\223\261\353\271\204\354\210\230\354\227\264.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\223\261\353\271\204\354\210\230\354\227\264.md" index 71c9c6cf..2d1a571f 100644 --- "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\223\261\353\271\204\354\210\230\354\227\264.md" +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\223\261\353\271\204\354\210\230\354\227\264.md" @@ -23,7 +23,7 @@ **등비수열의 n번째 항 공식:** -가 초항, 이 공비일 때, 번째 항은: +$a$가 초항, $r$이 공비일 때, $n$번째 항은:

@@ -37,16 +37,15 @@ **등비수열에 관련된 문제를 풀기 위한 일반적인 공식:** -가 초항, 이 공비일 때: +$a$가 초항, $r$이 공비일 때: -- 등비급수 (r < 1) = -- 등비급수 (r > 1) = -- 무한등비급수 (r < 1) = +- 등비급수 $(r < 1) = \frac{a(1-r^n)}{1-r}$ +- 등비급수 $(r > 1) = \frac{a(r^n-1)}{r-1}$ +- 무한등비급수 $(r < 1) = \frac{a}{1-r}$ ## 영상 URL - [Don't Memorise](https://youtu.be/gua96ju_FBk) -- [Code Bashers (C++)](https://youtu.be/92ZldzuGUHs) ## 출처 diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\223\261\354\260\250\354\210\230\354\227\264.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\223\261\354\260\250\354\210\230\354\227\264.md" index 03a96763..23ac8ad7 100644 --- "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\223\261\354\260\250\354\210\230\354\227\264.md" +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\223\261\354\260\250\354\210\230\354\227\264.md" @@ -16,7 +16,7 @@ **등차수열의 n번째 항 공식:** -가 초항, 가 공차일 때, 번째 항은: +$a$가 초항, $d$가 공차일 때, $n$번째 항은:

@@ -30,10 +30,10 @@ **등차수열에 관련된 물제를 풀기 위한 일반적인 공식:** -가 초항, 가 공차일 때: +$a$가 초항, $d$가 공차일 때: - 산술평균 = `전체 항의 합 / 항의 개수` -- 등차급수 = `n * (초항 + 말항) / 2` = +- 등차급수 = `n * (초항 + 말항) / 2` = $\frac{n \cdot (2a + (n-1)d)}{2}$ ## 영상 URL diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\247\210\353\260\251\354\247\204.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\247\210\353\260\251\354\247\204.md" new file mode 100644 index 00000000..5639c404 --- /dev/null +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\353\247\210\353\260\251\354\247\204.md" @@ -0,0 +1,72 @@ +# 마방진이란? + +마방진이란 모든 행, 열, 주대각선과 일반적으로 다른 대각선의 일부 혹은 모든 대각선 방향으로 수를 모두 더하면 그 합이 같도록 배열된 고유한 정수를 포함하는 정사각형으로 정의한다. + +# 마방진 공식 + +`n`차 마방진은 일반적으로 `n²`개의 고유한 정수 숫자들을 정사각형 안에 정리한 것이다. 모든 행, 열, 대각선의 `n` 개의 숫자를 합하면 같은 상수가 된다. 마방진은 1부터 `n²`까지의 정수를 가진다. 모든 행, 열 및 대각선의 고정 합을 마법 상수 또는 마법합이라고 한다. 이를 M이라는 문자로 표시한다. 전형적인 마방진의 마법 상수는 전적으로 `n`의 값에 따라 결정된다. 따라서 마법합의 값은 다음 공식을 사용하여 계산한다: + +- M = `n(n² + 1)/2` + +- 이는 다른 차수의 마방진을 만드는 데 사용되는 마방진 공식이다. (`n²` + 1)에서 각 위치의 숫자를 빼면, 또 다른 마방진을 만들 수 있는데, 이를 서로 보완적인 마방진(complementary magic square)이라고 부른다. 그리고 1부터 시작하여 연속된 자연수들로 이루어진 마방진을 정규(normal) 마방진이라고 알려져 있다. + +# 마방진을 푸는 방법 + +위에서 언급한 바와 같이, 마법합의 공식은 n(n² + 1)/2이다.\ +3차 마방진에 경우, n = 3 을 대입하여 마법합의 값을 구한다면 3×3 마방진을 쉽게 형성할 수 있다. + +`n = 3`일 경우, 마법합 = 3(3\*3 + 1)/2 = 3(9 + 1)/2 = (3 × 10)/2 = 15이다.\ +이제, 우리는 각 행, 열, 대각선 방향으로 더한 숫자들의 합이 15와 동일하도록 각각의 위치에 숫자를 배치해야 한다. + +## 3차 마방진 만들기 요령 + +`x`를 마방진의 차수라고 하자. + +이 경우, `x = 3`이다. + +`x`와 `y`의 곱이 마법합의 값인 15가 되는 또 다른 숫자 `y`를 생각해 보자. + +그렇다면, `y = 5 {xy = (3)(5) = 15}` + +y의 값은 항상 정사각형 정중앙에 있어야 하고, x의 값은 y의 값 왼쪽 셀에 있어야 한다.\ +x 위의 셀은 아래의 이미지처럼 y – 1를 가진다: + +![magic-square-formula](https://user-images.githubusercontent.com/106215707/192823452-3eea7074-c8f0-4b30-9e83-ef7fb6641a01.png) +![magic-square-1](https://user-images.githubusercontent.com/106215707/192823521-c992c61b-055a-4af8-b697-71fb0ed22566.png) +![magic-square-2](https://user-images.githubusercontent.com/106215707/192823583-8a375043-21d7-4a74-b2d8-119a6ca727eb.png) + +위 마방진의 서로 보완적인 마방진(complementary magic square)을 만들자. + +`(n² + 1) = 32 + 1 = 9 + 1 = 10` + +이제, (n² + 1)의 값인 10에서 각 숫자를 빼라. + +- 첫 번째 행의 숫자들: + + - 10 – 4 = 6 + - 10 – 3 = 7 + - 10 – 8 = 2 + +- 두 번째 행의 숫자들: + + - 10 – 9 = 1 , + - 10 – 5 = 5 , + - 10 – 1 = 9 + +- 세 번째 행의 숫자들: + - 10 – 2 = 8 , + - 10 – 7 = 3 , + - 10 – 6 = 4 + +![magic-square-3](https://user-images.githubusercontent.com/106215707/192823650-21655cfe-0b8f-4bcb-b7d0-76280770c615.png) + +# 참조 + +## 웹사이트 + +- [Byjus](https://byjus.com/maths/magic-square/) +- [geeksforgeeks](https://www.geeksforgeeks.org/magic-square/) + +## The Algorithms 페이지 + +- [마방진](https://the-algorithms.com/ko/algorithm/magic-square) diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\234\240\355\201\264\353\246\254\353\223\234 \354\225\214\352\263\240\353\246\254\354\246\230.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\234\240\355\201\264\353\246\254\353\223\234 \354\225\214\352\263\240\353\246\254\354\246\230.md" new file mode 100644 index 00000000..d0c7fb0d --- /dev/null +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\234\240\355\201\264\353\246\254\353\223\234 \354\225\214\352\263\240\353\246\254\354\246\230.md" @@ -0,0 +1,92 @@ +# 유클리드 알고리즘 + +## 문제 + +양의 정수 $a$와 $b$의 최대공약수 $g = gcd(a, b)$를 구하시오. 여기서 $g$는 나머지 없이 $a$와 $b$ 모두 나누는 가장 큰 수로 정의한다. + +## 발상 + +유클리드 알고리즘은 큰 수에서 작은 수를 빼면 두 수의 최대공약수가 변하지 않는다는 단순한 관찰을 기반한다: + +$a > b$인 상황에서 $g$는 $a$와 $b$의 최대공약수라고 하자. +그렇다면 $g$는 $a$와 $b$를 나눌 수 있다. 따라서 $g$는 $a - b$도 나눌 수 있다. (분배법칙) + +$g'$를 $b$와 $a - b$의 최대공약수라 하자. + +$g' = g$ 귀류법: + +$g' < g$ 또는 $g' > g$이라고 가정하자. + +$g' < g$일 때, $g'$는 _최대_ 공약수가 될 수 없다. +$g$도 $a - b$와 $b$의 공약수이기 때문이다. + +$g' > g$일 때, $g'$는 $b$와 $a - b$의 약수이다 - +즉, $g'n = b$와 $g'm = a - b$로 표현할 수 있는 정수 $n, m$이 존재한다. +따라서 $g'm = a - g'n \iff g'm + g'n = a \iff g'(m + n) = a$이다. +이는 $g'$도 $a$의 약수이며, $g$가 $a$와 $b$의 최대공약수라는 초기 가정과 $g' > g$는 모순이다. + +## 구현 + +실제 실행에서 속도를 높이기 위해 반복해서 뺄셈하는 대신 나머지 연산이 사용된다: +$b$는 $a >= b$만큼 $a$에서 여러 번 반복해서 뺄 수 있다. +이러한 뺄셈 후에는 $b$로 나눌 때 $a$의 나머지만 남게 된다. + +간단한 Lua 구현은 다음과 같다: + +```lua +function gcd(a, b) + while b ~= 0 do + a, b = b, a % b + end + return a +end +``` + +`%`가 나머지 연산자임을 유의하자; +각 단계에서 새로운 `a`에 `b`를 할당하고, +새로운 `b`에는 `a`를 `b`로 나눈 나머지 연산한 값을 할당한다. + +## 분석 + +### 공간 복잡도 + +공간 복잡도는 약간 일정하다: +(일정한 크기로 가정된) $a$와 $b$라는 두 개의 숫자만 저장한다. + +### 시간 복잡도 + +while문의 각 반복은 일정한 시간에 실행되며 최소한 $b$를 절반으로 줄인다. 따라서 $O(log_2(n))$는 런타임의 상한값이다. + +## 연습 + +$a = 42$와 $b = 12$의 최대공약수를 구하라: + +1. $42 \mod 12 = 6$ +2. $12 \mod 6 = 0$ + +결과는 $gcd(42, 12) = 6$. + +유클리드 알고리즘을 사용하여 $a = 633$와 $b = 142$의 최대공약수를 구하라: + +1. $633 \mod 142 = 65$ +2. $142 \mod 65 = 12$ +3. $65 \mod 12 = 5$ +4. $12 \mod 5 = 2$ +5. $5 \mod 2 = 1$ +6. $2 \mod 1 = 0$ + +결과는 $gcd(633, 142) = 1$: $a$와 $b$는 서로소이다. + +## 활용 + +- 분수 단축하기 +- 최소공배수 구하기 +- 두 수가 서로소인지 효율적으로 확인하기 (예: RSA 암호화 시스템에 필요) + +## 참고자료 + +- [위키피디아 "유클리드 호제법" 항목](https://ko.wikipedia.org/wiki/%EC%9C%A0%ED%81%B4%EB%A6%AC%EB%93%9C_%ED%98%B8%EC%A0%9C%EB%B2%95) + +## The Algorithms 페이지 + +- [유클리드 알고리즘](https://the-algorithms.com/ko/algorithm/euclidean-gcd) diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\236\220\353\246\277\354\210\230.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\236\220\353\246\277\354\210\230.md" index 09c2f4fe..114be2d0 100644 --- "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\236\220\353\246\277\354\210\230.md" +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\236\220\353\246\277\354\210\230.md" @@ -24,7 +24,7 @@ N = 10000 [양수] 3. N을 10으로 나눈다. 4. N이 0이 될 때까지 위의 과정을 반복한다. -**알고리즘 분석:** 위 방법에서 수행되는 작업의 수는 숫자 N의 자릿수와 같다는 사실을 쉽게 알 수 있다. 따라서 이 방법의 시간 복잡도는 이다. (는 숫자 N의 자릿수) +**알고리즘 분석:** 위 방법에서 수행되는 작업의 수는 숫자 N의 자릿수와 같다는 사실을 쉽게 알 수 있다. 따라서 이 방법의 시간 복잡도는 $O(d)$이다. ($d$는 숫자 N의 자릿수) **모의 실행:** `N = 58964`라고 할 때, diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\247\204\354\225\275\354\210\230\354\235\230 \355\225\251.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\247\204\354\225\275\354\210\230\354\235\230 \355\225\251.md" new file mode 100644 index 00000000..8014d44b --- /dev/null +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\247\204\354\225\275\354\210\230\354\235\230 \355\225\251.md" @@ -0,0 +1,48 @@ +# 진약수의 합 + +$s(n)$은 양의 정수 $n$에 대한 모든 진약수의 합을 구하는 표현식이다. 여기서, 진약수는 자기 자신인 $n$을 제외한 $n$의 모든 약수를 의미한다. + +$$ s(n) = \sum\_{d | n, d \neq n} {d} $$ + +예를 들면, $15$ 에 대한 진약수의 합은 $(1 + 3 + 5) = 9$ 이다. + +진약수의 합은 정수론에서 매우 유용한 성질이며, 다음을 정의하는 데 사용할 수 있다: + +- 소수(Prime Numbers) +- 부족수(Deficient Numbers) +- 과잉수(Abundant Numbers) +- 완전수(Perfect Numbers) +- 친화수(Amicable Numbers) +- 불가촉수(Untouchable Numbers) +- 진약수의 합 수열(Aliquot Sequence of a number) +- 준완전수&근완전수(Quasiperfect & Almost Perfect Numbers) +- 사교수(Sociable Numbers) + +## 진약수의 합에 관한 사실들 + +- 1은 진약수의 합이 0인 유일한 수 +- 완전수는 진약수들의 합이 자기 자신이 되는 수 +- $pq$처럼 곱셈 형태인 [_준소수_](https://en.wikipedia.org/wiki/Semiprime)에 대한 진약수의 합은 $p + q + 1$ 이다 (p와 q는 1이 아닌 서로 다른 숫자인 상황을 가정) +- 진약수의 합은 세계적으로 유명한 수학자 [Paul Erdős](https://en.wikipedia.org/wiki/Paul_Erd%C5%91s)가 가장 좋아하는 조사 주제 중 하나 + +## 진약수의 합을 찾는 접근방식 + +### 1단계: _진약수 구하기_ + +$1$부터 $[\frac{n} 2]$까지의 모든 수를 반복하여, $n$을 나눌 수 있는지 확인하고, 분할할 수 있다면 진약수에 추가한다. + +$[\frac{n} 2]$와 같은 상계를 가지는 이유는 $n$이 짝수인 경우, 가능한 진약수 중 가장 큰 진약수는 $\frac{n} 2 $이며, $n$이 홀수인 경우, 가능한 진약수 중 가장 큰 진약수가 $[\frac{n} 2]$보다 작다. 따라서, 상계를 만들어 계산하는 방법이 $1$부터 $n$까지 모든 수를 반복하는 방법보다 불필요한 계산을 줄일 수 있다. + +### 2단계: _진약수 더하기_ + +이렇게 구한 합은 진약수의 합이다 + +## 출처 + +- [위키피디아 "진약수의 합" 항목](https://ko.wikipedia.org/wiki/%EC%A7%84%EC%95%BD%EC%88%98%EC%9D%98_%ED%95%A9) +- [Wikipedia "Aliquot sum" 항목](https://en.wikipedia.org/wiki/Aliquot_sum) +- [GeeksForGeeks](https://www.geeksforgeeks.org/aliquot-sum/) + +## The Algorithms 페이지 + +- [진약수의 합](https://the-algorithms.com/ko/algorithm/aliquot-sum) diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\265\234\353\214\223\352\260\222.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\265\234\353\214\223\352\260\222.md" index 6b3596cc..2eb04336 100644 --- "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\265\234\353\214\223\352\260\222.md" +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\354\265\234\353\214\223\352\260\222.md" @@ -85,10 +85,6 @@ `70`을 반환한다. -## 구현 - -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) - ## 영상 URL - [GeeksforGeeks](https://youtu.be/En68ipRaFOU) diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\355\217\211\352\267\240\352\260\222.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\355\217\211\352\267\240\352\260\222.md" index 7212ef98..553fcacf 100644 --- "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\355\217\211\352\267\240\352\260\222.md" +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\355\217\211\352\267\240\352\260\222.md" @@ -55,14 +55,9 @@ count = 7 22.857142나 23을 반환한다. -## 구현 - -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/average_mean.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/maths/average_mean.rb) - ## 영상 URL -- [Khan Academy](https://www.khanacademy.org/math/ap-statistics/summarizing-quantitative-data-ap/measuring-center-quantitative/v/mean-median-and-mode) +- [Khan Academy](https://www.khanacademy.org/math/cc-sixth-grade-math/cc-6th-data-statistics/mean-and-median/v/mean-median-and-mode) ## 기타 diff --git "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\355\224\274\353\263\264\353\202\230\354\271\230 \354\210\230.md" "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\355\224\274\353\263\264\353\202\230\354\271\230 \354\210\230.md" index a2d9338c..b1731808 100644 --- "a/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\355\224\274\353\263\264\353\202\230\354\271\230 \354\210\230.md" +++ "b/ko/\352\270\260\354\264\210 \354\210\230\355\225\231/\355\224\274\353\263\264\353\202\230\354\271\230 \354\210\230.md" @@ -65,13 +65,6 @@ F(8) = 21 ``` -## 구현 - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fibonacci.cpp) -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciNumber.java) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/80c2dc85d714f73783f133964d6acd9b5625ddd9/Maths/Fibonacci.js) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/fibonacci.py) - ## 영상 URL - [Gaurav Sen](https://www.youtube.com/watch?v=EEb6JP3NXBI) diff --git "a/ko/\354\204\240\355\203\235 \354\225\214\352\263\240\353\246\254\354\246\230/\355\200\265 \354\205\200\353\240\211\355\212\270.md" "b/ko/\354\204\240\355\203\235 \354\225\214\352\263\240\353\246\254\354\246\230/\355\200\265 \354\205\200\353\240\211\355\212\270.md" index 7a6bdfb6..94779760 100644 --- "a/ko/\354\204\240\355\203\235 \354\225\214\352\263\240\353\246\254\354\246\230/\355\200\265 \354\205\200\353\240\211\355\212\270.md" +++ "b/ko/\354\204\240\355\203\235 \354\225\214\352\263\240\353\246\254\354\246\230/\355\200\265 \354\205\200\353\240\211\355\212\270.md" @@ -40,13 +40,6 @@ k = 4, 즉 4번째로 작은 원소를 찾고 싶다고 하자. 4. 7의 위치가 4번째이므로, 우리가 찾는 원소이다. 7을 반환한다. ``` -### 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/QuickSelect.java) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/quick_select.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/search/selectk.go) -- [JavaScript](https://github.com/TheAlgorithms/JavaScript/blob/master/Data-Structures/Array/QuickSelect.js) - ### 관련 영상 [여러가지 시간 복잡도에 따라 K번째로 작은/큰 원소를 찾는 방법을 설명하는 영상](https://youtu.be/hGK_5n81drs) diff --git "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\352\267\270\353\236\230\355\224\204/\353\262\250\353\250\274-\355\217\254\353\223\234 \354\225\214\352\263\240\353\246\254\354\246\230.md" "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\352\267\270\353\236\230\355\224\204/\353\262\250\353\250\274-\355\217\254\353\223\234 \354\225\214\352\263\240\353\246\254\354\246\230.md" index a632daec..a5f41609 100644 --- "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\352\267\270\353\236\230\355\224\204/\353\262\250\353\250\274-\355\217\254\353\223\234 \354\225\214\352\263\240\353\246\254\354\246\230.md" +++ "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\352\267\270\353\236\230\355\224\204/\353\262\250\353\250\274-\355\217\254\353\223\234 \354\225\214\352\263\240\353\246\254\354\246\230.md" @@ -2,15 +2,15 @@ ## 문제 -방향 가중치 그래프 와 시작점 가 주어졌을 때, 각 점 에 대하여 를 잇는 가장 짧은 경로를 구하라. (는 꼭짓점의 집합, 는 간선의 집합) +방향 가중치 그래프 $G(V, E)$와 시작점 $s \in V$가 주어졌을 때, 각 점 $v \in V$에 대하여 $s$와 $v$를 잇는 가장 짧은 경로를 구하라. ($V$는 꼭짓점의 집합, $E$는 간선의 집합) ## 절차 1. 시작점에서 모든 꼭짓점까지의 거리를 무한대로 초기화한다. 2. 시작점으로의 거리를 0으로 초기화한다. -3. `dist[s]`를 제외한 모든 값을 무한대로 하는 크기가 인 `dist`라는 배열을 만든다. -4. 다음을 회 반복한다. -5. 에 속한 모든 간선 `(u,v)`에 대해 다음을 반복한다: +3. `dist[s]`를 제외한 모든 값을 무한대로 하는 크기가 $|V|$인 `dist`라는 배열을 만든다. +4. 다음을 $|V|-1$회 반복한다. +5. $E$에 속한 모든 간선 `(u,v)`에 대해 다음을 반복한다: ``` dist[v] = minimum(dist[v], dist[u] + weight of edge) @@ -20,11 +20,11 @@ ## 시간 복잡도 - +$O(VE)$ ## 공간 복잡도 - +$O(V^2)$ ## 만든 사람 @@ -94,13 +94,6 @@ E 1 (A->B->E = -1 + 2) ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Dynamic%20Programming/Bellman-Ford.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/graph/bellman_ford.py) -- [C](https://github.com/TheAlgorithms/C/blob/master/data_structures/graphs/Bellman-Ford.c) - ## 영상 URL - [Yusuf Shakeel (C)](https://www.youtube.com/watch?v=hxMWBBCpR6A) diff --git "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\353\260\260\354\227\264/\353\260\260\354\227\264.md" "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\353\260\260\354\227\264/\353\260\260\354\227\264.md" index 35612e38..78536127 100644 --- "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\353\260\260\354\227\264/\353\260\260\354\227\264.md" +++ "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\353\260\260\354\227\264/\353\260\260\354\227\264.md" @@ -2,7 +2,7 @@ 배열은 프로그래밍에서 가장 기본적인 데이터 구조이다. 배열은 정적 배열과 동적 배열로 나눠진다. 정적 배열은 요소의 수가 고정되어 있고, 각각은 메모리의 동일한 공간을 차지한다. 즉, 정적 배열이 차지하는 메모리는 컴파일 시간에 결정되지만, 동적 배열의 경우 크기가 고정되지 않는다. -배열 요소의 값은 시간 안에 검색할 수 있다. +배열 요소의 값은 $O(1)$ 시간 안에 검색할 수 있다. 모든 배열은 연속된 메모리 주소를 가진다. 우리는 인덱스로 각 요소에 접근할 수 있다. 가장 낮은 인덱스는 첫 요소에 해당하고 가장 높은 인덱스는 마지막 요소에 해당한다. diff --git "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\212\244\355\203\235/\354\212\244\355\203\235.md" "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\212\244\355\203\235/\354\212\244\355\203\235.md" new file mode 100644 index 00000000..50106851 --- /dev/null +++ "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\212\244\355\203\235/\354\212\244\355\203\235.md" @@ -0,0 +1,27 @@ +# 스택 + +스택은 객체에 접근하는 순서가 정해진 기본적인 선형 데이터 구조이다. 이 순서는 LIFO (Last In First Out) 또는 FILO (First in Last Out)라고 불린다. 대표적인 스택 예시로는 식당의 접시, 쌓인 책 더미, 프링글스 상자 등이 있다. +스택은 파서 및 식 평가, 백트래킹 알고리즘 등을 구현하는 데 사용된다. 기본 작업은 스택에 요소를 넣는 것(push)과 스택에서 요소를 빼는 것(pop)이다. +연결 리스트 또는 리스트 배열을 사용하여 구현할 수 있다. 스택은 가장 위에 있는 요소를 가리키는 "top 포인터" 하나만 가진다. 삽입과 삭제는 스택의 한쪽 끝에서만 발생한다. + +# 표준 스택 연산자 + +1) push(): 스택의 맨 위에 요소 삽입 +2) pop(): 스택의 맨 위에 있는 요소 삭제 +3) isEmpty(): 스택이 비어 있는지 여부 확인 +4) isFull(): 스택이 가득 찼는지 여부 확인 +5) peek(): 맨 위에 있는 요소의 값을 가져옴(제거X) + +# 스택으로 작업하기 + +스택에서는 TOP이라는 포인터를 사용하여 스택의 맨 위에 있는 요소를 추적한다. 스택을 초기화할 때, TOP의 값을 -1로 설정하여 TOP == -1인 경우 스택이 비어 있는지 확인할 수 있다. 요소를 push할 때마다, TOP의 값을 증가시키고, TOP이 가리키는 위치에 새로운 요소를 넣는다. 요소를 pop할 때, TOP이 가리키는 값을 반환하고, TOP의 값을 감소시킨다. push하기 전에 스택이 가득 차 있는지 확인하고, pop하기 전에 스택이 이미 비어 있는지 확인한다. + +# 소스 + +1) [Stack Data Structure - GeeksForGeeks](https://www.geeksforgeeks.org/stack-data-structure/) +2) [DS-Stack JavaPoint](https://www.javatpoint.com/data-structure-stack) +3) [Stack Data Structure](https://www.programiz.com/dsa/stack) + +# 영상 URL + +- [Stack Data Structure](https://youtu.be/F1F2imiOJfk) diff --git "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\353\213\250\354\235\274 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\353\213\250\354\235\274 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" index ac53bd43..d07fe863 100644 --- "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\353\213\250\354\235\274 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" +++ "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\353\213\250\354\235\274 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" @@ -14,12 +14,12 @@ ### 시간 복잡도 -| 작업 | 평균 | 최악 | -| ---- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | -| 접근 | | | -| 탐색 | | | -| 삽입 | | | -| 제거 | | | +| 작업 | 평균 | 최악 | +| --- | ------ | ------ | +| 접근 | $O(n)$ | $O(n)$ | +| 탐색 | $O(n)$ | $O(n)$ | +| 삽입 | $O(1)$ | $O(1)$ | +| 제거 | $O(1)$ | $O(1)$ | ## 예시 @@ -38,13 +38,6 @@ class LinkedList { } ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Data%20Structure/Linked%20List.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/singly_linked_list.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/single_list.rb) - ## 영상 URL - [CS50](https://www.youtube.com/watch?v=5nsKtQuT6E8) diff --git "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\354\233\220\355\230\225 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\354\233\220\355\230\225 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" index 623c3f24..5e956227 100644 --- "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\354\233\220\355\230\225 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" +++ "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\354\233\220\355\230\225 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" @@ -37,7 +37,7 @@ ### SLL v.s. CLL -![영상](https://i0.wp.com/algorithms.tutorialhorizon.com/files/2016/03/Circular-Linked-List.png) +![영상](https://tutorialhorizon.com/static/media/algorithms/2016/03/Circular-Linked-List.png) ### 예시 @@ -64,12 +64,6 @@ public void insertHead(int data) } ``` -## 구현 - -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Linked-List/SingleCircularLinkedList.js.js) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/cll/cll.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/circular_linked_list.py) - ## 영상 URL [유투브 영상](https://youtu.be/HMkdlu5sP4A) diff --git "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\354\235\264\354\244\221 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\354\235\264\354\244\221 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" index 2fb6a7f8..df89bcec 100644 --- "a/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\354\235\264\354\244\221 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" +++ "b/ko/\354\236\220\353\243\214\352\265\254\354\241\260/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/\354\235\264\354\244\221 \354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270.md" @@ -18,12 +18,12 @@ ### 시간 복잡도 -| 작업 | 평균 | 최악 | -| ---- | --------------------------------------------------------------------------- | ---------------------------------------------------------------------- | -| 접근 | | | -| 탐색 | | | -| 삽입 | | | -| 제거 | | | +| 작업 | 평균 | 최악 | +| --- | ----------- | ------ | +| 접근 | $\Theta(n)$ | $O(n)$ | +| 탐색 | $\Theta(n)$ | $O(n)$ | +| 삽입 | $\Theta(1)$ | $O(1)$ | +| 제거 | $\Theta(1)$ | $O(1)$ | ## 예시 @@ -100,14 +100,6 @@ class LinkedList { } ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Data%20Structure/Doubly%20Linked%20List.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/doubly_linked_list.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/data-structures/linked-list/double-linkedlist.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/double_list.rb) - ## 영상 URL - [CS50](https://www.youtube.com/watch?v=FHMPswJDCvU) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\352\263\204\354\210\230 \354\240\225\353\240\254.md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\352\263\204\354\210\230 \354\240\225\353\240\254.md" index a388f7e0..4f53712e 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\352\263\204\354\210\230 \354\240\225\353\240\254.md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\352\263\204\354\210\230 \354\240\225\353\240\254.md" @@ -15,11 +15,11 @@ n개 원소로 구성된 배열이 주어졌을 때, 이 배열을 정렬하는 ## 시간 복잡도 -- (는 음수가 아닌 key 값의 범위) +- $O(n+k)$ ($k$는 음수가 아닌 key 값의 범위) ## 공간 복잡도 -- (는 음수가 아닌 key 값의 범위) +- $O(n+k)$ ($k$는 음수가 아닌 key 값의 범위) ## 만든 사람 @@ -41,15 +41,6 @@ countingSort(array, size) decrease count of each element restored by 1 ``` -## 구현 - -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/counting_sort.c) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/counting_sort.cpp) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/CountingSort.js) -- [Matlab](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/counting_sort.m) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/counting_sort.py) -- [Rust](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/counting_sort.rs) - ## 영상 URL - [GeeksforGeeks](https://www.youtube.com/watch?v=7zuGmKfUt7s) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\262\204\353\270\224 \354\240\225\353\240\254 (\354\236\254\352\267\200 \353\262\204\354\240\204).md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\262\204\353\270\224 \354\240\225\353\240\254 (\354\236\254\352\267\200 \353\262\204\354\240\204).md" index 2ef2515e..2c65b559 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\262\204\353\270\224 \354\240\225\353\240\254 (\354\236\254\352\267\200 \353\262\204\354\240\204).md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\262\204\353\270\224 \354\240\225\353\240\254 (\354\236\254\352\267\200 \353\262\204\354\240\204).md" @@ -12,12 +12,12 @@ Base case: If the size of the array is 1, return. ## 시간 복잡도 -- 최선: -- 평균: +- 최선: $O(n)$ +- 평균: $O(n^2)$ ## 공간 복잡도 -- 최악: (참고: 기존 버블 정렬의 공간 복잡도는 ) +- 최악: $O(n)$ (참고: 기존 버블 정렬의 공간 복잡도는 $O(1)$) ## 예시 @@ -69,11 +69,6 @@ void bubbleSort(arr[], n) bubbleSort(arr, n-1) ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/BubbleSortRecursion.java) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/bubble_sort_recursion.c) - ## 영상 URL - [Programming Tutorials](https://www.youtube.com/watch?v=gDMDVLBfCI0) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\262\204\353\270\224 \354\240\225\353\240\254.md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\262\204\353\270\224 \354\240\225\353\240\254.md" index 776d1982..577e27a3 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\262\204\353\270\224 \354\240\225\353\240\254.md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\262\204\353\270\224 \354\240\225\353\240\254.md" @@ -79,18 +79,6 @@ $O(1)$ 최악의 경우 위 단계에서 교환이 없기 때문에 배열이 정렬되었음을 의미하고, 여기서 멈출 수 있다. ``` -## 구현 - -- [자바](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bubble_sort.cpp) -- [파이썬](https://github.com/TheAlgorithms/Python/blob/master/sorts/bubble_sort.py) -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/BubbleSorter.cs) -- [고](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubblesort.go) -- [루비](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/bubble_sort.c) -- [스칼라](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/BubbleSort.scala) -- [자바스크립트](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/BubbleSort.js) - ## 영상 URL - [버블정렬 알고리즘에 대한 영상 설명](https://www.youtube.com/watch?v=Jdtq5uKz-w4) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\263\221\355\225\251 \354\240\225\353\240\254.md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\263\221\355\225\251 \354\240\225\353\240\254.md" index 93669e29..905846b3 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\263\221\355\225\251 \354\240\225\353\240\254.md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\353\263\221\355\225\251 \354\240\225\353\240\254.md" @@ -12,11 +12,11 @@ n개 원소로 구성된 배열이 주어졌을 때, 이 배열을 정렬하는 ## 시간 복잡도 -- +- $O(n \log n)$ ## 공간 복잡도 -- +- $O(n)$ ## 예시 @@ -31,15 +31,6 @@ Recursively call merge sort function for both these halves which will provide so Now merge both these halves to get the sorted array [0, 1, 2, 3, 5, 9] ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/MergeSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/merge_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort.py) -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/MergeSorter.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/merge_sort.c) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/merge_sort.rb) - ## 영상 URL - [CS50](https://www.youtube.com/watch?v=EeQ8pwjQxTM) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\202\275\354\236\205 \354\240\225\353\240\254.md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\202\275\354\236\205 \354\240\225\353\240\254.md" index 0d66ae1a..7b9b3310 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\202\275\354\236\205 \354\240\225\353\240\254.md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\202\275\354\236\205 \354\240\225\353\240\254.md" @@ -14,15 +14,15 @@ n개 원소로 구성된 배열이 주어졌을 때, 이 배열을 정렬하는 ## 시간 복잡도 - 최악 - - 비교: - - 교환: + - 비교: $O(n^2)$ + - 교환: $O(n^2)$ - 최선 - - 비교: - - 교환: + - 비교: $O(n)$ + - 교환: $O(1)$ ## 공간 복잡도 -- 최악: ([In-place 알고리즘](https://en.wikipedia.org/wiki/In-place_algorithm)으로, 추가적인 메모리 할당이 필요하지 않다) +- 최악: $O(1)$ ([In-place 알고리즘](https://en.wikipedia.org/wiki/In-place_algorithm)으로, 추가적인 메모리 할당이 필요하지 않다) ## 예시 @@ -51,16 +51,6 @@ and elements from 11 to 13 will move one position ahead of their current positio 5, 6, 11, 12, 13 -- sorted array ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/InsertionSort.java) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/insertion_sort.c) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/insertion_sort.cpp) -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/InsertionSorter.cs) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/InsertionSort.scala) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/insertion_sort.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/insertion_sort.rb) - ## 영상 URL - [CS50](https://www.youtube.com/watch?v=DFG-XuyPYUQ) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\204\240\355\203\235 \354\240\225\353\240\254.md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\204\240\355\203\235 \354\240\225\353\240\254.md" index 073421eb..1f81c92a 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\204\240\355\203\235 \354\240\225\353\240\254.md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\204\240\355\203\235 \354\240\225\353\240\254.md" @@ -15,13 +15,13 @@ n개 원소로 구성된 배열이 주어졌을 때, 이 배열을 정렬하는 ## 시간 복잡도 -- 최악: -- 최선: -- 평균: +- 최악: $O(n^2)$ +- 최선: $O(n^2)$ +- 평균: $O(n^2)$ ## 공간 복잡도 -- 최악: +- 최악: $O(1)$ ## 예시 @@ -47,17 +47,6 @@ Indexes: 0 1 2 3 The array is now sorted. ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/SelectionSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Selection%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/selection_sort.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/selection_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/selection_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/SelectionSort.c) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/SelectionSort.scala) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/selectionSort.js) - ## 영상 URL - [CS50](https://www.youtube.com/watch?v=f8hXR_Hvybo) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\205\270 \354\240\225\353\240\254.md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\205\270 \354\240\225\353\240\254.md" index a7a32492..81efb901 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\205\270 \354\240\225\353\240\254.md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\354\205\270 \354\240\225\353\240\254.md" @@ -14,15 +14,15 @@ n개 원소로 구성된 배열이 주어졌을 때, 이 배열을 정렬하는 ## 시간 복잡도 -셸 정렬의 시간 복잡도는 gap sequences에 따라 다르다. 아래 시간 복잡도는 의 gap sequences를 가정한다. +셸 정렬의 시간 복잡도는 gap sequences에 따라 다르다. 아래 시간 복잡도는 $(\frac{n}{2})^k$의 gap sequences를 가정한다. -- 최악: -- 최선: -- 평균: +- 최악: $O(n^2)$ +- 최선: $O(n)$ +- 평균: $O(n^2)$ ## 공간 복잡도 -- 최악: +- 최악: $O(1)$ ## 만든 사람 @@ -52,17 +52,6 @@ Initial Gap: 4 12. Divide the gap by 2 and repeat until gap = 1 ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/ShellSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Shell%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/shell_sort.py) -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/ShellSorter.cs) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/shell_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/shell_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/shellSort.c) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/shellSort.js) - ## 영상 URL - [Computer Education for All](https://www.youtube.com/watch?v=H8NiFkGu2PY) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\355\200\265 \354\240\225\353\240\254.md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\355\200\265 \354\240\225\353\240\254.md" index e9ff369b..07a8c779 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\355\200\265 \354\240\225\353\240\254.md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\355\200\265 \354\240\225\353\240\254.md" @@ -13,13 +13,13 @@ n개 원소로 구성된 배열이 주어졌을 때, 이 배열을 정렬하는 ## 시간 복잡도 -- 최악: -- 최선: -- 평균: +- 최악: $O(n^2)$ +- 최선: $O(n \log n)$ +- 평균: $O(n \log n)$ ## 공간 복잡도 -- 최악: +- 최악: $O(\log n)$ ## 만든 사람 @@ -67,13 +67,6 @@ Now 70 is at its correct place. All elements smaller than it. ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/QuickSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Quick%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/quick_sort.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/quicksort.rb) - ## 영상 URL - [mycodeschool](https://www.youtube.com/watch?v=COk73cpQbFQ) diff --git "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\355\236\231 \354\240\225\353\240\254.md" "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\355\236\231 \354\240\225\353\240\254.md" index 8cf6ef8b..68bc3fc3 100644 --- "a/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\355\236\231 \354\240\225\353\240\254.md" +++ "b/ko/\354\240\225\353\240\254 \354\225\214\352\263\240\353\246\254\354\246\230/\355\236\231 \354\240\225\353\240\254.md" @@ -53,17 +53,6 @@ $O(1)$ 최악의 경우 ![힙 이미지](https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif) -## 구현 - -- [자바](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/HeapSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/heap_sort.cpp) -- [파이썬](https://github.com/TheAlgorithms/Python/blob/master/sorts/heap_sort.py) -- [고](https://github.com/TheAlgorithms/Go/blob/master/sorts/heapsort.go) -- [루비](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/heap_sort.rb) -- [C-sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/HeapSorter.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/heap_sort.c) -- [자바스크립트](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/HeapSort.js) - ## 영상 URL [힙 정렬 알고리즘에 대한 영상 설명](https://www.youtube.com/watch?v=MtQL_ll5KhQ) diff --git "a/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\204\240\355\230\225 \355\203\220\354\203\211.md" "b/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\204\240\355\230\225 \355\203\220\354\203\211.md" index 4b0f1ba4..d024fdeb 100644 --- "a/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\204\240\355\230\225 \355\203\220\354\203\211.md" +++ "b/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\204\240\355\230\225 \355\203\220\354\203\211.md" @@ -44,12 +44,6 @@ target = 6 마지막 원소가 목표와 같지 않으므로 6이 배열에 들어있지 않다고 판단하여 -1을 반환한다. ``` -## 구현 - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/Searches/LinearSearch.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Search/Linear%20Search.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/linear_search.py) - ## 영상 URL - [CS50](https://www.youtube.com/watch?v=CX2CYIJLwfg) diff --git "a/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\235\264\354\247\204 \355\203\220\354\203\211.md" "b/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\235\264\354\247\204 \355\203\220\354\203\211.md" index 59f7dc29..9e378db2 100644 --- "a/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\235\264\354\247\204 \355\203\220\354\203\211.md" +++ "b/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\235\264\354\247\204 \355\203\220\354\203\211.md" @@ -53,14 +53,6 @@ arr = [7] 유일한 원소가 목표와 같지 않으므로 9가 배열에 들어있지 않다고 판단하여 -1을 반환한다. ``` -## 구현 - -- [자바](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/BinarySearch.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Search/Binary%20Search.cpp) -- [파이썬](https://github.com/TheAlgorithms/Python/blob/master/searches/binary_search.py) -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Search/BinarySearcher.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/Binary_Search.c) - ## 영상 URL - [CS50: 이진 탐색](https://www.youtube.com/watch?v=5xlIPT1FRcA) diff --git "a/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\247\200\354\210\230 \355\203\220\354\203\211.md" "b/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\247\200\354\210\230 \355\203\220\354\203\211.md" index 779d51ea..ff42267a 100644 --- "a/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\247\200\354\210\230 \355\203\220\354\203\211.md" +++ "b/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\354\247\200\354\210\230 \355\203\220\354\203\211.md" @@ -55,8 +55,3 @@ target = 998 - 이진 탐색은 배열의 중간부터 시작하여 많은 반복문을 지나야 4번째 원소에 도착한다. - 지수 탐색은 2번 만에 4번째 원소에 도착한다. - -## 구현 - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/exponential_search.cpp) -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Search/ExponentialSearch.js) diff --git "a/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\355\224\214\353\241\234\354\235\264\353\223\234 \354\210\234\355\231\230 \355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230.md" "b/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\355\224\214\353\241\234\354\235\264\353\223\234 \354\210\234\355\231\230 \355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230.md" index 06c2738a..70162f38 100644 --- "a/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\355\224\214\353\241\234\354\235\264\353\223\234 \354\210\234\355\231\230 \355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230.md" +++ "b/ko/\355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230/\355\224\214\353\241\234\354\235\264\353\223\234 \354\210\234\355\231\230 \355\203\220\354\203\211 \354\225\214\352\263\240\353\246\254\354\246\230.md" @@ -29,11 +29,6 @@ arr = [3, 4, 8, 5, 9, 1, 2, 6, 7, 4] return value = 4 ``` -## 구현 - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/search/floyd_cycle_detection_algo.cpp) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/floyd_cycle_detection_algorithm.c) - ## 영상 URL - [플로이드 순환 탐색 알고리즘 유튜브 영상](https://www.youtube.com/watch?v=B6smdk7pZ14) diff --git a/pt-br/Algoritmos de Busca/Busca Binaria.md b/pt-br/Algoritmos de Busca/Busca Binaria.md index 5c08ec26..cd350166 100644 --- a/pt-br/Algoritmos de Busca/Busca Binaria.md +++ b/pt-br/Algoritmos de Busca/Busca Binaria.md @@ -40,14 +40,6 @@ alvo = 9 # A pesquisa binária deve retornar -1, pois 9 não está presente na matriz ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/BinarySearch.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Search/Binary%20Search.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/binary_search.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Search/BinarySearcher.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/searching/Binary_Search.c) - #### Explicação em vídeo [Um vídeo CS50 explicando o algoritmo de pesquisa binária](https://www.youtube.com/watch?v=5xlIPT1FRcA) diff --git a/pt-br/Algoritmos de Busca/Busca Linear.md b/pt-br/Algoritmos de Busca/Busca Linear.md index f88b10ca..5d6690e0 100644 --- a/pt-br/Algoritmos de Busca/Busca Linear.md +++ b/pt-br/Algoritmos de Busca/Busca Linear.md @@ -33,12 +33,6 @@ alvo = 6 # A pesquisa linear deve retornar -1, pois 6 não está presente na matriz ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LinearSearch.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Search/Linear%20Search.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/searches/linear_search.py) - #### Explicação em vídeo [Um vídeo CS50 explicando o algoritmo de pesquisa linear](https://www.youtube.com/watch?v=CX2CYIJLwfg) diff --git "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Bubble Sort.md" "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Bubble Sort.md" index 61ff8707..d4599dd9 100644 --- "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Bubble Sort.md" +++ "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Bubble Sort.md" @@ -79,18 +79,6 @@ arr[] = {10, 30, 40, 80} Como não há trocas nas etapas acima, isso significa que a matriz está classificada e podemos parar por aqui. ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bubble_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/bubble_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/BubbleSorter.cs) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubblesort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/bubble_sort.c) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/BubbleSort.scala) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/BubbleSort.js) - #### Explicação em vídeo [Um vídeo explicando o algoritmo de classificação por bolha](https://www.youtube.com/watch?v=Jdtq5uKz-w4) diff --git "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Heap Sort.md" "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Heap Sort.md" index 787fa9ba..461cb947 100644 --- "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Heap Sort.md" +++ "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Heap Sort.md" @@ -55,17 +55,6 @@ O procedimento heapify chama a si mesmo recursivamente para construir heap de ci ![heap-image](https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif "Heap Sort") -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/HeapSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/heap_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/heap_sort.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/heapsort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/heap_sort.rb) -- [C-sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/HeapSorter.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/heap_sort.c) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/HeapSort.js) - #### Explicação em vídeo [Um vídeo explicando o algoritmo de classificação por seleção](https://www.youtube.com/watch?v=MtQL_ll5KhQ) diff --git "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Insertion Sort.md" "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Insertion Sort.md" index 3ec6b5e1..4d85bda3 100644 --- "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Insertion Sort.md" +++ "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Insertion Sort.md" @@ -46,16 +46,6 @@ e os elementos de 11 a 13 se moverão uma posição à frente de sua posição a 5, 6, 11, 12, 13 - matriz classificada ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/InsertionSort.java) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/insertion_sort.c) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/insertion_sort.cpp) -- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/InsertionSorter.cs) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/InsertionSort.scala) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/insertion_sort.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/insertion_sort.rb) - #### Explicação em vídeo [Um vídeo CS50 explicando o algoritmo de pesquisa de inserção](https://www.youtube.com/watch?v=DFG-XuyPYUQ) diff --git "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Merge Sort.md" "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Merge Sort.md" index 8f989b47..a29a4285 100644 --- "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Merge Sort.md" +++ "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Merge Sort.md" @@ -31,15 +31,6 @@ Chame recursivamente a função merge sort para ambas as metades, o que fornecer Agora mescle as duas metades para obter a matriz classificada [0, 1, 2, 3, 5, 9] ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/MergeSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/merge_sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/MergeSorter.cs) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/merge_sort.c) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/merge_sort.rb) - #### Explicação em vídeo [Um vídeo CS50 explicando o algoritmo de classificação de mesclagem](https://www.youtube.com/watch?v=EeQ8pwjQxTM) diff --git "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Quick Sort.md" "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Quick Sort.md" index 2d2c9af6..765d5a27 100644 --- "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Quick Sort.md" +++ "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Quick Sort.md" @@ -67,13 +67,6 @@ Agora, 70 está em seu lugar correto. Todos os elementos menores que isto. ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/QuickSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Quick%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/quick_sort.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/quicksort.rb) - #### Explicação em vídeo [Um vídeo explicando o algoritmo de classificação rápida](https://www.youtube.com/watch?v=COk73cpQbFQ) diff --git "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Selection Sort.md" "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Selection Sort.md" index bd15d406..575bbc7d 100644 --- "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Selection Sort.md" +++ "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Selection Sort.md" @@ -47,17 +47,6 @@ Selecione o número mínimo da matriz (entre o índice 2-3), ou seja, 40 A matriz agora está classificada. ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SelectionSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Selection%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/selection_sort.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/selection_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/selection_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/SelectionSort.c) -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/SelectionSort.scala) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/selectionSort.js) - #### Explicação em vídeo [Um vídeo explicando o algoritmo de classificação por seleção](https://www.youtube.com/watch?v=f8hXR_Hvybo) diff --git "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Shell Sort.md" "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Shell Sort.md" index 7a1372ba..535e7ecf 100644 --- "a/pt-br/Algoritmos de Ordena\303\247\303\243o/Shell Sort.md" +++ "b/pt-br/Algoritmos de Ordena\303\247\303\243o/Shell Sort.md" @@ -52,17 +52,6 @@ Lacuna inicial: 4 12. Divida a lacuna por 2 e repita até lacuna = 1 ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/ShellSort.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Shell%20Sort.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/shell_sort.py) -- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/ShellSorter.cs) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/shell_sort.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/Sorting/shell_sort.rb) -- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/shellSort.c) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/shellSort.js) - #### Explicação em vídeo [Um vídeo explicando o algoritmo de classificação Shell](https://www.youtube.com/watch?v=H8NiFkGu2PY) diff --git a/pt-br/Estruturas de Dados/Graph/Bellman-Ford.md b/pt-br/Estruturas de Dados/Graph/Bellman-Ford.md index 52a31bd2..14beb730 100644 --- a/pt-br/Estruturas de Dados/Graph/Bellman-Ford.md +++ b/pt-br/Estruturas de Dados/Graph/Bellman-Ford.md @@ -86,13 +86,6 @@ D -2 A-> B-> E-> D = -1 + 2 + -3 E 1 A-> B-> E = -1 + 2 ``` -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/dynamic_programming/bellman_ford.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/graphs/bellman_ford.py) -- [C](https://github.com/TheAlgorithms/C/blob/master/data_structures/graphs/bellman_ford.c) - #### Explicação em vídeo [Um vídeo explicando o Algoritmo Bellman-Ford](https://www.youtube.com/watch?v=hxMWBBCpR6A) diff --git a/pt-br/Estruturas de Dados/Linked Lists/Lista Duplamente Vinculada.md b/pt-br/Estruturas de Dados/Linked Lists/Lista Duplamente Vinculada.md index b17cfc55..dc09750d 100644 --- a/pt-br/Estruturas de Dados/Linked Lists/Lista Duplamente Vinculada.md +++ b/pt-br/Estruturas de Dados/Linked Lists/Lista Duplamente Vinculada.md @@ -102,14 +102,6 @@ comprimento interno; // opcional ! [Rastreamento de algoritmo](https://www.geeksforgeeks.org/wp-content/uploads/gq/2014/03/DLL_add_middle1.png) -## Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Data%20Structure/Doubly%20Linked%20List.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/doubly_linked_list.py) -- [Go](https://github.com/TheAlgorithms/Go/blob/master/data-structures/linked-list/double-linkedlist.go) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/double_list.rb) - ## Explicação em vídeo [Um vídeo CS50 explicando a estrutura de dados da lista duplamente vinculada](https://www.youtube.com/watch?v=FHMPswJDCvU) diff --git a/pt-br/Estruturas de Dados/Linked Lists/Lista individual.md b/pt-br/Estruturas de Dados/Linked Lists/Lista individual.md index 4066be8a..d66044aa 100644 --- a/pt-br/Estruturas de Dados/Linked Lists/Lista individual.md +++ b/pt-br/Estruturas de Dados/Linked Lists/Lista individual.md @@ -37,13 +37,6 @@ class LinkedList { } ``` -## Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Data%20Structure/Linked%20List.cpp) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/singly_linked_list.py) -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/single_list.rb) - ## Explicação em vídeo [Um vídeo CS50 explicando a estrutura de dados da lista vinculada](https://www.youtube.com/watch?v=5nsKtQuT6E8) diff --git "a/pt-br/Matem\303\241tica B\303\241sica/M\303\251dia.md" "b/pt-br/Matem\303\241tica B\303\241sica/M\303\251dia.md" index 5ba6f38c..40193b9f 100644 --- "a/pt-br/Matem\303\241tica B\303\241sica/M\303\251dia.md" +++ "b/pt-br/Matem\303\241tica B\303\241sica/M\303\251dia.md" @@ -58,13 +58,9 @@ Se considerarmos corretamente os dígitos significativos: `soma / contagem = 23` Retorne o valor de 22 ou `23`. -## Implementação - -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/average_mean.py) - ## URL do vídeo -- [Média na Khan Academy](https://www.khanacademy.org/math/ap-statistics/summarizing-quantitative-data-ap/measuring-center-quantitative/v/mean-median-and-mode) +- [Média na Khan Academy](https://www.khanacademy.org/math/cc-sixth-grade-math/cc-6th-data-statistics/mean-and-median/v/mean-median-and-mode) ## Outros diff --git "a/pt-br/Programa\303\247\303\243o Din\303\242mica/Subsequencia Maxima - Maior Subsequencia Comum (LCS).md" "b/pt-br/Programa\303\247\303\243o Din\303\242mica/Subsequencia Maxima - Maior Subsequencia Comum (LCS).md" index 554c3b56..8535f49b 100644 --- "a/pt-br/Programa\303\247\303\243o Din\303\242mica/Subsequencia Maxima - Maior Subsequencia Comum (LCS).md" +++ "b/pt-br/Programa\303\247\303\243o Din\303\242mica/Subsequencia Maxima - Maior Subsequencia Comum (LCS).md" @@ -79,13 +79,6 @@ B 0 0 1 2 3 Sendo o comprimento da maior subsequência comum igual a: `dp[4][4] = 3`. -#### Links de implementação de código - -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/longest_common_subsequence.py) -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Dynamic%20Programming/Longest%20Common%20Subsequence.cpp) - #### Explicação em vídeo - [Vídeo do canal OnlineBioinfo Bioinformática explicando sobre o algoritmo LCS](https://youtu.be/cX_hFqA8wDI) -- [Video de analise do algoritmo pelo canal Delacyr Ferreira](https://youtu.be/wnq0SqzjbNU) \ No newline at end of file diff --git "a/pt-br/Programa\303\247\303\243o Din\303\242mica/Trocando moedas.md" "b/pt-br/Programa\303\247\303\243o Din\303\242mica/Trocando moedas.md" index 5144bdd5..763ee879 100644 --- "a/pt-br/Programa\303\247\303\243o Din\303\242mica/Trocando moedas.md" +++ "b/pt-br/Programa\303\247\303\243o Din\303\242mica/Trocando moedas.md" @@ -57,10 +57,6 @@ Digamos que temos 3 tipos de moeda `[1,2,3]` e queremos mudar para `7` centavos. Portanto, a resposta final é **8**. 8 maneiras de fazer troco de 7 centavos usando todos os tipos de moedas. `{{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}}` -#### Link de implementação de código - -[Python](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/coin_change.py) - #### Explicação em vídeo [Total de maneiras exclusivas de fazer a mudança em back to back SWE](https://www.youtube.com/watch?v=DJ4a7cmjZY0) diff --git a/ru/README.md b/ru/README.md new file mode 100644 index 00000000..71964fa8 --- /dev/null +++ b/ru/README.md @@ -0,0 +1,31 @@ +# Имя алгоритма + +Напишите краткое описание алгоритма, например: + +1. Временная сложность +2. Пространственная сложность +3. Приложения +4. Имя основателя +5. и т.д. + +## Шаги + +Опишите алгоритм в ясных, простых и понятных шагах. + +## Пример + +Проконтролируйте алгоритм на примере входных данных. + +## Реализация + +Ссылки на реализацию на языках программирования. + +ПРИМЕЧАНИЕ: Ссылка должна быть только в других репозиториях этой организации. + +## URL-адрес видео + +Прикрепите URL-адрес видео, объясняющего алгоритм. + +## Другие + +Любая другая информация всегда приветствуется и должна быть включена в этот раздел. diff --git "a/ru/\320\220\320\273\320\263\320\276\321\200\320\270\321\202\320\274\321\213 \320\237\320\276\320\270\321\201\320\272\320\260/\320\221\320\270\320\275\320\260\321\200\320\275\321\213\320\271 \320\237\320\276\320\270\321\201\320\272.md" "b/ru/\320\220\320\273\320\263\320\276\321\200\320\270\321\202\320\274\321\213 \320\237\320\276\320\270\321\201\320\272\320\260/\320\221\320\270\320\275\320\260\321\200\320\275\321\213\320\271 \320\237\320\276\320\270\321\201\320\272.md" new file mode 100644 index 00000000..a35ed96c --- /dev/null +++ "b/ru/\320\220\320\273\320\263\320\276\321\200\320\270\321\202\320\274\321\213 \320\237\320\276\320\270\321\201\320\272\320\260/\320\221\320\270\320\275\320\260\321\200\320\275\321\213\320\271 \320\237\320\276\320\270\321\201\320\272.md" @@ -0,0 +1,47 @@ +# Бинарный поиск (алгоритм "разделяй и властвуй") + +#### Постановка задачи + +Дан остортированный массив из `n` элементов. Написать функцию поиска индекса заданного (целевого) элемента. + +#### Подход + +- Поиск массива путем многократного деления массива на половины. +- Изначально рассмотрим фактический массив и выберем элемент в среднем индексе. +- Сохраняем нижний индекс (0) и верхний индекс (длина массива). +- Если элемент равен целевому элементу, то возвращаем индекс. +- Если элемент больше целевого элемента, то рассматриваем только левую половину массива (нижний индекс = 0, верхний индекс = `middle - 1`). +- Если элемент меньше целевого элемента, то рассматриваем только правую половину массива (нижний индекс = `middle + 1`, верхний индекс = длина массива). +- Возвращаем `-(индекс вставки + 1)`, если целевой элемент не найден в массиве (если нижний индекс больше или равен верхнему индексу). Некоторые более простые реализации просто возвращают `-1`, если элемент не найден. Смещение 1 должно быть добавлено, так как индекс вставки может быть `0` (искомое значение может быть меньше всех элементов в массиве). Поскольку индексация начинается с `0`, это должно быть отличимо от случая, когда целевой элемент имеет индекс `0`. + +#### Временная сложность + +- O(log n) - в худшем случае; +- O(1) - в лучшем случае (если средний элемент изначального массива является целевым элементом). + +##### Пространственная сложность + +- O(1) - для итеративного подхода; +- O(1) - для рекурсивного подхода если используется оптимизация хвостовых вызовов, `O(log n)` из-за стека вызовов рекурсии в противном случае. + +#### Пример + +```python +arr = [1,2,3,4,5,6,7] + +target = 2 +``` + +Изначально элемент в среднем индексе - `4`, который больше `2`. Поэтому мы ищем левую половину массива, т. е. `[1,2,3]`. + +Здесь мы находим средний элемент, равный целевому элементу, поэтому возвращаем его индекс, т. е. `1`. + +``` +target = 9 +``` + +#### Видео обзоры + +#### Визуальное представление + +- [Tute Board](https://boardhub.github.io/tute/?wd=binarySearchAlgo2) diff --git "a/ru/\320\220\320\273\320\263\320\276\321\200\320\270\321\202\320\274\321\213 \320\241\320\276\321\200\321\202\320\270\321\200\320\276\320\262\320\272\320\270/\320\244\320\273\320\260\320\263 \320\235\320\270\320\264\320\265\321\200\320\273\320\260\320\275\320\264\320\276\320\262.md" "b/ru/\320\220\320\273\320\263\320\276\321\200\320\270\321\202\320\274\321\213 \320\241\320\276\321\200\321\202\320\270\321\200\320\276\320\262\320\272\320\270/\320\244\320\273\320\260\320\263 \320\235\320\270\320\264\320\265\321\200\320\273\320\260\320\275\320\264\320\276\320\262.md" new file mode 100644 index 00000000..93fa214e --- /dev/null +++ "b/ru/\320\220\320\273\320\263\320\276\321\200\320\270\321\202\320\274\321\213 \320\241\320\276\321\200\321\202\320\270\321\200\320\276\320\262\320\272\320\270/\320\244\320\273\320\260\320\263 \320\235\320\270\320\264\320\265\321\200\320\273\320\260\320\275\320\264\320\276\320\262.md" @@ -0,0 +1,34 @@ +# Задача флага Нидерландов + +#### Постановка задачи + +Дан массив с несколькими цветами (красный, белый и синий), нужно упорядочить его таким образом, чтобы все цвета были сгруппированы вместе. Мы будем использовать целые числа `0`, `1` и `2` для представления красного, белого и синего цветов соответственно. + +Нужно отсортировать массив на месте без использования дополнительной памяти и стандартной функции сортировки. + +#### Алгоритм + +1. Создайте три указателя - `low`, `mid` и `high`. +1. Установите `low` и `mid` в начало массива, а `high` в конец массива. +1. Сравните `nums[mid]` со значением `1`. + - Если `nums[mid]` равен 1, просто увеличьте mid. + - Если `nums[mid]` равен 0, поменяйте `nums[mid]` и `nums[low]`, а затем увеличьте `mid` и `low` на 1. + - Если `nums[mid]` равен 2, поменяйте `nums[mid]` и `nums[high]`, а затем уменьшите `high` на 1. +1. Продолжайте шаги 3 до тех пор, пока `mid <= high`. + +#### Временная сложность + +- O(n) + +#### Пространственная сложность + +- O(1) + +#### Пример + +```python +nums = [2, 0, 2, 1, 1, 0] + +print(dutch_flag_sort(nums)) +# Output: [0, 0, 1, 1, 2, 2] +``` diff --git a/uz/Boshlang'ich Matematika/Fibonachi sonlari.md b/uz/Boshlang'ich Matematika/Fibonachi sonlari.md index 30ab542b..c65daca2 100644 --- a/uz/Boshlang'ich Matematika/Fibonachi sonlari.md +++ b/uz/Boshlang'ich Matematika/Fibonachi sonlari.md @@ -38,13 +38,6 @@ Fibonachi sonlarning 8chi hadini topishni ko'rib chiqamiz: f(8)=21 -## Fibonachi algoritmning dasturlash tillaridagi ko'rinishi: - -- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/fibonacci.cpp) -- [Java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciNumber.java) -- [Javascript](https://github.com/TheAlgorithms/Javascript/blob/80c2dc85d714f73783f133964d6acd9b5625ddd9/Maths/Fibonacci.js) -- [Python](https://github.com/TheAlgorithms/Python/blob/master/maths/fibonacci.py) - ## Video bog'ich - [YouTube](https://youtu.be/FQiRf4jb3PU) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy