Compare commits
226 Commits
master
...
Developmen
Author | SHA1 | Date | |
---|---|---|---|
|
da85d4115d | ||
|
bd60e13d79 | ||
|
09765b8ab4 | ||
|
8eb27d712f | ||
|
1012ff74f3 | ||
|
546bc3f5c8 | ||
|
459188428a | ||
|
f4f0dfd2d3 | ||
|
b9dcb85af5 | ||
|
56a611a9e1 | ||
|
be160de58b | ||
|
72efcaa564 | ||
|
3c71071e2b | ||
|
bdaabbb2aa | ||
|
18b2930d4f | ||
|
8e9482682c | ||
|
452fa5659c | ||
|
87485b0109 | ||
|
dcdd17d4c9 | ||
|
dd3b2d2ac1 | ||
|
32b02af2bb | ||
|
60c77e5730 | ||
|
84914c878f | ||
|
e7304d367e | ||
|
e55f994a4f | ||
|
2d797fb976 | ||
|
6aecb37b49 | ||
|
57c1967be0 | ||
|
7fbf8f221c | ||
|
56a527aa26 | ||
|
5466ff0d57 | ||
|
80b765ba30 | ||
|
36e23bb402 | ||
|
bf223bbf56 | ||
|
17ae1c6137 | ||
|
9f8abb0f55 | ||
|
9ee9612b43 | ||
|
fd24ffc5e3 | ||
|
724ff7ef30 | ||
|
ccf506514a | ||
|
8426bedf86 | ||
|
2567859e32 | ||
|
4690efbea4 | ||
|
6111fb7629 | ||
|
c6c6fffac9 | ||
|
a3c111b5f5 | ||
|
f82bf1a149 | ||
|
9086252da5 | ||
|
fc75a15ef1 | ||
|
7b1c328594 | ||
|
f3f2661d35 | ||
|
d678faeab6 | ||
|
2d4d7dd742 | ||
|
573b1ce056 | ||
|
8b416b1267 | ||
|
f015210382 | ||
|
3fe20e3eff | ||
|
78f7a803ea | ||
|
59eb36e4ab | ||
|
c52e12aa05 | ||
|
15d0f56c7a | ||
|
5ec13c6bcb | ||
|
56b374ce9f | ||
|
45fee1868e | ||
|
e30d11545f | ||
|
6ad2c9ff3b | ||
|
5d790266e7 | ||
|
6c8151f64e | ||
|
98982f8f25 | ||
|
3750999f5a | ||
|
d6002f87da | ||
|
87693f051c | ||
|
d579b8e903 | ||
|
837f635001 | ||
|
c31c39a08e | ||
|
a7a9abd8c0 | ||
|
afe5d241b9 | ||
|
13a08836be | ||
|
fc421591fc | ||
|
7e33042c3a | ||
|
8841314c87 | ||
|
ceae5ee44a | ||
|
4456658f82 | ||
|
3f9ff6e3b5 | ||
|
c25da3ce97 | ||
|
5358f8ddc9 | ||
|
b6772c5fb1 | ||
|
d8bfa59b14 | ||
|
132060f078 | ||
|
4fd7698fd2 | ||
|
ba90059624 | ||
|
04f6924ec5 | ||
|
ee985d510b | ||
|
6458e31c45 | ||
|
b532d70716 | ||
|
21f82001dd | ||
|
616d5cfcc8 | ||
|
321ebea864 | ||
|
6ffb2d5b4e | ||
|
77881f67fd | ||
|
c11a0611a0 | ||
|
c29640e0e2 | ||
|
43d47225be | ||
|
f01927dcb3 | ||
|
4a3f871218 | ||
|
ea6c4e5a8a | ||
|
e2a6b024b1 | ||
|
09c4cd790f | ||
|
36f977936d | ||
|
0276ccd903 | ||
|
e5856e329f | ||
|
af6daf7af6 | ||
|
fa1503fa77 | ||
|
ada660a4c3 | ||
|
cac1b0b4c7 | ||
|
1041b02e6b | ||
|
fbffeb658c | ||
|
64bd1a147e | ||
|
184f644bd7 | ||
|
0c015fc605 | ||
|
8e8e14d1c2 | ||
|
60bb026f8a | ||
|
37e6717be9 | ||
|
46e52f4378 | ||
|
1bf9cf6019 | ||
|
f5754d3aef | ||
|
c85caf50d6 | ||
|
230f04f614 | ||
|
785b570167 | ||
|
4d9965cb94 | ||
|
6938c409f9 | ||
|
3b72294f25 | ||
|
91c19921ef | ||
|
7216f28cb3 | ||
|
39806e3fe6 | ||
|
9ee8039fdd | ||
|
4721cff668 | ||
|
2eec474f13 | ||
|
09ed874e55 | ||
|
e5b07ebc3e | ||
|
1093a496b9 | ||
|
46df09ab86 | ||
|
27753bb8d1 | ||
|
5f2257017f | ||
|
822c91c13c | ||
|
01b0296dad | ||
|
ee8147cdda | ||
|
7842c01bed | ||
|
233f05d862 | ||
|
c2e2402e21 | ||
|
61bb8b3aab | ||
|
7f523ffee8 | ||
|
481be6290c | ||
|
965c288b3a | ||
|
37b99ff6dd | ||
|
5ce337fa54 | ||
|
320b5de0fe | ||
|
c8ee96d9d5 | ||
|
3551433e46 | ||
|
ed53bd0353 | ||
|
a023542464 | ||
|
5227629d3e | ||
|
5c946119e7 | ||
|
50c7ba4442 | ||
|
edac7f3a5e | ||
|
bf64bc6a2e | ||
|
df085d0e1d | ||
|
023ddee5db | ||
|
a3b4e1421a | ||
|
c7f8f772c0 | ||
|
fe277cf053 | ||
|
4f1fceeb7f | ||
|
d082862fb4 | ||
|
6312a1ee87 | ||
|
2bcc4c9640 | ||
|
6268d39250 | ||
|
e631e3214b | ||
|
9de5a024ec | ||
|
a8862c3eb4 | ||
|
2ef1e90aad | ||
|
b61eb8cca3 | ||
|
4f10211147 | ||
|
2b04588708 | ||
|
87eec2d6fb | ||
|
2f918ed722 | ||
|
604d5d36d8 | ||
|
2e618c86a0 | ||
|
e7a182b03e | ||
|
1274140ea3 | ||
|
9fe55c82d8 | ||
|
005380f538 | ||
|
a7a087da0c | ||
|
c22449acc5 | ||
|
9763b6df89 | ||
|
e15d329c71 | ||
|
f65fc4dabc | ||
|
d814728210 | ||
|
6dcbaca774 | ||
|
7c0c4bcfe1 | ||
|
c0ca53743a | ||
|
829f7d7313 | ||
|
7281281d33 | ||
|
c6ce36b19b | ||
|
08dc6adfcc | ||
|
999dc93f23 | ||
|
4e7843b801 | ||
|
c4a13fc64c | ||
|
7a8191f097 | ||
|
0128a014c6 | ||
|
6d2fa795f7 | ||
|
e4827bdb23 | ||
|
6de87051fd | ||
|
47093451ac | ||
|
0adfcaca7a | ||
|
3eff87291b | ||
|
89f1c37502 | ||
|
90a4c36618 | ||
|
5b76fca9f6 | ||
|
d9c46396d8 | ||
|
bcf4b617bb | ||
|
db9e4bbbe7 | ||
|
ee0940d654 | ||
|
39fb7902cf | ||
|
da58e6bd0f | ||
|
90a38205a1 | ||
|
3e999d9445 |
136
.clang-format
136
.clang-format
@ -1,136 +0,0 @@
|
||||
---
|
||||
Language: Java
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
AlignConsecutiveMacros: false
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: false
|
||||
AlignTrailingComments: false
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 300
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertNewlineAtEOF: true
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: Inner
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 4
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Left
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: true
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
...
|
@ -1,25 +0,0 @@
|
||||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/java/.devcontainer/base.Dockerfile
|
||||
|
||||
# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster
|
||||
ARG VARIANT="21-bullseye"
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/java:1.1.0-${VARIANT}
|
||||
|
||||
# [Option] Install Maven
|
||||
ARG INSTALL_MAVEN="false"
|
||||
ARG MAVEN_VERSION=""
|
||||
# [Option] Install Gradle
|
||||
ARG INSTALL_GRADLE="false"
|
||||
ARG GRADLE_VERSION=""
|
||||
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
|
||||
&& if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
|
||||
|
||||
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
|
||||
ARG NODE_VERSION="none"
|
||||
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
|
||||
|
||||
# [Optional] Uncomment this section to install additional OS packages.
|
||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
||||
|
||||
# [Optional] Uncomment this line to install global node packages.
|
||||
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
|
@ -1,47 +0,0 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/java
|
||||
{
|
||||
"name": "Java",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"args": {
|
||||
// Update the VARIANT arg to pick a Java version: 11, 17
|
||||
// Append -bullseye or -buster to pin to an OS version.
|
||||
// Use the -bullseye variants on local arm64/Apple Silicon.
|
||||
"VARIANT": "21-bullseye",
|
||||
// Options
|
||||
"INSTALL_MAVEN": "true",
|
||||
"INSTALL_GRADLE": "true",
|
||||
"NODE_VERSION": "lts/*"
|
||||
}
|
||||
},
|
||||
|
||||
// Configure tool-specific properties.
|
||||
"customizations": {
|
||||
// Configure properties specific to VS Code.
|
||||
"vscode": {
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"vscjava.vscode-java-pack",
|
||||
"GitHub.copilot",
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
"postCreateCommand": "java -version",
|
||||
|
||||
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "vscode",
|
||||
"features": {
|
||||
"git": "os-provided",
|
||||
"github-cli": "latest"
|
||||
}
|
||||
}
|
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@ -1 +0,0 @@
|
||||
* @yanglbme @vil02 @BamaCharanChhandogi @alxkm @siriak
|
45
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
45
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -1,45 +0,0 @@
|
||||
name: "Bug report"
|
||||
description: "Create a report to help us improve"
|
||||
title: "[BUG] <title>"
|
||||
labels: ["bug"]
|
||||
body:
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: "Description"
|
||||
description: "A clear and concise description of what the bug is."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: "Steps to reproduce"
|
||||
description: "Steps to reproduce the behavior (if applicable)"
|
||||
placeholder: |
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: exceptedbhv
|
||||
attributes:
|
||||
label: "Excepted behavior"
|
||||
description: "A clear and concise description of what you expected to happen."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: "Screenshots"
|
||||
description: "If applicable, add screenshots to help explain your problem."
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: context
|
||||
attributes:
|
||||
label: "Additional context"
|
||||
description: "Is there anything else we should know about this bug report?"
|
||||
validations:
|
||||
required: false
|
5
.github/ISSUE_TEMPLATE/config.yml
vendored
5
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,5 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Discord community
|
||||
url: https://the-algorithms.com/discord/
|
||||
about: Have any questions or found any bugs? Please contact us via Discord
|
34
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
34
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@ -1,34 +0,0 @@
|
||||
name: "Feature Request"
|
||||
description: "Suggest an idea for this project"
|
||||
title: "[FEATURE REQUEST] <title>"
|
||||
labels: ["enhancement"]
|
||||
body:
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: What would you like to Propose?
|
||||
description: Provide a clear and concise explanation of your Proposal.
|
||||
validations:
|
||||
required: true
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
For new implementations, please specify the name and problem statement for the algorithm.
|
||||
For algorithm enhancements, specify what needs to be changed and why. For example:
|
||||
- Adding tests.
|
||||
- Optimizing logic.
|
||||
- Refactoring the file and folders for better structure.
|
||||
- type: textarea
|
||||
id: needdetails
|
||||
attributes:
|
||||
label: "Issue details"
|
||||
description: "Write down all the issue/algorithm details description mentioned above."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: extrainfo
|
||||
attributes:
|
||||
label: "Additional Information"
|
||||
description: "Add any other information or screenshots about the request here."
|
||||
validations:
|
||||
required: false
|
19
.github/ISSUE_TEMPLATE/other.yml
vendored
19
.github/ISSUE_TEMPLATE/other.yml
vendored
@ -1,19 +0,0 @@
|
||||
name: Other
|
||||
description: Use this for any other issues. Do NOT create blank issues
|
||||
title: "[OTHER]"
|
||||
labels: ["awaiting triage"]
|
||||
body:
|
||||
- type: textarea
|
||||
id: issuedescription
|
||||
attributes:
|
||||
label: What would you like to share?
|
||||
description: Provide a clear and concise explanation of your issue.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: extrainfo
|
||||
attributes:
|
||||
label: Additional information
|
||||
description: Is there anything else we should know about this issue?
|
||||
validations:
|
||||
required: false
|
18
.github/dependabot.yml
vendored
18
.github/dependabot.yml
vendored
@ -1,18 +0,0 @@
|
||||
---
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "docker"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/.github/workflows/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
- package-ecosystem: "maven"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
...
|
16
.github/pull_request_template.md
vendored
16
.github/pull_request_template.md
vendored
@ -1,16 +0,0 @@
|
||||
<!--
|
||||
Thank you for your contribution!
|
||||
In order to reduce the number of notifications sent to the maintainers, please:
|
||||
- create your PR as draft, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests,
|
||||
- make sure that all of the CI checks pass,
|
||||
- mark your PR as ready for review, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#marking-a-pull-request-as-ready-for-review
|
||||
-->
|
||||
|
||||
<!-- For completed items, change [ ] to [x] -->
|
||||
|
||||
- [ ] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
|
||||
- [ ] This pull request is all my own work -- I have not plagiarized it.
|
||||
- [ ] All filenames are in PascalCase.
|
||||
- [ ] All functions and variable names follow Java naming conventions.
|
||||
- [ ] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
|
||||
- [ ] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`
|
37
.github/workflows/build.yml
vendored
37
.github/workflows/build.yml
vendored
@ -1,37 +0,0 @@
|
||||
name: Build
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: 21
|
||||
distribution: 'adopt'
|
||||
- name: Build with Maven
|
||||
run: mvn --batch-mode --update-snapshots verify
|
||||
- name: Upload coverage to codecov (tokenless)
|
||||
if: >-
|
||||
github.event_name == 'pull_request' &&
|
||||
github.event.pull_request.head.repo.full_name != github.repository
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
fail_ci_if_error: true
|
||||
- name: Upload coverage to codecov (with token)
|
||||
if: >
|
||||
github.repository == 'TheAlgorithms/Java' &&
|
||||
(github.event_name != 'pull_request' ||
|
||||
github.event.pull_request.head.repo.full_name == github.repository)
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
fail_ci_if_error: true
|
||||
- name: Checkstyle
|
||||
run: mvn checkstyle:check
|
||||
- name: SpotBugs
|
||||
run: mvn spotbugs:check
|
||||
- name: PMD
|
||||
run: mvn pmd:check
|
16
.github/workflows/clang-format-lint.yml
vendored
16
.github/workflows/clang-format-lint.yml
vendored
@ -1,16 +0,0 @@
|
||||
name: Clang format linter
|
||||
on:
|
||||
push: {}
|
||||
pull_request: {}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: DoozyX/clang-format-lint-action@v0.18
|
||||
with:
|
||||
source: './src'
|
||||
extensions: 'java'
|
||||
clangFormatVersion: 16
|
47
.github/workflows/codeql.yml
vendored
47
.github/workflows/codeql.yml
vendored
@ -1,47 +0,0 @@
|
||||
---
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '53 3 * * 0'
|
||||
|
||||
env:
|
||||
LANGUAGE: 'java-kotlin'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: 'ubuntu-latest'
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: 21
|
||||
distribution: 'adopt'
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ env.LANGUAGE }}
|
||||
|
||||
- name: Build
|
||||
run: mvn --batch-mode --update-snapshots verify
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
with:
|
||||
category: "/language:${{env.LANGUAGE}}"
|
||||
...
|
41
.github/workflows/gradle.yml
vendored
Normal file
41
.github/workflows/gradle.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
name: Java gradle CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- Development
|
||||
pull_request:
|
||||
branches:
|
||||
- Development
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test algorithms
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
java-version: [1.8, 11]
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout project
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: Development
|
||||
- name: Set up jdk
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: ${{ matrix.java-version }}
|
||||
- name: JUnit5 tests on ubuntu
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
run: |
|
||||
chmod +x gradlew
|
||||
./gradlew clean test
|
||||
- name: JUnit5 tests on macos
|
||||
if: startsWith(matrix.os, 'macos')
|
||||
run: |
|
||||
chmod +x gradlew
|
||||
./gradlew clean test
|
||||
- name: JUnit5 tests on windows
|
||||
if: startsWith(matrix.os, 'windows')
|
||||
run: gradle clean test
|
18
.github/workflows/stale.yml
vendored
18
.github/workflows/stale.yml
vendored
@ -1,18 +0,0 @@
|
||||
name: 'Close stale issues and PRs'
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v9
|
||||
with:
|
||||
stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!'
|
||||
close-issue-message: 'Please reopen this issue once you have made the required changes. If you need help, feel free to ask in our [Discord](https://the-algorithms.com/discord) server or ping one of the maintainers here. Thank you for your contribution!'
|
||||
stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!'
|
||||
close-pr-message: 'Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our [Discord](https://the-algorithms.com/discord) server or ping one of the maintainers here. Thank you for your contribution!'
|
||||
exempt-issue-labels: 'dont-close'
|
||||
exempt-pr-labels: 'dont-close'
|
||||
days-before-stale: 30
|
||||
days-before-close: 7
|
92
.github/workflows/update_directory.yml
vendored
92
.github/workflows/update_directory.yml
vendored
@ -1,92 +0,0 @@
|
||||
# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push or pull_request
|
||||
name: Update Directory
|
||||
permissions:
|
||||
contents: write
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- 'src/**'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'src/**'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
logLevel:
|
||||
description: 'Log level'
|
||||
required: true
|
||||
default: 'info'
|
||||
type: choice
|
||||
options:
|
||||
- info
|
||||
- warning
|
||||
- debug
|
||||
jobs:
|
||||
update_directory_md:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- name: Update Directory
|
||||
shell: python
|
||||
run: |
|
||||
import os
|
||||
from typing import Iterator
|
||||
|
||||
URL_BASE = "https://github.com/TheAlgorithms/Java/blob/master"
|
||||
g_output = []
|
||||
|
||||
|
||||
def good_filepaths(top_dir: str = ".") -> Iterator[str]:
|
||||
for dirpath, dirnames, filenames in os.walk(top_dir):
|
||||
dirnames[:] = [d for d in dirnames if d[0] not in "._"]
|
||||
for filename in filenames:
|
||||
if os.path.splitext(filename)[1].lower() == ".java":
|
||||
yield os.path.join(dirpath, filename).lstrip("./")
|
||||
|
||||
|
||||
def md_prefix(i):
|
||||
return f"{i * ' '}*" if i else "\n##"
|
||||
|
||||
|
||||
def print_path(old_path: str, new_path: str) -> str:
|
||||
global g_output
|
||||
old_parts = old_path.split(os.sep)
|
||||
mid_diff = False
|
||||
new_parts = new_path.split(os.sep)
|
||||
for i, new_part in enumerate(new_parts):
|
||||
if i + 1 > len(old_parts) or old_parts[i] != new_part or mid_diff:
|
||||
if i + 1 < len(new_parts):
|
||||
mid_diff = True
|
||||
if new_part:
|
||||
g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ')}")
|
||||
return new_path
|
||||
|
||||
|
||||
def build_directory_md(top_dir: str = ".") -> str:
|
||||
global g_output
|
||||
old_path = ""
|
||||
for filepath in sorted(good_filepaths(top_dir), key=str.lower):
|
||||
filepath, filename = os.path.split(filepath)
|
||||
if filepath != old_path:
|
||||
old_path = print_path(old_path, filepath)
|
||||
indent = (filepath.count(os.sep) + 1) if filepath else 0
|
||||
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
|
||||
filename = os.path.splitext(filename.replace("_", " "))[0]
|
||||
g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
|
||||
return "\n".join(g_output)
|
||||
|
||||
|
||||
with open("DIRECTORY.md", "w") as out_file:
|
||||
out_file.write(build_directory_md(".") + "\n")
|
||||
|
||||
- name: Update DIRECTORY.md
|
||||
run: |
|
||||
cat DIRECTORY.md
|
||||
git config --global user.name "$GITHUB_ACTOR"
|
||||
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
|
||||
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
|
||||
git add DIRECTORY.md
|
||||
git commit -am "Update directory" || true
|
||||
git push --force origin HEAD:$GITHUB_REF || true
|
49
.gitignore
vendored
49
.gitignore
vendored
@ -1,44 +1,15 @@
|
||||
/gradle/wrapper/gradle-wrapper.properties
|
||||
.settings
|
||||
|
||||
##----------Android----------
|
||||
*.apk
|
||||
*.ap_
|
||||
*.dex
|
||||
*.class
|
||||
bin/
|
||||
gen/
|
||||
build/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
Java.iml
|
||||
.idea/*
|
||||
out/
|
||||
|
||||
# Ignoring Gradle build artifacts and project files
|
||||
##----------Gradle----------
|
||||
.gradle/
|
||||
gradle-app.setting
|
||||
!gradle-wrapper.jar
|
||||
build/
|
||||
|
||||
# Ignoring Maven build artifacts and project files
|
||||
##----------Maven----------
|
||||
*.classpath
|
||||
*.project
|
||||
*.settings
|
||||
/target/
|
||||
local.properties
|
||||
|
||||
# Ignoring IntelliJ IDEA project files and configurations
|
||||
##----------IDEA----------
|
||||
*.iml
|
||||
.idea/
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# Ignoring Android Studio Navigation editor temporary files
|
||||
.navigation/
|
||||
.gradle
|
||||
|
||||
# Ignoring common system and editor-generated files
|
||||
##----------Other----------
|
||||
*~
|
||||
.DS_Store
|
||||
gradle.properties
|
||||
.vscode
|
||||
*.log
|
||||
bin
|
||||
target
|
||||
build
|
||||
|
@ -1,22 +0,0 @@
|
||||
FROM gitpod/workspace-java-21:2024-07-14-17-19-51
|
||||
|
||||
ENV LLVM_SCRIPT="tmp_llvm.sh"
|
||||
|
||||
RUN test ! -f "$LLVM_SCRIPT" \
|
||||
&& wget https://apt.llvm.org/llvm.sh -O "$LLVM_SCRIPT" \
|
||||
&& chmod +x "$LLVM_SCRIPT"
|
||||
|
||||
USER root
|
||||
|
||||
RUN ./"$LLVM_SCRIPT" 16 \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
clang-format-16=1:16.0.6~++20231112100510+7cbf1a259152-1~exp1~20231112100554.106 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN ln -s "$(command -v clang-format-16)" "/usr/bin/clang-format"
|
||||
|
||||
USER gitpod
|
||||
|
||||
RUN rm "$LLVM_SCRIPT"
|
13
.gitpod.yml
13
.gitpod.yml
@ -1,13 +0,0 @@
|
||||
---
|
||||
image:
|
||||
file: .gitpod.dockerfile
|
||||
|
||||
tasks:
|
||||
- init: |
|
||||
mvn dependency:resolve
|
||||
mvn compile
|
||||
|
||||
vscode:
|
||||
extensions:
|
||||
- xaver.clang-format
|
||||
|
@ -1,31 +0,0 @@
|
||||
## How to contribute?
|
||||
|
||||
NOTE: *We DO NOT add leetcode problems. They are just applications of basic principles that can be found in other algorithms included in the repository.*
|
||||
|
||||
### Did you find a bug?
|
||||
|
||||
**Ensure the bug was not already reported** by searching on GitHub under [Project Issues](https://github.com/TheAlgorithms/Java/issues).
|
||||
- If it is mentioned in the issues and you want to fix it, [fork](https://github.com/TheAlgorithms/Java/fork) the repository and submit your implementation in a pull request. The project maintainers will evaluate it.
|
||||
- If the bug is **NOT** mentioned in the issues, [open a new issue](https://github.com/TheAlgorithms/Java/issues/new). Be sure to include a **title**, a clear **description** and a **test case** demonstrating the expected behavior that is not occurring.
|
||||
|
||||
NOTE: *Please avoid opening issues asking to be "assigned" to a particular algorithm. This merely creates unnecessary noise for maintainers. Instead, please submit your implementation in a pull request and project maintainers will evaluate it.*
|
||||
|
||||
|
||||
|
||||
### Do you want to contribute to the documentation?
|
||||
- [Fork](https://github.com/TheAlgorithms/Java/fork) the repository and make necessary changes.
|
||||
- Create a pull request.
|
||||
- It will be put under review for approval.
|
||||
- If approved, the requested changes will be merged to the repository.
|
||||
|
||||
### Do you want to add a new feature?
|
||||
|
||||
- [Open a new issue](https://github.com/TheAlgorithms/Java/issues/new).
|
||||
- Be sure to include a **title**, a clear **description** and a **test case** demonstrating the new feature you want to add to the project.
|
||||
|
||||
|
||||
### Do you have questions about the source code?
|
||||
|
||||
- Ask any question about how to use the repository in the [TheAlgorithms room in GITTER](https://gitter.im/TheAlgorithms/community?source=orgpage#) or [open a new issue](https://github.com/TheAlgorithms/Java/issues/new)
|
||||
|
||||
:+1::tada: That's all you need to know about the process now it's your turn to help us improve the repository, thank you again! :+1::tada:
|
992
DIRECTORY.md
992
DIRECTORY.md
@ -1,992 +0,0 @@
|
||||
|
||||
## src
|
||||
* main
|
||||
* java
|
||||
* com
|
||||
* thealgorithms
|
||||
* audiofilters
|
||||
* [IIRFilter](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/audiofilters/IIRFilter.java)
|
||||
* backtracking
|
||||
* [AllPathsFromSourceToTarget](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java)
|
||||
* [ArrayCombination](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/ArrayCombination.java)
|
||||
* [Combination](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/Combination.java)
|
||||
* [FloodFill](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/FloodFill.java)
|
||||
* [KnightsTour](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/KnightsTour.java)
|
||||
* [MazeRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/MazeRecursion.java)
|
||||
* [MColoring](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/MColoring.java)
|
||||
* [NQueens](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/NQueens.java)
|
||||
* [ParenthesesGenerator](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/ParenthesesGenerator.java)
|
||||
* [Permutation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/Permutation.java)
|
||||
* [PowerSum](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/PowerSum.java)
|
||||
* [SubsequenceFinder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/SubsequenceFinder.java)
|
||||
* [WordSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/WordSearch.java)
|
||||
* bitmanipulation
|
||||
* [BitSwap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/BitSwap.java)
|
||||
* [HighestSetBit](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/HighestSetBit.java)
|
||||
* [IndexOfRightMostSetBit](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBit.java)
|
||||
* [IsEven](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java)
|
||||
* [IsPowerTwo](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/IsPowerTwo.java)
|
||||
* [NonRepeatingNumberFinder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/NonRepeatingNumberFinder.java)
|
||||
* [NumbersDifferentSigns](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java)
|
||||
* [ReverseBits](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/ReverseBits.java)
|
||||
* [SingleBitOperations](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/SingleBitOperations.java)
|
||||
* ciphers
|
||||
* a5
|
||||
* [A5Cipher](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/a5/A5Cipher.java)
|
||||
* [A5KeyStreamGenerator](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/a5/A5KeyStreamGenerator.java)
|
||||
* [BaseLFSR](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/a5/BaseLFSR.java)
|
||||
* [CompositeLFSR](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/a5/CompositeLFSR.java)
|
||||
* [LFSR](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/a5/LFSR.java)
|
||||
* [Utils](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/a5/Utils.java)
|
||||
* [AES](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/AES.java)
|
||||
* [AESEncryption](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/AESEncryption.java)
|
||||
* [AffineCipher](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/AffineCipher.java)
|
||||
* [Blowfish](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/Blowfish.java)
|
||||
* [Caesar](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/Caesar.java)
|
||||
* [ColumnarTranspositionCipher](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/ColumnarTranspositionCipher.java)
|
||||
* [DES](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/DES.java)
|
||||
* [HillCipher](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/HillCipher.java)
|
||||
* [PlayfairCipher](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/PlayfairCipher.java)
|
||||
* [Polybius](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/Polybius.java)
|
||||
* [ProductCipher](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/ProductCipher.java)
|
||||
* [RSA](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/RSA.java)
|
||||
* [SimpleSubCipher](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/SimpleSubCipher.java)
|
||||
* [Vigenere](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/ciphers/Vigenere.java)
|
||||
* conversions
|
||||
* [AffineConverter](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/AffineConverter.java)
|
||||
* [AnyBaseToAnyBase](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java)
|
||||
* [AnyBaseToDecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/AnyBaseToDecimal.java)
|
||||
* [AnytoAny](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/AnytoAny.java)
|
||||
* [BinaryToDecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/BinaryToDecimal.java)
|
||||
* [BinaryToHexadecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/BinaryToHexadecimal.java)
|
||||
* [BinaryToOctal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/BinaryToOctal.java)
|
||||
* [DecimalToAnyBase](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/DecimalToAnyBase.java)
|
||||
* [DecimalToBinary](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/DecimalToBinary.java)
|
||||
* [DecimalToHexadecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/DecimalToHexadecimal.java)
|
||||
* [DecimalToOctal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/DecimalToOctal.java)
|
||||
* [HexaDecimalToBinary](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java)
|
||||
* [HexaDecimalToDecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/HexaDecimalToDecimal.java)
|
||||
* [HexToOct](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/HexToOct.java)
|
||||
* [IntegerToRoman](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/IntegerToRoman.java)
|
||||
* [OctalToBinary](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/OctalToBinary.java)
|
||||
* [OctalToDecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/OctalToDecimal.java)
|
||||
* [OctalToHexadecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/OctalToHexadecimal.java)
|
||||
* [RgbHsvConversion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/RgbHsvConversion.java)
|
||||
* [RomanToInteger](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/RomanToInteger.java)
|
||||
* [TurkishToLatinConversion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/TurkishToLatinConversion.java)
|
||||
* [UnitConversions](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/UnitConversions.java)
|
||||
* [UnitsConverter](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/UnitsConverter.java)
|
||||
* datastructures
|
||||
* bags
|
||||
* [Bag](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/bags/Bag.java)
|
||||
* bloomfilter
|
||||
* [BloomFilter](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/bloomfilter/BloomFilter.java)
|
||||
* buffers
|
||||
* [CircularBuffer](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/buffers/CircularBuffer.java)
|
||||
* caches
|
||||
* [LFUCache](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/caches/LFUCache.java)
|
||||
* [LRUCache](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/caches/LRUCache.java)
|
||||
* [MRUCache](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/caches/MRUCache.java)
|
||||
* crdt
|
||||
* [GCounter](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/crdt/GCounter.java)
|
||||
* [GSet](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/crdt/GSet.java)
|
||||
* [LWWElementSet](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/crdt/LWWElementSet.java)
|
||||
* [ORSet](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/crdt/ORSet.java)
|
||||
* [PNCounter](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/crdt/PNCounter.java)
|
||||
* [TwoPSet](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/crdt/TwoPSet.java)
|
||||
* disjointsetunion
|
||||
* [DisjointSetUnion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/disjointsetunion/DisjointSetUnion.java)
|
||||
* [Node](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/disjointsetunion/Node.java)
|
||||
* dynamicarray
|
||||
* [DynamicArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/dynamicarray/DynamicArray.java)
|
||||
* graphs
|
||||
* [AStar](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/AStar.java)
|
||||
* [BellmanFord](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java)
|
||||
* [BipartiteGraphDFS](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGraphDFS.java)
|
||||
* [BoruvkaAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithm.java)
|
||||
* [ConnectedComponent](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java)
|
||||
* [Cycles](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/Cycles.java)
|
||||
* [DijkstraAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraAlgorithm.java)
|
||||
* [FloydWarshall](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java)
|
||||
* [FordFulkerson](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/FordFulkerson.java)
|
||||
* [Graphs](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/Graphs.java)
|
||||
* [HamiltonianCycle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java)
|
||||
* [KahnsAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java)
|
||||
* [Kosaraju](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/Kosaraju.java)
|
||||
* [Kruskal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/Kruskal.java)
|
||||
* [MatrixGraphs](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/MatrixGraphs.java)
|
||||
* [PrimMST](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/PrimMST.java)
|
||||
* [TarjansAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java)
|
||||
* [WelshPowell](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/graphs/WelshPowell.java)
|
||||
* hashmap
|
||||
* hashing
|
||||
* [GenericHashMapUsingArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArray.java)
|
||||
* [GenericHashMapUsingArrayList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArrayList.java)
|
||||
* [HashMap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMap.java)
|
||||
* [HashMapCuckooHashing](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java)
|
||||
* [Intersection](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Intersection.java)
|
||||
* [LinearProbingHashMap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/LinearProbingHashMap.java)
|
||||
* [MainCuckooHashing](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java)
|
||||
* [MajorityElement](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MajorityElement.java)
|
||||
* [Map](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Map.java)
|
||||
* heaps
|
||||
* [EmptyHeapException](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/EmptyHeapException.java)
|
||||
* [FibonacciHeap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/FibonacciHeap.java)
|
||||
* [GenericHeap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/GenericHeap.java)
|
||||
* [Heap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/Heap.java)
|
||||
* [HeapElement](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/HeapElement.java)
|
||||
* [LeftistHeap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/LeftistHeap.java)
|
||||
* [MaxHeap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/MaxHeap.java)
|
||||
* [MinHeap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java)
|
||||
* [MinPriorityQueue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/heaps/MinPriorityQueue.java)
|
||||
* lists
|
||||
* [CircleLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/CircleLinkedList.java)
|
||||
* [CountSinglyLinkedListRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/CountSinglyLinkedListRecursion.java)
|
||||
* [CreateAndDetectLoop](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/CreateAndDetectLoop.java)
|
||||
* [CursorLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/CursorLinkedList.java)
|
||||
* [DoublyLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java)
|
||||
* [MergeKSortedLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/MergeKSortedLinkedList.java)
|
||||
* [MergeSortedArrayList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/MergeSortedArrayList.java)
|
||||
* [MergeSortedSinglyLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/MergeSortedSinglyLinkedList.java)
|
||||
* [QuickSortLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/QuickSortLinkedList.java)
|
||||
* [RandomNode](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java)
|
||||
* [ReverseKGroup](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java)
|
||||
* [RotateSinglyLinkedLists](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedLists.java)
|
||||
* [SearchSinglyLinkedListRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/SearchSinglyLinkedListRecursion.java)
|
||||
* [SinglyLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java)
|
||||
* [SkipList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/SkipList.java)
|
||||
* [Node](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/Node.java)
|
||||
* queues
|
||||
* [CircularQueue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/queues/CircularQueue.java)
|
||||
* [Deque](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/queues/Deque.java)
|
||||
* [GenericArrayListQueue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/queues/GenericArrayListQueue.java)
|
||||
* [LinkedQueue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/queues/LinkedQueue.java)
|
||||
* [PriorityQueues](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/queues/PriorityQueues.java)
|
||||
* [Queue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/queues/Queue.java)
|
||||
* stacks
|
||||
* [NodeStack](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java)
|
||||
* [ReverseStack](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/stacks/ReverseStack.java)
|
||||
* [Stack](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/stacks/Stack.java)
|
||||
* [StackArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/stacks/StackArray.java)
|
||||
* [StackArrayList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/stacks/StackArrayList.java)
|
||||
* [StackOfLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/stacks/StackOfLinkedList.java)
|
||||
* trees
|
||||
* [AVLSimple](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/AVLSimple.java)
|
||||
* [AVLTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java)
|
||||
* [BinaryTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/BinaryTree.java)
|
||||
* [BSTFromSortedArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/BSTFromSortedArray.java)
|
||||
* [BSTIterative](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/BSTIterative.java)
|
||||
* [BSTRecursive](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursive.java)
|
||||
* [BSTRecursiveGeneric](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java)
|
||||
* [CeilInBinarySearchTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java)
|
||||
* [CheckBinaryTreeIsValidBST](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/CheckBinaryTreeIsValidBST.java)
|
||||
* [CheckIfBinaryTreeBalanced](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/CheckIfBinaryTreeBalanced.java)
|
||||
* [CheckTreeIsSymmetric](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java)
|
||||
* [CreateBinaryTreeFromInorderPreorder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/CreateBinaryTreeFromInorderPreorder.java)
|
||||
* [FenwickTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/FenwickTree.java)
|
||||
* [GenericTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java)
|
||||
* [InorderTraversal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/InorderTraversal.java)
|
||||
* [KDTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java)
|
||||
* [LazySegmentTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/LazySegmentTree.java)
|
||||
* [LCA](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/LCA.java)
|
||||
* [LevelOrderTraversal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/LevelOrderTraversal.java)
|
||||
* [nearestRightKey](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/nearestRightKey.java)
|
||||
* [PostOrderTraversal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/PostOrderTraversal.java)
|
||||
* [PreOrderTraversal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/PreOrderTraversal.java)
|
||||
* [PrintTopViewofTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java)
|
||||
* [RedBlackBST](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java)
|
||||
* [SameTreesCheck](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/SameTreesCheck.java)
|
||||
* [SegmentTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree.java)
|
||||
* [SplayTree](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/SplayTree.java)
|
||||
* [TreeRandomNode](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java)
|
||||
* [TrieImp](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java)
|
||||
* [VerticalOrderTraversal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/VerticalOrderTraversal.java)
|
||||
* [ZigzagTraversal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/ZigzagTraversal.java)
|
||||
* devutils
|
||||
* entities
|
||||
* [ProcessDetails](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/devutils/entities/ProcessDetails.java)
|
||||
* nodes
|
||||
* [LargeTreeNode](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/devutils/nodes/LargeTreeNode.java)
|
||||
* [Node](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/devutils/nodes/Node.java)
|
||||
* [SimpleNode](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/devutils/nodes/SimpleNode.java)
|
||||
* [SimpleTreeNode](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/devutils/nodes/SimpleTreeNode.java)
|
||||
* [TreeNode](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/devutils/nodes/TreeNode.java)
|
||||
* searches
|
||||
* [MatrixSearchAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/devutils/searches/MatrixSearchAlgorithm.java)
|
||||
* [SearchAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/devutils/searches/SearchAlgorithm.java)
|
||||
* divideandconquer
|
||||
* [BinaryExponentiation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java)
|
||||
* [ClosestPair](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/divideandconquer/ClosestPair.java)
|
||||
* [SkylineAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/divideandconquer/SkylineAlgorithm.java)
|
||||
* [StrassenMatrixMultiplication](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/divideandconquer/StrassenMatrixMultiplication.java)
|
||||
* dynamicprogramming
|
||||
* [BoardPath](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/BoardPath.java)
|
||||
* [BoundaryFill](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java)
|
||||
* [BruteForceKnapsack](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java)
|
||||
* [CatalanNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java)
|
||||
* [ClimbingStairs](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/ClimbingStairs.java)
|
||||
* [CoinChange](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java)
|
||||
* [CountFriendsPairing](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java)
|
||||
* [DiceThrow](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/DiceThrow.java)
|
||||
* [EditDistance](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java)
|
||||
* [EggDropping](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/EggDropping.java)
|
||||
* [Fibonacci](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java)
|
||||
* [KadaneAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java)
|
||||
* [Knapsack](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/Knapsack.java)
|
||||
* [KnapsackMemoization](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackMemoization.java)
|
||||
* [LevenshteinDistance](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java)
|
||||
* [LongestAlternatingSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequence.java)
|
||||
* [LongestCommonSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java)
|
||||
* [LongestIncreasingSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequence.java)
|
||||
* [LongestPalindromicSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubsequence.java)
|
||||
* [LongestPalindromicSubstring](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java)
|
||||
* [LongestValidParentheses](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestValidParentheses.java)
|
||||
* [MatrixChainMultiplication](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainMultiplication.java)
|
||||
* [MatrixChainRecursiveTopDownMemoisation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainRecursiveTopDownMemoisation.java)
|
||||
* [MinimumPathSum](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/MinimumPathSum.java)
|
||||
* [MinimumSumPartition](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/MinimumSumPartition.java)
|
||||
* [NewManShanksPrime](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java)
|
||||
* [OptimalJobScheduling](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java)
|
||||
* [PalindromicPartitioning](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/PalindromicPartitioning.java)
|
||||
* [PartitionProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java)
|
||||
* [RegexMatching](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java)
|
||||
* [RodCutting](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/RodCutting.java)
|
||||
* [ShortestCommonSupersequenceLength](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/ShortestCommonSupersequenceLength.java)
|
||||
* [SubsetCount](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java)
|
||||
* [SubsetSum](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSum.java)
|
||||
* [SumOfSubset](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java)
|
||||
* [Tribonacci](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java)
|
||||
* [UniquePaths](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java)
|
||||
* [WildcardMatching](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/WildcardMatching.java)
|
||||
* [WineProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java)
|
||||
* geometry
|
||||
* [GrahamScan](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/geometry/GrahamScan.java)
|
||||
* greedyalgorithms
|
||||
* [ActivitySelection](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/greedyalgorithms/ActivitySelection.java)
|
||||
* [CoinChange](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/greedyalgorithms/CoinChange.java)
|
||||
* [FractionalKnapsack](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java)
|
||||
* [JobSequencing](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/greedyalgorithms/JobSequencing.java)
|
||||
* [MinimizingLateness](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/greedyalgorithms/MinimizingLateness.java)
|
||||
* io
|
||||
* [BufferedReader](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/io/BufferedReader.java)
|
||||
* maths
|
||||
* [AbsoluteMax](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AbsoluteMax.java)
|
||||
* [AbsoluteMin](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AbsoluteMin.java)
|
||||
* [AbsoluteValue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AbsoluteValue.java)
|
||||
* [ADTFraction](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/ADTFraction.java)
|
||||
* [AliquotSum](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AliquotSum.java)
|
||||
* [AmicableNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AmicableNumber.java)
|
||||
* [Area](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Area.java)
|
||||
* [Armstrong](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Armstrong.java)
|
||||
* [AutoCorrelation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AutoCorrelation.java)
|
||||
* [AutomorphicNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java)
|
||||
* [Average](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Average.java)
|
||||
* [BinaryPow](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/BinaryPow.java)
|
||||
* [BinomialCoefficient](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/BinomialCoefficient.java)
|
||||
* [Ceil](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Ceil.java)
|
||||
* [CircularConvolutionFFT](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java)
|
||||
* [CollatzConjecture](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/CollatzConjecture.java)
|
||||
* [Combinations](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Combinations.java)
|
||||
* [Convolution](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Convolution.java)
|
||||
* [ConvolutionFFT](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java)
|
||||
* [CrossCorrelation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/CrossCorrelation.java)
|
||||
* [DeterminantOfMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java)
|
||||
* [DigitalRoot](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/DigitalRoot.java)
|
||||
* [DistanceFormula](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/DistanceFormula.java)
|
||||
* [DudeneyNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/DudeneyNumber.java)
|
||||
* [EulerMethod](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/EulerMethod.java)
|
||||
* [EulersFunction](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/EulersFunction.java)
|
||||
* [Factorial](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Factorial.java)
|
||||
* [FactorialRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FactorialRecursion.java)
|
||||
* [FastInverseSqrt](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java)
|
||||
* [FFT](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FFT.java)
|
||||
* [FFTBluestein](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FFTBluestein.java)
|
||||
* [FibonacciJavaStreams](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciJavaStreams.java)
|
||||
* [FibonacciLoop](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciLoop.java)
|
||||
* [FibonacciNumberCheck](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciNumberCheck.java)
|
||||
* [FibonacciNumberGoldenRation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FibonacciNumberGoldenRation.java)
|
||||
* [FindKthNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FindKthNumber.java)
|
||||
* [FindMax](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FindMax.java)
|
||||
* [FindMaxRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java)
|
||||
* [FindMin](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FindMin.java)
|
||||
* [FindMinRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FindMinRecursion.java)
|
||||
* [Floor](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Floor.java)
|
||||
* [FrizzyNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/FrizzyNumber.java)
|
||||
* [Gaussian](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Gaussian.java)
|
||||
* [GCD](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/GCD.java)
|
||||
* [GCDRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/GCDRecursion.java)
|
||||
* [GenericRoot](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/GenericRoot.java)
|
||||
* [HarshadNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/HarshadNumber.java)
|
||||
* [HeronsFormula](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/HeronsFormula.java)
|
||||
* [JosephusProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/JosephusProblem.java)
|
||||
* [JugglerSequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/JugglerSequence.java)
|
||||
* [KaprekarNumbers](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/KaprekarNumbers.java)
|
||||
* [KeithNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/KeithNumber.java)
|
||||
* [KrishnamurthyNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/KrishnamurthyNumber.java)
|
||||
* [LeastCommonMultiple](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java)
|
||||
* [LeonardoNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LeonardoNumber.java)
|
||||
* [LinearDiophantineEquationsSolver](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LinearDiophantineEquationsSolver.java)
|
||||
* [LiouvilleLambdaFunction](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java)
|
||||
* [LongDivision](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LongDivision.java)
|
||||
* [LucasSeries](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LucasSeries.java)
|
||||
* [MagicSquare](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MagicSquare.java)
|
||||
* [MatrixRank](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MatrixRank.java)
|
||||
* [MatrixUtil](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MatrixUtil.java)
|
||||
* [MaxValue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MaxValue.java)
|
||||
* [Means](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Means.java)
|
||||
* [Median](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Median.java)
|
||||
* [MillerRabinPrimalityCheck](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java)
|
||||
* [MinValue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MinValue.java)
|
||||
* [MobiusFunction](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MobiusFunction.java)
|
||||
* [Mode](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Mode.java)
|
||||
* [NonRepeatingElement](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java)
|
||||
* [NthUglyNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/NthUglyNumber.java)
|
||||
* [NumberOfDigits](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/NumberOfDigits.java)
|
||||
* [PalindromeNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PalindromeNumber.java)
|
||||
* [ParseInteger](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/ParseInteger.java)
|
||||
* [PascalTriangle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PascalTriangle.java)
|
||||
* [PerfectCube](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PerfectCube.java)
|
||||
* [PerfectNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PerfectNumber.java)
|
||||
* [PerfectSquare](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PerfectSquare.java)
|
||||
* [Perimeter](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Perimeter.java)
|
||||
* [PiNilakantha](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PiNilakantha.java)
|
||||
* [PollardRho](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PollardRho.java)
|
||||
* [Pow](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Pow.java)
|
||||
* [PowerOfTwoOrNot](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PowerOfTwoOrNot.java)
|
||||
* [PowerUsingRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java)
|
||||
* [PrimeCheck](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PrimeCheck.java)
|
||||
* [PrimeFactorization](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PrimeFactorization.java)
|
||||
* [PronicNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PronicNumber.java)
|
||||
* [PythagoreanTriple](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PythagoreanTriple.java)
|
||||
* [ReverseNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/ReverseNumber.java)
|
||||
* [RomanNumeralUtil](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/RomanNumeralUtil.java)
|
||||
* [SecondMinMax](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SecondMinMax.java)
|
||||
* [SieveOfEratosthenes](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java)
|
||||
* [SimpsonIntegration](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SimpsonIntegration.java)
|
||||
* [SquareFreeInteger](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SquareFreeInteger.java)
|
||||
* [SquareRootWithBabylonianMethod](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SquareRootWithBabylonianMethod.java)
|
||||
* [SquareRootWithNewtonRaphsonMethod](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java)
|
||||
* [StandardDeviation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/StandardDeviation.java)
|
||||
* [StandardScore](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/StandardScore.java)
|
||||
* [StrobogrammaticNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/StrobogrammaticNumber.java)
|
||||
* [SumOfArithmeticSeries](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java)
|
||||
* [SumOfDigits](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SumOfDigits.java)
|
||||
* [SumWithoutArithmeticOperators](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java)
|
||||
* [TrinomialTriangle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/TrinomialTriangle.java)
|
||||
* [TwinPrime](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/TwinPrime.java)
|
||||
* [VampireNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/VampireNumber.java)
|
||||
* [VectorCrossProduct](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java)
|
||||
* [Volume](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Volume.java)
|
||||
* matrixexponentiation
|
||||
* [Fibonacci](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java)
|
||||
* misc
|
||||
* [ColorContrastRatio](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/ColorContrastRatio.java)
|
||||
* [InverseOfMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/InverseOfMatrix.java)
|
||||
* [MapReduce](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MapReduce.java)
|
||||
* [MatrixTranspose](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MatrixTranspose.java)
|
||||
* [MedianOfMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MedianOfMatrix.java)
|
||||
* [MedianOfRunningArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MedianOfRunningArray.java)
|
||||
* [MedianOfRunningArrayByte](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MedianOfRunningArrayByte.java)
|
||||
* [MedianOfRunningArrayDouble](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MedianOfRunningArrayDouble.java)
|
||||
* [MedianOfRunningArrayFloat](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MedianOfRunningArrayFloat.java)
|
||||
* [MedianOfRunningArrayInteger](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MedianOfRunningArrayInteger.java)
|
||||
* [MedianOfRunningArrayLong](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MedianOfRunningArrayLong.java)
|
||||
* [MirrorOfMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java)
|
||||
* [PalindromePrime](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/PalindromePrime.java)
|
||||
* [PalindromeSinglyLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java)
|
||||
* [RangeInSortedArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/RangeInSortedArray.java)
|
||||
* [Sort012D](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/Sort012D.java)
|
||||
* [Sparsity](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/Sparsity.java)
|
||||
* [ThreeSumProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java)
|
||||
* [TwoSumProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/TwoSumProblem.java)
|
||||
* [WordBoggle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/WordBoggle.java)
|
||||
* others
|
||||
* [ArrayLeftRotation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/ArrayLeftRotation.java)
|
||||
* [BankersAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/BankersAlgorithm.java)
|
||||
* [BFPRT](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/BFPRT.java)
|
||||
* [BoyerMoore](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/BoyerMoore.java)
|
||||
* [BrianKernighanAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/BrianKernighanAlgorithm.java)
|
||||
* cn
|
||||
* [HammingDistance](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/cn/HammingDistance.java)
|
||||
* [Conway](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Conway.java)
|
||||
* [CountChar](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CountChar.java)
|
||||
* [CountSetBits](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CountSetBits.java)
|
||||
* [CountWords](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CountWords.java)
|
||||
* [CRC16](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CRC16.java)
|
||||
* [CRC32](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CRC32.java)
|
||||
* [CRCAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CRCAlgorithm.java)
|
||||
* [Damm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Damm.java)
|
||||
* [Dijkstra](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Dijkstra.java)
|
||||
* [FibbonaciSeries](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/FibbonaciSeries.java)
|
||||
* [FloydTriangle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/FloydTriangle.java)
|
||||
* [GaussLegendre](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/GaussLegendre.java)
|
||||
* [HappyNumbersSeq](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/HappyNumbersSeq.java)
|
||||
* [Huffman](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Huffman.java)
|
||||
* [Implementing auto completing features using trie](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Implementing_auto_completing_features_using_trie.java)
|
||||
* [InsertDeleteInArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/InsertDeleteInArray.java)
|
||||
* [KochSnowflake](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/KochSnowflake.java)
|
||||
* [Krishnamurthy](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Krishnamurthy.java)
|
||||
* [LinearCongruentialGenerator](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java)
|
||||
* [LineSweep](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/LineSweep.java)
|
||||
* [LowestBasePalindrome](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/LowestBasePalindrome.java)
|
||||
* [Luhn](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Luhn.java)
|
||||
* [Mandelbrot](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Mandelbrot.java)
|
||||
* [MaximumSumOfDistinctSubarraysWithLengthK](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/MaximumSumOfDistinctSubarraysWithLengthK.java)
|
||||
* [MemoryManagementAlgorithms](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java)
|
||||
* [MiniMaxAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java)
|
||||
* [PageRank](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/PageRank.java)
|
||||
* [PasswordGen](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/PasswordGen.java)
|
||||
* [PerlinNoise](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/PerlinNoise.java)
|
||||
* [PrintAMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/PrintAMatrixInSpiralOrder.java)
|
||||
* [QueueUsingTwoStacks](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/QueueUsingTwoStacks.java)
|
||||
* [RemoveDuplicateFromString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/RemoveDuplicateFromString.java)
|
||||
* [ReturnSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/ReturnSubsequence.java)
|
||||
* [ReverseStackUsingRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/ReverseStackUsingRecursion.java)
|
||||
* [RotateMatrixBy90Degrees](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java)
|
||||
* [SkylineProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/SkylineProblem.java)
|
||||
* [StringMatchFiniteAutomata](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/StringMatchFiniteAutomata.java)
|
||||
* [Sudoku](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Sudoku.java)
|
||||
* [TowerOfHanoi](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/TowerOfHanoi.java)
|
||||
* [TwoPointers](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/TwoPointers.java)
|
||||
* [Verhoeff](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Verhoeff.java)
|
||||
* scheduling
|
||||
* [FCFSScheduling](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/scheduling/FCFSScheduling.java)
|
||||
* [PreemptivePriorityScheduling](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/scheduling/PreemptivePriorityScheduling.java)
|
||||
* [RRScheduling](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/scheduling/RRScheduling.java)
|
||||
* [SJFScheduling](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java)
|
||||
* [SRTFScheduling](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java)
|
||||
* searches
|
||||
* [BinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/BinarySearch.java)
|
||||
* [BinarySearch2dArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java)
|
||||
* [BreadthFirstSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/BreadthFirstSearch.java)
|
||||
* [DepthFirstSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/DepthFirstSearch.java)
|
||||
* [ExponentalSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/ExponentalSearch.java)
|
||||
* [FibonacciSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/FibonacciSearch.java)
|
||||
* [HowManyTimesRotated](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/HowManyTimesRotated.java)
|
||||
* [InterpolationSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/InterpolationSearch.java)
|
||||
* [IterativeBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java)
|
||||
* [IterativeTernarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/IterativeTernarySearch.java)
|
||||
* [JumpSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/JumpSearch.java)
|
||||
* [KMPSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/KMPSearch.java)
|
||||
* [LinearSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LinearSearch.java)
|
||||
* [LinearSearchThread](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LinearSearchThread.java)
|
||||
* [LowerBound](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LowerBound.java)
|
||||
* [MonteCarloTreeSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/MonteCarloTreeSearch.java)
|
||||
* [OrderAgnosticBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/OrderAgnosticBinarySearch.java)
|
||||
* [PerfectBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/PerfectBinarySearch.java)
|
||||
* [QuickSelect](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/QuickSelect.java)
|
||||
* [RabinKarpAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/RabinKarpAlgorithm.java)
|
||||
* [RecursiveBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/RecursiveBinarySearch.java)
|
||||
* [RowColumnWiseSorted2dArrayBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/RowColumnWiseSorted2dArrayBinarySearch.java)
|
||||
* [SaddlebackSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java)
|
||||
* [SearchInARowAndColWiseSortedMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/SearchInARowAndColWiseSortedMatrix.java)
|
||||
* [SortOrderAgnosticBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/SortOrderAgnosticBinarySearch.java)
|
||||
* [SquareRootBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/SquareRootBinarySearch.java)
|
||||
* [TernarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/TernarySearch.java)
|
||||
* [UnionFind](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/UnionFind.java)
|
||||
* [UpperBound](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/UpperBound.java)
|
||||
* sorts
|
||||
* [BeadSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BeadSort.java)
|
||||
* [BinaryInsertionSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BinaryInsertionSort.java)
|
||||
* [BitonicSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BitonicSort.java)
|
||||
* [BogoSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BogoSort.java)
|
||||
* [BubbleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSort.java)
|
||||
* [BubbleSortRecursive](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSortRecursive.java)
|
||||
* [BucketSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BucketSort.java)
|
||||
* [CircleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CircleSort.java)
|
||||
* [CocktailShakerSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CocktailShakerSort.java)
|
||||
* [CombSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CombSort.java)
|
||||
* [CountingSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CountingSort.java)
|
||||
* [CycleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CycleSort.java)
|
||||
* [DNFSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/DNFSort.java)
|
||||
* [DualPivotQuickSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/DualPivotQuickSort.java)
|
||||
* [DutchNationalFlagSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/DutchNationalFlagSort.java)
|
||||
* [ExchangeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/ExchangeSort.java)
|
||||
* [FlashSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/FlashSort.java)
|
||||
* [GnomeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/GnomeSort.java)
|
||||
* [HeapSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/HeapSort.java)
|
||||
* [InsertionSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/InsertionSort.java)
|
||||
* [IntrospectiveSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/IntrospectiveSort.java)
|
||||
* [LinkListSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/LinkListSort.java)
|
||||
* [MergeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/MergeSort.java)
|
||||
* [MergeSortNoExtraSpace](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/MergeSortNoExtraSpace.java)
|
||||
* [MergeSortRecursive](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/MergeSortRecursive.java)
|
||||
* [OddEvenSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/OddEvenSort.java)
|
||||
* [PancakeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/PancakeSort.java)
|
||||
* [PatienceSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/PatienceSort.java)
|
||||
* [PigeonholeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/PigeonholeSort.java)
|
||||
* [QuickSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/QuickSort.java)
|
||||
* [RadixSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/RadixSort.java)
|
||||
* [SelectionSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SelectionSort.java)
|
||||
* [SelectionSortRecursive](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SelectionSortRecursive.java)
|
||||
* [ShellSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/ShellSort.java)
|
||||
* [SimpleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SimpleSort.java)
|
||||
* [SlowSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SlowSort.java)
|
||||
* [SortAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SortAlgorithm.java)
|
||||
* [SortUtils](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SortUtils.java)
|
||||
* [SortUtilsRandomGenerator](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SortUtilsRandomGenerator.java)
|
||||
* [SpreadSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SpreadSort.java)
|
||||
* [StoogeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/StoogeSort.java)
|
||||
* [StrandSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/StrandSort.java)
|
||||
* [SwapSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SwapSort.java)
|
||||
* [TimSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/TimSort.java)
|
||||
* [TopologicalSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/TopologicalSort.java)
|
||||
* [TreeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/TreeSort.java)
|
||||
* [WaveSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/WaveSort.java)
|
||||
* [WiggleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/WiggleSort.java)
|
||||
* stacks
|
||||
* [BalancedBrackets](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/BalancedBrackets.java)
|
||||
* [DecimalToAnyUsingStack](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/DecimalToAnyUsingStack.java)
|
||||
* [DuplicateBrackets](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/DuplicateBrackets.java)
|
||||
* [InfixToPostfix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/InfixToPostfix.java)
|
||||
* [LargestRectangle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/LargestRectangle.java)
|
||||
* [MaximumMinimumWindow](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/MaximumMinimumWindow.java)
|
||||
* [NextGreaterElement](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/NextGreaterElement.java)
|
||||
* [NextSmallerElement](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/NextSmallerElement.java)
|
||||
* [PostfixToInfix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/PostfixToInfix.java)
|
||||
* [StackPostfixNotation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/StackPostfixNotation.java)
|
||||
* strings
|
||||
* [AhoCorasick](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/AhoCorasick.java)
|
||||
* [Alphabetical](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Alphabetical.java)
|
||||
* [Anagrams](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Anagrams.java)
|
||||
* [CharactersSame](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/CharactersSame.java)
|
||||
* [CheckAnagrams](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/CheckAnagrams.java)
|
||||
* [CheckVowels](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/CheckVowels.java)
|
||||
* [HammingDistance](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/HammingDistance.java)
|
||||
* [HorspoolSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/HorspoolSearch.java)
|
||||
* [Isomorphic](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Isomorphic.java)
|
||||
* [KMP](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/KMP.java)
|
||||
* [LetterCombinationsOfPhoneNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/LetterCombinationsOfPhoneNumber.java)
|
||||
* [LongestNonRepetitiveSubstring](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/LongestNonRepetitiveSubstring.java)
|
||||
* [LongestPalindromicSubstring](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/LongestPalindromicSubstring.java)
|
||||
* [Lower](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Lower.java)
|
||||
* [MyAtoi](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/MyAtoi.java)
|
||||
* [Palindrome](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Palindrome.java)
|
||||
* [Pangram](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Pangram.java)
|
||||
* [PermuteString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/PermuteString.java)
|
||||
* [RabinKarp](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/RabinKarp.java)
|
||||
* [ReverseString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ReverseString.java)
|
||||
* [ReverseStringRecursive](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ReverseStringRecursive.java)
|
||||
* [ReverseWordsInString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ReverseWordsInString.java)
|
||||
* [Rotation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Rotation.java)
|
||||
* [StringCompression](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/StringCompression.java)
|
||||
* [Upper](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Upper.java)
|
||||
* [ValidParentheses](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ValidParentheses.java)
|
||||
* [WordLadder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/WordLadder.java)
|
||||
* zigZagPattern
|
||||
* [ZigZagPattern](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/zigZagPattern/ZigZagPattern.java)
|
||||
* test
|
||||
* java
|
||||
* com
|
||||
* thealgorithms
|
||||
* backtracking
|
||||
* [AllPathsFromSourceToTargetTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/AllPathsFromSourceToTargetTest.java)
|
||||
* [ArrayCombinationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/ArrayCombinationTest.java)
|
||||
* [CombinationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/CombinationTest.java)
|
||||
* [FloodFillTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/FloodFillTest.java)
|
||||
* [MazeRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/MazeRecursionTest.java)
|
||||
* [MColoringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/MColoringTest.java)
|
||||
* [NQueensTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/NQueensTest.java)
|
||||
* [ParenthesesGeneratorTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/ParenthesesGeneratorTest.java)
|
||||
* [PermutationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/PermutationTest.java)
|
||||
* [PowerSumTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/PowerSumTest.java)
|
||||
* [SubsequenceFinderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/SubsequenceFinderTest.java)
|
||||
* [WordSearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/WordSearchTest.java)
|
||||
* bitmanipulation
|
||||
* [BitSwapTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/BitSwapTest.java)
|
||||
* [HighestSetBitTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/HighestSetBitTest.java)
|
||||
* [IndexOfRightMostSetBitTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBitTest.java)
|
||||
* [IsEvenTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/IsEvenTest.java)
|
||||
* [IsPowerTwoTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/IsPowerTwoTest.java)
|
||||
* [NonRepeatingNumberFinderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/NonRepeatingNumberFinderTest.java)
|
||||
* [NumbersDifferentSignsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java)
|
||||
* [ReverseBitsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/ReverseBitsTest.java)
|
||||
* [SingleBitOperationsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/SingleBitOperationsTest.java)
|
||||
* ciphers
|
||||
* a5
|
||||
* [LFSRTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/a5/LFSRTest.java)
|
||||
* [BlowfishTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/BlowfishTest.java)
|
||||
* [CaesarTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/CaesarTest.java)
|
||||
* [DESTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/DESTest.java)
|
||||
* [PlayfairTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/PlayfairTest.java)
|
||||
* [PolybiusTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/PolybiusTest.java)
|
||||
* [RSATest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/RSATest.java)
|
||||
* [SimpleSubCipherTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/SimpleSubCipherTest.java)
|
||||
* [VigenereTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/VigenereTest.java)
|
||||
* conversions
|
||||
* [AnyBaseToDecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/AnyBaseToDecimalTest.java)
|
||||
* [BinaryToDecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/BinaryToDecimalTest.java)
|
||||
* [BinaryToHexadecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/BinaryToHexadecimalTest.java)
|
||||
* [BinaryToOctalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/BinaryToOctalTest.java)
|
||||
* [DecimalToAnyBaseTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/DecimalToAnyBaseTest.java)
|
||||
* [DecimalToBinaryTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/DecimalToBinaryTest.java)
|
||||
* [DecimalToHexadecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/DecimalToHexadecimalTest.java)
|
||||
* [DecimalToOctalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/DecimalToOctalTest.java)
|
||||
* [HexaDecimalToBinaryTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/HexaDecimalToBinaryTest.java)
|
||||
* [HexaDecimalToDecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/HexaDecimalToDecimalTest.java)
|
||||
* [HexToOctTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/HexToOctTest.java)
|
||||
* [IntegerToRomanTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/IntegerToRomanTest.java)
|
||||
* [OctalToBinaryTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/OctalToBinaryTest.java)
|
||||
* [OctalToDecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/OctalToDecimalTest.java)
|
||||
* [OctalToHexadecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/OctalToHexadecimalTest.java)
|
||||
* [RomanToIntegerTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/RomanToIntegerTest.java)
|
||||
* [UnitConversionsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/UnitConversionsTest.java)
|
||||
* [UnitsConverterTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/UnitsConverterTest.java)
|
||||
* datastructures
|
||||
* bag
|
||||
* [BagTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/bag/BagTest.java)
|
||||
* bloomfilter
|
||||
* [BloomFilterTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/bloomfilter/BloomFilterTest.java)
|
||||
* buffers
|
||||
* [CircularBufferTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/buffers/CircularBufferTest.java)
|
||||
* caches
|
||||
* [LFUCacheTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/caches/LFUCacheTest.java)
|
||||
* [LRUCacheTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/caches/LRUCacheTest.java)
|
||||
* [MRUCacheTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/caches/MRUCacheTest.java)
|
||||
* crdt
|
||||
* [GCounterTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/crdt/GCounterTest.java)
|
||||
* [GSetTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/crdt/GSetTest.java)
|
||||
* [LWWElementSetTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/crdt/LWWElementSetTest.java)
|
||||
* [ORSetTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/crdt/ORSetTest.java)
|
||||
* [PNCounterTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/crdt/PNCounterTest.java)
|
||||
* [TwoPSetTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/crdt/TwoPSetTest.java)
|
||||
* disjointsetunion
|
||||
* [DisjointSetUnionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/disjointsetunion/DisjointSetUnionTest.java)
|
||||
* dynamicarray
|
||||
* [DynamicArrayTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/dynamicarray/DynamicArrayTest.java)
|
||||
* graphs
|
||||
* [BoruvkaAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithmTest.java)
|
||||
* [DijkstraAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/graphs/DijkstraAlgorithmTest.java)
|
||||
* [FordFulkersonTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/graphs/FordFulkersonTest.java)
|
||||
* [HamiltonianCycleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/graphs/HamiltonianCycleTest.java)
|
||||
* [KosarajuTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/graphs/KosarajuTest.java)
|
||||
* [TarjansAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithmTest.java)
|
||||
* [WelshPowellTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/graphs/WelshPowellTest.java)
|
||||
* hashmap
|
||||
* hashing
|
||||
* [GenericHashMapUsingArrayListTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArrayListTest.java)
|
||||
* [GenericHashMapUsingArrayTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArrayTest.java)
|
||||
* [HashMapTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapTest.java)
|
||||
* [LinearProbingHashMapTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/hashmap/hashing/LinearProbingHashMapTest.java)
|
||||
* [MajorityElementTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/hashmap/hashing/MajorityElementTest.java)
|
||||
* [MapTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/hashmap/hashing/MapTest.java)
|
||||
* [HashMapCuckooHashingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/hashmap/HashMapCuckooHashingTest.java)
|
||||
* heaps
|
||||
* [FibonacciHeapTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/heaps/FibonacciHeapTest.java)
|
||||
* [LeftistHeapTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/heaps/LeftistHeapTest.java)
|
||||
* lists
|
||||
* [CircleLinkedListTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/lists/CircleLinkedListTest.java)
|
||||
* [QuickSortLinkedListTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/lists/QuickSortLinkedListTest.java)
|
||||
* [ReverseKGroupTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java)
|
||||
* [RotateSinglyLinkedListsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java)
|
||||
* [SinglyLinkedListTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/lists/SinglyLinkedListTest.java)
|
||||
* [SkipListTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/lists/SkipListTest.java)
|
||||
* queues
|
||||
* [CircularQueueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/queues/CircularQueueTest.java)
|
||||
* [DequeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/queues/DequeTest.java)
|
||||
* [GenericArrayListQueueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/queues/GenericArrayListQueueTest.java)
|
||||
* [LinkedQueueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/queues/LinkedQueueTest.java)
|
||||
* [PriorityQueuesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java)
|
||||
* [QueueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/queues/QueueTest.java)
|
||||
* stacks
|
||||
* [LinkedListStackTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/stacks/LinkedListStackTest.java)
|
||||
* [StackArrayListTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/stacks/StackArrayListTest.java)
|
||||
* [StackArrayTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/stacks/StackArrayTest.java)
|
||||
* trees
|
||||
* [BinaryTreeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/BinaryTreeTest.java)
|
||||
* [BSTFromSortedArrayTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/BSTFromSortedArrayTest.java)
|
||||
* [BSTIterativeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/BSTIterativeTest.java)
|
||||
* [BSTRecursiveTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/BSTRecursiveTest.java)
|
||||
* [CeilInBinarySearchTreeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTreeTest.java)
|
||||
* [CheckBinaryTreeIsValidBSTTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/CheckBinaryTreeIsValidBSTTest.java)
|
||||
* [CheckIfBinaryTreeBalancedTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/CheckIfBinaryTreeBalancedTest.java)
|
||||
* [CheckTreeIsSymmetricTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetricTest.java)
|
||||
* [CreateBinaryTreeFromInorderPreorderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/CreateBinaryTreeFromInorderPreorderTest.java)
|
||||
* [InorderTraversalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/InorderTraversalTest.java)
|
||||
* [KDTreeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/KDTreeTest.java)
|
||||
* [LazySegmentTreeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/LazySegmentTreeTest.java)
|
||||
* [LevelOrderTraversalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/LevelOrderTraversalTest.java)
|
||||
* [PostOrderTraversalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/PostOrderTraversalTest.java)
|
||||
* [PreOrderTraversalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/PreOrderTraversalTest.java)
|
||||
* [SameTreesCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/SameTreesCheckTest.java)
|
||||
* [SplayTreeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/SplayTreeTest.java)
|
||||
* [TreeTestUtils](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/TreeTestUtils.java)
|
||||
* [VerticalOrderTraversalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/VerticalOrderTraversalTest.java)
|
||||
* [ZigzagTraversalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/ZigzagTraversalTest.java)
|
||||
* divideandconquer
|
||||
* [BinaryExponentiationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/divideandconquer/BinaryExponentiationTest.java)
|
||||
* [StrassenMatrixMultiplicationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/divideandconquer/StrassenMatrixMultiplicationTest.java)
|
||||
* dynamicprogramming
|
||||
* [BoardPathTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/BoardPathTest.java)
|
||||
* [CatalanNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/CatalanNumberTest.java)
|
||||
* [ClimbStairsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/ClimbStairsTest.java)
|
||||
* [EditDistanceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/EditDistanceTest.java)
|
||||
* [EggDroppingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/EggDroppingTest.java)
|
||||
* [KnapsackMemoizationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/KnapsackMemoizationTest.java)
|
||||
* [KnapsackTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/KnapsackTest.java)
|
||||
* [LevenshteinDistanceTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LevenshteinDistanceTests.java)
|
||||
* [LongestAlternatingSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequenceTest.java)
|
||||
* [LongestIncreasingSubsequenceTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceTests.java)
|
||||
* [LongestPalindromicSubstringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstringTest.java)
|
||||
* [LongestValidParenthesesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestValidParenthesesTest.java)
|
||||
* [MinimumPathSumTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/MinimumPathSumTest.java)
|
||||
* [MinimumSumPartitionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/MinimumSumPartitionTest.java)
|
||||
* [OptimalJobSchedulingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/OptimalJobSchedulingTest.java)
|
||||
* [PalindromicPartitioningTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/PalindromicPartitioningTest.java)
|
||||
* [PartitionProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/PartitionProblemTest.java)
|
||||
* [RegexMatchingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/RegexMatchingTest.java)
|
||||
* [ShortestCommonSupersequenceLengthTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/ShortestCommonSupersequenceLengthTest.java)
|
||||
* [SubsetCountTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/SubsetCountTest.java)
|
||||
* [SubsetSumTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/SubsetSumTest.java)
|
||||
* [SumOfSubsetTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/SumOfSubsetTest.java)
|
||||
* [TribonacciTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/TribonacciTest.java)
|
||||
* [UniquePathsTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/UniquePathsTests.java)
|
||||
* [WildcardMatchingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/WildcardMatchingTest.java)
|
||||
* geometry
|
||||
* [GrahamScanTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/geometry/GrahamScanTest.java)
|
||||
* greedyalgorithms
|
||||
* [ActivitySelectionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/greedyalgorithms/ActivitySelectionTest.java)
|
||||
* [CoinChangeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/greedyalgorithms/CoinChangeTest.java)
|
||||
* [FractionalKnapsackTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/greedyalgorithms/FractionalKnapsackTest.java)
|
||||
* [JobSequencingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/greedyalgorithms/JobSequencingTest.java)
|
||||
* [MinimizingLatenessTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/greedyalgorithms/MinimizingLatenessTest.java)
|
||||
* io
|
||||
* [BufferedReaderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/io/BufferedReaderTest.java)
|
||||
* maths
|
||||
* [AbsoluteMaxTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AbsoluteMaxTest.java)
|
||||
* [AbsoluteMinTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AbsoluteMinTest.java)
|
||||
* [AbsoluteValueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AbsoluteValueTest.java)
|
||||
* [ADTFractionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/ADTFractionTest.java)
|
||||
* [AliquotSumTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AliquotSumTest.java)
|
||||
* [AmicableNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AmicableNumberTest.java)
|
||||
* [AreaTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AreaTest.java)
|
||||
* [ArmstrongTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/ArmstrongTest.java)
|
||||
* [AutoCorrelationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AutoCorrelationTest.java)
|
||||
* [AutomorphicNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AutomorphicNumberTest.java)
|
||||
* [AverageTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/AverageTest.java)
|
||||
* [BinaryPowTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/BinaryPowTest.java)
|
||||
* [BinomialCoefficientTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/BinomialCoefficientTest.java)
|
||||
* [CeilTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/CeilTest.java)
|
||||
* [CollatzConjectureTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/CollatzConjectureTest.java)
|
||||
* [CombinationsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/CombinationsTest.java)
|
||||
* [CrossCorrelationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/CrossCorrelationTest.java)
|
||||
* [DeterminantOfMatrixTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/DeterminantOfMatrixTest.java)
|
||||
* [DigitalRootTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/DigitalRootTest.java)
|
||||
* [DistanceFormulaTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/DistanceFormulaTest.java)
|
||||
* [DudeneyNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/DudeneyNumberTest.java)
|
||||
* [EulersFunctionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/EulersFunctionTest.java)
|
||||
* [FactorialRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FactorialRecursionTest.java)
|
||||
* [FactorialTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FactorialTest.java)
|
||||
* [FastInverseSqrtTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FastInverseSqrtTests.java)
|
||||
* [FFTTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FFTTest.java)
|
||||
* [FibonacciJavaStreamsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FibonacciJavaStreamsTest.java)
|
||||
* [FibonacciLoopTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FibonacciLoopTest.java)
|
||||
* [FibonacciNumberCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FibonacciNumberCheckTest.java)
|
||||
* [FibonacciNumberGoldenRationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FibonacciNumberGoldenRationTest.java)
|
||||
* [FindKthNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FindKthNumberTest.java)
|
||||
* [FindMaxRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FindMaxRecursionTest.java)
|
||||
* [FindMaxTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FindMaxTest.java)
|
||||
* [FindMinRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FindMinRecursionTest.java)
|
||||
* [FindMinTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FindMinTest.java)
|
||||
* [FloorTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FloorTest.java)
|
||||
* [FrizzyNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/FrizzyNumberTest.java)
|
||||
* [GaussianTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/GaussianTest.java)
|
||||
* [GCDRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/GCDRecursionTest.java)
|
||||
* [GCDTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/GCDTest.java)
|
||||
* [GenericRootTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/GenericRootTest.java)
|
||||
* [HarshadNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/HarshadNumberTest.java)
|
||||
* [HeronsFormulaTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/HeronsFormulaTest.java)
|
||||
* [JosephusProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/JosephusProblemTest.java)
|
||||
* [KaprekarNumbersTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/KaprekarNumbersTest.java)
|
||||
* [LeastCommonMultipleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java)
|
||||
* [LeonardoNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LeonardoNumberTest.java)
|
||||
* [LiouvilleLambdaFunctionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LiouvilleLambdaFunctionTest.java)
|
||||
* [LongDivisionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LongDivisionTest.java)
|
||||
* [LucasSeriesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LucasSeriesTest.java)
|
||||
* [MatrixRankTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MatrixRankTest.java)
|
||||
* [MatrixUtilTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MatrixUtilTest.java)
|
||||
* [MaxValueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MaxValueTest.java)
|
||||
* [MeansTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MeansTest.java)
|
||||
* [MedianTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MedianTest.java)
|
||||
* [MillerRabinPrimalityCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MillerRabinPrimalityCheckTest.java)
|
||||
* [MinValueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MinValueTest.java)
|
||||
* [MobiusFunctionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MobiusFunctionTest.java)
|
||||
* [ModeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/ModeTest.java)
|
||||
* [NonRepeatingElementTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/NonRepeatingElementTest.java)
|
||||
* [NthUglyNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/NthUglyNumberTest.java)
|
||||
* [NumberOfDigitsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/NumberOfDigitsTest.java)
|
||||
* [PalindromeNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PalindromeNumberTest.java)
|
||||
* [ParseIntegerTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/ParseIntegerTest.java)
|
||||
* [PascalTriangleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PascalTriangleTest.java)
|
||||
* [PerfectCubeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PerfectCubeTest.java)
|
||||
* [PerfectNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PerfectNumberTest.java)
|
||||
* [PerfectSquareTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PerfectSquareTest.java)
|
||||
* [PerimeterTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PerimeterTest.java)
|
||||
* [PollardRhoTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PollardRhoTest.java)
|
||||
* [PowerOfTwoOrNotTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PowerOfTwoOrNotTest.java)
|
||||
* [PowerUsingRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PowerUsingRecursionTest.java)
|
||||
* [PowTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PowTest.java)
|
||||
* [PrimeCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PrimeCheckTest.java)
|
||||
* [PrimeFactorizationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java)
|
||||
* [PronicNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PronicNumberTest.java)
|
||||
* [PythagoreanTripleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PythagoreanTripleTest.java)
|
||||
* [ReverseNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/ReverseNumberTest.java)
|
||||
* [SecondMinMaxTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/SecondMinMaxTest.java)
|
||||
* [SieveOfEratosthenesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/SieveOfEratosthenesTest.java)
|
||||
* [SquareFreeIntegerTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/SquareFreeIntegerTest.java)
|
||||
* [SquareRootwithBabylonianMethodTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/SquareRootwithBabylonianMethodTest.java)
|
||||
* [SquareRootWithNewtonRaphsonTestMethod](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonTestMethod.java)
|
||||
* [StandardDeviationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/StandardDeviationTest.java)
|
||||
* [StandardScoreTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/StandardScoreTest.java)
|
||||
* [StrobogrammaticNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/StrobogrammaticNumberTest.java)
|
||||
* [SumOfArithmeticSeriesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/SumOfArithmeticSeriesTest.java)
|
||||
* [SumOfDigitsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/SumOfDigitsTest.java)
|
||||
* [SumWithoutArithmeticOperatorsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/SumWithoutArithmeticOperatorsTest.java)
|
||||
* [TestArmstrong](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/TestArmstrong.java)
|
||||
* [TwinPrimeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/TwinPrimeTest.java)
|
||||
* [VolumeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/VolumeTest.java)
|
||||
* misc
|
||||
* [MapReduceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/MapReduceTest.java)
|
||||
* [MedianOfMatrixtest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/MedianOfMatrixtest.java)
|
||||
* [MedianOfRunningArrayTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/MedianOfRunningArrayTest.java)
|
||||
* [MirrorOfMatrixTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/MirrorOfMatrixTest.java)
|
||||
* [PalindromeSinglyLinkedListTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/PalindromeSinglyLinkedListTest.java)
|
||||
* [TwoSumProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/TwoSumProblemTest.java)
|
||||
* others
|
||||
* [ArrayLeftRotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ArrayLeftRotationTest.java)
|
||||
* [ArrayRightRotation](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ArrayRightRotation.java)
|
||||
* [ArrayRightRotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ArrayRightRotationTest.java)
|
||||
* [BestFitCPUTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/BestFitCPUTest.java)
|
||||
* [BoyerMooreTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/BoyerMooreTest.java)
|
||||
* cn
|
||||
* [HammingDistanceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/cn/HammingDistanceTest.java)
|
||||
* [ConwayTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ConwayTest.java)
|
||||
* [CountCharTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CountCharTest.java)
|
||||
* [CountFriendsPairingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CountFriendsPairingTest.java)
|
||||
* [CountSetBitsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CountSetBitsTest.java)
|
||||
* [CountWordsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CountWordsTest.java)
|
||||
* [CRC16Test](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CRC16Test.java)
|
||||
* [CRCAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CRCAlgorithmTest.java)
|
||||
* [FirstFitCPUTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/FirstFitCPUTest.java)
|
||||
* [FloydTriangleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/FloydTriangleTest.java)
|
||||
* [KadaneAlogrithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/KadaneAlogrithmTest.java)
|
||||
* [LineSweepTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/LineSweepTest.java)
|
||||
* [LinkListSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/LinkListSortTest.java)
|
||||
* [LowestBasePalindromeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/LowestBasePalindromeTest.java)
|
||||
* [MaximumSumOfDistinctSubarraysWithLengthKTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/MaximumSumOfDistinctSubarraysWithLengthKTest.java)
|
||||
* [NewManShanksPrimeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/NewManShanksPrimeTest.java)
|
||||
* [NextFitTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/NextFitTest.java)
|
||||
* [PasswordGenTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/PasswordGenTest.java)
|
||||
* [QueueUsingTwoStacksTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/QueueUsingTwoStacksTest.java)
|
||||
* [RemoveDuplicateFromStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/RemoveDuplicateFromStringTest.java)
|
||||
* [ReturnSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ReturnSubsequenceTest.java)
|
||||
* [ReverseStackUsingRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ReverseStackUsingRecursionTest.java)
|
||||
* [StringMatchFiniteAutomataTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/StringMatchFiniteAutomataTest.java)
|
||||
* [TestPrintMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java)
|
||||
* [TwoPointersTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TwoPointersTest.java)
|
||||
* [WorstFitCPUTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/WorstFitCPUTest.java)
|
||||
* scheduling
|
||||
* [FCFSSchedulingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/scheduling/FCFSSchedulingTest.java)
|
||||
* [PreemptivePrioritySchedulingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/scheduling/PreemptivePrioritySchedulingTest.java)
|
||||
* [RRSchedulingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/scheduling/RRSchedulingTest.java)
|
||||
* [SJFSchedulingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/scheduling/SJFSchedulingTest.java)
|
||||
* [SRTFSchedulingTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/scheduling/SRTFSchedulingTest.java)
|
||||
* searches
|
||||
* [BinarySearch2dArrayTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/BinarySearch2dArrayTest.java)
|
||||
* [BreadthFirstSearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/BreadthFirstSearchTest.java)
|
||||
* [DepthFirstSearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/DepthFirstSearchTest.java)
|
||||
* [HowManyTimesRotatedTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/HowManyTimesRotatedTest.java)
|
||||
* [KMPSearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/KMPSearchTest.java)
|
||||
* [OrderAgnosticBinarySearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/OrderAgnosticBinarySearchTest.java)
|
||||
* [PerfectBinarySearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/PerfectBinarySearchTest.java)
|
||||
* [QuickSelectTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/QuickSelectTest.java)
|
||||
* [RabinKarpAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/RabinKarpAlgorithmTest.java)
|
||||
* [RecursiveBinarySearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/RecursiveBinarySearchTest.java)
|
||||
* [RowColumnWiseSorted2dArrayBinarySearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/RowColumnWiseSorted2dArrayBinarySearchTest.java)
|
||||
* [SortOrderAgnosticBinarySearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/SortOrderAgnosticBinarySearchTest.java)
|
||||
* [TestSearchInARowAndColWiseSortedMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/TestSearchInARowAndColWiseSortedMatrix.java)
|
||||
* sorts
|
||||
* [BeadSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BeadSortTest.java)
|
||||
* [BinaryInsertionSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BinaryInsertionSortTest.java)
|
||||
* [BitonicSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BitonicSortTest.java)
|
||||
* [BogoSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BogoSortTest.java)
|
||||
* [BubbleSortRecursiveTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BubbleSortRecursiveTest.java)
|
||||
* [BubbleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java)
|
||||
* [BucketSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BucketSortTest.java)
|
||||
* [CircleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CircleSortTest.java)
|
||||
* [CocktailShakerSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CocktailShakerSortTest.java)
|
||||
* [CombSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CombSortTest.java)
|
||||
* [CountingSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CountingSortTest.java)
|
||||
* [CycleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CycleSortTest.java)
|
||||
* [DualPivotQuickSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/DualPivotQuickSortTest.java)
|
||||
* [DutchNationalFlagSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/DutchNationalFlagSortTest.java)
|
||||
* [ExchangeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/ExchangeSortTest.java)
|
||||
* [FlashSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/FlashSortTest.java)
|
||||
* [GnomeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java)
|
||||
* [HeapSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/HeapSortTest.java)
|
||||
* [InsertionSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java)
|
||||
* [IntrospectiveSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/IntrospectiveSortTest.java)
|
||||
* [MergeSortNoExtraSpaceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/MergeSortNoExtraSpaceTest.java)
|
||||
* [MergeSortRecursiveTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/MergeSortRecursiveTest.java)
|
||||
* [MergeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/MergeSortTest.java)
|
||||
* [OddEvenSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/OddEvenSortTest.java)
|
||||
* [PancakeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/PancakeSortTest.java)
|
||||
* [PatienceSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/PatienceSortTest.java)
|
||||
* [PigeonholeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/PigeonholeSortTest.java)
|
||||
* [QuickSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/QuickSortTest.java)
|
||||
* [RadixSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/RadixSortTest.java)
|
||||
* [SelectionSortRecursiveTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SelectionSortRecursiveTest.java)
|
||||
* [SelectionSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SelectionSortTest.java)
|
||||
* [ShellSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/ShellSortTest.java)
|
||||
* [SimpleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SimpleSortTest.java)
|
||||
* [SlowSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SlowSortTest.java)
|
||||
* [SortingAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SortingAlgorithmTest.java)
|
||||
* [SortUtilsRandomGeneratorTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SortUtilsRandomGeneratorTest.java)
|
||||
* [SortUtilsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SortUtilsTest.java)
|
||||
* [SpreadSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SpreadSortTest.java)
|
||||
* [StoogeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/StoogeSortTest.java)
|
||||
* [StrandSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/StrandSortTest.java)
|
||||
* [SwapSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SwapSortTest.java)
|
||||
* [TimSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/TimSortTest.java)
|
||||
* [TopologicalSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/TopologicalSortTest.java)
|
||||
* [TreeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/TreeSortTest.java)
|
||||
* [WaveSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/WaveSortTest.java)
|
||||
* [WiggleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/WiggleSortTest.java)
|
||||
* stacks
|
||||
* [BalancedBracketsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/BalancedBracketsTest.java)
|
||||
* [DecimalToAnyUsingStackTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/DecimalToAnyUsingStackTest.java)
|
||||
* [DuplicateBracketsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/DuplicateBracketsTest.java)
|
||||
* [InfixToPostfixTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/InfixToPostfixTest.java)
|
||||
* [LargestRectangleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/LargestRectangleTest.java)
|
||||
* [NextGreaterElementTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/NextGreaterElementTest.java)
|
||||
* [NextSmallerElementTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/NextSmallerElementTest.java)
|
||||
* [PostfixToInfixTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/PostfixToInfixTest.java)
|
||||
* [StackPostfixNotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/StackPostfixNotationTest.java)
|
||||
* strings
|
||||
* [AhoCorasickTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/AhoCorasickTest.java)
|
||||
* [AlphabeticalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/AlphabeticalTest.java)
|
||||
* [AnagramsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/AnagramsTest.java)
|
||||
* [CharacterSameTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/CharacterSameTest.java)
|
||||
* [CheckAnagramsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/CheckAnagramsTest.java)
|
||||
* [CheckVowelsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/CheckVowelsTest.java)
|
||||
* [HammingDistanceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/HammingDistanceTest.java)
|
||||
* [HorspoolSearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/HorspoolSearchTest.java)
|
||||
* [IsomorphicTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/IsomorphicTest.java)
|
||||
* [LetterCombinationsOfPhoneNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/LetterCombinationsOfPhoneNumberTest.java)
|
||||
* [LongestNonRepetitiveSubstringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/LongestNonRepetitiveSubstringTest.java)
|
||||
* [LongestPalindromicSubstringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/LongestPalindromicSubstringTest.java)
|
||||
* [LowerTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/LowerTest.java)
|
||||
* [MyAtoiTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/MyAtoiTest.java)
|
||||
* [PalindromeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/PalindromeTest.java)
|
||||
* [PangramTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/PangramTest.java)
|
||||
* [PermuteStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/PermuteStringTest.java)
|
||||
* [ReverseStringRecursiveTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ReverseStringRecursiveTest.java)
|
||||
* [ReverseStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ReverseStringTest.java)
|
||||
* [ReverseWordsInStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ReverseWordsInStringTest.java)
|
||||
* [RotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/RotationTest.java)
|
||||
* [StringCompressionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/StringCompressionTest.java)
|
||||
* [UpperTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/UpperTest.java)
|
||||
* [ValidParenthesesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ValidParenthesesTest.java)
|
||||
* [WordLadderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/WordLadderTest.java)
|
||||
* zigZagPattern
|
||||
* [ZigZagPatternTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/zigZagPattern/ZigZagPatternTest.java)
|
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 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.
|
191
README-ko.md
191
README-ko.md
@ -1,191 +0,0 @@
|
||||
# 알고리즘 - 자바
|
||||
|
||||
## 이 [개발브런치](https://github.com/TheAlgorithms/Java/tree/Development)는 기존 프로젝트를 Java 프로젝트 구조로 재개발하기 위해 작성되었다. 기여도를 위해 개발 지사로 전환할 수 있다. 자세한 내용은 이 문제를 참조하십시오. 컨트리뷰션을 위해 [개발브런치](https://github.com/TheAlgorithms/Java/tree/Development)로 전환할 수 있다. 자세한 내용은 [이 이슈](https://github.com/TheAlgorithms/Java/issues/474)를 참고하십시오.
|
||||
|
||||
### 자바로 구현된 모든 알고리즘들 (교육용)
|
||||
|
||||
이것들은 단지 시범을 위한 것이다. 표준 자바 라이브러리에는 성능상의 이유로 더 나은 것들이 구현되어있다
|
||||
|
||||
## 정렬 알고리즘
|
||||
|
||||
### Bubble(버블 정렬)
|
||||
|
||||
![alt text][bubble-image]
|
||||
|
||||
From [Wikipedia][bubble-wiki]: 버블 소트(sinking sor라고도 불리움)는 리스트를 반복적인 단계로 접근하여 정렬한다. 각각의 짝을 비교하며, 순서가 잘못된 경우 그접한 아이템들을 스왑하는 알고리즘이다. 더 이상 스왑할 것이 없을 때까지 반복하며, 반복이 끝남음 리스트가 정렬되었음을 의미한다.
|
||||
|
||||
**속성**
|
||||
|
||||
- 최악의 성능 O(n^2)
|
||||
- 최고의 성능 O(n)
|
||||
- 평균 성능 O(n^2)
|
||||
|
||||
###### View the algorithm in [action][bubble-toptal]
|
||||
|
||||
### Insertion(삽입 정렬)
|
||||
|
||||
![alt text][insertion-image]
|
||||
|
||||
From [Wikipedia][insertion-wiki]: 삽입 정렬은 최종 정렬된 배열(또는 리스트)을 한번에 하나씩 구축하는 알고리즘이다. 이것은 큰 리스트에서 더 나은 알고리즘인 퀵 소트, 힙 소트, 또는 머지 소트보다 훨씬 안좋은 효율을 가진다. 그림에서 각 막대는 정렬해야 하는 배열의 요소를 나타낸다. 상단과 두 번째 상단 막대의 첫 번째 교차점에서 발생하는 것은 두 번째 요소가 첫 번째 요소보다 더 높은 우선 순위를 가지기 때문에 막대로 표시되는 이러한 요소를 교환한 것이다. 이 방법을 반복하면 삽입 정렬이 완료된다.
|
||||
|
||||
**속성**
|
||||
|
||||
- 최악의 성능 O(n^2)
|
||||
- 최고의 성능 O(n)
|
||||
- 평균 O(n^2)
|
||||
|
||||
###### View the algorithm in [action][insertion-toptal]
|
||||
|
||||
### Merge(합병 정렬)
|
||||
|
||||
![alt text][merge-image]
|
||||
|
||||
From [Wikipedia][merge-wiki]: 컴퓨터 과학에서, 합병 정렬은 효율적인, 범용적인, 비교 기반 정렬 알고리즘이다. 대부분의 구현은 안정적인 분류를 이루는데, 이것은 구현이 정렬된 출력에 동일한 요소의 입력 순서를 유지한다는 것을 의미한다. 합병 정렬은 1945년에 John von Neumann이 발명한 분할 정복 알고리즘이다.
|
||||
|
||||
**속성**
|
||||
|
||||
- 최악의 성능 O(n log n) (일반적)
|
||||
- 최고의 성능 O(n log n)
|
||||
- 평균 O(n log n)
|
||||
|
||||
###### View the algorithm in [action][merge-toptal]
|
||||
|
||||
### Quick(퀵 정렬)
|
||||
|
||||
![alt text][quick-image]
|
||||
|
||||
From [Wikipedia][quick-wiki]: 퀵 정렬sometimes called partition-exchange sort)은 효율적인 정렬 알고리즘으로, 배열의 요소를 순서대로 정렬하는 체계적인 방법 역활을 한다.
|
||||
|
||||
**속성**
|
||||
|
||||
- 최악의 성능 O(n^2)
|
||||
- 최고의 성능 O(n log n) or O(n) with three-way partition
|
||||
- 평균 O(n log n)
|
||||
|
||||
###### View the algorithm in [action][quick-toptal]
|
||||
|
||||
### Selection(선택 정렬)
|
||||
|
||||
![alt text][selection-image]
|
||||
|
||||
From [Wikipedia][selection-wiki]: 알고리즘 입력 리스트를 두 부분으로 나눈다 : 첫 부분은 아이템들이 이미 왼쪽에서 오른쪽으로 정렬되었다. 그리고 남은 부분의 아이템들은 나머지 항목을 차지하는 리스트이다. 처음에는 정렬된 리스트는 공백이고 나머지가 전부이다. 오르차순(또는 내림차순) 알고리즘은 가장 작은 요소를 정렬되지 않은 리스트에서 찾고 정렬이 안된 가장 왼쪽(정렬된 리스트) 리스트와 바꾼다. 이렇게 오른쪽으로 나아간다.
|
||||
|
||||
**속성**
|
||||
|
||||
- 최악의 성능 O(n^2)
|
||||
- 최고의 성능 O(n^2)
|
||||
- 평균 O(n^2)
|
||||
|
||||
###### View the algorithm in [action][selection-toptal]
|
||||
|
||||
### Shell(쉘 정렬)
|
||||
|
||||
![alt text][shell-image]
|
||||
|
||||
From [Wikipedia][shell-wiki]: 쉘 정렬은 멀리 떨어져 있는 항목의 교환을 허용하는 삽입 종류의 일반화이다. 그 아이디어는 모든 n번째 요소가 정렬된 목록을 제공한다는 것을 고려하여 어느 곳에서든지 시작하도록 요소의 목록을 배열하는 것이다. 이러한 목록은 h-sorted로 알려져 있다. 마찬가지로, 각각 개별적으로 정렬된 h 인터리브 목록으로 간주할 수 있다.
|
||||
|
||||
**속성**
|
||||
|
||||
- 최악의 성능 O(nlog2 2n)
|
||||
- 최고의 성능 O(n log n)
|
||||
- Average case performance depends on gap sequence
|
||||
|
||||
###### View the algorithm in [action][shell-toptal]
|
||||
|
||||
### 시간 복잡성 그래프
|
||||
|
||||
정렬 알고리즘의 복잡성 비교 (버블 정렬, 삽입 정렬, 선택 정렬)
|
||||
|
||||
[복잡성 그래프](https://github.com/prateekiiest/Python/blob/master/sorts/sortinggraphs.png)
|
||||
|
||||
---
|
||||
|
||||
## 검색 알고리즘
|
||||
|
||||
### Linear (선형 탐색)
|
||||
|
||||
![alt text][linear-image]
|
||||
|
||||
From [Wikipedia][linear-wiki]: 선형 탐색 또는 순차 탐색은 목록 내에서 목표값을 찾는 방법이다. 일치 항목이 발견되거나 모든 요소가 탐색될 때까지 목록의 각 요소에 대해 목표값을 순차적으로 검사한다.
|
||||
선형 검색은 최악의 선형 시간으로 실행되며 최대 n개의 비교에서 이루어진다. 여기서 n은 목록의 길이다.
|
||||
|
||||
**속성**
|
||||
|
||||
- 최악의 성능 O(n)
|
||||
- 최고의 성능 O(1)
|
||||
- 평균 O(n)
|
||||
- 최악의 경우 공간 복잡성 O(1) iterative
|
||||
|
||||
### Binary (이진 탐색)
|
||||
|
||||
![alt text][binary-image]
|
||||
|
||||
From [Wikipedia][binary-wiki]: 이진 탐색, (also known as half-interval search or logarithmic search), 은 정렬된 배열 내에서 목표값의 위치를 찾는 검색 알고리즘이다. 목표값을 배열의 중간 요소와 비교한다; 만약 목표값이 동일하지 않으면, 목표물의 절반이 제거되고 검색이 성공할 때까지 나머지 절반에서 속된다.
|
||||
|
||||
**속성**
|
||||
|
||||
- 최악의 성능 O(log n)
|
||||
- 최고의 성능 O(1)
|
||||
- 평균 O(log n)
|
||||
- 최악의 경우 공간 복잡성 O(1)
|
||||
|
||||
[bubble-toptal]: https://www.toptal.com/developers/sorting-algorithms/bubble-sort
|
||||
[bubble-wiki]: https://en.wikipedia.org/wiki/Bubble_sort
|
||||
[bubble-image]: https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Bubblesort-edited-color.svg/220px-Bubblesort-edited-color.svg.png "Bubble Sort"
|
||||
[insertion-toptal]: https://www.toptal.com/developers/sorting-algorithms/insertion-sort
|
||||
[insertion-wiki]: https://en.wikipedia.org/wiki/Insertion_sort
|
||||
[insertion-image]: https://upload.wikimedia.org/wikipedia/commons/7/7e/Insertionsort-edited.png "Insertion Sort"
|
||||
[quick-toptal]: https://www.toptal.com/developers/sorting-algorithms/quick-sort
|
||||
[quick-wiki]: https://en.wikipedia.org/wiki/Quicksort
|
||||
[quick-image]: https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif "Quick Sort"
|
||||
[merge-toptal]: https://www.toptal.com/developers/sorting-algorithms/merge-sort
|
||||
[merge-wiki]: https://en.wikipedia.org/wiki/Merge_sort
|
||||
[merge-image]: https://upload.wikimedia.org/wikipedia/commons/c/cc/Merge-sort-example-300px.gif "Merge Sort"
|
||||
[selection-toptal]: https://www.toptal.com/developers/sorting-algorithms/selection-sort
|
||||
[selection-wiki]: https://en.wikipedia.org/wiki/Selection_sort
|
||||
[selection-image]: https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Selection_sort_animation.gif/250px-Selection_sort_animation.gif "Selection Sort Sort"
|
||||
[shell-toptal]: https://www.toptal.com/developers/sorting-algorithms/shell-sort
|
||||
[shell-wiki]: https://en.wikipedia.org/wiki/Shellsort
|
||||
[shell-image]: https://upload.wikimedia.org/wikipedia/commons/d/d8/Sorting_shellsort_anim.gif "Shell Sort"
|
||||
[linear-wiki]: https://en.wikipedia.org/wiki/Linear_search
|
||||
[linear-image]: http://www.tutorialspoint.com/data_structures_algorithms/images/linear_search.gif
|
||||
[binary-wiki]: https://en.wikipedia.org/wiki/Binary_search_algorithm
|
||||
[binary-image]: https://upload.wikimedia.org/wikipedia/commons/f/f7/Binary_search_into_array.png
|
||||
|
||||
---
|
||||
|
||||
## 나머지 알고리즘에 대한 링크
|
||||
|
||||
| 전환 | 다이나믹프로그래밍(DP) | 암호 | 그 외 것들 |
|
||||
| --------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------ |
|
||||
| [Any Base to Any Base](Conversions/AnyBaseToAnyBase.java) | [Coin Change](DynamicProgramming/CoinChange.java) | [Caesar](Ciphers/Caesar.java) | [Heap Sort](Sorts/HeapSort.java) |
|
||||
| [Any Base to Decimal](Conversions/AnyBaseToDecimal.java) | [Egg Dropping](DynamicProgramming/EggDropping.java) | [Columnar Transposition Cipher](Ciphers/ColumnarTranspositionCipher.java) | [Palindromic Prime Checker](Misc/PalindromePrime.java) |
|
||||
| [Binary to Decimal](Conversions/BinaryToDecimal.java) | [Fibonacci](DynamicProgramming/Fibonacci.java) | [RSA](Ciphers/RSA.java) | More soon... |
|
||||
| [Binary to HexaDecimal](Conversions/BinaryToHexadecimal.java) | [Kadane Algorithm](DynamicProgramming/KadaneAlgorithm.java) | more coming soon... |
|
||||
| [Binary to Octal](Conversions/BinaryToOctal.java) | [Knapsack](DynamicProgramming/Knapsack.java) |
|
||||
| [Decimal To Any Base](Conversions/DecimalToAnyBase.java) | [Longest Common Subsequence](DynamicProgramming/LongestCommonSubsequence.java) |
|
||||
| [Decimal To Binary](Conversions/DecimalToBinary.java) | [Longest Increasing Subsequence](DynamicProgramming/LongestIncreasingSubsequence.java) |
|
||||
| [Decimal To Hexadecimal](Conversions/DecimalToHexaDecimal.java) | [Rod Cutting](DynamicProgramming/RodCutting.java) |
|
||||
| and much more... | and more... |
|
||||
|
||||
### 자료 구조
|
||||
|
||||
| 그래프 | 힙 | 리스트 | 큐 |
|
||||
| ------------------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------- | --------------------------------------------------------------------------- |
|
||||
| | [빈 힙 예외처리](DataStructures/Heaps/EmptyHeapException.java) | [원형 연결리스트](DataStructures/Lists/CircleLinkedList.java) | [제너릭 어레이 리스트 큐](DataStructures/Queues/GenericArrayListQueue.java) |
|
||||
| | [힙](DataStructures/Heaps/Heap.java) | [이중 연결리스트](DataStructures/Lists/DoublyLinkedList.java) | [큐](DataStructures/Queues/Queues.java) |
|
||||
| [그래프](DataStructures/Graphs/Graphs.java) | [힙 요소](DataStructures/Heaps/HeapElement.java) | [단순 연결리스트](DataStructures/Lists/SinglyLinkedList.java) |
|
||||
| [크루스칼 알고리즘](DataStructures/Graphs/Kruskal.java) | [최대힙](DataStructures/Heaps/MaxHeap.java) |
|
||||
| [행렬 그래프](DataStructures/Graphs/MatrixGraphs.java) | [최소힙](DataStructures/Heaps/MinHeap.java) |
|
||||
| [프림 최소신장트리](DataStructures/Graphs/PrimMST.java) |
|
||||
|
||||
| 스택 | 트리 |
|
||||
| --------------------------------------------------------------- | ------------------------------------------------- |
|
||||
| [노드 스택](DataStructures/Stacks/NodeStack.java) | [AVL 트리](DataStructures/Trees/AVLTree.java) |
|
||||
| [연결리스트 스택](DataStructures/Stacks/StackOfLinkedList.java) | [이진 트리](DataStructures/Trees/BinaryTree.java) |
|
||||
| [스택](DataStructures/Stacks) | And much more... |
|
||||
|
||||
- [Bags](DataStructures/Bags/Bag.java)
|
||||
- [Buffer](DataStructures/Buffers/CircularBuffer.java)
|
||||
- [HashMap](DataStructures/HashMap/Hashing/HashMap.java)
|
||||
-
|
33
README.md
33
README.md
@ -1,20 +1,21 @@
|
||||
# The Algorithms - Java
|
||||
# The Algorithms - Java (WORK IN PROGRESS)
|
||||
|
||||
[![Build](https://github.com/TheAlgorithms/Java/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/TheAlgorithms/Java/actions/workflows/build.yml)
|
||||
[![codecov](https://codecov.io/gh/TheAlgorithms/Java/graph/badge.svg?token=XAdPyqTIqR)](https://codecov.io/gh/TheAlgorithms/Java)
|
||||
[![Discord chat](https://img.shields.io/discord/808045925556682782.svg?logo=discord&colorB=7289DA&style=flat-square)](https://discord.gg/c7MnfGFGa6)
|
||||
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/Java)
|
||||
|
||||
|
||||
You can run and edit the algorithms, or contribute to them using Gitpod.io (a free online development environment) with a single click.
|
||||
|
||||
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/TheAlgorithms/Java)
|
||||
|
||||
### All algorithms are implemented in Java (for educational purposes)
|
||||
These implementations are intended for learning purposes. As such, they may be less efficient than the Java standard library.
|
||||
## Goal
|
||||
Make it a working Java project with full fledged test cases for each algorithm and correct package structures. Once we have enough test coverage, we would merge it with master.
|
||||
|
||||
## Contribution Guidelines
|
||||
Please read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute to this project.
|
||||
- If you add an algorithm then you have to add a test along with it. In the absence of a test, the PR would not be approved.
|
||||
- Follow the correct coding guidelines with proper description of the methods. Refer to [DecimalToAnyBase.java](https://github.com/TheAlgorithms/Java/blob/Development/src/main/java/com/conversions/DecimalToAnyBase.java) and [DecimalToAnyBaseTest.java](https://github.com/TheAlgorithms/Java/blob/Development/src/test/java/com/conversions/DecimalToAnyBaseTest.java) for the algorithms and tests coding standards, respectively.
|
||||
- Do not add a main method as we just need the actual algorithm in a method for the class which we are going to test in the test cases.
|
||||
- Please do not add a signature inside the code. The commit history is sufficient to determine who has added the code to the repo.
|
||||
- Make sure the algorithm which is getting added comes under a certain domain of Algorithms. Please don't create a package with a name such as Misc, Others, etc.
|
||||
- While making a PR, make sure you are committing the Java files only and not any project specific files. If you feel that your IDE is generating some extra files, then either don't add them to git, or add the extensions to ```.gitignore```.
|
||||
- Please don't add solutions to problems from online judges such as Hackerrank, Leetcode, etc.
|
||||
|
||||
## Algorithms
|
||||
Our [directory](DIRECTORY.md) has the full list of applications.
|
||||
## Steps to raise a PR
|
||||
- Fork the [Java Repo](https://github.com/TheAlgorithms/Java)
|
||||
- Open the forked repo on your local machine
|
||||
- Switch to the ```Development``` branch by using the command ```git checkout Development```
|
||||
- Make the changes on your local machine
|
||||
- Push the changes to the forked repository
|
||||
- Raise a PR against the Development branch
|
||||
|
28
build.gradle
Normal file
28
build.gradle
Normal file
@ -0,0 +1,28 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = 'https://repo.maven.apache.org/maven2'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation('org.junit.jupiter:junit-jupiter-api:5.5.0')
|
||||
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.5.0')
|
||||
compile 'junit:junit:4.13'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed", "standardOut", "standardError"
|
||||
}
|
||||
}
|
||||
|
||||
group = 'algorithm'
|
||||
version = '1.0-SNAPSHOT'
|
||||
description = 'java-algorithm'
|
||||
sourceCompatibility = '1.8'
|
198
checkstyle.xml
198
checkstyle.xml
@ -1,198 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||
|
||||
<!--
|
||||
|
||||
Checkstyle configuration that checks the sun coding conventions from:
|
||||
|
||||
- the Java Language Specification at
|
||||
https://docs.oracle.com/javase/specs/jls/se11/html/index.html
|
||||
|
||||
- the Sun Code Conventions at https://www.oracle.com/java/technologies/javase/codeconventions-contents.html
|
||||
|
||||
- the Javadoc guidelines at
|
||||
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html
|
||||
|
||||
- the JDK Api documentation https://docs.oracle.com/en/java/javase/11/
|
||||
|
||||
- some best practices
|
||||
|
||||
Checkstyle is very configurable. Be sure to read the documentation at
|
||||
https://checkstyle.org (or in your downloaded distribution).
|
||||
|
||||
Most Checks are configurable, be sure to consult the documentation.
|
||||
|
||||
To completely disable a check, just comment it out or delete it from the file.
|
||||
To suppress certain violations please review suppression filters.
|
||||
|
||||
Finally, it is worth reading the documentation.
|
||||
|
||||
-->
|
||||
|
||||
<module name="Checker">
|
||||
<!--
|
||||
If you set the basedir property below, then all reported file
|
||||
names will be relative to the specified directory. See
|
||||
https://checkstyle.org/config.html#Checker
|
||||
|
||||
<property name="basedir" value="${basedir}"/>
|
||||
-->
|
||||
<property name="severity" value="error"/>
|
||||
|
||||
<property name="fileExtensions" value="java, properties, xml"/>
|
||||
|
||||
<!-- Excludes all 'module-info.java' files -->
|
||||
<!-- See https://checkstyle.org/filefilters/index.html -->
|
||||
<module name="BeforeExecutionExclusionFileFilter">
|
||||
<property name="fileNamePattern" value="module\-info\.java$"/>
|
||||
</module>
|
||||
|
||||
<!-- https://checkstyle.org/filters/suppressionfilter.html -->
|
||||
<module name="SuppressionFilter">
|
||||
<property name="file" value="${org.checkstyle.sun.suppressionfilter.config}"
|
||||
default="checkstyle-suppressions.xml" />
|
||||
<property name="optional" value="true"/>
|
||||
</module>
|
||||
|
||||
<!-- Checks that a package-info.java file exists for each package. -->
|
||||
<!-- See https://checkstyle.org/checks/javadoc/javadocpackage.html#JavadocPackage -->
|
||||
<!-- TODO <module name="JavadocPackage"/> -->
|
||||
|
||||
<!-- Checks whether files end with a new line. -->
|
||||
<!-- See https://checkstyle.org/checks/misc/newlineatendoffile.html -->
|
||||
<module name="NewlineAtEndOfFile"/>
|
||||
|
||||
<!-- Checks that property files contain the same keys. -->
|
||||
<!-- See https://checkstyle.org/checks/misc/translation.html -->
|
||||
<module name="Translation"/>
|
||||
|
||||
<!-- Checks for Size Violations. -->
|
||||
<!-- See https://checkstyle.org/checks/sizes/index.html -->
|
||||
<!-- TODO <module name="FileLength"/> -->
|
||||
<!-- TODO <module name="LineLength">
|
||||
<property name="fileExtensions" value="java"/>
|
||||
</module> -->
|
||||
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See https://checkstyle.org/checks/whitespace/index.html -->
|
||||
<!-- TODO <module name="FileTabCharacter"/> -->
|
||||
|
||||
<!-- Miscellaneous other checks. -->
|
||||
<!-- See https://checkstyle.org/checks/misc/index.html -->
|
||||
<module name="RegexpSingleline">
|
||||
<property name="format" value="\s+$"/>
|
||||
<property name="minimum" value="0"/>
|
||||
<property name="maximum" value="0"/>
|
||||
<property name="message" value="Line has trailing spaces."/>
|
||||
</module>
|
||||
|
||||
<!-- Checks for Headers -->
|
||||
<!-- See https://checkstyle.org/checks/header/index.html -->
|
||||
<!-- <module name="Header"> -->
|
||||
<!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
|
||||
<!-- <property name="fileExtensions" value="java"/> -->
|
||||
<!-- </module> -->
|
||||
|
||||
<module name="TreeWalker">
|
||||
|
||||
<!-- Checks for Javadoc comments. -->
|
||||
<!-- See https://checkstyle.org/checks/javadoc/index.html -->
|
||||
<module name="InvalidJavadocPosition"/>
|
||||
<!-- TODO <module name="JavadocMethod"/> -->
|
||||
<!-- TODO <module name="JavadocType"/> -->
|
||||
<!-- TODO <module name="JavadocVariable"/> -->
|
||||
<!-- TODO <module name="JavadocStyle"/> -->
|
||||
<!-- TODO <module name="MissingJavadocMethod"/> -->
|
||||
|
||||
<!-- Checks for Naming Conventions. -->
|
||||
<!-- See https://checkstyle.org/checks/naming/index.html -->
|
||||
<module name="ConstantName"/>
|
||||
<module name="LocalFinalVariableName"/>
|
||||
<module name="LocalVariableName"/>
|
||||
<module name="MemberName"/>
|
||||
<module name="MethodName"/>
|
||||
<module name="PackageName"/>
|
||||
<module name="ParameterName"/>
|
||||
<module name="StaticVariableName"/>
|
||||
<module name="TypeName"/>
|
||||
|
||||
<!-- Checks for imports -->
|
||||
<!-- See https://checkstyle.org/checks/imports/index.html -->
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports">
|
||||
<property name="processJavadoc" value="false"/>
|
||||
</module>
|
||||
|
||||
<!-- Checks for Size Violations. -->
|
||||
<!-- See https://checkstyle.org/checks/sizes/index.html -->
|
||||
<module name="MethodLength"/>
|
||||
<module name="ParameterNumber"/>
|
||||
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See https://checkstyle.org/checks/whitespace/index.html -->
|
||||
<module name="EmptyForIteratorPad"/>
|
||||
<!-- TODO <module name="GenericWhitespace"/> -->
|
||||
<module name="MethodParamPad"/>
|
||||
<!-- TODO <module name="NoWhitespaceAfter"/> -->
|
||||
<module name="NoWhitespaceBefore"/>
|
||||
<module name="OperatorWrap"/>
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad"/>
|
||||
<module name="WhitespaceAfter"/>
|
||||
<module name="WhitespaceAround"/>
|
||||
|
||||
<!-- Modifier Checks -->
|
||||
<!-- See https://checkstyle.org/checks/modifier/index.html -->
|
||||
<module name="ModifierOrder"/>
|
||||
<module name="RedundantModifier"/>
|
||||
|
||||
<!-- Checks for blocks. You know, those {}'s -->
|
||||
<!-- See https://checkstyle.org/checks/blocks/index.html -->
|
||||
<module name="AvoidNestedBlocks"/>
|
||||
<!-- TODO <module name="EmptyBlock"/> -->
|
||||
<!-- TODO <module name="LeftCurly"/> -->
|
||||
<module name="NeedBraces"/>
|
||||
<!-- TODO <module name="RightCurly"/> -->
|
||||
|
||||
<!-- Checks for common coding problems -->
|
||||
<!-- See https://checkstyle.org/checks/coding/index.html -->
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
<!-- TODO <module name="HiddenField"/> -->
|
||||
<module name="IllegalInstantiation"/>
|
||||
<module name="InnerAssignment"/>
|
||||
<!-- TODO <module name="MagicNumber"/> -->
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="MultipleVariableDeclarations"/>
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<module name="SimplifyBooleanReturn"/>
|
||||
|
||||
<!-- Checks for class design -->
|
||||
<!-- See https://checkstyle.org/checks/design/index.html -->
|
||||
<!-- TODO <module name="DesignForExtension"/> -->
|
||||
<module name="FinalClass"/>
|
||||
<module name="HideUtilityClassConstructor"/>
|
||||
<module name="InterfaceIsType"/>
|
||||
<!-- TODO <module name="VisibilityModifier"/> -->
|
||||
|
||||
<!-- Miscellaneous other checks. -->
|
||||
<!-- See https://checkstyle.org/checks/misc/index.html -->
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<!-- TODO <module name="FinalParameters"/> -->
|
||||
<!-- TODO <module name="TodoComment"/> -->
|
||||
<module name="UpperEll"/>
|
||||
|
||||
<!-- https://checkstyle.org/filters/suppressionxpathfilter.html -->
|
||||
<module name="SuppressionXpathFilter">
|
||||
<property name="file" value="${org.checkstyle.sun.suppressionxpathfilter.config}"
|
||||
default="checkstyle-xpath-suppressions.xml" />
|
||||
<property name="optional" value="true"/>
|
||||
</module>
|
||||
|
||||
</module>
|
||||
|
||||
</module>
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
172
gradlew
vendored
Executable file
172
gradlew
vendored
Executable file
@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
@ -1,90 +0,0 @@
|
||||
com.thealgorithms.bitmanipulation.SingleBitOperations=UselessParentheses
|
||||
com.thealgorithms.ciphers.AffineCipher=UselessParentheses
|
||||
com.thealgorithms.ciphers.ColumnarTranspositionCipher=UnnecessaryFullyQualifiedName
|
||||
com.thealgorithms.ciphers.DES=UselessParentheses
|
||||
com.thealgorithms.ciphers.HillCipher=UselessParentheses
|
||||
com.thealgorithms.ciphers.RSA=UselessParentheses
|
||||
com.thealgorithms.conversions.AnyBaseToAnyBase=UselessParentheses
|
||||
com.thealgorithms.conversions.AnytoAny=UselessParentheses
|
||||
com.thealgorithms.conversions.HexToOct=UselessParentheses
|
||||
com.thealgorithms.conversions.IntegerToRoman=UnnecessaryFullyQualifiedName
|
||||
com.thealgorithms.datastructures.crdt.LWWElementSet=UselessParentheses
|
||||
com.thealgorithms.datastructures.crdt.Pair=UnusedPrivateField
|
||||
com.thealgorithms.datastructures.graphs.AStar=UselessParentheses
|
||||
com.thealgorithms.datastructures.graphs.AdjacencyMatrixGraph=CollapsibleIfStatements,UnnecessaryFullyQualifiedName,UselessParentheses
|
||||
com.thealgorithms.datastructures.graphs.BipartiteGraphDFS=CollapsibleIfStatements
|
||||
com.thealgorithms.datastructures.graphs.Kruskal=UselessParentheses
|
||||
com.thealgorithms.datastructures.hashmap.hashing.HashMapCuckooHashing=UselessParentheses
|
||||
com.thealgorithms.datastructures.heaps.FibonacciHeap=UselessParentheses
|
||||
com.thealgorithms.datastructures.heaps.HeapElement=UselessParentheses
|
||||
com.thealgorithms.datastructures.heaps.HeapNode=UselessParentheses
|
||||
com.thealgorithms.datastructures.lists.DoublyLinkedList=UselessParentheses
|
||||
com.thealgorithms.datastructures.lists.SearchSinglyLinkedListRecursion=UselessParentheses
|
||||
com.thealgorithms.datastructures.lists.SinglyLinkedList=UnusedLocalVariable
|
||||
com.thealgorithms.datastructures.queues.PriorityQueue=UselessParentheses
|
||||
com.thealgorithms.datastructures.stacks.NodeStack=UnnecessaryFullyQualifiedName,UnusedFormalParameter
|
||||
com.thealgorithms.datastructures.stacks.StackArray=UselessParentheses
|
||||
com.thealgorithms.datastructures.trees.CheckBinaryTreeIsValidBST=UselessParentheses
|
||||
com.thealgorithms.datastructures.trees.SegmentTree=UselessParentheses
|
||||
com.thealgorithms.devutils.nodes.LargeTreeNode=UselessParentheses
|
||||
com.thealgorithms.devutils.nodes.SimpleNode=UselessParentheses
|
||||
com.thealgorithms.devutils.nodes.SimpleTreeNode=UselessParentheses
|
||||
com.thealgorithms.devutils.nodes.TreeNode=UselessParentheses
|
||||
com.thealgorithms.divideandconquer.ClosestPair=UnnecessaryFullyQualifiedName,UselessParentheses
|
||||
com.thealgorithms.divideandconquer.Point=UselessParentheses
|
||||
com.thealgorithms.dynamicprogramming.MatrixChainMultiplication=UselessParentheses
|
||||
com.thealgorithms.dynamicprogramming.ShortestSuperSequence=UselessParentheses
|
||||
com.thealgorithms.dynamicprogramming.UniquePaths=UnnecessarySemicolon
|
||||
com.thealgorithms.dynamicprogramming.WineProblem=UselessParentheses
|
||||
com.thealgorithms.maths.BinomialCoefficient=UselessParentheses
|
||||
com.thealgorithms.maths.Complex=UselessParentheses
|
||||
com.thealgorithms.maths.DistanceFormulaTest=UnnecessaryFullyQualifiedName
|
||||
com.thealgorithms.maths.Gaussian=UselessParentheses
|
||||
com.thealgorithms.maths.GcdSolutionWrapper=UselessParentheses
|
||||
com.thealgorithms.maths.HeronsFormula=UselessParentheses
|
||||
com.thealgorithms.maths.KaprekarNumbers=UselessParentheses
|
||||
com.thealgorithms.maths.KeithNumber=UselessParentheses
|
||||
com.thealgorithms.maths.LeonardoNumber=UselessParentheses
|
||||
com.thealgorithms.maths.LinearDiophantineEquationsSolver=UselessParentheses
|
||||
com.thealgorithms.maths.MatrixUtil=UselessParentheses
|
||||
com.thealgorithms.maths.RomanNumeralUtil=UselessParentheses
|
||||
com.thealgorithms.maths.SecondMinMax=UselessParentheses
|
||||
com.thealgorithms.maths.SecondMinMaxTest=UnnecessaryFullyQualifiedName
|
||||
com.thealgorithms.maths.StandardDeviation=UselessParentheses
|
||||
com.thealgorithms.maths.SumOfArithmeticSeries=UselessParentheses
|
||||
com.thealgorithms.maths.TrinomialTriangle=UselessParentheses
|
||||
com.thealgorithms.maths.VampireNumber=CollapsibleIfStatements
|
||||
com.thealgorithms.maths.Volume=UselessParentheses
|
||||
com.thealgorithms.matrixexponentiation.Fibonacci=UnnecessaryFullyQualifiedName
|
||||
com.thealgorithms.misc.Sparsity=UselessParentheses
|
||||
com.thealgorithms.misc.ThreeSumProblem=UselessParentheses
|
||||
com.thealgorithms.misc.WordBoggle=UselessParentheses
|
||||
com.thealgorithms.others.CRC16=UselessParentheses
|
||||
com.thealgorithms.others.Damm=UnnecessaryFullyQualifiedName
|
||||
com.thealgorithms.others.Luhn=UnnecessaryFullyQualifiedName
|
||||
com.thealgorithms.others.Mandelbrot=UselessParentheses
|
||||
com.thealgorithms.others.MaximumSumOfDistinctSubarraysWithLengthK=CollapsibleIfStatements
|
||||
com.thealgorithms.others.MiniMaxAlgorithm=UselessParentheses
|
||||
com.thealgorithms.others.PageRank=UselessParentheses
|
||||
com.thealgorithms.others.PerlinNoise=UselessParentheses
|
||||
com.thealgorithms.others.QueueUsingTwoStacks=UselessParentheses
|
||||
com.thealgorithms.others.QueueWithStack=UselessParentheses
|
||||
com.thealgorithms.others.Trieac=UselessParentheses
|
||||
com.thealgorithms.others.Verhoeff=UnnecessaryFullyQualifiedName
|
||||
com.thealgorithms.searches.InterpolationSearch=UselessParentheses
|
||||
com.thealgorithms.searches.KMPSearch=UselessParentheses
|
||||
com.thealgorithms.searches.LinearSearchThread=EmptyCatchBlock
|
||||
com.thealgorithms.searches.RabinKarpAlgorithm=UselessParentheses
|
||||
com.thealgorithms.sorts.CircleSort=EmptyControlStatement
|
||||
com.thealgorithms.sorts.CombSort=UselessParentheses
|
||||
com.thealgorithms.sorts.DutchNationalFlagSort=UselessParentheses
|
||||
com.thealgorithms.sorts.LinkListSort=EmptyControlStatement,UnusedLocalVariable
|
||||
com.thealgorithms.sorts.MergeSortNoExtraSpace=UselessParentheses
|
||||
com.thealgorithms.sorts.PigeonholeSort=UselessParentheses
|
||||
com.thealgorithms.sorts.RadixSort=UselessParentheses
|
||||
com.thealgorithms.sorts.WiggleSort=UselessParentheses
|
||||
com.thealgorithms.stacks.PostfixToInfix=UselessParentheses
|
||||
com.thealgorithms.strings.HorspoolSearch=UnnecessaryFullyQualifiedName,UselessParentheses
|
||||
com.thealgorithms.strings.MyAtoi=UselessParentheses
|
||||
com.thealgorithms.strings.Palindrome=UselessParentheses
|
||||
com.thealgorithms.strings.Solution=CollapsibleIfStatements
|
159
pom.xml
159
pom.xml
@ -1,159 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.thealgorithms</groupId>
|
||||
<artifactId>Java</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<assertj.version>3.26.3</assertj.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>5.11.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.11.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.11.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.5.0-M2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>21</source>
|
||||
<target>21</target>
|
||||
<compilerArgs>
|
||||
<arg>-Xlint:all</arg>
|
||||
<arg>-Xlint:-auxiliaryclass</arg>
|
||||
<arg>-Xlint:-rawtypes</arg>
|
||||
<arg>-Xlint:-unchecked</arg>
|
||||
<arg>-Xlint:-lossy-conversions</arg>
|
||||
<arg>-Werror</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.12</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>generate-code-coverage-report</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
<consoleOutput>true</consoleOutput>
|
||||
<includeTestSourceDirectory>true</includeTestSourceDirectory>
|
||||
<violationSeverity>warning</violationSeverity>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.puppycrawl.tools</groupId>
|
||||
<artifactId>checkstyle</artifactId>
|
||||
<version>10.18.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||
<version>4.8.6.3</version>
|
||||
<configuration>
|
||||
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
|
||||
<includeTests>true</includeTests>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.mebigfatguy.fb-contrib</groupId>
|
||||
<artifactId>fb-contrib</artifactId>
|
||||
<version>7.6.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.h3xstream.findsecbugs</groupId>
|
||||
<artifactId>findsecbugs-plugin</artifactId>
|
||||
<version>1.13.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-pmd-plugin</artifactId>
|
||||
<version>3.25.0</version>
|
||||
<configuration>
|
||||
<printFailingErrors>true</printFailingErrors>
|
||||
<includeTests>true</includeTests>
|
||||
<linkXRef>false</linkXRef>
|
||||
<excludeFromFailureFile>pmd-exclude.properties</excludeFromFailureFile>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
5
settings.gradle
Normal file
5
settings.gradle
Normal file
@ -0,0 +1,5 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
|
||||
rootProject.name = 'java-algorithm'
|
@ -1,217 +0,0 @@
|
||||
<FindBugsFilter>
|
||||
<Match>
|
||||
<Bug pattern="DM_DEFAULT_ENCODING" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="EI_EXPOSE_REP2" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="DMI_RANDOM_USED_ONLY_ONCE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SF_SWITCH_NO_DEFAULT" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="DM_NEXTINT_VIA_NEXTDOUBLE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SIC_INNER_SHOULD_BE_STATIC" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="EI_EXPOSE_REP" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="EI_EXPOSE_REP" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SBSC_USE_STRINGBUFFER_CONCATENATION" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="PA_PUBLIC_PRIMITIVE_ATTRIBUTE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="MS_PKGPROTECT" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SE_COMPARATOR_SHOULD_BE_SERIALIZABLE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="INT_BAD_REM_BY_1" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="ICAST_IDIV_CAST_TO_DOUBLE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="FE_FLOATING_POINT_EQUALITY" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="CT_CONSTRUCTOR_THROW" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="URF_UNREAD_FIELD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="RC_REF_COMPARISON" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="MS_EXPOSE_REP" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="DM_BOXED_PRIMITIVE_FOR_PARSING" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="UWF_UNWRITTEN_FIELD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="UWF_NULL_FIELD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="NP_UNWRITTEN_FIELD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="NP_IMMEDIATE_DEREFERENCE_OF_READLINE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="EQ_COMPARETO_USE_OBJECT_EQUALS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SA_FIELD_SELF_ASSIGNMENT" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
|
||||
</Match>
|
||||
<!-- fb-contrib -->
|
||||
<Match>
|
||||
<Bug pattern="OCP_OVERLY_CONCRETE_PARAMETER" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="LSC_LITERAL_STRING_COMPARISON" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="CE_CLASS_ENVY" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="PSC_PRESIZE_COLLECTIONS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SACM_STATIC_ARRAY_CREATED_IN_METHOD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="LUI_USE_SINGLETON_LIST" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="CLI_CONSTANT_LIST_INDEX" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="CNC_COLLECTION_NAMING_CONFUSION" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="TR_TAIL_RECURSION" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="USBR_UNNECESSARY_STORE_BEFORE_RETURN" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="BL_BURYING_LOGIC" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="UTWR_USE_TRY_WITH_RESOURCES" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="MUI_CONTAINSKEY_BEFORE_GET" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="IMC_IMMATURE_CLASS_PRINTSTACKTRACE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SUA_SUSPICIOUS_UNINITIALIZED_ARRAY" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SPP_USE_MATH_CONSTANT" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="UJM_UNJITABLE_METHOD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SEC_SIDE_EFFECT_CONSTRUCTOR" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="MDM_STRING_BYTES_ENCODING" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="PMB_POSSIBLE_MEMORY_BLOAT" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="LSYC_LOCAL_SYNCHRONIZED_COLLECTION" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="IOI_USE_OF_FILE_STREAM_CONSTRUCTORS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="UP_UNUSED_PARAMETER" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="DSOC_DUBIOUS_SET_OF_COLLECTIONS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="NAB_NEEDLESS_BOX_TO_UNBOX" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="FPL_FLOATING_POINT_LOOPS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="ITU_INAPPROPRIATE_TOSTRING_USE" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SPP_PASSING_THIS_AS_PARM" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="FCBL_FIELD_COULD_BE_LOCAL" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="CFS_CONFUSING_FUNCTION_SEMANTICS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="FCCD_FIND_CLASS_CIRCULAR_DEPENDENCY" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="PL_PARALLEL_LISTS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="STT_STRING_PARSING_A_FIELD" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="IMC_IMMATURE_CLASS_BAD_SERIALVERSIONUID" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="DRE_DECLARED_RUNTIME_EXCEPTION" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="SLS_SUSPICIOUS_LOOP_SEARCH" />
|
||||
</Match>
|
||||
<!-- find-sec-bugs -->
|
||||
<Match>
|
||||
<Bug pattern="PREDICTABLE_RANDOM" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="HARD_CODE_KEY" />
|
||||
</Match>
|
||||
</FindBugsFilter>
|
155
src/main/java/com/caching/LFUCache.java
Normal file
155
src/main/java/com/caching/LFUCache.java
Normal file
@ -0,0 +1,155 @@
|
||||
package com.caching;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Your LFUCache object can be instantiated and called as such: LFUCache
|
||||
* lfuCache = new LFUCache(capacity); lfuCache.put(key,value); int param_1 =
|
||||
* lfuCache.get(key);
|
||||
*/
|
||||
class LFUCache<T> {
|
||||
// internal Node to store cache element
|
||||
private class Node {
|
||||
int key;
|
||||
T value;
|
||||
int freq;
|
||||
Node next;
|
||||
Node pre;
|
||||
|
||||
public Node(int key, T value, int freq) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.freq = freq;
|
||||
next = pre = null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return " Key: " + key + "Value: " + value + "Freq: " + freq;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// internal Doubly Linked List to store cache nodes
|
||||
private class DLL {
|
||||
Node head;
|
||||
Node tail;
|
||||
int len;
|
||||
|
||||
public DLL() {
|
||||
head = new Node(-1, null, -1);
|
||||
tail = new Node(-1, null, -1);
|
||||
head.next = tail;
|
||||
tail.pre = head;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
public void addToHead(Node node) {
|
||||
node.next = head.next;
|
||||
head.next.pre = node;
|
||||
head.next = node;
|
||||
node.pre = head;
|
||||
len++;
|
||||
}
|
||||
|
||||
public void deleteNode(Node node) {
|
||||
node.pre.next = node.next;
|
||||
node.next.pre = node.pre;
|
||||
len--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int capacity;
|
||||
private int size;
|
||||
private TreeMap<Integer, DLL> freq;
|
||||
private HashMap<Integer, Node> map;
|
||||
|
||||
/**
|
||||
* instantiates LFUCache with fixed capacity
|
||||
*
|
||||
* @param capacity The capacity of the cache. Once the cache reaches capacity,
|
||||
* new elements will replace old elements in LFU manner
|
||||
*/
|
||||
public LFUCache(int capacity) {
|
||||
this.capacity = capacity;
|
||||
size = 0;
|
||||
freq = new TreeMap<>();
|
||||
map = new HashMap<>();
|
||||
System.out.println("LFUCache initialised with capacity: " + capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* To get the cached value for given key
|
||||
*
|
||||
* @param key The key (int) of the expected value
|
||||
* @return corresponding value for input key
|
||||
* @throws NoSuchElementException if key is absent
|
||||
*/
|
||||
public T get(int key) {
|
||||
// Cache hit condition
|
||||
if (map.containsKey(key)) {
|
||||
Node node = map.get(key);
|
||||
System.out.println("Returning value from cache:" + node.toString());
|
||||
DLL dll = freq.get(node.freq);
|
||||
dll.deleteNode(node);
|
||||
if (dll.len == 0)
|
||||
freq.remove(node.freq);
|
||||
node.freq += 1;
|
||||
dll = freq.computeIfAbsent(node.freq, k -> new DLL());
|
||||
dll.addToHead(node);
|
||||
return node.value;
|
||||
}
|
||||
// Cache miss condition
|
||||
throw new NoSuchElementException("No element for key: " + key);
|
||||
}
|
||||
|
||||
/**
|
||||
* To put a value in LFU cache with corresponding key
|
||||
*
|
||||
* @param key The key (int)
|
||||
* @param value The value to be cached
|
||||
*/
|
||||
public void put(int key, T value) {
|
||||
if (capacity == 0) {
|
||||
System.out.println("Cache set to 0 capacity. No element will be cached");
|
||||
return;
|
||||
}
|
||||
if (map.containsKey(key)) {
|
||||
System.out.println("Key " + key + " already present in cache.Value will be replaced");
|
||||
Node node = map.get(key);
|
||||
node.value = value;
|
||||
DLL dll = freq.get(node.freq);
|
||||
dll.deleteNode(node);
|
||||
if (dll.len == 0)
|
||||
freq.remove(node.freq);
|
||||
node.freq += 1;
|
||||
dll = freq.computeIfAbsent(node.freq, k -> new DLL());
|
||||
dll.addToHead(node);
|
||||
} else {
|
||||
System.out.println("Adding new key " + key + " to cache");
|
||||
Node node = new Node(key, value, 1);
|
||||
map.put(key, node);
|
||||
|
||||
if (size < capacity) {
|
||||
size++;
|
||||
DLL dll = freq.computeIfAbsent(1, k -> new DLL());
|
||||
dll.addToHead(node);
|
||||
} else {
|
||||
System.out.println("Cache at peak capacity.Old values will be removed in LFU fashion");
|
||||
Integer lowest = freq.firstKey();
|
||||
DLL dll = freq.get(lowest);
|
||||
map.remove(dll.tail.pre.key);
|
||||
System.out.println("Value removed:" + dll.tail.pre.value.toString());
|
||||
dll.deleteNode(dll.tail.pre);
|
||||
if (dll.len == 0 && lowest != 1)
|
||||
freq.remove(lowest);
|
||||
DLL freqOne = freq.computeIfAbsent(1, k -> new DLL());
|
||||
freqOne.addToHead(node);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
92
src/main/java/com/caching/LRUCache.java
Normal file
92
src/main/java/com/caching/LRUCache.java
Normal file
@ -0,0 +1,92 @@
|
||||
package com.caching;
|
||||
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Your LRUCache can be instantiated and called as such:
|
||||
* LRUCache lruCache = new LRUCache(capacity);
|
||||
* lruCache.put(key,value);
|
||||
* int param_1 = lruCache.get(key);
|
||||
*/
|
||||
|
||||
public class LRUCache<T> {
|
||||
/**
|
||||
* The class LinkedHashMap,is a subclass of HashMap that preserves the insertion order.
|
||||
* We can take advantage of this class to avoid having to implement the linked list.
|
||||
* A special constructor is provided to create a linked hash map whose order of
|
||||
* iteration is the order in which its entries were least-recently (access-order).
|
||||
*/
|
||||
private final LinkedHashMap<Integer, T> cache;
|
||||
private final int capacity;
|
||||
|
||||
/**
|
||||
* @param capacity - Instantiates LRUCache with the given capacity.
|
||||
*/
|
||||
public LRUCache(int capacity) {
|
||||
this.capacity = capacity;
|
||||
|
||||
/*
|
||||
@param loadFactor Load Factor is a measure, which decides when exactly to resize the
|
||||
* HashMap. By default capacity = 16 and loadFactor = 0.75f. This means
|
||||
* that reisze when HashMap reaches 75% of its capacity. For we will
|
||||
* remove an element only if the cache reaches 100% capacity (1.0f).
|
||||
*
|
||||
* @param accessOrder - Set to true if ordering mode is specified (removeEldestEntry).
|
||||
*/
|
||||
this.cache = new LinkedHashMap<Integer, T>(capacity, 1.0f, true) {
|
||||
/**
|
||||
* @param eldest - The least recently accessed entry This is the entry that will
|
||||
* be removed if the method returns {@code true}.
|
||||
* returns {@code false} if it should be retained.
|
||||
*/
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry eldest) {
|
||||
return this.size() > capacity;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To put a value in LRU cache with corresponding key
|
||||
* We add the value for key only if the key is not present.
|
||||
* We don't update existing values, only access-order is updated.
|
||||
*
|
||||
* @param key The key (int)
|
||||
* @param value The value to be cached
|
||||
*/
|
||||
public void put(int key, T value) {
|
||||
if (capacity == 0) {
|
||||
System.out.println("Cache set to 0 capacity. No elements will be cached");
|
||||
}
|
||||
|
||||
if (!cache.containsKey(key)) {
|
||||
cache.put(key, value);
|
||||
System.out.println("Adding new key:" + key + " to cache");
|
||||
} else {
|
||||
System.out.println("Key:" + key + " already present in cache. Access order will be updated.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To get the cached value for given key
|
||||
*
|
||||
* @param key The key (int) of the expected value
|
||||
* @return corresponding value for input key
|
||||
* @throws NoSuchElementException if key is absent
|
||||
*/
|
||||
public T get(int key) {
|
||||
// cache hit condition
|
||||
if (cache.containsKey(key)) {
|
||||
T value = cache.get(key);
|
||||
System.out.println("Returning value from cache:" + value);
|
||||
return value;
|
||||
}
|
||||
// cache miss condition
|
||||
throw new NoSuchElementException("No element found for key:" + key);
|
||||
}
|
||||
}
|
29
src/main/java/com/ciphers/CaesarBruteForce.java
Normal file
29
src/main/java/com/ciphers/CaesarBruteForce.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.ciphers;
|
||||
|
||||
public class CaesarBruteForce {
|
||||
|
||||
/**
|
||||
* Recursively Brute forces a parsed encrypted text, trying out all shifting keys from 1-26, printing out all decryption attempts
|
||||
* @param message (String) The encrypted text.
|
||||
* @param key (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
|
||||
* @return (String) Concatenated string of all decryption attempts (For unit testing purposes).
|
||||
*/
|
||||
public String decrypt(String message, int key) {
|
||||
final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
if (key > 26){ System.out.println(); return null; }
|
||||
|
||||
StringBuilder plainText = new StringBuilder();
|
||||
for (char character : message.toUpperCase().toCharArray()) {
|
||||
int index = LETTERS.indexOf(character);
|
||||
|
||||
if (index != -1) {
|
||||
index -= key;
|
||||
//Wrap around index value range[1-26]
|
||||
if (index < 0) { index += LETTERS.length(); }
|
||||
plainText.append(LETTERS.toCharArray()[index]);
|
||||
} else { plainText.append(character); }
|
||||
}
|
||||
System.out.println(String.format("Current Decryption Key %d : %s", key, plainText));
|
||||
return plainText.append(decrypt(message, key+1)).toString();
|
||||
}
|
||||
}
|
40
src/main/java/com/conversions/AnyBaseToDecimal.java
Normal file
40
src/main/java/com/conversions/AnyBaseToDecimal.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.conversions;
|
||||
|
||||
public class AnyBaseToDecimal {
|
||||
/**
|
||||
* This method produces a decimal value of any given input number of any base
|
||||
*
|
||||
* @param inpNum String of which we need the decimal value and base in integer format
|
||||
* @return string format of the decimal value
|
||||
*/
|
||||
|
||||
public String convertToDecimal(String inpNum, int base) {
|
||||
int len = inpNum.length();
|
||||
int num = 0;
|
||||
int pow = 1;
|
||||
|
||||
for (int i = len - 1; i >= 0; i--) {
|
||||
if (valOfChar(inpNum.charAt(i)) >= base) {
|
||||
return "Invalid Number";
|
||||
}
|
||||
num += valOfChar(inpNum.charAt(i)) * pow;
|
||||
pow *= base;
|
||||
}
|
||||
return String.valueOf(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method produces integer value of the input character and returns it
|
||||
*
|
||||
* @param c Char of which we need the integer value of
|
||||
* @return integer value of input char
|
||||
*/
|
||||
|
||||
private static int valOfChar(char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return (int) c - '0';
|
||||
} else {
|
||||
return (int) c - 'A' + 10;
|
||||
}
|
||||
}
|
||||
}
|
26
src/main/java/com/conversions/BinaryToGray.java
Normal file
26
src/main/java/com/conversions/BinaryToGray.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.conversions;
|
||||
|
||||
/**
|
||||
* Convert the binary number into gray code
|
||||
*/
|
||||
public class BinaryToGray {
|
||||
|
||||
/**
|
||||
* convert the binary number into gray code
|
||||
*
|
||||
* @param binaryCode binary number
|
||||
* @return grayCode return as string
|
||||
*/
|
||||
public String binaryToGray(String binaryCode) {
|
||||
StringBuilder grayCode = new StringBuilder(Character.toString(binaryCode.charAt(0)));
|
||||
|
||||
for (int i = 0; i < binaryCode.length() - 1; i++) {
|
||||
if (binaryCode.charAt(i) == binaryCode.charAt(i + 1))
|
||||
grayCode.append("0");
|
||||
else
|
||||
grayCode.append("1");
|
||||
}
|
||||
return grayCode.toString();
|
||||
}
|
||||
|
||||
}
|
52
src/main/java/com/conversions/BinaryToHexadecimal.java
Normal file
52
src/main/java/com/conversions/BinaryToHexadecimal.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.conversions;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class BinaryToHexadecimal {
|
||||
|
||||
/**
|
||||
* hm to store hexadecimal codes for binary numbers
|
||||
* within the range: 0000 to 1111 i.e. for decimal numbers 0 to 15
|
||||
*/
|
||||
private static Map<Integer, String> hmHexadecimal = new HashMap<>(16);
|
||||
|
||||
static {
|
||||
int i;
|
||||
for (i = 0; i < 10; i++)
|
||||
hmHexadecimal.put(i, String.valueOf(i));
|
||||
|
||||
for (i = 10; i < 16; i++)
|
||||
hmHexadecimal.put(i, String.valueOf((char) ('A' + i - 10)));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts a binary number to
|
||||
* a hexadecimal number.
|
||||
*
|
||||
* @param binStr The binary number
|
||||
* @return The hexadecimal number
|
||||
*/
|
||||
|
||||
public String binToHex(String binStr) {
|
||||
BigInteger binary = new BigInteger(binStr);
|
||||
// String to store hexadecimal code
|
||||
String hex = "";
|
||||
|
||||
int currentBit;
|
||||
BigInteger tenValue = BigInteger.valueOf(10);
|
||||
while (binary.compareTo(BigInteger.ZERO) != 0) {
|
||||
// to store decimal equivalent of number formed by 4 decimal digits
|
||||
int code4 = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
currentBit = binary.mod(tenValue).intValueExact();
|
||||
binary = binary.divide(tenValue);
|
||||
code4 += currentBit * Math.pow(2, i);
|
||||
}
|
||||
hex = hmHexadecimal.get(code4) + hex;
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
}
|
43
src/main/java/com/conversions/DecimalToAnyBase.java
Normal file
43
src/main/java/com/conversions/DecimalToAnyBase.java
Normal file
@ -0,0 +1,43 @@
|
||||
package com.conversions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DecimalToAnyBase {
|
||||
|
||||
/**
|
||||
* This method produces a String value of any given input decimal in any base
|
||||
*
|
||||
* @param inp Decimal of which we need the value in base in String format
|
||||
* @param base base in which we want the decimal value to be converted into
|
||||
* @return string format of the converted value in the given base
|
||||
*/
|
||||
public String convertToAnyBase(int inp, int base) {
|
||||
ArrayList<Character> charArr = new ArrayList<>();
|
||||
|
||||
while (inp > 0) {
|
||||
charArr.add(reVal(inp % base));
|
||||
inp /= base;
|
||||
}
|
||||
|
||||
StringBuilder str = new StringBuilder(charArr.size());
|
||||
for (Character ch : charArr) {
|
||||
str.append(ch);
|
||||
}
|
||||
|
||||
return str.reverse().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method produces character value of the input integer and returns it
|
||||
*
|
||||
* @param num integer of which we need the character value of
|
||||
* @return character value of input integer
|
||||
*/
|
||||
|
||||
private char reVal(int num) {
|
||||
if (num >= 0 && num <= 9)
|
||||
return (char) (num + '0');
|
||||
else
|
||||
return (char) (num - 10 + 'A');
|
||||
}
|
||||
}
|
27
src/main/java/com/conversions/DecimalToHexadecimal.java
Normal file
27
src/main/java/com/conversions/DecimalToHexadecimal.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.conversions;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class DecimalToHexadecimal {
|
||||
private static final char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
private static final BigInteger valueHex = BigInteger.valueOf(16);
|
||||
|
||||
/**
|
||||
* This method converts and decimal number to a Hexadecimal number
|
||||
*
|
||||
* @param decimalStr
|
||||
* @return hexadecimal number
|
||||
*/
|
||||
public String decimalToHex(String decimalStr) {
|
||||
BigInteger decimal = new BigInteger(decimalStr);
|
||||
|
||||
int rem;
|
||||
String hex = "";
|
||||
while (decimal.compareTo(BigInteger.ZERO) > 0) {
|
||||
rem = decimal.mod(valueHex).intValueExact();
|
||||
hex = hexChars[rem] + hex;
|
||||
decimal = decimal.divide(valueHex);
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
}
|
27
src/main/java/com/conversions/DecimalToOctal.java
Normal file
27
src/main/java/com/conversions/DecimalToOctal.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.conversions;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class DecimalToOctal {
|
||||
private static final char[] octalChars = {'0', '1', '2', '3', '4', '5', '6', '7'};
|
||||
private static final BigInteger valueOctal = BigInteger.valueOf(8);
|
||||
|
||||
/**
|
||||
* This method converts and decimal number to a octal number
|
||||
*
|
||||
* @param decimalStr
|
||||
* @return octal number
|
||||
*/
|
||||
public String decimalToOctal(String decimalStr) {
|
||||
BigInteger decimal = new BigInteger(decimalStr);
|
||||
|
||||
int rem;
|
||||
String octal = "";
|
||||
while (decimal.compareTo(BigInteger.ZERO) > 0) {
|
||||
rem = decimal.mod(valueOctal).intValueExact();
|
||||
octal = octalChars[rem] + octal;
|
||||
decimal = decimal.divide(valueOctal);
|
||||
}
|
||||
return octal;
|
||||
}
|
||||
}
|
106
src/main/java/com/conversions/HexadecimalToBinary.java
Normal file
106
src/main/java/com/conversions/HexadecimalToBinary.java
Normal file
@ -0,0 +1,106 @@
|
||||
package com.conversions;
|
||||
|
||||
public class HexadecimalToBinary {
|
||||
/**
|
||||
* This method converts a hexadecimal number to
|
||||
* a binary number.
|
||||
*
|
||||
* @param hexStr The hexadecimal number
|
||||
* @return The binary number
|
||||
*/
|
||||
|
||||
public String hexToBin (String hexStr) {
|
||||
|
||||
String binaryString = "", hexaNumbers = "0123456789ABCDEF",
|
||||
decimalStr ="", binaryStringBefore ="" , binaryStringAfter = "";
|
||||
int indexOfHex, decimalNumber = 0, k = 1, n =1, z=1, decimalNumberBefore = 0
|
||||
, decimalNumberAfter = 0;
|
||||
char letter;
|
||||
int binaryArray[] = new int [60];
|
||||
int binaryArrayBefore[] = new int [60];
|
||||
int binaryArrayAfter[] = new int [60];
|
||||
|
||||
hexStr = hexStr.toUpperCase();
|
||||
int pointPosition = hexStr.indexOf(".");
|
||||
/**
|
||||
* Transform the hexadecimal number to decimal number
|
||||
*/
|
||||
if ( pointPosition == -1) {
|
||||
for ( int i = 0 ; i < hexStr.length(); i++) {
|
||||
letter = hexStr.charAt(i);
|
||||
indexOfHex = hexaNumbers.indexOf(letter);
|
||||
decimalNumber = 16 * decimalNumber + indexOfHex;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for ( int i = 0 ; i < pointPosition ; i++) {
|
||||
letter = hexStr.charAt(i);
|
||||
indexOfHex = hexaNumbers.indexOf(letter);
|
||||
decimalNumberBefore = 16 * decimalNumberBefore + indexOfHex;
|
||||
}
|
||||
String decimalNumberBeforeStr = String.valueOf(decimalNumberBefore);
|
||||
|
||||
for ( int i = pointPosition+1 ; i < hexStr.length() ; i++) {
|
||||
letter = hexStr.charAt(i);
|
||||
indexOfHex = hexaNumbers.indexOf(letter);
|
||||
decimalNumberAfter = 16 * decimalNumberAfter + indexOfHex;
|
||||
}
|
||||
|
||||
String decimalNumberAfterStr = String.valueOf(decimalNumberAfter);
|
||||
|
||||
decimalStr = decimalNumberBeforeStr + '.' + decimalNumberAfterStr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pointPositionDec = decimalStr.indexOf(".");
|
||||
/**
|
||||
* Check whether the result contains a floating point or not
|
||||
*/
|
||||
if (pointPositionDec == -1) {
|
||||
while (decimalNumber != 0) {
|
||||
binaryArray[k++] = decimalNumber % 2;
|
||||
decimalNumber = decimalNumber / 2;
|
||||
}
|
||||
|
||||
}else {
|
||||
/**
|
||||
* If it contains floating points we need to divide it into two parts before the point and after it
|
||||
*/
|
||||
while (decimalNumberBefore != 0) {
|
||||
binaryArrayBefore[z++] = decimalNumberBefore % 2;
|
||||
decimalNumberBefore = decimalNumberBefore / 2;
|
||||
}
|
||||
while (decimalNumberAfter != 0) {
|
||||
binaryArrayAfter[n++] = decimalNumberAfter % 2;
|
||||
decimalNumberAfter = decimalNumberAfter / 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(pointPositionDec == -1) {
|
||||
for ( int j = k-1 ; j>0 ; j--) {
|
||||
binaryString = binaryString + binaryArray[j];
|
||||
}
|
||||
}else {
|
||||
for ( int j = z-1 ; j>0 ; j--) {
|
||||
binaryStringBefore = binaryStringBefore + binaryArrayBefore[j];
|
||||
}
|
||||
|
||||
for ( int j = n-1 ; j>0 ; j--) {
|
||||
binaryStringAfter = binaryStringAfter + binaryArrayAfter[j];
|
||||
}
|
||||
/**
|
||||
* Remove the zeroes in the end of the hexadecimal
|
||||
*/
|
||||
binaryStringAfter = binaryStringAfter.replaceAll("0*$", "").replaceAll("\\.$", "");
|
||||
|
||||
|
||||
binaryString = binaryStringBefore + "." + binaryStringAfter;
|
||||
}
|
||||
|
||||
return binaryString;
|
||||
|
||||
}
|
||||
|
||||
}
|
68
src/main/java/com/conversions/HexadecimalToDecimal.java
Normal file
68
src/main/java/com/conversions/HexadecimalToDecimal.java
Normal file
@ -0,0 +1,68 @@
|
||||
package com.conversions;
|
||||
|
||||
|
||||
public class HexadecimalToDecimal {
|
||||
|
||||
/**
|
||||
* This method converts a Hexadecimal number to a decimal number
|
||||
*
|
||||
* @param hexadecimalStr
|
||||
* @return decimal number
|
||||
*/
|
||||
public String hexToDecimal(String hexaStr) {
|
||||
String hexaNumbers = "0123456789ABCDEF";
|
||||
int m, result = 0, decimalNumberBefore = 0, power = -1;
|
||||
Double decimalNumberAfter = 0.0;
|
||||
char letter;
|
||||
String decimalStr;
|
||||
hexaStr = hexaStr.toUpperCase();
|
||||
int pointPosition = hexaStr.indexOf(".");
|
||||
/**
|
||||
* Check whether the number contains a float point or not
|
||||
*/
|
||||
if ( pointPosition == -1) {
|
||||
for (int i = 0 ; i < hexaStr.length() ; i++) {
|
||||
/**
|
||||
* Letter will store the hexadecimal number as long as we loop through
|
||||
* the string
|
||||
*/
|
||||
letter = hexaStr.charAt(i);
|
||||
|
||||
/**
|
||||
* m is the index of the number that we are looping through in the
|
||||
* hexaNumbers
|
||||
*/
|
||||
m = hexaNumbers.indexOf(letter);
|
||||
result = 16*result + m;
|
||||
}
|
||||
decimalStr = String.valueOf(result);
|
||||
|
||||
}
|
||||
else {
|
||||
for ( int i = 0 ; i < pointPosition ; i++) {
|
||||
letter = hexaStr.charAt(i);
|
||||
m = hexaNumbers.indexOf(letter);
|
||||
decimalNumberBefore = 16*decimalNumberBefore + m;
|
||||
}
|
||||
|
||||
String decimalNumberBeforeStr = String.valueOf(decimalNumberBefore);
|
||||
|
||||
for ( int i = pointPosition+1 ; i < hexaStr.length() ; i++) {
|
||||
letter = hexaStr.charAt(i);
|
||||
m = hexaNumbers.indexOf(letter);
|
||||
decimalNumberAfter = (decimalNumberAfter + (Math.pow(16, power))*m);
|
||||
power = power-1;
|
||||
}
|
||||
/**
|
||||
* Retrieve the decimal part of the result
|
||||
*/
|
||||
String decimalNumberAfterStr = String.valueOf(decimalNumberAfter);
|
||||
int indexOfDecimal = decimalNumberAfterStr.indexOf(".");
|
||||
decimalNumberAfterStr = decimalNumberAfterStr.substring(indexOfDecimal);
|
||||
|
||||
decimalStr = decimalNumberBeforeStr + decimalNumberAfterStr;
|
||||
}
|
||||
|
||||
return decimalStr ;
|
||||
}
|
||||
}
|
233
src/main/java/com/crypto/codec/Base64.java
Normal file
233
src/main/java/com/crypto/codec/Base64.java
Normal file
@ -0,0 +1,233 @@
|
||||
package com.crypto.codec;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* <p>This class implements the Base64 codec as it is specified in the RFC 4648.
|
||||
* Base64 represents binary data as a text string. It is used to store or transfer
|
||||
* data in legacy systems that are restricted to 7 bit per character. There are
|
||||
* many variations of Base64, e.g. MIME (RFC 2045) specifies Base64 slightly
|
||||
* different. The RFC 4648 tries to solve this disambiguation.
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4648">RFC 4648</a>
|
||||
*/
|
||||
public class Base64 {
|
||||
private static final char pad = '=';
|
||||
private static final char[] encodeAlphabet = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
|
||||
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
|
||||
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
private static final byte[] decodeAlphabet = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57,
|
||||
58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1,
|
||||
-1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
|
||||
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>Encodes user-provided data with the Base64 encoding. For this, the data
|
||||
* is split in to blocks of 3-byte length. The last block may be of a shorter
|
||||
* length. The blocks are then encoded, and the last block is padded.
|
||||
*
|
||||
* @param data The data that is to be Base64-encoded
|
||||
* @return Base64-encoded data
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4648#section-4">RFC 4648 - Base64 encoding</a>
|
||||
*/
|
||||
public static String encode(byte[] data) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int blockCount = data.length / 3;
|
||||
|
||||
// if last block is shorter than 3 bytes, then it's not buffered
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data, 0, blockCount * 3);
|
||||
|
||||
// encode buffered data
|
||||
while (buffer.hasRemaining()) {
|
||||
byte[] dataBlock = new byte[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
dataBlock[i] = buffer.get();
|
||||
}
|
||||
builder.append(encodeBlock(dataBlock));
|
||||
}
|
||||
|
||||
// encode (pad) last block, if it was shorter than 3 bytes
|
||||
int remaining = data.length % 3;
|
||||
if (remaining > 0) {
|
||||
byte[] lastBlock = Arrays.copyOfRange(data, data.length - remaining, data.length);
|
||||
char[] padding = padBlock(lastBlock);
|
||||
builder.append(padding);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Encodes one block of data.
|
||||
*
|
||||
* @param block The block to be encoded with a length of 3 bytes
|
||||
* @return The encoded block
|
||||
*/
|
||||
private static char[] encodeBlock(byte[] block) {
|
||||
char[] encodedBlock = new char[4];
|
||||
|
||||
// split 3 bytes in to 4 6-bit blocks
|
||||
encodedBlock[0] = encodeAlphabet[block[0] >>> 2];
|
||||
encodedBlock[1] = encodeAlphabet[(block[0] & 0b11) << 4 | block[1] >>> 4];
|
||||
encodedBlock[2] = encodeAlphabet[(block[1] & 0b1111) << 2 | block[2] >>> 6];
|
||||
encodedBlock[3] = encodeAlphabet[block[2] & 0b11_1111];
|
||||
|
||||
return encodedBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Pads a block of data with a padding character ('='). A data block can
|
||||
* have one or two elements. The resulting encoded block has always four
|
||||
* characters.
|
||||
* <p>There are two cases:
|
||||
* <ul>
|
||||
* <li>If data block has one element, then the encoded block has two
|
||||
* characters and two padding characters</li>
|
||||
* <li>If data block has two elements, the the encoded block has three
|
||||
* characters and one padding character</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param block A block of data with a length of one or two
|
||||
* @return The encoded and padded block
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4648#section-4">RFC 4648 - Base64 encoding</a>
|
||||
*/
|
||||
private static char[] padBlock(byte[] block) {
|
||||
char[] paddedBlock = new char[4];
|
||||
|
||||
paddedBlock[0] = encodeAlphabet[block[0] >>> 2];
|
||||
if (block.length == 1) {
|
||||
// pad with 2 padding characters
|
||||
paddedBlock[1] = encodeAlphabet[(block[0] & 0b11) << 4];
|
||||
paddedBlock[2] = pad;
|
||||
paddedBlock[3] = pad;
|
||||
} else { // block.length == 2
|
||||
// pad with 1 padding character
|
||||
paddedBlock[1] = encodeAlphabet[(block[0] & 0b11) << 4 | block[1] >>> 4];
|
||||
paddedBlock[2] = encodeAlphabet[(block[1] & 0b1111) << 2];
|
||||
paddedBlock[3] = pad;
|
||||
}
|
||||
|
||||
return paddedBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Decodes original data from a Base64 string. The string has always
|
||||
* a length of the multiple of four characters (empty string included). The
|
||||
* last block of four characters can contain one or two padding characters ('=').
|
||||
* <p>Each block is decoded in to 3 bytes of data. The last block is
|
||||
* processed separately to reverse the padding.
|
||||
*
|
||||
* @param base64String Base64 encoded data
|
||||
* @return original data
|
||||
*/
|
||||
public static byte[] decode(String base64String) {
|
||||
if (base64String == null) {
|
||||
throw new IllegalArgumentException("Base64 string must not be null!");
|
||||
}
|
||||
// remove trailing spaces if any
|
||||
base64String = base64String.trim();
|
||||
if (!isValidBase64String(base64String)) {
|
||||
throw new IllegalArgumentException("String is not a valid Base64 string!");
|
||||
}
|
||||
|
||||
// an empty base64 string decodes in to an empty byte array
|
||||
if (base64String.length() == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
int blockCount = base64String.length() / 4;
|
||||
ByteBuffer stringBuffer = ByteBuffer.wrap(base64String.getBytes(StandardCharsets.ISO_8859_1),
|
||||
0, base64String.length());
|
||||
// separate last block from data
|
||||
ByteBuffer dataBuffer = ByteBuffer.allocate((blockCount - 1) * 3);
|
||||
|
||||
byte[] encodedBlock = new byte[4];
|
||||
// decode bulk of data
|
||||
for (int i = 0; i < blockCount - 1; ++i) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
encodedBlock[j] = stringBuffer.get();
|
||||
}
|
||||
dataBuffer.put(decodeBlock(encodedBlock));
|
||||
}
|
||||
// decode last block
|
||||
for (int i = 0; i < 4; i++) {
|
||||
encodedBlock[i] = stringBuffer.get();
|
||||
}
|
||||
byte[] lastDataBlock = undoPadding(encodedBlock);
|
||||
|
||||
// glue bulk of data and last block together
|
||||
ByteBuffer decodedData = ByteBuffer.allocate(dataBuffer.capacity() + lastDataBlock.length);
|
||||
decodedData.put(dataBuffer.array());
|
||||
decodedData.put(lastDataBlock);
|
||||
return decodedData.array();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Decodes an encoded block.
|
||||
*
|
||||
* @param block The encoded block with a length of 4 bytes
|
||||
* @return The decoded block
|
||||
*/
|
||||
private static byte[] decodeBlock(byte[] block) {
|
||||
byte[] decodedBlock = new byte[3];
|
||||
|
||||
decodedBlock[0] = (byte) (decodeAlphabet[block[0]] << 2 | decodeAlphabet[block[1]] >>> 4);
|
||||
decodedBlock[1] = (byte) (decodeAlphabet[block[1]] << 4 | decodeAlphabet[block[2]] >>> 2);
|
||||
decodedBlock[2] = (byte) (decodeAlphabet[block[2]] << 6 | decodeAlphabet[block[3]] & 0xff);
|
||||
|
||||
return decodedBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Removes the padding from the last block.
|
||||
*
|
||||
* @param block
|
||||
* @return The decoded last block of data
|
||||
*/
|
||||
private static byte[] undoPadding(byte[] block) {
|
||||
int padCount = 0;
|
||||
byte[] decodedBlock;
|
||||
|
||||
// count padding characters
|
||||
if (block[3] == (byte) pad) padCount++;
|
||||
if (block[2] == (byte) pad) padCount++;
|
||||
|
||||
if (padCount == 2) {
|
||||
decodedBlock = new byte[1];
|
||||
decodedBlock[0] = (byte) (decodeAlphabet[block[0]] << 2 | decodeAlphabet[block[1]] >>> 4);
|
||||
} else if (padCount == 1) {
|
||||
decodedBlock = new byte[2];
|
||||
decodedBlock[0] = (byte) (decodeAlphabet[block[0]] << 2 | decodeAlphabet[block[1]] >>> 4);
|
||||
decodedBlock[1] = (byte) (decodeAlphabet[block[1]] << 4 | decodeAlphabet[block[2]] >>> 2);
|
||||
} else {
|
||||
decodedBlock = decodeBlock(block);
|
||||
}
|
||||
return decodedBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Check if the provided string is a valid Base64 string.
|
||||
* <p>The specification (RFC 4648) says: <i>"Implementations MUST reject the
|
||||
* encoded data if it contains characters outside the base alphabet when
|
||||
* interpreting base-encoded data, unless the specification referring to this
|
||||
* document explicitly states otherwise."</i>
|
||||
*
|
||||
* @param base64String
|
||||
* @return <code>true</code> if the string is valid;
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
private static boolean isValidBase64String(String base64String) {
|
||||
return base64String.matches("^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=)?$");
|
||||
}
|
||||
}
|
408
src/main/java/com/crypto/hash/Sha2.java
Normal file
408
src/main/java/com/crypto/hash/Sha2.java
Normal file
@ -0,0 +1,408 @@
|
||||
package com.crypto.hash;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* <p>This class implements the Secure Hash Algorithm 2 family, namely SHA-224,
|
||||
* SHA-256, SHA-384 and SHA-512. These algorithms produce a compressed
|
||||
* representation with fixed length of any message provided by the user.
|
||||
* The result is called a message digest. Any change to the message will
|
||||
* result in a different message digest.
|
||||
* <p>SHA-2 has many possible areas of application. For example, someone
|
||||
* can determine if a file was manipulated, by comparing the message digest
|
||||
* of the original file with the message digest of the file in question.
|
||||
* Another example is the use of SHA-256 in the Proof-of-work algorithm of Bitcoin.
|
||||
* <p>
|
||||
* This implementation is based on the RFC 6234 specification. The original
|
||||
* specification of SHA-2 is defined in FIPS PUB 180-4. Due to the U.S.
|
||||
* government shutdown by the end of 2018 the original specification was offline.
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc6234">RFC 6234</a>
|
||||
* @see <a href="http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf">FIPS PUB 180-4</a>
|
||||
*/
|
||||
public final class Sha2 {
|
||||
|
||||
/**
|
||||
* <p>Returns a SHA-224 message digest with a fixed length of 224 bit (28 byte).
|
||||
* By specification, the user-provided data can have a length of 0 <= L < 2^61 byte.
|
||||
* The JVM, though, allows an array with a maximum length of approximately
|
||||
* Integer.MAX_VALUE.</p>
|
||||
*
|
||||
* @param data the data/message to be digested
|
||||
* @return the message digest with a fixed length of 224 bit (28 byte)
|
||||
*/
|
||||
public static String SHA224(byte[] data) {
|
||||
final int[] initialHash = {
|
||||
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
||||
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
|
||||
};
|
||||
|
||||
int[] finalHash = digest(data, initialHash);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < finalHash.length - 1; i++) {
|
||||
builder.append(String.format("%1$08x", finalHash[i]));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns a SHA-256 message digest with a fixed length of 256 bit (32 byte).<p>
|
||||
*
|
||||
* @param data the data/message to be digested
|
||||
* @return the message digest with a fixed length of 256 bit (32 byte)
|
||||
* @see com.crypto.hash.Sha2#SHA224(byte[]) SHA224()
|
||||
*/
|
||||
public static String SHA256(byte[] data) {
|
||||
final int[] initialHash = {
|
||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
||||
};
|
||||
|
||||
int[] finalHash = digest(data, initialHash);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int aFinalHash : finalHash) {
|
||||
builder.append(String.format("%1$08x", aFinalHash));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns a SHA-384 message digest with a fixed length of 384 bit (48 byte).
|
||||
* By specification, the user-provided data can have a length of 0 <= L < 2^125 byte.
|
||||
* The JVM, though, allows an array with a maximum length of approximately
|
||||
* Integer.MAX_VALUE.</p>
|
||||
*
|
||||
* @param data the data/message to be digested
|
||||
* @return the message digest with a fixed length of 384 bit (48 byte)
|
||||
*/
|
||||
public static String SHA384(byte[] data) {
|
||||
final long[] initialHash = {
|
||||
0xcbbb9d5dc1059ed8L, 0x629a292a367cd507L, 0x9159015a3070dd17L, 0x152fecd8f70e5939L,
|
||||
0x67332667ffc00b31L, 0x8eb44a8768581511L, 0xdb0c2e0d64f98fa7L, 0x47b5481dbefa4fa4L
|
||||
};
|
||||
|
||||
long[] finalHash = digest(data, initialHash);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < finalHash.length - 2; i++) {
|
||||
builder.append(String.format("%1$016x", finalHash[i]));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns a SHA-512 message digest with a fixed length of 512 bit (64 byte).</p>
|
||||
*
|
||||
* @param data the data/message to be digested
|
||||
* @return the message digest with a fixed length of 512 bit (64 byte)
|
||||
* @see com.crypto.hash.Sha2#SHA384(byte[]) SHA384()
|
||||
*/
|
||||
public static String SHA512(byte[] data) {
|
||||
final long[] initialHash = {
|
||||
0x6a09e667f3bcc908L, 0xbb67ae8584caa73bL, 0x3c6ef372fe94f82bL, 0xa54ff53a5f1d36f1L,
|
||||
0x510e527fade682d1L, 0x9b05688c2b3e6c1fL, 0x1f83d9abfb41bd6bL, 0x5be0cd19137e2179L
|
||||
};
|
||||
|
||||
long[] finalHash = digest(data, initialHash);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (long aFinalHash : finalHash) {
|
||||
builder.append(String.format("%1$016x", aFinalHash));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Returns an integer array, which holds the raw message digest.</p>
|
||||
* <p>This method is wrapped by SHA224() and SHA256(). Both algorithms differ
|
||||
* only in two points: the initialization hashes are different and for SHA-224
|
||||
* the raw message digest is truncated by 1 byte.</p>
|
||||
*
|
||||
* @param data the data/message to be digested
|
||||
* @param hash the initial hash value, which in the process gets used
|
||||
* for the intermediate hashes
|
||||
* @return the raw message digest
|
||||
*/
|
||||
private static int[] digest(byte[] data, int[] hash) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("data must not be null");
|
||||
}
|
||||
|
||||
byte[] padding = pad(data, 64);
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(data.length + padding.length);
|
||||
buffer.put(data).put(padding);
|
||||
buffer.rewind();
|
||||
|
||||
while (buffer.hasRemaining()) {
|
||||
int[] messageBlock = new int[16];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
messageBlock[i] = buffer.getInt();
|
||||
}
|
||||
hashBlock(messageBlock, hash);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns an integer array, which holds the raw message digest.</p>
|
||||
* <p>This method is wrapped by SHA384() and SHA512(). Both algorithms differ
|
||||
* only in two points: the initialization hashes are different and for SHA-384
|
||||
* the raw message digest is truncated by 2 byte.</p>
|
||||
*
|
||||
* @param data the data/message to be digested
|
||||
* @param hash the initial hash value, which in the process gets used
|
||||
* for the intermediate hashes
|
||||
* @return the raw message digest
|
||||
*/
|
||||
private static long[] digest(byte[] data, long[] hash) {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("data must not be null");
|
||||
}
|
||||
|
||||
byte[] padding = pad(data, 128);
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(data.length + padding.length);
|
||||
buffer.put(data).put(padding);
|
||||
buffer.rewind();
|
||||
|
||||
while (buffer.hasRemaining()) {
|
||||
long[] messageBlock = new long[16];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
messageBlock[i] = buffer.getLong();
|
||||
}
|
||||
hashBlock(messageBlock, hash);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Pads the user-provided data.</p>
|
||||
*
|
||||
* @param data the data/message to be digested
|
||||
* @param blockSize the size of a data block (64 or 128 byte)
|
||||
* @return the padding for the data
|
||||
* @see <a href="https://tools.ietf.org/html/rfc6234#section-4">RFC 6234 - Message padding</a>
|
||||
*/
|
||||
private static byte[] pad(byte[] data, int blockSize) {
|
||||
byte[] padding;
|
||||
int lastBlockLength = data.length % blockSize;
|
||||
if (lastBlockLength + 1 > (blockSize / 8) * 7) {
|
||||
padding = new byte[blockSize * 2 - lastBlockLength];
|
||||
} else {
|
||||
padding = new byte[blockSize - lastBlockLength];
|
||||
}
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(padding);
|
||||
buffer.put((byte) 0b1000_0000);
|
||||
while (buffer.position() < buffer.capacity() - 8) {
|
||||
buffer.put((byte) 0);
|
||||
}
|
||||
buffer.putLong((long) data.length * 8);
|
||||
|
||||
return padding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrambles data blocks in a deterministic way.
|
||||
*
|
||||
* @param dataBlock the data blocks to be scrambled
|
||||
* @param hash the resulting hash
|
||||
* @see <a href="https://tools.ietf.org/html/rfc6234#section-6.2">SHA-224 and SHA-256 Processing</a>
|
||||
*/
|
||||
private static void hashBlock(int[] dataBlock, int[] hash) {
|
||||
int[] W = new int[64];
|
||||
int[] reg = new int[8];
|
||||
int temp1;
|
||||
int temp2;
|
||||
|
||||
// Prepare the message schedule W
|
||||
for (int i = 0; i < 16; i++) {
|
||||
W[i] = dataBlock[i];
|
||||
}
|
||||
for (int i = 16; i < 64; i++) {
|
||||
W[i] = SSIG1(W[i - 2]) + W[i - 7] + SSIG0(W[i - 15]) + W[i - 16];
|
||||
}
|
||||
|
||||
// Initialize the working variables
|
||||
for (int i = 0; i < 8; i++) {
|
||||
reg[i] = hash[i];
|
||||
}
|
||||
|
||||
// Perform the main hash computation
|
||||
for (int i = 0; i < 64; i++) {
|
||||
temp1 = reg[7] + BSIG1(reg[4]) + CH(reg[4], reg[5], reg[6]) + K_int[i] + W[i];
|
||||
temp2 = BSIG0(reg[0]) + MAJ(reg[0], reg[1], reg[2]);
|
||||
reg[7] = reg[6];
|
||||
reg[6] = reg[5];
|
||||
reg[5] = reg[4];
|
||||
reg[4] = reg[3] + temp1;
|
||||
reg[3] = reg[2];
|
||||
reg[2] = reg[1];
|
||||
reg[1] = reg[0];
|
||||
reg[0] = temp1 + temp2;
|
||||
}
|
||||
|
||||
// Compute the intermediate hash value H(i)
|
||||
for (int i = 0; i < 8; i++) {
|
||||
hash[i] = reg[i] + hash[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrambles data blocks in a deterministic way.
|
||||
*
|
||||
* @param dataBlock the data blocks to be scrambled
|
||||
* @param hash the resulting hash
|
||||
* @see <a href="https://tools.ietf.org/html/rfc6234#section-6.4">SHA-384 and SHA-512 Processing</a>
|
||||
*/
|
||||
private static void hashBlock(long[] dataBlock, long[] hash) {
|
||||
long[] W = new long[80];
|
||||
long[] reg = new long[8];
|
||||
long temp1;
|
||||
long temp2;
|
||||
|
||||
// Prepare the message schedule W
|
||||
for (int i = 0; i < 16; i++) {
|
||||
W[i] = dataBlock[i];
|
||||
}
|
||||
for (int i = 16; i < 80; i++) {
|
||||
W[i] = SSIG1(W[i - 2]) + W[i - 7] + SSIG0(W[i - 15]) + W[i - 16];
|
||||
}
|
||||
|
||||
// Initialize the working variables
|
||||
for (int i = 0; i < 8; i++) {
|
||||
reg[i] = hash[i];
|
||||
}
|
||||
|
||||
// Perform the main hash computation
|
||||
for (int i = 0; i < 80; i++) {
|
||||
temp1 = reg[7] + BSIG1(reg[4]) + CH(reg[4], reg[5], reg[6]) + K_long[i] + W[i];
|
||||
temp2 = BSIG0(reg[0]) + MAJ(reg[0], reg[1], reg[2]);
|
||||
reg[7] = reg[6];
|
||||
reg[6] = reg[5];
|
||||
reg[5] = reg[4];
|
||||
reg[4] = reg[3] + temp1;
|
||||
reg[3] = reg[2];
|
||||
reg[2] = reg[1];
|
||||
reg[1] = reg[0];
|
||||
reg[0] = temp1 + temp2;
|
||||
}
|
||||
|
||||
// Compute the intermediate hash value H(i)
|
||||
for (int i = 0; i < 8; i++) {
|
||||
hash[i] = reg[i] + hash[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions and Constants used
|
||||
* https://tools.ietf.org/html/rfc6234#section-5
|
||||
*/
|
||||
|
||||
private static final int[] K_int = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
private static final long[] K_long = {
|
||||
0x428a2f98d728ae22L, 0x7137449123ef65cdL, 0xb5c0fbcfec4d3b2fL, 0xe9b5dba58189dbbcL,
|
||||
0x3956c25bf348b538L, 0x59f111f1b605d019L, 0x923f82a4af194f9bL, 0xab1c5ed5da6d8118L,
|
||||
0xd807aa98a3030242L, 0x12835b0145706fbeL, 0x243185be4ee4b28cL, 0x550c7dc3d5ffb4e2L,
|
||||
0x72be5d74f27b896fL, 0x80deb1fe3b1696b1L, 0x9bdc06a725c71235L, 0xc19bf174cf692694L,
|
||||
0xe49b69c19ef14ad2L, 0xefbe4786384f25e3L, 0x0fc19dc68b8cd5b5L, 0x240ca1cc77ac9c65L,
|
||||
0x2de92c6f592b0275L, 0x4a7484aa6ea6e483L, 0x5cb0a9dcbd41fbd4L, 0x76f988da831153b5L,
|
||||
0x983e5152ee66dfabL, 0xa831c66d2db43210L, 0xb00327c898fb213fL, 0xbf597fc7beef0ee4L,
|
||||
0xc6e00bf33da88fc2L, 0xd5a79147930aa725L, 0x06ca6351e003826fL, 0x142929670a0e6e70L,
|
||||
0x27b70a8546d22ffcL, 0x2e1b21385c26c926L, 0x4d2c6dfc5ac42aedL, 0x53380d139d95b3dfL,
|
||||
0x650a73548baf63deL, 0x766a0abb3c77b2a8L, 0x81c2c92e47edaee6L, 0x92722c851482353bL,
|
||||
0xa2bfe8a14cf10364L, 0xa81a664bbc423001L, 0xc24b8b70d0f89791L, 0xc76c51a30654be30L,
|
||||
0xd192e819d6ef5218L, 0xd69906245565a910L, 0xf40e35855771202aL, 0x106aa07032bbd1b8L,
|
||||
0x19a4c116b8d2d0c8L, 0x1e376c085141ab53L, 0x2748774cdf8eeb99L, 0x34b0bcb5e19b48a8L,
|
||||
0x391c0cb3c5c95a63L, 0x4ed8aa4ae3418acbL, 0x5b9cca4f7763e373L, 0x682e6ff3d6b2b8a3L,
|
||||
0x748f82ee5defb2fcL, 0x78a5636f43172f60L, 0x84c87814a1f0ab72L, 0x8cc702081a6439ecL,
|
||||
0x90befffa23631e28L, 0xa4506cebde82bde9L, 0xbef9a3f7b2c67915L, 0xc67178f2e372532bL,
|
||||
0xca273eceea26619cL, 0xd186b8c721c0c207L, 0xeada7dd6cde0eb1eL, 0xf57d4f7fee6ed178L,
|
||||
0x06f067aa72176fbaL, 0x0a637dc5a2c898a6L, 0x113f9804bef90daeL, 0x1b710b35131c471bL,
|
||||
0x28db77f523047d84L, 0x32caab7b40c72493L, 0x3c9ebe0a15c9bebcL, 0x431d67c49c100d4cL,
|
||||
0x4cc5d4becb3e42b6L, 0x597f299cfc657e2aL, 0x5fcb6fab3ad6faecL, 0x6c44198c4a475817L
|
||||
};
|
||||
|
||||
private static int CH(int x, int y, int z) {
|
||||
return (x & y) ^ ((~x) & z);
|
||||
}
|
||||
|
||||
private static long CH(long x, long y, long z) {
|
||||
return (x & y) ^ ((~x) & z);
|
||||
}
|
||||
|
||||
private static int MAJ(int x, int y, int z) {
|
||||
return (x & y) ^ (x & z) ^ (y & z);
|
||||
}
|
||||
|
||||
private static long MAJ(long x, long y, long z) {
|
||||
return (x & y) ^ (x & z) ^ (y & z);
|
||||
}
|
||||
|
||||
private static int BSIG0(int x) {
|
||||
return ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22);
|
||||
}
|
||||
|
||||
private static long BSIG0(long x) {
|
||||
return ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39);
|
||||
}
|
||||
|
||||
private static int BSIG1(int x) {
|
||||
return ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25);
|
||||
}
|
||||
|
||||
private static long BSIG1(long x) {
|
||||
return ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41);
|
||||
}
|
||||
|
||||
private static int SSIG0(int x) {
|
||||
return ROTR(x, 7) ^ ROTR(x, 18) ^ (x >>> 3);
|
||||
}
|
||||
|
||||
private static long SSIG0(long x) {
|
||||
return ROTR(x, 1) ^ ROTR(x, 8) ^ (x >>> 7);
|
||||
}
|
||||
|
||||
private static int SSIG1(int x) {
|
||||
return ROTR(x, 17) ^ ROTR(x, 19) ^ (x >>> 10);
|
||||
}
|
||||
|
||||
private static long SSIG1(long x) {
|
||||
return ROTR(x, 19) ^ ROTR(x, 61) ^ (x >>> 6);
|
||||
}
|
||||
|
||||
private static int ROTR(int x, int n) {
|
||||
return (x >>> n) | (x << (32 - n));
|
||||
}
|
||||
|
||||
private static long ROTR(long x, long n) {
|
||||
return (x >>> n) | (x << (64 - n));
|
||||
}
|
||||
}
|
134
src/main/java/com/datastructures/BinaryTree.java
Normal file
134
src/main/java/com/datastructures/BinaryTree.java
Normal file
@ -0,0 +1,134 @@
|
||||
package com.datastructures;
|
||||
|
||||
/**
|
||||
* Binary tree for general value type, without redundancy
|
||||
*
|
||||
* @param <T> root data
|
||||
*/
|
||||
|
||||
public class BinaryTree<T extends Comparable> {
|
||||
private final T data;
|
||||
private BinaryTree<T> right, // the upper binary tree
|
||||
left; // the lower binary tree
|
||||
|
||||
public BinaryTree(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.data.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* inserts a new value in it's correspondent place
|
||||
*
|
||||
* @param newDataValue value of the new binary tree to add on this tree
|
||||
*/
|
||||
public void insert(T newDataValue) {
|
||||
this.insert(new BinaryTree<>(newDataValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* inserts a new binary tree in it's correspondent place
|
||||
*
|
||||
* @param newData new value to add on this tree
|
||||
*/
|
||||
public void insert(BinaryTree<T> newData) {
|
||||
|
||||
int cpr = newData.data.compareTo(this.data); //new value comparission respect to actual value
|
||||
|
||||
if (cpr < 0) {
|
||||
if (this.left == null) {
|
||||
this.setLeft(newData);
|
||||
} else {
|
||||
this.left.insert(newData);
|
||||
}
|
||||
} else if (cpr > 0) {
|
||||
if (this.right == null) {
|
||||
this.setRight(newData);
|
||||
} else {
|
||||
this.right.insert(newData);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Redundant value, not added");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* search and specific value on the tree
|
||||
*
|
||||
* @param data Searched value
|
||||
* @return Binary tree which contains the value, null if it doesn't exist
|
||||
*/
|
||||
public BinaryTree<T> search(T data) {
|
||||
int cpr = data.compareTo(this.data); //new value comparison respect to actual value
|
||||
|
||||
if (cpr < 0) {
|
||||
if (this.left == null)
|
||||
return null; //the value doesn't exist
|
||||
return this.left.search(data);
|
||||
}
|
||||
if (cpr > 0) {
|
||||
if (this.right == null)
|
||||
return null; //the value doesn't exist
|
||||
return this.right.search(data);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the data value exist in the tree
|
||||
*
|
||||
* @param data data to be searched
|
||||
* @return true if this tree contains the data value, false if not.
|
||||
*/
|
||||
public boolean contains(T data) {
|
||||
return this.search(data) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* uses recursive black magic to print this tree in console
|
||||
*
|
||||
* @param tabCounter prev tabs
|
||||
*/
|
||||
private void print(int tabCounter) {
|
||||
for (int i = 0; i < tabCounter; i++)
|
||||
System.out.print("\t");
|
||||
|
||||
System.out.println(this);
|
||||
|
||||
if (this.left != null)
|
||||
this.left.print(tabCounter + 1); //it can't be ++ , pls don't change it
|
||||
if (this.right != null)
|
||||
this.right.print(tabCounter + 1); //it can't be ++ , pls don't change it
|
||||
}
|
||||
|
||||
/**
|
||||
* uses black magic to print this tree in console
|
||||
*/
|
||||
public void print() {
|
||||
this.print(0);
|
||||
}
|
||||
|
||||
//getters and setters
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public BinaryTree<T> getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public void setRight(BinaryTree<T> right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public BinaryTree<T> getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public void setLeft(BinaryTree<T> left) {
|
||||
this.left = left;
|
||||
}
|
||||
}
|
136
src/main/java/com/datastructures/DisjointSet.java
Normal file
136
src/main/java/com/datastructures/DisjointSet.java
Normal file
@ -0,0 +1,136 @@
|
||||
package com.datastructures;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* An implementation of disjoint-set, represented by rooted trees.
|
||||
* <p>
|
||||
* Actually, the instance of {@link DisjointSet} is a disjoint-set forests.
|
||||
*
|
||||
* <p>
|
||||
* Disjoint-set operations:
|
||||
* <p>
|
||||
* 1. quickly unites two sets into a new set, requiring O(1) time.
|
||||
* <p>
|
||||
* 2. quickly query two elements whether contained in the same set, requiring about O(1) time.
|
||||
*
|
||||
*/
|
||||
public class DisjointSet<T> implements Serializable {
|
||||
private static final long serialVersionUID = 3134700471905625636L;
|
||||
private static final String elementKey = "element";
|
||||
|
||||
private final Map<T, Node<T>> nodeMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Add an element to the disjoint-set forests as a set.
|
||||
*/
|
||||
public void makeSet(T element) {
|
||||
checkNotNull(element, elementKey);
|
||||
nodeMap.putIfAbsent(element, new Node<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unites the set that contains left and the set that contains right
|
||||
* into a new set with the union-by-rank heuristic.
|
||||
* <p>
|
||||
* Rank is an upper bound on the height of node.
|
||||
*/
|
||||
public void union(T left, T right) {
|
||||
checkNotNull(left, elementKey);
|
||||
checkNotNull(right, elementKey);
|
||||
|
||||
Node<T> leftNode = nodeMap.get(left),
|
||||
rightNode = nodeMap.get(right);
|
||||
|
||||
if (leftNode == null) {
|
||||
throw new NoSuchElementException(left.toString());
|
||||
}
|
||||
|
||||
if (rightNode == null) {
|
||||
throw new NoSuchElementException(right.toString());
|
||||
}
|
||||
|
||||
Node<T> leftSet = findSet(leftNode),
|
||||
rightSet = findSet(rightNode);
|
||||
|
||||
if (leftSet == rightSet) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (leftSet.rank < rightSet.rank) {
|
||||
leftSet.parent = rightSet;
|
||||
} else {
|
||||
rightSet.parent = leftSet;
|
||||
if (leftSet.rank == rightSet.rank) {
|
||||
leftSet.rank++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query two elements whether contained in the same set.
|
||||
*/
|
||||
public boolean isConnected(T left, T right) {
|
||||
if (left == null || right == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Node<T> leftNode = nodeMap.get(left);
|
||||
if (leftNode == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Node<T> rightNode = nodeMap.get(right);
|
||||
if (rightNode == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (leftNode == rightNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return findSet(leftNode) == findSet(rightNode);
|
||||
}
|
||||
|
||||
public Collection<Set<T>> toSets() {
|
||||
Map<Node<T>, Set<T>> setMap = new HashMap<>();
|
||||
for (Map.Entry<T, Node<T>> entry : nodeMap.entrySet()) {
|
||||
setMap.computeIfAbsent(findSet(entry.getValue()), k -> new HashSet<>())
|
||||
.add(entry.getKey());
|
||||
}
|
||||
return setMap.values();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
toSets().forEach(System.out::println);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the set that contains the node, actual is the first node of the set.
|
||||
* <p>
|
||||
* Backtracking with path compression.
|
||||
*/
|
||||
private Node<T> findSet(Node<T> node) {
|
||||
if (node != node.parent) {
|
||||
node.parent = findSet(node.parent);
|
||||
}
|
||||
return node.parent;
|
||||
}
|
||||
|
||||
private static void checkNotNull(Object obj, String msg) {
|
||||
if (obj == null) {
|
||||
throw new NullPointerException(msg + " must be not null");
|
||||
}
|
||||
}
|
||||
|
||||
static class Node<T> {
|
||||
int rank;
|
||||
Node<T> parent;
|
||||
|
||||
Node() {
|
||||
parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
136
src/main/java/com/datastructures/GeneralQueue.java
Normal file
136
src/main/java/com/datastructures/GeneralQueue.java
Normal file
@ -0,0 +1,136 @@
|
||||
package com.datastructures;
|
||||
|
||||
import com.types.Queue;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* linkedList based implementation of queue.
|
||||
* This implementation is not thread safe and need exclusive thread safety measures from the client.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class GeneralQueue<T> implements Queue<T> {
|
||||
|
||||
private LinkedList<T> queue;
|
||||
private Iterator<T> itr;
|
||||
|
||||
/**
|
||||
* Overloaded constructor to create queue of specific size
|
||||
*/
|
||||
public GeneralQueue() {
|
||||
queue = new LinkedList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(T t) {
|
||||
|
||||
if (queue == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (t == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
queue.add(t);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(T t) {
|
||||
if (null == queue) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (queue.isEmpty()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
queue.remove(t);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return null == queue || queue.size() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
if (queue == null) {
|
||||
return null;
|
||||
}
|
||||
itr = queue.iterator();
|
||||
return itr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean offer(T t) {
|
||||
if (null == queue) {
|
||||
return false;
|
||||
}
|
||||
if (t == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
queue.add(t);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T poll() {
|
||||
if (queue == null || queue.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return queue.pollFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T element() {
|
||||
if (queue == null || queue.isEmpty()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return queue.peekFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T peek() {
|
||||
if (null == queue || queue.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return queue.peekFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return itr.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
return itr.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
Object[] elements = {};
|
||||
if (null == queue || queue.isEmpty()) {
|
||||
return elements;
|
||||
}
|
||||
elements = new Object[queue.size()];
|
||||
for (int i = 0; i < queue.size(); i++) {
|
||||
elements[i] = queue.get(i);
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
if (null == queue || queue.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return queue.size();
|
||||
}
|
||||
}
|
111
src/main/java/com/datastructures/IntQueue.java
Normal file
111
src/main/java/com/datastructures/IntQueue.java
Normal file
@ -0,0 +1,111 @@
|
||||
package com.datastructures;
|
||||
|
||||
/**
|
||||
* This file contains an implementation of an integer only queue which is extremely quick and
|
||||
* lightweight. In terms of performance it can outperform java.util.ArrayDeque (Java's fastest queue
|
||||
* implementation) by a factor of 40+! See the benchmark test below for proof. However, the downside
|
||||
* is you need to know an upper bound on the number of elements that will be inside the queue at any
|
||||
* given time for this queue to work.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
public class IntQueue {
|
||||
|
||||
private int[] ar;
|
||||
private int front, end, sz;
|
||||
|
||||
// maxSize is the maximum number of items
|
||||
// that can be in the queue at any given time
|
||||
public IntQueue(int maxSize) {
|
||||
front = end = 0;
|
||||
sz = maxSize + 1;
|
||||
ar = new int[sz];
|
||||
}
|
||||
|
||||
// Return true/false on whether the queue is empty
|
||||
public boolean isEmpty() {
|
||||
return front == end;
|
||||
}
|
||||
|
||||
// Return the number of elements inside the queue
|
||||
public int size() {
|
||||
if (front > end) return (end + sz - front);
|
||||
return end - front;
|
||||
}
|
||||
|
||||
public int peek() {
|
||||
return ar[front];
|
||||
}
|
||||
|
||||
// Add an element to the queue
|
||||
public void enqueue(int value) {
|
||||
ar[end] = value;
|
||||
if (++end == sz) end = 0;
|
||||
if (end == front) throw new RuntimeException("Queue too small!");
|
||||
}
|
||||
|
||||
// Make sure you check is the queue is not empty before calling dequeue!
|
||||
public int dequeue() {
|
||||
int ret_val = ar[front];
|
||||
if (++front == sz) front = 0;
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
// Example usage to check the how fast this implementation is
|
||||
public static void main(String[] args) {
|
||||
|
||||
IntQueue q = new IntQueue(5);
|
||||
|
||||
q.enqueue(1);
|
||||
q.enqueue(2);
|
||||
q.enqueue(3);
|
||||
q.enqueue(4);
|
||||
q.enqueue(5);
|
||||
|
||||
System.out.println(q.dequeue()); // 1
|
||||
System.out.println(q.dequeue()); // 2
|
||||
System.out.println(q.dequeue()); // 3
|
||||
System.out.println(q.dequeue()); // 4
|
||||
|
||||
System.out.println(q.isEmpty()); // false
|
||||
|
||||
q.enqueue(1);
|
||||
q.enqueue(2);
|
||||
q.enqueue(3);
|
||||
|
||||
System.out.println(q.dequeue()); // 5
|
||||
System.out.println(q.dequeue()); // 1
|
||||
System.out.println(q.dequeue()); // 2
|
||||
System.out.println(q.dequeue()); // 3
|
||||
|
||||
System.out.println(q.isEmpty()); // true
|
||||
|
||||
benchMarkTest();
|
||||
}
|
||||
|
||||
// BenchMark IntQueue vs ArrayDeque.
|
||||
private static void benchMarkTest() {
|
||||
|
||||
int n = 10000000;
|
||||
IntQueue intQ = new IntQueue(n);
|
||||
|
||||
// IntQueue times at around 0.0324 seconds
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < n; i++) intQ.enqueue(i);
|
||||
for (int i = 0; i < n; i++) intQ.dequeue();
|
||||
long end = System.nanoTime();
|
||||
System.out.println("IntQueue Time: " + (end - start) / 1e9);
|
||||
|
||||
// ArrayDeque times at around 1.438 seconds
|
||||
java.util.ArrayDeque<Integer> arrayDeque = new java.util.ArrayDeque<>();
|
||||
// java.util.ArrayDeque <Integer> arrayDeque = new java.util.ArrayDeque<>(n); // strangely the
|
||||
// ArrayQueue is slower when you give it an initial capacity.
|
||||
start = System.nanoTime();
|
||||
for (int i = 0; i < n; i++) arrayDeque.offer(i);
|
||||
for (int i = 0; i < n; i++) arrayDeque.poll();
|
||||
end = System.nanoTime();
|
||||
System.out.println("ArrayDeque Time: " + (end - start) / 1e9);
|
||||
}
|
||||
}
|
102
src/main/java/com/datastructures/SinglyLinkedList.java
Normal file
102
src/main/java/com/datastructures/SinglyLinkedList.java
Normal file
@ -0,0 +1,102 @@
|
||||
package com.datastructures;
|
||||
|
||||
|
||||
|
||||
|
||||
public class SinglyLinkedList<T> {
|
||||
|
||||
/**
|
||||
* Define a node in the singly linked list
|
||||
*/
|
||||
private static class Node<T> {
|
||||
T data;
|
||||
Node<T> next;
|
||||
|
||||
Node(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference to the first node of the singly linked list
|
||||
*/
|
||||
private Node<T> head;
|
||||
|
||||
/**
|
||||
* Method to return the size of the singly linked list
|
||||
*/
|
||||
public int size() {
|
||||
int size = 0;
|
||||
Node<T> node = head;
|
||||
while (node != null) {
|
||||
++size;
|
||||
node = node.next;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to add a node at the end of the singly linked list
|
||||
*/
|
||||
public void add(T data) {
|
||||
Node<T> newNode = new Node<>(data);
|
||||
if (head == null) {
|
||||
head = newNode;
|
||||
} else {
|
||||
Node<T> last = head;
|
||||
while (last.next != null) {
|
||||
last = last.next;
|
||||
}
|
||||
last.next = newNode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to add a node at the beginning of the singly linked list
|
||||
*/
|
||||
public void insertAtStart (T data) {
|
||||
Node<T> node = new Node<>(data);
|
||||
node.data = data;
|
||||
node.next = null;
|
||||
node.next = head;
|
||||
head = node;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to remove a node at any position in the singly linked list
|
||||
*/
|
||||
public void remove(int position) {
|
||||
Node<T> prev = null, node = head;
|
||||
while (position > 0 && node != null) {
|
||||
--position;
|
||||
prev = node;
|
||||
node = node.next;
|
||||
}
|
||||
if (node != null) {
|
||||
if (prev == null) {
|
||||
head = node.next;
|
||||
} else {
|
||||
prev.next = node.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to print the content of the singly linked list for better
|
||||
* understanding
|
||||
*/
|
||||
public void printContent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Node<T> node = head;
|
||||
while (node != null) {
|
||||
sb.append(node.data).append('-').append('>');
|
||||
node = node.next;
|
||||
}
|
||||
int lastComma = sb.lastIndexOf(",");
|
||||
if (lastComma != -1) {
|
||||
sb.deleteCharAt(lastComma);
|
||||
}
|
||||
System.out.println(sb);
|
||||
}
|
||||
}
|
123
src/main/java/com/datastructures/Stack.java
Normal file
123
src/main/java/com/datastructures/Stack.java
Normal file
@ -0,0 +1,123 @@
|
||||
package com.datastructures;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.EmptyStackException;
|
||||
|
||||
public class Stack<E> implements Serializable {
|
||||
|
||||
/**
|
||||
* Initial capacity allocated to stack on object creation
|
||||
*/
|
||||
private final int INITIAL_CAPACITY = 10;
|
||||
|
||||
/**
|
||||
* Increment in memory space once stack is out of space
|
||||
*/
|
||||
private final int EXTENDED_CAPACITY = 10;
|
||||
|
||||
|
||||
/**
|
||||
* Position of tail in stack
|
||||
*/
|
||||
private int tail = -1;
|
||||
|
||||
/**
|
||||
* Size of stack at any given time
|
||||
*/
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* Uninitialized array to hold stack elements.
|
||||
* Will be initialized with initial capacity once the object is created
|
||||
*/
|
||||
private E[] elements;
|
||||
|
||||
/**
|
||||
* No argument to create stack object with initial capacity
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Stack() {
|
||||
elements = (E[]) new Object[INITIAL_CAPACITY];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if the given stack is empty or not
|
||||
*/
|
||||
public boolean empty() {
|
||||
return elements == null || size == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check the element on head without removing it
|
||||
*/
|
||||
public E peek() {
|
||||
if (empty()) {
|
||||
throw new EmptyStackException();
|
||||
}
|
||||
|
||||
return elements[tail];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to remove the top element from stack
|
||||
*/
|
||||
public E pop() {
|
||||
if (empty()) {
|
||||
throw new EmptyStackException();
|
||||
}
|
||||
|
||||
E removedElement = elements[tail];
|
||||
tail--;
|
||||
size--;
|
||||
return removedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to add element to stack
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void push(E e) {
|
||||
|
||||
tail = tail + 1;
|
||||
if (tail >= INITIAL_CAPACITY) {
|
||||
E[] extendedElements = (E[]) new Object[INITIAL_CAPACITY + EXTENDED_CAPACITY];
|
||||
System.arraycopy(elements, 0, extendedElements, 0, tail);
|
||||
elements = extendedElements;
|
||||
}
|
||||
elements[tail] = e;
|
||||
size = size + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to search for an element in stack
|
||||
*/
|
||||
public int search(E o) {
|
||||
|
||||
int index = -1;
|
||||
boolean found = false;
|
||||
if (empty()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size(); i++) {
|
||||
if (elements[i].equals(o)) {
|
||||
index = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
index = tail - index + 1;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get size of stack
|
||||
*/
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
/**
|
||||
* The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme
|
||||
* without specifying their concrete classes. In normal usage, the client software creates a concrete implementation of
|
||||
* the abstract factory and then uses the generic interface of the factory to create the concrete objects that are part
|
||||
* of the theme. The client doesn't know (or care) which concrete objects it gets from each of these internal factories,
|
||||
* since it uses only the generic interfaces of their products.
|
||||
* <p>
|
||||
* This pattern separates the details of implementation of a set of objects from their general usage and relies on
|
||||
* object composition, as object creation is implemented in methods exposed in the factory interface.
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Abstract_factory_pattern">Abstract Factory Pattern</a>
|
||||
*/
|
||||
public abstract class AbstractShapeFactory {
|
||||
/**
|
||||
* Creates the appropriate shape object depending on the type of the shape
|
||||
*
|
||||
* @param name enum defining the name of the shape
|
||||
* @return shape object
|
||||
*/
|
||||
public abstract Shape getShape(ShapeType name);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public class Circle implements Shape {
|
||||
@Override
|
||||
public double surfaceArea(float radius) {
|
||||
return Math.PI * radius * radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeType getShapeType() {
|
||||
return ShapeType.CIRCLE;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public class FactoryProvider {
|
||||
public static AbstractShapeFactory getShapeFactory(FactoryType factoryType) {
|
||||
if (FactoryType.TWO_D_FACTORY == factoryType) {
|
||||
return new TwoDShapeFactory();
|
||||
} else if (FactoryType.THREE_D_FACTORY == factoryType) {
|
||||
return new ThreeDShapeFactory();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public enum FactoryType {
|
||||
TWO_D_FACTORY,
|
||||
THREE_D_FACTORY
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public class Line implements Shape {
|
||||
@Override
|
||||
public double surfaceArea(float radius) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeType getShapeType() {
|
||||
return ShapeType.LINE;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public interface Shape {
|
||||
/**
|
||||
* calculates the surface area for the shape object
|
||||
*
|
||||
* @param radius the radius or length of shape whose area is to be calculated
|
||||
* @return total surface area for the shape
|
||||
*/
|
||||
double surfaceArea(float radius);
|
||||
|
||||
/**
|
||||
* A property to identity the type of the shape for testing the pattern
|
||||
*
|
||||
* @return an enum describing the shape type
|
||||
*/
|
||||
ShapeType getShapeType();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public enum ShapeType {
|
||||
LINE,
|
||||
CIRCLE,
|
||||
SPHERE
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public class Sphere implements Shape {
|
||||
@Override
|
||||
public double surfaceArea(float radius) {
|
||||
return 4 * Math.PI * radius * radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeType getShapeType() {
|
||||
return ShapeType.SPHERE;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public class ThreeDShapeFactory extends AbstractShapeFactory {
|
||||
@Override
|
||||
public Shape getShape(ShapeType name) {
|
||||
if (ShapeType.SPHERE == name) {
|
||||
return new Sphere();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.designpatterns.creational.abstractfactory;
|
||||
|
||||
public class TwoDShapeFactory extends AbstractShapeFactory {
|
||||
@Override
|
||||
public Shape getShape(ShapeType name) {
|
||||
if (ShapeType.LINE == name) {
|
||||
return new Line();
|
||||
} else if (ShapeType.CIRCLE == name) {
|
||||
return new Circle();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package com.designpatterns.creational.builder;
|
||||
|
||||
/**
|
||||
* The Builder is a design pattern designed to provide a flexible solution to various object creation problems in
|
||||
* object-oriented programming. The intent of the Builder design pattern is to separate the construction of a complex
|
||||
* object from its representation.
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Builder_pattern">Builder Pattern</a>
|
||||
*/
|
||||
|
||||
public class Desktop {
|
||||
private String CPU;
|
||||
private String RAM;
|
||||
|
||||
private boolean isGraphicCardEnabled;
|
||||
private String operatingSystem;
|
||||
private int diskSizeGB;
|
||||
private String graphicCard;
|
||||
|
||||
private Desktop(DesktopBuilder builder) {
|
||||
this.CPU = builder.CPU;
|
||||
this.RAM = builder.RAM;
|
||||
this.isGraphicCardEnabled = builder.isGraphicCardEnabled;
|
||||
this.operatingSystem = builder.operatingSystem;
|
||||
this.diskSizeGB = builder.diskSizeGB;
|
||||
this.graphicCard = builder.graphicCard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder class for the above Desktop class. Constructs the Desktop by invoking the Desktop class constructor and
|
||||
* allows access to set optional fields in the Desktop class.
|
||||
*/
|
||||
public static class DesktopBuilder {
|
||||
private String CPU;
|
||||
private String RAM;
|
||||
private boolean isGraphicCardEnabled;
|
||||
private String operatingSystem;
|
||||
private int diskSizeGB;
|
||||
private String graphicCard;
|
||||
|
||||
public DesktopBuilder(String CPU, String RAM) {
|
||||
this.CPU = CPU;
|
||||
this.RAM = RAM;
|
||||
}
|
||||
|
||||
public DesktopBuilder setGraphicCardEnabled(boolean graphicCardEnabled) {
|
||||
this.isGraphicCardEnabled = graphicCardEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DesktopBuilder setOperatingSystem(String operatingSystem) {
|
||||
this.operatingSystem = operatingSystem;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DesktopBuilder setDiskSizeGB(int diskSize) {
|
||||
this.diskSizeGB = diskSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DesktopBuilder setGraphicCard(String graphicCard) {
|
||||
this.graphicCard = graphicCard;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Desktop build() {
|
||||
return new Desktop(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Desktop{" +
|
||||
"CPU='" + CPU + '\'' +
|
||||
", RAM='" + RAM + '\'' +
|
||||
", isGraphicCardEnabled=" + isGraphicCardEnabled +
|
||||
", operatingSystem='" + operatingSystem + '\'' +
|
||||
", diskSizeGB=" + diskSizeGB +
|
||||
", graphicCard='" + graphicCard + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.designpatterns.creational.factory;
|
||||
|
||||
public class Pentagon implements Polygon {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Pentagon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double area(double side) {
|
||||
return 3.847104 * side * side;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.designpatterns.creational.factory;
|
||||
|
||||
public interface Polygon {
|
||||
/**
|
||||
* Should be overriden to describe the type of each polygon
|
||||
*
|
||||
* @return a String value describing the name of the polygon
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* Calculates the area of the regular polygon
|
||||
*
|
||||
* @param side The length of the side of regular polygon
|
||||
* @return area of the polygon
|
||||
*/
|
||||
double area(double side);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.designpatterns.creational.factory;
|
||||
|
||||
/**
|
||||
* In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal
|
||||
* with the problem of creating objects without having to specify the exact class of the object that will be created.
|
||||
* This is done by creating objects by calling a factory method-either specified in an interface and implemented by
|
||||
* child classes, or implemented in a base class and optionally overridden by derived classes-rather than by calling
|
||||
* a constructor.
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Factory_method_pattern">Factory Pattern</a>
|
||||
*/
|
||||
public class PolygonFactory {
|
||||
/**
|
||||
* Factory pattern implementation for the Polygon Interface to return the correct regular polygon object
|
||||
* depending on the number of sides it has.
|
||||
*
|
||||
* @param numberOfSides in the polygon to initialize.
|
||||
* @return the object having the respective number of sides
|
||||
*/
|
||||
public Polygon getPolygon(int numberOfSides) {
|
||||
switch (numberOfSides) {
|
||||
case 3:
|
||||
return new Triangle();
|
||||
case 4:
|
||||
return new Square();
|
||||
case 5:
|
||||
return new Pentagon();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.designpatterns.creational.factory;
|
||||
|
||||
public class Square implements Polygon {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Square";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double area(double side) {
|
||||
return side * side;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.designpatterns.creational.factory;
|
||||
|
||||
public class Triangle implements Polygon {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Triangle";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double area(double side) {
|
||||
return 0.433013 * side * side;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.designpatterns.creational.prototype;
|
||||
|
||||
class BlackColor extends Color {
|
||||
|
||||
BlackColor() {
|
||||
this.colorName = "black";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addColor() {
|
||||
return "Black color added";
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.designpatterns.creational.prototype;
|
||||
|
||||
class BlueColor extends Color {
|
||||
|
||||
BlueColor() {
|
||||
this.colorName = "blue";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addColor() {
|
||||
return "Blue color added";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.designpatterns.creational.prototype;
|
||||
|
||||
/**
|
||||
* The prototype pattern is used when the type of objects to create is determined by a prototypical instance, which
|
||||
* is cloned to produce new objects. <p>
|
||||
* This pattern is used to:
|
||||
* 1. avoid subclasses of an object creator in the client application, like the factory method pattern does.
|
||||
* 2. avoid the inherent cost of creating a new object in the standard way (e.g., using the 'new' keyword) when it is
|
||||
* prohibitively expensive for a given application.
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Prototype_pattern">Prototype Pattern</a>
|
||||
*/
|
||||
public abstract class Color implements Cloneable {
|
||||
|
||||
String colorName;
|
||||
|
||||
public abstract String addColor();
|
||||
|
||||
/**
|
||||
* This method should be called from the client instead of writing code that invokes the "new" operator on a
|
||||
* hard-coded class name.
|
||||
*
|
||||
* @return a clone for the object
|
||||
*/
|
||||
public Object clone() {
|
||||
Object clone = null;
|
||||
try {
|
||||
clone = super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.designpatterns.creational.prototype;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ColorStore {
|
||||
private static Map<String, Color> colorMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
colorMap.put("blue", new BlueColor());
|
||||
colorMap.put("black", new BlackColor());
|
||||
colorMap.put("red", new RedColor());
|
||||
}
|
||||
|
||||
public static Color getColor(String colorName) {
|
||||
return (Color) colorMap.get(colorName).clone();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.designpatterns.creational.prototype;
|
||||
|
||||
class RedColor extends Color {
|
||||
|
||||
RedColor() {
|
||||
this.colorName = "red";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addColor() {
|
||||
return "Red color added";
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.designpatterns.creational.singleton;
|
||||
|
||||
/**
|
||||
* The singleton pattern is a design pattern that restricts the instantiation of a class to one "single" instance.
|
||||
* This is useful when exactly one object is needed to coordinate actions across the system. The term comes from the
|
||||
* mathematical concept of a singleton.
|
||||
* <p>
|
||||
* The key idea in this pattern is to make the class itself responsible for controlling its instantiation (only once).
|
||||
* The hidden constructor (declared private) ensures that the class can never be instantiated from outside the class.
|
||||
* The public static operation can be accessed easily by using the class name and function name(Singleton.getInstance())
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Singleton_pattern">Singleton Pattern</a>
|
||||
*/
|
||||
public class Singleton {
|
||||
private volatile static Singleton instance = null;
|
||||
|
||||
private Singleton() {
|
||||
}
|
||||
|
||||
/**
|
||||
* A singleton implementation may use lazy initialization, where the instance is created when the static method
|
||||
* is first invoked.
|
||||
* <p>
|
||||
* If the static method might be called from multiple threads simultaneously, measures may need
|
||||
* to be taken to prevent race conditions that could result in the creation of multiple instances of the class.
|
||||
* <p>
|
||||
* The following implementation is a thread-safe sample implementation, using lazy initialization with
|
||||
* double-checked locking.
|
||||
*
|
||||
* @return the single instance of the Singleton class
|
||||
*/
|
||||
public static Singleton getInstance() {
|
||||
if (instance == null) {
|
||||
// First attempt to make thread safe
|
||||
synchronized (Singleton.class) {
|
||||
// Double Checked locking as multiple threads can reach the above step
|
||||
if (instance == null) {
|
||||
instance = new Singleton();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.designpatterns.structural.adapter;
|
||||
|
||||
public class BugattiVeyron implements Movable {
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return 268;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.designpatterns.structural.adapter;
|
||||
|
||||
public interface Movable {
|
||||
// Returns the speed of the movable in MPH
|
||||
double getSpeed();
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.designpatterns.structural.adapter;
|
||||
|
||||
/**
|
||||
* An Adapter pattern acts as a connector between two incompatible interfaces that otherwise cannot be connected
|
||||
* directly. An Adapter wraps an existing class with a new interface so that it becomes compatible with the client's
|
||||
* interface.
|
||||
* <br>
|
||||
* The main motive behind using this pattern is to convert an existing interface into another interface that the client
|
||||
* expects. It's usually implemented once the application is designed.
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Adapter_pattern">Adapter Pattern</a>
|
||||
*/
|
||||
public interface MovableAdapter {
|
||||
// Returns the speed of the movable in KPH
|
||||
double getSpeed();
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.designpatterns.structural.adapter;
|
||||
|
||||
public class MovableAdapterImpl implements MovableAdapter {
|
||||
private Movable luxuryCars;
|
||||
|
||||
public MovableAdapterImpl(Movable luxuryCars) {
|
||||
this.luxuryCars = luxuryCars;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return convertMPHtoKMPH(luxuryCars.getSpeed());
|
||||
}
|
||||
|
||||
private double convertMPHtoKMPH(double mph) {
|
||||
return mph * 1.60934;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.designpatterns.structural.decorator;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* this is one of the concrete decorators
|
||||
*/
|
||||
public class CompressingDecorator extends SenderDecorator {
|
||||
|
||||
public CompressingDecorator(Sender sender) {
|
||||
super(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String send(String content) {
|
||||
byte[] compressedBytes = compressContent(content);
|
||||
String compressedContent = new String(compressedBytes);
|
||||
super.send(compressedContent);
|
||||
return compressedContent;
|
||||
}
|
||||
|
||||
private byte[] compressContent(String content) {
|
||||
try (ByteArrayOutputStream baostream = new ByteArrayOutputStream();
|
||||
OutputStream outStream = new GZIPOutputStream(baostream)){
|
||||
outStream.write(content.getBytes());
|
||||
outStream.close();
|
||||
return baostream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("exception happened while compressing email content");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.designpatterns.structural.decorator;
|
||||
|
||||
/**
|
||||
* this is the class which should be decorated without any modification
|
||||
*/
|
||||
public class EmailSender implements Sender {
|
||||
@Override
|
||||
public String send(String content) {
|
||||
System.out.println("sending \"" + content + "\" as email");
|
||||
return content;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.designpatterns.structural.decorator;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* this is another concrete decorator.
|
||||
*/
|
||||
public class EncodingDecorator extends SenderDecorator {
|
||||
|
||||
public EncodingDecorator(Sender sender) {
|
||||
super(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String send(String content) {
|
||||
String encodedContent = encodeContent(content);
|
||||
super.send(encodedContent);
|
||||
return encodedContent;
|
||||
}
|
||||
|
||||
private String encodeContent(String content){
|
||||
return Base64.getEncoder().encodeToString(content.getBytes());
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.designpatterns.structural.decorator;
|
||||
|
||||
public interface Sender {
|
||||
String send(String content);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.designpatterns.structural.decorator;
|
||||
|
||||
/**
|
||||
* this is the base decorator.
|
||||
*/
|
||||
public class SenderDecorator implements Sender {
|
||||
private Sender sender;
|
||||
|
||||
public SenderDecorator(Sender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String send(String content) {
|
||||
return this.sender.send(content);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.designpatterns.structural.proxy.president;
|
||||
|
||||
import com.designpatterns.creational.singleton.Singleton;
|
||||
|
||||
/**
|
||||
* This is a class which is gonna be proxied by PresidentSecretary.
|
||||
* Whenever any citizen decides to contact the President, they have to talk to the Secretary.
|
||||
*/
|
||||
public class President {
|
||||
|
||||
private volatile static President instance = null;
|
||||
|
||||
private President() {}
|
||||
|
||||
static President getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (Singleton.class) {
|
||||
if (instance == null) {
|
||||
instance = new President();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void talkToThePresident(String message){
|
||||
System.out.println("President: I have received the message:" + message);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.designpatterns.structural.proxy.president;
|
||||
|
||||
public class PresidentSecretary {
|
||||
|
||||
private President president;
|
||||
|
||||
public PresidentSecretary() {
|
||||
this.president = President.getInstance();
|
||||
}
|
||||
|
||||
public void leaveValidMessageForPresident(String message){
|
||||
|
||||
if(!isMessageValid(message))
|
||||
throw new RuntimeException("invalid message");
|
||||
|
||||
System.out.println("Secretary: message is being sent to the President...");
|
||||
president.talkToThePresident(message);
|
||||
System.out.println("Secretary: message is sent to the President.");
|
||||
|
||||
}
|
||||
|
||||
private boolean isMessageValid(String message) {
|
||||
return message != null && !message.isEmpty() && message.length() >= 10 && message.length() <= 100;
|
||||
}
|
||||
}
|
137
src/main/java/com/generation/SimplexNoise.java
Normal file
137
src/main/java/com/generation/SimplexNoise.java
Normal file
@ -0,0 +1,137 @@
|
||||
package com.generation;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Implementation of the simplex noise algorithm.
|
||||
*/
|
||||
public class SimplexNoise {
|
||||
|
||||
private SimplexNoiseOctave[] octaves;
|
||||
private double[] frequencys;
|
||||
private double[] amplitudes;
|
||||
private int largestFeature;
|
||||
private double persistance;
|
||||
private long seed;
|
||||
|
||||
/**
|
||||
* @param largestFeature the diameter of the largest possible "cloud".
|
||||
* @param persistence the persistence. a low persistence causes smoother transition between the features while a high one makes the transition hard. (range = {@code 0.0F} - {@code 1.0F})
|
||||
* @param seed the seed this algorithm will use to generate pseudo random numbers. The generation will always look the same if the seed and the other parameters have the same value as in a previous generation
|
||||
*/
|
||||
public SimplexNoise(int largestFeature, double persistence, long seed) {
|
||||
|
||||
this.largestFeature = largestFeature;
|
||||
this.persistance = persistence;
|
||||
this.seed = seed;
|
||||
|
||||
int octaveCount = (int) Math.ceil(Math.log10(largestFeature) / Math.log10(2.0D));
|
||||
this.octaves = new SimplexNoiseOctave[octaveCount];
|
||||
this.frequencys = new double[octaveCount];
|
||||
this.amplitudes = new double[octaveCount];
|
||||
|
||||
Random random = new Random(seed);
|
||||
|
||||
for (int index = 0; index < octaveCount; index++) {
|
||||
|
||||
this.octaves[index] = new SimplexNoiseOctave(random.nextInt());
|
||||
this.frequencys[index] = Math.pow(2, index);
|
||||
this.amplitudes[index] = Math.pow(persistence, (double) octaveCount - index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a height map.
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param width width
|
||||
* @param height height
|
||||
* @return the generated height map
|
||||
*/
|
||||
public float[][] generateHeightMap(int x, int y, int width, int height) {
|
||||
|
||||
int xEnd = x + width;
|
||||
int yEnd = y + height;
|
||||
|
||||
float[][] result = new float[width][height];
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
|
||||
for (int j = 0; j < height; j++) {
|
||||
|
||||
int posX = x + i * ((xEnd - x) / width);
|
||||
int posY = y + j * ((yEnd - y) / height);
|
||||
result[i][j] = Math.min(1.0F, Math.max(0.0F, (float) (0.5D * (1 + this.getNoise(posX, posY)))));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a two dimensional noise.
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @return the generated noise
|
||||
*/
|
||||
public double getNoise(int x, int y) {
|
||||
|
||||
double result = 0;
|
||||
|
||||
for (int index = 0; index < this.octaves.length; index++) {
|
||||
|
||||
result += this.octaves[index].noise(x / this.frequencys[index], y / this.frequencys[index]) * this.amplitudes[index];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a three dimensional noise.
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param z Z coordinate
|
||||
* @return the generated noise
|
||||
*/
|
||||
public double getNoise(int x, int y, int z) {
|
||||
|
||||
double result = 0;
|
||||
|
||||
for (int index = 0; index < this.octaves.length; index++) {
|
||||
|
||||
double frequency = Math.pow(2, index);
|
||||
double amplitude = Math.pow(this.persistance, (double) this.octaves.length - index);
|
||||
|
||||
result += this.octaves[index].noise(x / frequency, y / frequency, z / frequency) * amplitude;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the largest possible feature
|
||||
*/
|
||||
public int getLargestFeature() {
|
||||
|
||||
return this.largestFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the persistence
|
||||
*/
|
||||
public double getPersistance() {
|
||||
|
||||
return this.persistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the seed
|
||||
*/
|
||||
public long getSeed() {
|
||||
|
||||
return this.seed;
|
||||
}
|
||||
}
|
395
src/main/java/com/generation/SimplexNoiseOctave.java
Normal file
395
src/main/java/com/generation/SimplexNoiseOctave.java
Normal file
@ -0,0 +1,395 @@
|
||||
package com.generation;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Implementation of a simplex noise octave.
|
||||
*/
|
||||
public class SimplexNoiseOctave {
|
||||
|
||||
private static final Gradient[] GRADIENTS = {
|
||||
|
||||
new Gradient(1, 1, 0), new Gradient(-1, 1, 0), new Gradient(1, -1, 0),
|
||||
new Gradient(-1, -1, 0), new Gradient(1, 0, 1), new Gradient(-1, 0, 1),
|
||||
new Gradient(1, 0, -1), new Gradient(-1, 0, -1), new Gradient(0, 1, 1),
|
||||
new Gradient(0, -1, 1), new Gradient(0, 1, -1), new Gradient(0, -1, -1)
|
||||
};
|
||||
private static final short[] P_SUPPLY = {
|
||||
|
||||
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225,
|
||||
140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148,
|
||||
247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32,
|
||||
57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175,
|
||||
74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122,
|
||||
60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54,
|
||||
65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169,
|
||||
200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64,
|
||||
52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212,
|
||||
207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213,
|
||||
119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
|
||||
129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104,
|
||||
218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241,
|
||||
81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157,
|
||||
184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93,
|
||||
222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180
|
||||
};
|
||||
private static final int LENGTH = P_SUPPLY.length * 2;
|
||||
private static final int SWAP_COUNT = 20;
|
||||
private static final double F2 = 0.5D * (Math.sqrt(3.0D) - 1.0D);
|
||||
private static final double G2 = (3.0D - Math.sqrt(3.0D)) / 6.0D;
|
||||
private static final double F3 = 1.0D / 3.0D;
|
||||
private static final double G3 = 1.0D / 6.0D;
|
||||
|
||||
private final short[] p = P_SUPPLY.clone();
|
||||
private final short[] perm = new short[LENGTH];
|
||||
private final short[] permMod12 = new short[LENGTH];
|
||||
|
||||
/**
|
||||
* @param seed the seed that this octave uses to generate pseudo random numbers
|
||||
*/
|
||||
public SimplexNoiseOctave(long seed) {
|
||||
|
||||
Random random = new Random(seed);
|
||||
|
||||
for (int index = 0; index < SWAP_COUNT; index++) {
|
||||
|
||||
int swapFrom = random.nextInt(this.p.length);
|
||||
int swapTo = random.nextInt(this.p.length);
|
||||
|
||||
short temp = this.p[swapFrom];
|
||||
this.p[swapFrom] = this.p[swapTo];
|
||||
this.p[swapTo] = temp;
|
||||
}
|
||||
|
||||
for (int index = 0; index < LENGTH; index++) {
|
||||
|
||||
this.perm[index] = this.p[index & 255];
|
||||
this.permMod12[index] = (short) (this.perm[index] % 12);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A method with the functionality of {@link Math#floor(double)} but it is faster.
|
||||
*
|
||||
* @param x the value
|
||||
* @return the result
|
||||
* @see Math#floor(double)
|
||||
*/
|
||||
private static final int fastfloor(double x) {
|
||||
|
||||
int xAsInt = (int) x;
|
||||
return x < xAsInt ? xAsInt - 1 : xAsInt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dot function for a gradient.
|
||||
*
|
||||
* @param gradient the gradient
|
||||
* @param x X
|
||||
* @param y Y
|
||||
* @return the dot value
|
||||
*/
|
||||
private static final double dot(Gradient gradient, double x, double y) {
|
||||
|
||||
return gradient.x * x + gradient.y * y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dot function for a gradient.
|
||||
*
|
||||
* @param gradient the gradient
|
||||
* @param x X
|
||||
* @param y Y
|
||||
* @param z Z
|
||||
* @return the dot value
|
||||
*/
|
||||
private static final double dot(Gradient gradient, double x, double y, double z) {
|
||||
|
||||
return gradient.x * x + gradient.y * y + gradient.z * z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a two dimensional noise.
|
||||
*
|
||||
* @param x X
|
||||
* @param y Y
|
||||
* @return the noise
|
||||
*/
|
||||
public double noise(double x, double y) {
|
||||
|
||||
double n0;
|
||||
double n1;
|
||||
double n2;
|
||||
|
||||
double s = (x + y) * F2;
|
||||
|
||||
int i = fastfloor(x + s);
|
||||
int j = fastfloor(y + s);
|
||||
|
||||
double t = (i + j) * G2;
|
||||
|
||||
double X0 = i - t;
|
||||
double Y0 = j - t;
|
||||
|
||||
double x0 = x - X0;
|
||||
double y0 = y - Y0;
|
||||
|
||||
int i1;
|
||||
int j1;
|
||||
|
||||
if (x0 > y0) {
|
||||
|
||||
i1 = 1;
|
||||
j1 = 0;
|
||||
|
||||
} else {
|
||||
|
||||
i1 = 0;
|
||||
j1 = 1;
|
||||
}
|
||||
|
||||
double x1 = x0 - i1 + G2;
|
||||
double y1 = y0 - j1 + G2;
|
||||
double x2 = x0 - 1.0D + 2.0D * G2;
|
||||
double y2 = y0 - 1.0D + 2.0D * G2;
|
||||
|
||||
int ii = i & 0xFF;
|
||||
int jj = j & 0xFF;
|
||||
|
||||
int gi0 = this.permMod12[ii + this.perm[jj]];
|
||||
int gi1 = this.permMod12[ii + i1 + this.perm[jj + j1]];
|
||||
int gi2 = this.permMod12[ii + 1 + this.perm[jj + 1]];
|
||||
|
||||
double t0 = 0.5D - x0 * x0 - y0 * y0;
|
||||
|
||||
if (t0 < 0) {
|
||||
|
||||
n0 = 0.0;
|
||||
|
||||
} else {
|
||||
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * dot(GRADIENTS[gi0], x0, y0);
|
||||
}
|
||||
|
||||
double t1 = 0.5D - x1 * x1 - y1 * y1;
|
||||
|
||||
if (t1 < 0.0D) {
|
||||
|
||||
n1 = 0.0;
|
||||
|
||||
} else {
|
||||
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * dot(GRADIENTS[gi1], x1, y1);
|
||||
}
|
||||
|
||||
double t2 = 0.5D - x2 * x2 - y2 * y2;
|
||||
|
||||
if (t2 < 0.0D) {
|
||||
|
||||
n2 = 0.0D;
|
||||
|
||||
} else {
|
||||
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * dot(GRADIENTS[gi2], x2, y2);
|
||||
}
|
||||
|
||||
return 70.0D * (n0 + n1 + n2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a three dimensional noise.
|
||||
*
|
||||
* @param x X
|
||||
* @param y Y
|
||||
* @param z Z
|
||||
* @return the noise
|
||||
*/
|
||||
public double noise(double x, double y, double z) {
|
||||
|
||||
double n0;
|
||||
double n1;
|
||||
double n2;
|
||||
double n3;
|
||||
|
||||
double s = (x + y + z) * F3;
|
||||
|
||||
int i = fastfloor(x + s);
|
||||
int j = fastfloor(y + s);
|
||||
int k = fastfloor(z + s);
|
||||
|
||||
double t = (i + j + k) * G3;
|
||||
|
||||
double X0 = i - t;
|
||||
double Y0 = j - t;
|
||||
double Z0 = k - t;
|
||||
|
||||
double x0 = x - X0;
|
||||
double y0 = y - Y0;
|
||||
double z0 = z - Z0;
|
||||
|
||||
int i1;
|
||||
int j1;
|
||||
int k1;
|
||||
int i2;
|
||||
int j2;
|
||||
int k2;
|
||||
|
||||
if (x0 >= y0) {
|
||||
|
||||
if (y0 >= z0) {
|
||||
|
||||
i1 = 1;
|
||||
j1 = 0;
|
||||
k1 = 0;
|
||||
i2 = 1;
|
||||
j2 = 1;
|
||||
k2 = 0;
|
||||
|
||||
} else if (x0 >= z0) {
|
||||
|
||||
i1 = 1;
|
||||
j1 = 0;
|
||||
k1 = 0;
|
||||
i2 = 1;
|
||||
j2 = 0;
|
||||
k2 = 1;
|
||||
|
||||
} else {
|
||||
|
||||
i1 = 0;
|
||||
j1 = 0;
|
||||
k1 = 1;
|
||||
i2 = 1;
|
||||
j2 = 0;
|
||||
k2 = 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (y0 < z0) {
|
||||
|
||||
i1 = 0;
|
||||
j1 = 0;
|
||||
k1 = 1;
|
||||
i2 = 0;
|
||||
j2 = 1;
|
||||
k2 = 1;
|
||||
|
||||
} else if (x0 < z0) {
|
||||
|
||||
i1 = 0;
|
||||
j1 = 1;
|
||||
k1 = 0;
|
||||
i2 = 0;
|
||||
j2 = 1;
|
||||
k2 = 1;
|
||||
|
||||
} else {
|
||||
|
||||
i1 = 0;
|
||||
j1 = 1;
|
||||
k1 = 0;
|
||||
i2 = 1;
|
||||
j2 = 1;
|
||||
k2 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
double x1 = x0 - i1 + G3;
|
||||
double y1 = y0 - j1 + G3;
|
||||
double z1 = z0 - k1 + G3;
|
||||
|
||||
double x2 = x0 - i2 + 2.0D * G3;
|
||||
double y2 = y0 - j2 + 2.0D * G3;
|
||||
double z2 = z0 - k2 + 2.0D * G3;
|
||||
|
||||
double x3 = x0 - 1.0D + 3.0D * G3;
|
||||
double y3 = y0 - 1.0D + 3.0D * G3;
|
||||
double z3 = z0 - 1.0D + 3.0D * G3;
|
||||
|
||||
int ii = i & 0xFF;
|
||||
int jj = j & 0xFF;
|
||||
int kk = k & 0xFF;
|
||||
|
||||
int gi0 = this.permMod12[ii + this.perm[jj + this.perm[kk]]];
|
||||
int gi1 = this.permMod12[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]];
|
||||
int gi2 = this.permMod12[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]];
|
||||
int gi3 = this.permMod12[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]];
|
||||
|
||||
double t0 = 0.6D - x0 * x0 - y0 * y0 - z0 * z0;
|
||||
|
||||
if (t0 < 0) {
|
||||
|
||||
n0 = 0.0D;
|
||||
|
||||
} else {
|
||||
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * dot(GRADIENTS[gi0], x0, y0, z0);
|
||||
}
|
||||
|
||||
double t1 = 0.6D - x1 * x1 - y1 * y1 - z1 * z1;
|
||||
|
||||
if (t1 < 0) {
|
||||
|
||||
n1 = 0.0D;
|
||||
|
||||
} else {
|
||||
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * dot(GRADIENTS[gi1], x1, y1, z1);
|
||||
}
|
||||
|
||||
double t2 = 0.6D - x2 * x2 - y2 * y2 - z2 * z2;
|
||||
|
||||
if (t2 < 0) {
|
||||
|
||||
n2 = 0.0D;
|
||||
|
||||
} else {
|
||||
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * dot(GRADIENTS[gi2], x2, y2, z2);
|
||||
}
|
||||
|
||||
double t3 = 0.6D - x3 * x3 - y3 * y3 - z3 * z3;
|
||||
|
||||
if (t3 < 0) {
|
||||
|
||||
n3 = 0.0D;
|
||||
|
||||
} else {
|
||||
|
||||
t3 *= t3;
|
||||
n3 = t3 * t3 * dot(GRADIENTS[gi3], x3, y3, z3);
|
||||
}
|
||||
|
||||
return 32.0D * (n0 + n1 + n2 + n3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a gradient.
|
||||
* Inner classes are faster than arrays.
|
||||
*/
|
||||
private static final class Gradient {
|
||||
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
/**
|
||||
* @param x X
|
||||
* @param y Y
|
||||
* @param z Z
|
||||
*/
|
||||
private Gradient(double x, double y, double z) {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
103
src/main/java/com/matchings/stablematching/GaleShapley.java
Normal file
103
src/main/java/com/matchings/stablematching/GaleShapley.java
Normal file
@ -0,0 +1,103 @@
|
||||
package com.matchings.stablematching;
|
||||
|
||||
public class GaleShapley {
|
||||
|
||||
/**
|
||||
* Return a stable matching between men and women according to their preferences,
|
||||
* following the Gale-Shapley algorithm.
|
||||
*
|
||||
* @param menPrefs for each man, for each preference rank, the corresponding woman
|
||||
* @param womenPrefs for each woman, for each preference rank, the corresponding man
|
||||
* @return for each man, the associated woman (1-dimensional array)
|
||||
*/
|
||||
|
||||
public int[] GaleShapleyStableMarriage(int[][] menPrefs, int[][] womenPrefs) {
|
||||
assert menPrefs.length == womenPrefs.length; // there are n individuals in each group
|
||||
|
||||
int n = menPrefs.length;
|
||||
if (n == 0)
|
||||
return new int[0]; // handle empty initial conditions right away
|
||||
|
||||
// Some implementation details: men, women and preference ranks are all labeled
|
||||
// from 0 to n-1.
|
||||
|
||||
// menMatching: for each man, the woman to whom he is engaged (or -1 if not engaged):
|
||||
int[] menMatching = new int[n];
|
||||
// the same for women:
|
||||
int[] womenMatching = new int[n];
|
||||
|
||||
// asked: for each man, highest rank asked (between 0 and n-1;
|
||||
// -1 if hasn't asked anyone yet)
|
||||
int[] asked = new int[n];
|
||||
|
||||
// Initialize all values of menMatching and womenMatching to -1,
|
||||
// otherwise woman 0 will be considered engaged to all men and idem for man 0.
|
||||
// Do the same for asked, otherwise each man will be considered as having
|
||||
// already asked his first choice.
|
||||
for (int i = 0; i < n; i++) {
|
||||
menMatching[i] = -1;
|
||||
womenMatching[i] = -1;
|
||||
asked[i] = -1;
|
||||
}
|
||||
|
||||
// to quickly retrieve the rank of men for a given woman, we create womenRanks.
|
||||
// For each woman, the array is:
|
||||
// index: man; value: rank
|
||||
// whereas in womenPrefs it was index: rank; value: man
|
||||
// Retrieving a rank will be done be simply looking up womenRanks[woman][man]
|
||||
int[][] womenRanks = new int[n][n];
|
||||
int man;
|
||||
for (int w = 0; w < n; w++) {
|
||||
for (int rank = 0; rank < n; rank++) {
|
||||
man = womenPrefs[w][rank];
|
||||
womenRanks[w][man] = rank;
|
||||
}
|
||||
}
|
||||
|
||||
int unengaged = 0; // at first all men are unengaged, we take the first one
|
||||
int notAsked; // first rank not asked by unengaged
|
||||
int prefWoman; // for the considered man, preferred woman among not asked ones
|
||||
int currentManPartner; // for the considered woman, current partner (-1 if none)
|
||||
while (unengaged != -1) { // while there is an unengaged man
|
||||
// unengaged is our proposing man.
|
||||
notAsked = asked[unengaged] + 1;
|
||||
prefWoman = menPrefs[unengaged][notAsked];
|
||||
currentManPartner = womenMatching[prefWoman];
|
||||
// now unengaged asks prefWoman for engagement.
|
||||
asked[unengaged] += 1;
|
||||
if (currentManPartner == -1) { // prefWoman is not engaged: the two engage
|
||||
menMatching[unengaged] = prefWoman;
|
||||
womenMatching[prefWoman] = unengaged;
|
||||
unengaged = getUnengaged(menMatching); // we need a new unengaged
|
||||
} else { // prefWoman is engaged to currentManPartner (therefore >= 0)
|
||||
if (womenRanks[prefWoman][unengaged] < womenRanks[prefWoman][currentManPartner]) {
|
||||
// prefWoman prefers unengaged: split prefWoman and currentManPartner
|
||||
menMatching[currentManPartner] = -1;
|
||||
// and engage prefWoman and unengaged
|
||||
menMatching[unengaged] = prefWoman;
|
||||
womenMatching[prefWoman] = unengaged;
|
||||
unengaged = getUnengaged(menMatching); // we need a new unengaged
|
||||
}
|
||||
// If prefWoman prefers currentManPartner over unengaged, nothing happens
|
||||
// (except that asked[unengaged] has been incremented so unengaged won't ask
|
||||
// prefWoman for engagement anymore).
|
||||
}
|
||||
}
|
||||
return menMatching;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a currently unengaged man, if there is one
|
||||
*
|
||||
* @param menMatching the current men matching array (being constructed)
|
||||
* @return the first man that is not engaged, or -1 if all men are engaged
|
||||
*/
|
||||
|
||||
public int getUnengaged(int[] menMatching) {
|
||||
for (int m = 0; m < menMatching.length; m++) {
|
||||
if (menMatching[m] == -1)
|
||||
return m;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
58
src/main/java/com/maths/CircularConvolutionFFT.java
Normal file
58
src/main/java/com/maths/CircularConvolutionFFT.java
Normal file
@ -0,0 +1,58 @@
|
||||
package com.maths;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Class for circular convolution of two discrete signals using the convolution theorem.
|
||||
*
|
||||
* @author Ioannis Karavitsis
|
||||
* @version 1.0
|
||||
* */
|
||||
public class CircularConvolutionFFT
|
||||
{
|
||||
/**
|
||||
* This method pads the signal with zeros until it reaches the new size.
|
||||
*
|
||||
* @param x The signal to be padded.
|
||||
* @param newSize The new size of the signal.
|
||||
* */
|
||||
private static void padding(ArrayList<FFT.Complex> x, int newSize)
|
||||
{
|
||||
if(x.size() < newSize)
|
||||
{
|
||||
int diff = newSize - x.size();
|
||||
for(int i = 0; i < diff; i++)
|
||||
x.add(new FFT.Complex());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discrete circular convolution function. It uses the convolution theorem for discrete signals: convolved = IDFT(DFT(a)*DFT(b)).
|
||||
* Then we use the FFT algorithm for faster calculations of the two DFTs and the final IDFT.
|
||||
*
|
||||
* More info:
|
||||
* https://en.wikipedia.org/wiki/Convolution_theorem
|
||||
*
|
||||
* @param a The first signal.
|
||||
* @param b The other signal.
|
||||
* @return The convolved signal.
|
||||
* */
|
||||
public static ArrayList<FFT.Complex> fftCircularConvolution(ArrayList<FFT.Complex> a, ArrayList<FFT.Complex> b)
|
||||
{
|
||||
int convolvedSize = Math.max(a.size(), b.size()); //The two signals must have the same size equal to the bigger one
|
||||
padding(a, convolvedSize); //Zero padding the smaller signal
|
||||
padding(b, convolvedSize);
|
||||
|
||||
/* Find the FFTs of both signal. Here we use the Bluestein algorithm because we want the FFT to have the same length with the signal and not bigger */
|
||||
FFTBluestein.fftBluestein(a, false);
|
||||
FFTBluestein.fftBluestein(b, false);
|
||||
ArrayList<FFT.Complex> convolved = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < a.size(); i++)
|
||||
convolved.add(a.get(i).multiply(b.get(i))); //FFT(a)*FFT(b)
|
||||
|
||||
FFTBluestein.fftBluestein(convolved, true); //IFFT
|
||||
|
||||
return convolved;
|
||||
}
|
||||
}
|
47
src/main/java/com/maths/Convolution.java
Normal file
47
src/main/java/com/maths/Convolution.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.maths;
|
||||
|
||||
/**
|
||||
* Class for linear convolution of two discrete signals
|
||||
*
|
||||
* @author Ioannis Karavitsis
|
||||
* @version 1.0
|
||||
* */
|
||||
public class Convolution
|
||||
{
|
||||
/**
|
||||
* Discrete linear convolution function. Both input signals and the output signal must start from 0.
|
||||
* If you have a signal that has values before 0 then shift it to start from 0.
|
||||
*
|
||||
* @param A The first discrete signal
|
||||
* @param B The second discrete signal
|
||||
* @return The convolved signal
|
||||
* */
|
||||
public static double[] convolution(double[] A, double[] B)
|
||||
{
|
||||
double[] convolved = new double[A.length + B.length - 1];
|
||||
|
||||
/*
|
||||
The discrete convolution of two signals A and B is defined as:
|
||||
|
||||
A.length
|
||||
C[i] = Σ (A[k]*B[i-k])
|
||||
k=0
|
||||
|
||||
It's obvious that: 0 <= k <= A.length , 0 <= i <= A.length + B.length - 2 and 0 <= i-k <= B.length - 1
|
||||
From the last inequality we get that: i - B.length + 1 <= k <= i and thus we get the conditions below.
|
||||
*/
|
||||
for(int i = 0; i < convolved.length; i++)
|
||||
{
|
||||
convolved[i] = 0;
|
||||
int k = Math.max(i - B.length + 1, 0);
|
||||
|
||||
while(k < i + 1 && k < A.length)
|
||||
{
|
||||
convolved[i] += A[k] * B[i - k];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
return convolved;
|
||||
}
|
||||
}
|
61
src/main/java/com/maths/ConvolutionFFT.java
Normal file
61
src/main/java/com/maths/ConvolutionFFT.java
Normal file
@ -0,0 +1,61 @@
|
||||
package com.maths;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Class for linear convolution of two discrete signals using the convolution theorem.
|
||||
*
|
||||
* @author Ioannis Karavitsis
|
||||
* @version 1.0
|
||||
* */
|
||||
public class ConvolutionFFT
|
||||
{
|
||||
/**
|
||||
* This method pads the signal with zeros until it reaches the new size.
|
||||
*
|
||||
* @param x The signal to be padded.
|
||||
* @param newSize The new size of the signal.
|
||||
* */
|
||||
private static void padding(ArrayList<FFT.Complex> x, int newSize)
|
||||
{
|
||||
if(x.size() < newSize)
|
||||
{
|
||||
int diff = newSize - x.size();
|
||||
for(int i = 0; i < diff; i++)
|
||||
x.add(new FFT.Complex());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discrete linear convolution function. It uses the convolution theorem for discrete signals convolved: = IDFT(DFT(a)*DFT(b)).
|
||||
* This is true for circular convolution. In order to get the linear convolution of the two signals we first pad the two signals to have the same size equal to the convolved signal (a.size() + b.size() - 1).
|
||||
* Then we use the FFT algorithm for faster calculations of the two DFTs and the final IDFT.
|
||||
*
|
||||
* More info:
|
||||
* https://en.wikipedia.org/wiki/Convolution_theorem
|
||||
* https://ccrma.stanford.edu/~jos/ReviewFourier/FFT_Convolution.html
|
||||
*
|
||||
* @param a The first signal.
|
||||
* @param b The other signal.
|
||||
* @return The convolved signal.
|
||||
* */
|
||||
public static ArrayList<FFT.Complex> convolutionFFT(ArrayList<FFT.Complex> a, ArrayList<FFT.Complex> b)
|
||||
{
|
||||
int convolvedSize = a.size() + b.size() - 1; //The size of the convolved signal
|
||||
padding(a, convolvedSize); //Zero padding both signals
|
||||
padding(b, convolvedSize);
|
||||
|
||||
/* Find the FFTs of both signals (Note that the size of the FFTs will be bigger than the convolvedSize because of the extra zero padding in FFT algorithm) */
|
||||
FFT.fft(a, false);
|
||||
FFT.fft(b, false);
|
||||
ArrayList<FFT.Complex> convolved = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < a.size(); i++)
|
||||
convolved.add(a.get(i).multiply(b.get(i))); //FFT(a)*FFT(b)
|
||||
|
||||
FFT.fft(convolved, true); //IFFT
|
||||
convolved.subList(convolvedSize, convolved.size()).clear(); //Remove the remaining zeros after the convolvedSize. These extra zeros came from paddingPowerOfTwo() method inside the fft() method.
|
||||
|
||||
return convolved;
|
||||
}
|
||||
}
|
@ -1,36 +1,32 @@
|
||||
package com.thealgorithms.maths;
|
||||
package com.maths;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Class for calculating the Fast Fourier Transform (FFT) of a discrete signal
|
||||
* using the Cooley-Tukey algorithm.
|
||||
* Class for calculating the Fast Fourier Transform (FFT) of a discrete signal using the Cooley-Tukey algorithm.
|
||||
*
|
||||
* @author Ioannis Karavitsis
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class FFT {
|
||||
private FFT() {
|
||||
}
|
||||
|
||||
* */
|
||||
public class FFT
|
||||
{
|
||||
/**
|
||||
* This class represents a complex number and has methods for basic
|
||||
* operations.
|
||||
* This class represents a complex number and has methods for basic operations.
|
||||
*
|
||||
* <p>
|
||||
* More info:
|
||||
* https://introcs.cs.princeton.edu/java/32class/Complex.java.html
|
||||
*/
|
||||
static class Complex {
|
||||
|
||||
private double real;
|
||||
private double img;
|
||||
* */
|
||||
static class Complex
|
||||
{
|
||||
private double real, img;
|
||||
|
||||
/**
|
||||
* Default Constructor. Creates the complex number 0.
|
||||
*/
|
||||
Complex() {
|
||||
* Default Constructor.
|
||||
* Creates the complex number 0.
|
||||
* */
|
||||
public Complex()
|
||||
{
|
||||
real = 0;
|
||||
img = 0;
|
||||
}
|
||||
@ -40,8 +36,9 @@ public final class FFT {
|
||||
*
|
||||
* @param r The real part of the number.
|
||||
* @param i The imaginary part of the number.
|
||||
*/
|
||||
Complex(double r, double i) {
|
||||
* */
|
||||
public Complex(double r, double i)
|
||||
{
|
||||
real = r;
|
||||
img = i;
|
||||
}
|
||||
@ -50,8 +47,9 @@ public final class FFT {
|
||||
* Returns the real part of the complex number.
|
||||
*
|
||||
* @return The real part of the complex number.
|
||||
*/
|
||||
public double getReal() {
|
||||
* */
|
||||
public double getReal()
|
||||
{
|
||||
return real;
|
||||
}
|
||||
|
||||
@ -59,8 +57,9 @@ public final class FFT {
|
||||
* Returns the imaginary part of the complex number.
|
||||
*
|
||||
* @return The imaginary part of the complex number.
|
||||
*/
|
||||
public double getImaginary() {
|
||||
* */
|
||||
public double getImaginary()
|
||||
{
|
||||
return img;
|
||||
}
|
||||
|
||||
@ -69,8 +68,9 @@ public final class FFT {
|
||||
*
|
||||
* @param z The number to be added.
|
||||
* @return The sum.
|
||||
*/
|
||||
public Complex add(Complex z) {
|
||||
* */
|
||||
public Complex add(Complex z)
|
||||
{
|
||||
Complex temp = new Complex();
|
||||
temp.real = this.real + z.real;
|
||||
temp.img = this.img + z.img;
|
||||
@ -82,8 +82,9 @@ public final class FFT {
|
||||
*
|
||||
* @param z The number to be subtracted.
|
||||
* @return The difference.
|
||||
*/
|
||||
public Complex subtract(Complex z) {
|
||||
* */
|
||||
public Complex subtract(Complex z)
|
||||
{
|
||||
Complex temp = new Complex();
|
||||
temp.real = this.real - z.real;
|
||||
temp.img = this.img - z.img;
|
||||
@ -95,11 +96,12 @@ public final class FFT {
|
||||
*
|
||||
* @param z The number to be multiplied.
|
||||
* @return The product.
|
||||
*/
|
||||
public Complex multiply(Complex z) {
|
||||
* */
|
||||
public Complex multiply(Complex z)
|
||||
{
|
||||
Complex temp = new Complex();
|
||||
temp.real = this.real * z.real - this.img * z.img;
|
||||
temp.img = this.real * z.img + this.img * z.real;
|
||||
temp.real = this.real*z.real - this.img*z.img;
|
||||
temp.img = this.real*z.img + this.img*z.real;
|
||||
return temp;
|
||||
}
|
||||
|
||||
@ -108,8 +110,9 @@ public final class FFT {
|
||||
*
|
||||
* @param n The real number to be multiplied.
|
||||
* @return The product.
|
||||
*/
|
||||
public Complex multiply(double n) {
|
||||
* */
|
||||
public Complex multiply(double n)
|
||||
{
|
||||
Complex temp = new Complex();
|
||||
temp.real = this.real * n;
|
||||
temp.img = this.img * n;
|
||||
@ -120,11 +123,12 @@ public final class FFT {
|
||||
* Finds the conjugate of this complex number.
|
||||
*
|
||||
* @return The conjugate.
|
||||
*/
|
||||
public Complex conjugate() {
|
||||
* */
|
||||
public Complex conjugate()
|
||||
{
|
||||
Complex temp = new Complex();
|
||||
temp.real = this.real;
|
||||
temp.img = -this.img;
|
||||
temp.img = -this.img;
|
||||
return temp;
|
||||
}
|
||||
|
||||
@ -132,8 +136,9 @@ public final class FFT {
|
||||
* Finds the magnitude of the complex number.
|
||||
*
|
||||
* @return The magnitude.
|
||||
*/
|
||||
public double abs() {
|
||||
* */
|
||||
public double abs()
|
||||
{
|
||||
return Math.hypot(this.real, this.img);
|
||||
}
|
||||
|
||||
@ -142,13 +147,12 @@ public final class FFT {
|
||||
*
|
||||
* @param z The divisor.
|
||||
* @return The quotient.
|
||||
*/
|
||||
public Complex divide(Complex z) {
|
||||
* */
|
||||
public Complex divide(Complex z)
|
||||
{
|
||||
Complex temp = new Complex();
|
||||
double d = z.abs() * z.abs();
|
||||
d = (double) Math.round(d * 1000000000d) / 1000000000d;
|
||||
temp.real = (this.real * z.real + this.img * z.img) / (d);
|
||||
temp.img = (this.img * z.real - this.real * z.img) / (d);
|
||||
temp.real = (this.real*z.real + this.img*z.img) / (z.abs()*z.abs());
|
||||
temp.img = (this.img*z.real - this.real*z.img) / (z.abs()*z.abs());
|
||||
return temp;
|
||||
}
|
||||
|
||||
@ -157,8 +161,9 @@ public final class FFT {
|
||||
*
|
||||
* @param n The divisor which is a real number.
|
||||
* @return The quotient.
|
||||
*/
|
||||
public Complex divide(double n) {
|
||||
* */
|
||||
public Complex divide(double n)
|
||||
{
|
||||
Complex temp = new Complex();
|
||||
temp.real = this.real / n;
|
||||
temp.img = this.img / n;
|
||||
@ -167,121 +172,110 @@ public final class FFT {
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterative In-Place Radix-2 Cooley-Tukey Fast Fourier Transform Algorithm
|
||||
* with Bit-Reversal. The size of the input signal must be a power of 2. If
|
||||
* it isn't then it is padded with zeros and the output FFT will be bigger
|
||||
* than the input signal.
|
||||
* Iterative In-Place Radix-2 Cooley-Tukey Fast Fourier Transform Algorithm with Bit-Reversal.
|
||||
* The size of the input signal must be a power of 2. If it isn't then it is padded with zeros and the output FFT will be bigger than the input signal.
|
||||
*
|
||||
* <p>
|
||||
* More info:
|
||||
* https://www.algorithm-archive.org/contents/cooley_tukey/cooley_tukey.html
|
||||
* https://www.geeksforgeeks.org/iterative-fast-fourier-transformation-polynomial-multiplication/
|
||||
* https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm
|
||||
* https://cp-algorithms.com/algebra/fft.html
|
||||
* @param x The discrete signal which is then converted to the FFT or the
|
||||
* IFFT of signal x.
|
||||
*
|
||||
* @param x The discrete signal which is then converted to the FFT or the IFFT of signal x.
|
||||
* @param inverse True if you want to find the inverse FFT.
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<Complex> fft(ArrayList<Complex> x, boolean inverse) {
|
||||
* */
|
||||
public static void fft(ArrayList<Complex> x, boolean inverse)
|
||||
{
|
||||
/* Pad the signal with zeros if necessary */
|
||||
paddingPowerOfTwo(x);
|
||||
int n = x.size();
|
||||
int log2n = findLog2(n);
|
||||
x = fftBitReversal(n, log2n, x);
|
||||
int N = x.size();
|
||||
|
||||
/* Find the log2(N) */
|
||||
int log2N = 0;
|
||||
while((1 << log2N) < N)
|
||||
log2N++;
|
||||
|
||||
/* Swap the values of the signal with bit-reversal method */
|
||||
int reverse;
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
reverse = reverseBits(i, log2N);
|
||||
if(i < reverse)
|
||||
Collections.swap(x, i, reverse);
|
||||
}
|
||||
|
||||
int direction = inverse ? -1 : 1;
|
||||
|
||||
/* Main loop of the algorithm */
|
||||
for (int len = 2; len <= n; len *= 2) {
|
||||
for(int len = 2; len <= N; len *= 2)
|
||||
{
|
||||
double angle = -2 * Math.PI / len * direction;
|
||||
Complex wlen = new Complex(Math.cos(angle), Math.sin(angle));
|
||||
for (int i = 0; i < n; i += len) {
|
||||
for(int i = 0; i < N; i += len)
|
||||
{
|
||||
Complex w = new Complex(1, 0);
|
||||
for (int j = 0; j < len / 2; j++) {
|
||||
for(int j = 0; j < len / 2; j++)
|
||||
{
|
||||
Complex u = x.get(i + j);
|
||||
Complex v = w.multiply(x.get(i + j + len / 2));
|
||||
Complex v = w.multiply(x.get(i + j + len/2));
|
||||
x.set(i + j, u.add(v));
|
||||
x.set(i + j + len / 2, u.subtract(v));
|
||||
x.set(i + j + len/2, u.subtract(v));
|
||||
w = w.multiply(wlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
x = inverseFFT(n, inverse, x);
|
||||
return x;
|
||||
}
|
||||
|
||||
/* Find the log2(n) */
|
||||
public static int findLog2(int n) {
|
||||
int log2n = 0;
|
||||
while ((1 << log2n) < n) {
|
||||
log2n++;
|
||||
}
|
||||
return log2n;
|
||||
}
|
||||
|
||||
/* Swap the values of the signal with bit-reversal method */
|
||||
public static ArrayList<Complex> fftBitReversal(int n, int log2n, ArrayList<Complex> x) {
|
||||
int reverse;
|
||||
for (int i = 0; i < n; i++) {
|
||||
reverse = reverseBits(i, log2n);
|
||||
if (i < reverse) {
|
||||
Collections.swap(x, i, reverse);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
/* Divide by n if we want the inverse FFT */
|
||||
public static ArrayList<Complex> inverseFFT(int n, boolean inverse, ArrayList<Complex> x) {
|
||||
if (inverse) {
|
||||
for (int i = 0; i < x.size(); i++) {
|
||||
/* Divide by N if we want the inverse FFT */
|
||||
if(inverse)
|
||||
{
|
||||
for (int i = 0; i < x.size(); i++)
|
||||
{
|
||||
Complex z = x.get(i);
|
||||
x.set(i, z.divide(n));
|
||||
x.set(i, z.divide(N));
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function reverses the bits of a number. It is used in Cooley-Tukey
|
||||
* FFT algorithm.
|
||||
* This function reverses the bits of a number.
|
||||
* It is used in Cooley-Tukey FFT algorithm.
|
||||
*
|
||||
* <p>
|
||||
* E.g. num = 13 = 00001101 in binary log2n = 8 Then reversed = 176 =
|
||||
* 10110000 in binary
|
||||
* E.g.
|
||||
* num = 13 = 00001101 in binary
|
||||
* log2N = 8
|
||||
* Then reversed = 176 = 10110000 in binary
|
||||
*
|
||||
* <p>
|
||||
* More info: https://cp-algorithms.com/algebra/fft.html
|
||||
* More info:
|
||||
* https://cp-algorithms.com/algebra/fft.html
|
||||
* https://www.geeksforgeeks.org/write-an-efficient-c-program-to-reverse-bits-of-a-number/
|
||||
*
|
||||
* @param num The integer you want to reverse its bits.
|
||||
* @param log2n The number of bits you want to reverse.
|
||||
* @param log2N The number of bits you want to reverse.
|
||||
* @return The reversed number
|
||||
*/
|
||||
private static int reverseBits(int num, int log2n) {
|
||||
* */
|
||||
private static int reverseBits(int num, int log2N)
|
||||
{
|
||||
int reversed = 0;
|
||||
for (int i = 0; i < log2n; i++) {
|
||||
if ((num & (1 << i)) != 0) {
|
||||
reversed |= 1 << (log2n - 1 - i);
|
||||
}
|
||||
for(int i = 0; i < log2N; i++)
|
||||
{
|
||||
if((num & (1 << i)) != 0)
|
||||
reversed |= 1 << (log2N - 1 - i);
|
||||
}
|
||||
return reversed;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method pads an ArrayList with zeros in order to have a size equal to
|
||||
* the next power of two of the previous size.
|
||||
* This method pads an ArrayList with zeros in order to have a size equal to the next power of two of the previous size.
|
||||
*
|
||||
* @param x The ArrayList to be padded.
|
||||
*/
|
||||
private static void paddingPowerOfTwo(ArrayList<Complex> x) {
|
||||
* */
|
||||
private static void paddingPowerOfTwo(ArrayList<Complex> x)
|
||||
{
|
||||
int n = 1;
|
||||
int oldSize = x.size();
|
||||
while (n < oldSize) {
|
||||
while(n < oldSize)
|
||||
n *= 2;
|
||||
}
|
||||
for (int i = 0; i < n - oldSize; i++) {
|
||||
for(int i = 0; i < n - oldSize; i++)
|
||||
x.add(new Complex());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +1,68 @@
|
||||
package com.thealgorithms.maths;
|
||||
package com.maths;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Class for calculating the Fast Fourier Transform (FFT) of a discrete signal
|
||||
* using the Bluestein's algorithm.
|
||||
* Class for calculating the Fast Fourier Transform (FFT) of a discrete signal using the Bluestein's algorithm.
|
||||
*
|
||||
* @author Ioannis Karavitsis
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class FFTBluestein {
|
||||
private FFTBluestein() {
|
||||
}
|
||||
|
||||
* */
|
||||
public class FFTBluestein
|
||||
{
|
||||
/**
|
||||
* Bluestein's FFT Algorithm.
|
||||
*
|
||||
* <p>
|
||||
* More info:
|
||||
* https://en.wikipedia.org/wiki/Chirp_Z-transform#Bluestein.27s_algorithm
|
||||
* http://tka4.org/materials/lib/Articles-Books/Numerical%20Algorithms/Hartley_Trasform/Bluestein%27s%20FFT%20algorithm%20-%20Wikipedia,%20the%20free%20encyclopedia.htm
|
||||
*
|
||||
* @param x The discrete signal which is then converted to the FFT or the
|
||||
* IFFT of signal x.
|
||||
* @param x The discrete signal which is then converted to the FFT or the IFFT of signal x.
|
||||
* @param inverse True if you want to find the inverse FFT.
|
||||
*/
|
||||
public static void fftBluestein(ArrayList<FFT.Complex> x, boolean inverse) {
|
||||
int n = x.size();
|
||||
int bnSize = 2 * n - 1;
|
||||
* */
|
||||
public static void fftBluestein(ArrayList<FFT.Complex> x, boolean inverse)
|
||||
{
|
||||
int N = x.size();
|
||||
int bnSize = 2*N - 1;
|
||||
int direction = inverse ? -1 : 1;
|
||||
ArrayList<FFT.Complex> an = new ArrayList<>();
|
||||
ArrayList<FFT.Complex> bn = new ArrayList<>();
|
||||
|
||||
/* Initialization of the b(n) sequence (see Wikipedia's article above for the symbols
|
||||
* used)*/
|
||||
for (int i = 0; i < bnSize; i++) {
|
||||
/* Initialization of the b(n) sequence (see Wikipedia's article above for the symbols used)*/
|
||||
for(int i = 0; i < bnSize; i++)
|
||||
bn.add(new FFT.Complex());
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
double angle = (i - n + 1) * (i - n + 1) * Math.PI / n * direction;
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
double angle = (i - N + 1) * (i - N + 1) * Math.PI / N * direction;
|
||||
bn.set(i, new FFT.Complex(Math.cos(angle), Math.sin(angle)));
|
||||
bn.set(bnSize - i - 1, new FFT.Complex(Math.cos(angle), Math.sin(angle)));
|
||||
}
|
||||
|
||||
/* Initialization of the a(n) sequence */
|
||||
for (int i = 0; i < n; i++) {
|
||||
double angle = -i * i * Math.PI / n * direction;
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
double angle = -i * i * Math.PI / N * direction;
|
||||
an.add(x.get(i).multiply(new FFT.Complex(Math.cos(angle), Math.sin(angle))));
|
||||
}
|
||||
|
||||
ArrayList<FFT.Complex> convolution = ConvolutionFFT.convolutionFFT(an, bn);
|
||||
|
||||
/* The final multiplication of the convolution with the b*(k) factor */
|
||||
for (int i = 0; i < n; i++) {
|
||||
double angle = -1 * i * i * Math.PI / n * direction;
|
||||
FFT.Complex bk = new FFT.Complex(Math.cos(angle), Math.sin(angle));
|
||||
x.set(i, bk.multiply(convolution.get(i + n - 1)));
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
double angle = -1 * i * i * Math.PI / N * direction;
|
||||
FFT.Complex bk = new FFT.Complex(Math.cos(angle), Math.sin(angle));
|
||||
x.set(i, bk.multiply(convolution.get(i + N - 1)));
|
||||
}
|
||||
|
||||
/* Divide by n if we want the inverse FFT */
|
||||
if (inverse) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
/* Divide by N if we want the inverse FFT */
|
||||
if(inverse)
|
||||
{
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
FFT.Complex z = x.get(i);
|
||||
x.set(i, z.divide(n));
|
||||
x.set(i, z.divide(N));
|
||||
}
|
||||
}
|
||||
}
|
34
src/main/java/com/others/Ackermann.java
Normal file
34
src/main/java/com/others/Ackermann.java
Normal file
@ -0,0 +1,34 @@
|
||||
package src.main.java.com.others;
|
||||
|
||||
|
||||
public class Ackermann {
|
||||
|
||||
|
||||
/**
|
||||
* Ackermann function - simplest and earliest-discovered examples of a total computable function
|
||||
* that is not primitive recursive.
|
||||
*
|
||||
* Defined only for NONNEGATIVE integers !!!
|
||||
*
|
||||
* Time complexity is super-exponential. O(n(^))
|
||||
* Any input m higher tahn (3,3) will result in StackOverflow
|
||||
* @param m
|
||||
* @param n
|
||||
* @return
|
||||
*
|
||||
*
|
||||
*/
|
||||
public long Ack(long m, long n) {
|
||||
|
||||
if (m == 0)
|
||||
return n + 1;
|
||||
|
||||
if (n == 0)
|
||||
return Ack(m - 1, 1);
|
||||
|
||||
return Ack(m - 1, Ack(m, n - 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
36
src/main/java/com/others/FastPower.java
Normal file
36
src/main/java/com/others/FastPower.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.others;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* We may calculate power with loops, but what if the index is too large ?
|
||||
* FastPower aims to calculate quickly in this circumstances with time complexity O(log k),
|
||||
* where k is the index.
|
||||
*
|
||||
*/
|
||||
public class FastPower {
|
||||
public static BigInteger calculate(BigInteger n, BigInteger k, BigInteger mod) {
|
||||
BigInteger ans = BigInteger.ONE;
|
||||
while (!k.equals(BigInteger.ZERO)) {
|
||||
int odd = k.mod(BigInteger.valueOf(2)).compareTo(BigInteger.ZERO);
|
||||
if (odd > 0) {
|
||||
ans = ans.multiply(n).mod(mod);
|
||||
}
|
||||
k = k.divide(BigInteger.valueOf(2));
|
||||
n = n.multiply(n).mod(mod);
|
||||
}
|
||||
return ans.mod(mod);
|
||||
}
|
||||
|
||||
public static long calculate(long n, long k, long mod) {
|
||||
long ans = 1;
|
||||
while (k != 0) {
|
||||
if (k % 2 == 1) {
|
||||
ans = (ans * n) % mod;
|
||||
}
|
||||
k >>= 1;
|
||||
n = (n * n) % mod;
|
||||
}
|
||||
return ans % mod;
|
||||
}
|
||||
}
|
141
src/main/java/com/others/RoundRobin.java
Normal file
141
src/main/java/com/others/RoundRobin.java
Normal file
@ -0,0 +1,141 @@
|
||||
package src.main.java.com.others;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* This class implements the Round Robin Algorithm which is an cpu scheduling algorithm.
|
||||
*
|
||||
* @author George Giannios
|
||||
*/
|
||||
public class RoundRobin {
|
||||
/**
|
||||
* This method calculates the waiting time for all processes
|
||||
*
|
||||
* @param burstTime an array with burst time for all processes
|
||||
* @param quantum the quantum quantity
|
||||
* @return an array with waiting time for all processes
|
||||
*/
|
||||
public int[] calcWaitingTime(int[] burstTime, int quantum) {
|
||||
int n = burstTime.length;
|
||||
//create a copy of burstTime table to executeTime table
|
||||
int[] executeTIme = new int[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
executeTIme[i] = burstTime[i];
|
||||
}
|
||||
|
||||
//initialize the waiting time table and set all waiting times equal to zero
|
||||
int[] waitingTime = new int[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
waitingTime[i] = 0;
|
||||
}
|
||||
|
||||
//initialize an array list to emulate the queue of ready processes
|
||||
ArrayList<Integer> readyQueue = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
readyQueue.add(i);
|
||||
}
|
||||
|
||||
//the total time that processes need to be finished
|
||||
int time = 0;
|
||||
int i = 0;
|
||||
//calculate waiting times while there are uncompleted processes
|
||||
while (!readyQueue.isEmpty()) {
|
||||
//check if a process has finished
|
||||
if (executeTIme[i] >= 0) {
|
||||
if (executeTIme[i] - quantum > 0) {
|
||||
//add time that have been passed
|
||||
time += quantum;
|
||||
//this is the remaining burst time for the process i
|
||||
executeTIme[i] -= quantum;
|
||||
|
||||
} else if (executeTIme[i] - quantum == 0) {
|
||||
//add time that have been passed
|
||||
time += quantum;
|
||||
//calculate the total waiting time
|
||||
waitingTime[i] = time - burstTime[i];
|
||||
|
||||
//mark the process as finished
|
||||
executeTIme[i] = -1;
|
||||
//remove the process that have finished by shrinking queue's length
|
||||
readyQueue.remove(readyQueue.size() - 1);
|
||||
|
||||
} else {
|
||||
//add time that have been passed
|
||||
time += executeTIme[i];
|
||||
//calculate the total waiting time
|
||||
waitingTime[i] = time - burstTime[i];
|
||||
|
||||
//mark the process as finished
|
||||
executeTIme[i] = -1;
|
||||
//remove the process that have finished by shrinking queue's length
|
||||
readyQueue.remove(readyQueue.size() - 1);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
if (i >= n) {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return waitingTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method calculates turn around time for all processes
|
||||
*
|
||||
* @param burstTime an array with burst time for all processes
|
||||
* @param waitingTime an array with waiting time for all processes
|
||||
* @return an array with turnaround time for all processes
|
||||
*/
|
||||
public int[] calcTurnAroundTime(int[] burstTime, int[] waitingTime) {
|
||||
int n = burstTime.length;
|
||||
//initialize the turnaround time table
|
||||
int[] turnAroundTime = new int[n];
|
||||
|
||||
//calculate turnaround time for each process (T.T= W.T + B.T)
|
||||
for (int i = 0; i < n; i++) {
|
||||
turnAroundTime[i] = waitingTime[i] + burstTime[i];
|
||||
}
|
||||
|
||||
//return the turnaround time table
|
||||
return turnAroundTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method prints the results and calculates the average waiting and turnaround times
|
||||
*
|
||||
* @param burstTime an array with burst time for all processes
|
||||
* @param quantum the quantum quantity
|
||||
*/
|
||||
void printAvgTimes(int[] burstTime, int quantum) {
|
||||
int n = burstTime.length;
|
||||
int totalWaitingTime = 0;
|
||||
int totalTurnAroundTime = 0;
|
||||
|
||||
// Find waiting time of all processes
|
||||
int[] waitingTime = calcWaitingTime(burstTime, quantum);
|
||||
|
||||
// Find turn around time for all processes
|
||||
int[] turnAroundTime = calcTurnAroundTime(burstTime, waitingTime);
|
||||
|
||||
// Display processes along with all details
|
||||
System.out.println("Process " + " Burst Time " +
|
||||
" Waiting Time " + " Turnaround Time");
|
||||
System.out.println("======= ========== ============ ===============");
|
||||
// Calculate total waiting time and total turn around time
|
||||
for (int i = 0; i < n; i++) {
|
||||
totalWaitingTime += waitingTime[i];
|
||||
totalTurnAroundTime += turnAroundTime[i];
|
||||
System.out.println(i + "\t\t " + burstTime[i] + "\t\t\t " +
|
||||
waitingTime[i] + "\t\t\t " + turnAroundTime[i]);
|
||||
}
|
||||
|
||||
System.out.println("\nAverage waiting time = " +
|
||||
(float) totalWaitingTime / (float) n);
|
||||
System.out.println("Average turnaround time = " +
|
||||
(float) totalTurnAroundTime / (float) n);
|
||||
}
|
||||
}
|
||||
|
49
src/main/java/com/search/BinarySearch.java
Normal file
49
src/main/java/com/search/BinarySearch.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.search;
|
||||
|
||||
/**
|
||||
* Binary search is an algorithm which finds the position of a target value within a sorted array
|
||||
* <p>
|
||||
* Worst-case performance O(log n)
|
||||
* Best-case performance O(1)
|
||||
* Average performance O(log n)
|
||||
* Worst-case space complexity O(1)
|
||||
*/
|
||||
public final class BinarySearch {
|
||||
|
||||
/**
|
||||
* @param array is an array where the element should be found
|
||||
* @param key is an element which should be found
|
||||
* @param <T> is any comparable type
|
||||
* @return index of the element
|
||||
*/
|
||||
public static <T extends Comparable<T>> int findIndex(T[] array, T key) {
|
||||
return search(array, key, 0, array.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array The array to search
|
||||
* @param key The element you are looking for
|
||||
* @param left The lower bound
|
||||
* @param right The upper bound
|
||||
* @return the location of the key
|
||||
**/
|
||||
private static <T extends Comparable<T>> int search(T[] array, T key, int left, int right) {
|
||||
if (left > right) {
|
||||
return -1; // Key not found
|
||||
}
|
||||
|
||||
// Find median
|
||||
int median = left + (right - left) / 2;
|
||||
int comp = key.compareTo(array[median]);
|
||||
|
||||
if (comp < 0) {
|
||||
return search(array, key, left, median - 1);
|
||||
}
|
||||
|
||||
if (comp > 0) {
|
||||
return search(array, key, median + 1, right);
|
||||
}
|
||||
|
||||
return median;
|
||||
}
|
||||
}
|
189
src/main/java/com/search/BloomFilter.java
Normal file
189
src/main/java/com/search/BloomFilter.java
Normal file
@ -0,0 +1,189 @@
|
||||
package com.search;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A simple implementation of Bloom filter.
|
||||
* <p>
|
||||
* Bloom filter have a chance of being wrong.
|
||||
* <p>
|
||||
* The Bloom filter assert that elements that do not exist must not exist,
|
||||
* if assert an element exists, but not necessarily.
|
||||
* <p>
|
||||
* The accuracy rate depends on capacity and hash functions.
|
||||
*
|
||||
*/
|
||||
public class BloomFilter implements Serializable {
|
||||
private static final long serialVersionUID = -4466610350741278658L;
|
||||
|
||||
private static final int LONG_SHIFT = 6;
|
||||
private static final int LONG_MASK = 63;
|
||||
|
||||
/**
|
||||
* hash functions
|
||||
*/
|
||||
private final List<Function<String, Integer>> hashFunctions;
|
||||
|
||||
private final long[] table;
|
||||
private final int tableMask;
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* @param capacity the filter capacity
|
||||
* @param hashFunctions hash functions
|
||||
* @see Builder must be build by {@link Builder}.
|
||||
*/
|
||||
private BloomFilter(int capacity, List<Function<String, Integer>> hashFunctions) {
|
||||
this.hashFunctions = hashFunctions;
|
||||
int cap = nextPowerOf2(capacity);
|
||||
tableMask = (cap << LONG_SHIFT) - 1;
|
||||
table = new long[cap];
|
||||
}
|
||||
|
||||
public static Builder builder(int capacity) {
|
||||
if (capacity < 1) {
|
||||
throw new IllegalStateException("capacity must be > 0");
|
||||
}
|
||||
|
||||
return new Builder(capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an element to the Bloom filter.
|
||||
*/
|
||||
public void add(String element) {
|
||||
checkNotNull(element, "element");
|
||||
|
||||
for (Function<String, Integer> hashFunction : hashFunctions) {
|
||||
int key = hashFunction.apply(element) & tableMask;
|
||||
table[key >>> LONG_SHIFT] |= (1 << (key & LONG_MASK));
|
||||
}
|
||||
size++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the element exists, otherwise false.
|
||||
*/
|
||||
public boolean contains(String element) {
|
||||
if (element == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Function<String, Integer> hashFunction : hashFunctions) {
|
||||
int key = hashFunction.apply(element) & tableMask;
|
||||
if ((table[key >>> LONG_SHIFT] & (1 << (key & LONG_MASK))) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Function<String, Integer>> getHashFunctions() {
|
||||
return hashFunctions;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
private static void checkNotNull(String element, String msg) {
|
||||
if (element == null) {
|
||||
throw new NullPointerException(msg + " must be not null");
|
||||
}
|
||||
}
|
||||
|
||||
private static int nextPowerOf2(int i) {
|
||||
int n = i - 1;
|
||||
n |= n >>> 1;
|
||||
n |= n >>> 2;
|
||||
n |= n >>> 4;
|
||||
n |= n >>> 8;
|
||||
n |= n >>> 16;
|
||||
return (n < 0) ? 1 : (n >= 0x40000000) ? 0x40000000 : n + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need a list of unmodifiable hash functions.
|
||||
*/
|
||||
public static class Builder {
|
||||
private int capacity;
|
||||
private List<Function<String, Integer>> hashFunctions = new ArrayList<>();
|
||||
|
||||
private Builder(int capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public Builder addHashFunction(Function<String, Integer> function) {
|
||||
hashFunctions.add(function);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BloomFilter build() {
|
||||
if (hashFunctions.isEmpty()) {
|
||||
addDefaultHashFunction();
|
||||
}
|
||||
return new BloomFilter(capacity, Collections.unmodifiableList(hashFunctions));
|
||||
}
|
||||
|
||||
/**
|
||||
* I provides several default hash functions
|
||||
*/
|
||||
private void addDefaultHashFunction() {
|
||||
// Java String Hash Function
|
||||
hashFunctions.add(String::hashCode);
|
||||
|
||||
// SDBM Hash Function
|
||||
hashFunctions.add(key -> {
|
||||
if (key == null || key.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hash = 0;
|
||||
for (int i = 0; i < key.length(); i++) {
|
||||
hash = key.charAt(i) + (hash << 6) + (hash << 16) - hash;
|
||||
}
|
||||
hash &= 0x7ffffff;
|
||||
return hash;
|
||||
});
|
||||
|
||||
// Robert Sedgwicks Hash Function
|
||||
hashFunctions.add(key -> {
|
||||
if (key == null || key.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hash = 0;
|
||||
int magic = 63689;
|
||||
for (int i = 0; i < key.length(); i++) {
|
||||
hash = hash * magic + key.charAt(i);
|
||||
magic *= 378551;
|
||||
}
|
||||
return hash;
|
||||
});
|
||||
|
||||
// Arash Partow Hash Function
|
||||
hashFunctions.add(key -> {
|
||||
if (key == null || key.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hash = 0;
|
||||
for (int i = 0; i < key.length(); i++) {
|
||||
char ch = key.charAt(i);
|
||||
if ((i & 1) == 0) {
|
||||
hash ^= ((hash << 7) ^ ch ^ (hash >> 3));
|
||||
} else {
|
||||
hash ^= (~((hash << 11) ^ ch ^ (hash >> 5)));
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
41
src/main/java/com/search/ExponentialSearch.java
Normal file
41
src/main/java/com/search/ExponentialSearch.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.search;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Exponential search (also called doubling search or galloping search or Struzik search) is an algorithm which finds
|
||||
* the position of a target value within an array. It works by determining a range that the search key resides in and
|
||||
* performing a binary search within that range
|
||||
* <p>
|
||||
* Worst-case performance O(n)
|
||||
* Best-case performance O(1)
|
||||
* Average performance O(Log n)
|
||||
* Worst-case space complexity O(Log n)
|
||||
*/
|
||||
public class ExponentialSearch {
|
||||
/**
|
||||
* @param array is an array where the element should be found
|
||||
* @param key is an element which should be found
|
||||
* @param <T> is any comparable type
|
||||
* @return The index position of the key in the array, returns -1 for empty array
|
||||
*/
|
||||
public <T extends Comparable<T>> int findIndex(T[] array, T key) {
|
||||
if (array == null || array.length == 0) {
|
||||
return -1;
|
||||
}
|
||||
int size = array.length;
|
||||
|
||||
// If the element is present at first position
|
||||
if (array[0] == key)
|
||||
return 0;
|
||||
|
||||
// Find the range for binary search by repeated doubling
|
||||
int i = 1;
|
||||
while (i < size && array[i].compareTo(key) <= 0) {
|
||||
i <<= 1;
|
||||
}
|
||||
|
||||
// Call binary search for the range found
|
||||
return Arrays.binarySearch(array, i >> 1, Math.min(i, size), key);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user