├── test
└── src
│ ├── fixtures
│ ├── selfLoop.txt
│ ├── tinyFN2.txt
│ ├── tinyDG2.txt
│ ├── sample.txt
│ ├── tinyEWDGnw.txt
│ ├── tinyDG3.txt
│ ├── tinyFN.txt
│ ├── tinyG.txt
│ ├── tinyFN3.txt
│ ├── tinyEWDG.txt
│ ├── tinyDG.txt
│ ├── tinyEWG.txt
│ ├── tinyEWDGnc.txt
│ └── fixtures.dart
│ ├── quick_select_test.dart
│ ├── binary_search_test.dart
│ ├── string_search_test.dart
│ ├── union_find_test.dart
│ ├── utils.dart
│ ├── priority_queue_test.dart
│ ├── sorting_test.dart
│ └── graph_test.dart
├── .github
├── ISSUE_TEMPLATE
│ ├── config.yml
│ ├── ci.md
│ ├── build.md
│ ├── chore.md
│ ├── documentation.md
│ ├── style.md
│ ├── test.md
│ ├── refactor.md
│ ├── performance.md
│ ├── revert.md
│ ├── feature_request.md
│ └── bug_report.md
├── dependabot.yaml
├── workflows
│ ├── main.yaml
│ ├── dart_package.yml
│ └── dart_package.yaml
└── PULL_REQUEST_TEMPLATE.md
├── .idea
├── dictionaries
├── vcs.xml
├── misc.xml
├── .gitignore
├── modules.xml
├── dart_algorithms.iml
└── libraries
│ ├── Dart_SDK.xml
│ └── Dart_Packages.xml
├── .gitignore
├── lib
├── src
│ ├── sorting
│ │ ├── sorting.dart
│ │ ├── selection_sort.dart
│ │ ├── insertion_sort.dart
│ │ ├── bubble_sort.dart
│ │ ├── shell_sort.dart
│ │ ├── heap_sort.dart
│ │ ├── merge_sort.dart
│ │ └── quick_sort.dart
│ ├── graph
│ │ ├── graphs.dart
│ │ ├── dfs.dart
│ │ ├── bfs.dart
│ │ ├── topological_sort.dart
│ │ ├── cycle_detection.dart
│ │ ├── minimum_spanning_tree.dart
│ │ ├── connected_components.dart
│ │ ├── shortest_path.dart
│ │ ├── max_flow.dart
│ │ └── graph.dart
│ ├── utils.dart
│ ├── binary_search.dart
│ ├── quick_select.dart
│ ├── kmp.dart
│ ├── union_find.dart
│ └── priority_queue.dart
└── dart_algorithms.dart
├── analysis_options.yaml
├── pubspec.yaml
├── challanges.txt
├── coverage_badge.svg
└── README.md
/test/src/fixtures/selfLoop.txt:
--------------------------------------------------------------------------------
1 | 1
2 | 1
3 | 0 0
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
--------------------------------------------------------------------------------
/test/src/fixtures/tinyFN2.txt:
--------------------------------------------------------------------------------
1 | 4
2 | 5
3 | 0 1 100
4 | 0 2 100
5 | 1 2 1
6 | 1 3 100
7 | 2 3 100
--------------------------------------------------------------------------------
/test/src/fixtures/tinyDG2.txt:
--------------------------------------------------------------------------------
1 | 6
2 | 8
3 | 5 0
4 | 2 4
5 | 3 2
6 | 1 2
7 | 0 1
8 | 4 3
9 | 3 5
10 | 0 2
--------------------------------------------------------------------------------
/test/src/fixtures/sample.txt:
--------------------------------------------------------------------------------
1 | 10
2 | 9
3 | 0 1
4 | 0 4
5 | 0 8
6 | 1 2
7 | 2 3
8 | 4 5
9 | 5 6
10 | 4 7
11 | 0 8
12 | 8 9
--------------------------------------------------------------------------------
/test/src/fixtures/tinyEWDGnw.txt:
--------------------------------------------------------------------------------
1 | 5
2 | 8
3 | 0 1 -1
4 | 0 2 4
5 | 1 2 3
6 | 1 3 2
7 | 1 4 2
8 | 3 1 1
9 | 3 2 5
10 | 4 3 -3
--------------------------------------------------------------------------------
/test/src/fixtures/tinyDG3.txt:
--------------------------------------------------------------------------------
1 | 7
2 | 11
3 | 0 1
4 | 1 4
5 | 0 5
6 | 0 2
7 | 5 2
8 | 3 2
9 | 3 5
10 | 3 4
11 | 3 6
12 | 6 0
13 | 6 4
--------------------------------------------------------------------------------
/test/src/fixtures/tinyFN.txt:
--------------------------------------------------------------------------------
1 | 6
2 | 8
3 | 0 1 2.0
4 | 0 2 3.0
5 | 1 3 3.0
6 | 1 4 1.0
7 | 2 3 1.0
8 | 2 4 1.0
9 | 3 5 2.0
10 | 4 5 3.0
--------------------------------------------------------------------------------
/test/src/fixtures/tinyG.txt:
--------------------------------------------------------------------------------
1 | 13
2 | 13
3 | 0 5
4 | 4 3
5 | 0 1
6 | 9 12
7 | 6 4
8 | 5 4
9 | 0 2
10 | 11 12
11 | 9 10
12 | 0 6
13 | 7 8
14 | 9 11
15 | 5 3
--------------------------------------------------------------------------------
/test/src/fixtures/tinyFN3.txt:
--------------------------------------------------------------------------------
1 | 8
2 | 13
3 | 0 1 1
4 | 0 2 4
5 | 0 3 6
6 | 1 4 3
7 | 2 1 8
8 | 2 4 1
9 | 2 5 3
10 | 3 5 7
11 | 3 6 4
12 | 4 7 5
13 | 5 6 2
14 | 6 4 10
15 | 6 7 6
--------------------------------------------------------------------------------
/.idea/dictionaries:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://www.dartlang.org/guides/libraries/private-files
2 |
3 | # Files and directories created by pub
4 | .dart_tool/
5 | build/
6 | .idea/*
7 | coverage/*
8 | .packages
9 | pubspec.lock
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/lib/src/sorting/sorting.dart:
--------------------------------------------------------------------------------
1 | export "bubble_sort.dart";
2 | export "heap_sort.dart";
3 | export "insertion_sort.dart";
4 | export "merge_sort.dart";
5 | export "quick_sort.dart";
6 | export "selection_sort.dart";
7 | export "shell_sort.dart";
8 |
--------------------------------------------------------------------------------
/test/src/fixtures/tinyEWDG.txt:
--------------------------------------------------------------------------------
1 | 8
2 | 15
3 | 4 5 0.35
4 | 5 4 0.35
5 | 4 7 0.37
6 | 5 7 0.28
7 | 7 5 0.28
8 | 5 1 0.32
9 | 0 4 0.38
10 | 0 2 0.26
11 | 7 3 0.39
12 | 1 3 0.29
13 | 2 7 0.34
14 | 6 2 0.40
15 | 3 6 0.52
16 | 6 0 0.58
17 | 6 4 0.93
--------------------------------------------------------------------------------
/test/src/fixtures/tinyDG.txt:
--------------------------------------------------------------------------------
1 | 13
2 | 22
3 | 4 2
4 | 2 3
5 | 3 2
6 | 6 0
7 | 0 1
8 | 2 0
9 | 11 12
10 | 12 9
11 | 9 10
12 | 9 11
13 | 7 9
14 | 10 12
15 | 11 4
16 | 4 3
17 | 3 5
18 | 6 8
19 | 8 6
20 | 5 4
21 | 0 5
22 | 6 4
23 | 6 9
24 | 7 6
--------------------------------------------------------------------------------
/test/src/fixtures/tinyEWG.txt:
--------------------------------------------------------------------------------
1 | 8
2 | 16
3 | 4 5 0.35
4 | 4 7 0.37
5 | 5 7 0.28
6 | 0 7 0.16
7 | 1 5 0.32
8 | 0 4 0.38
9 | 2 3 0.17
10 | 1 7 0.19
11 | 0 2 0.26
12 | 1 2 0.36
13 | 1 3 0.29
14 | 2 7 0.34
15 | 6 2 0.40
16 | 3 6 0.52
17 | 6 0 0.58
18 | 6 4 0.93
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:very_good_analysis/analysis_options.3.1.0.yaml
2 |
3 | linter:
4 | rules:
5 | prefer_double_quotes: true
6 | prefer_single_quotes: false
7 | sort_constructors_first: false
8 | lines_longer_than_80_chars: false
--------------------------------------------------------------------------------
/test/src/fixtures/tinyEWDGnc.txt:
--------------------------------------------------------------------------------
1 | 8
2 | 15
3 | 4 5 0.35
4 | 5 4 -0.66
5 | 4 7 0.37
6 | 5 7 0.28
7 | 7 5 0.28
8 | 5 1 0.32
9 | 0 4 0.38
10 | 0 2 0.26
11 | 7 3 0.39
12 | 1 3 0.29
13 | 2 7 0.34
14 | 6 2 0.40
15 | 3 6 0.52
16 | 6 0 0.58
17 | 6 4 0.93
--------------------------------------------------------------------------------
/lib/dart_algorithms.dart:
--------------------------------------------------------------------------------
1 | library dart_algorithms;
2 |
3 | export "src/binary_search.dart";
4 | export "src/graph/graphs.dart";
5 | export "src/kmp.dart";
6 | export "src/priority_queue.dart";
7 | export "src/sorting/sorting.dart";
8 | export "src/union_find.dart";
9 |
--------------------------------------------------------------------------------
/.github/dependabot.yaml:
--------------------------------------------------------------------------------
1 | version: 2
2 | enable-beta-ecosystems: true
3 | updates:
4 | - package-ecosystem: "github-actions"
5 | directory: "/"
6 | schedule:
7 | interval: "daily"
8 | - package-ecosystem: "pub"
9 | directory: "/"
10 | schedule:
11 | interval: "daily"
12 |
--------------------------------------------------------------------------------
/lib/src/graph/graphs.dart:
--------------------------------------------------------------------------------
1 | export "bfs.dart";
2 | export "connected_components.dart";
3 | export "cycle_detection.dart";
4 | export "dfs.dart";
5 | export "graph.dart";
6 | export "max_flow.dart";
7 | export "minimum_spanning_tree.dart";
8 | export "shortest_path.dart";
9 | export "topological_sort.dart";
10 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/src/fixtures/fixtures.dart:
--------------------------------------------------------------------------------
1 | import "dart:io";
2 |
3 | import "package:path/path.dart" as p;
4 |
5 | const _fixturesDir = "./test/src/fixtures";
6 |
7 | String _filePath(String fileName) => p.join(_fixturesDir, fileName);
8 |
9 | List loadTestFile(String fileName) => File(_filePath(fileName)).readAsLinesSync();
10 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/ci.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Continuous Integration
3 | about: Changes to the CI configuration files and scripts
4 | title: "ci: "
5 | labels: ci
6 | ---
7 |
8 | **Description**
9 |
10 | Describe what changes need to be done to the ci/cd system and why.
11 |
12 | **Requirements**
13 |
14 | - [ ] The ci system is passing
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/build.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Build System
3 | about: Changes that affect the build system or external dependencies
4 | title: "build: "
5 | labels: build
6 | ---
7 |
8 | **Description**
9 |
10 | Describe what changes need to be done to the build system and why.
11 |
12 | **Requirements**
13 |
14 | - [ ] The build system is passing
15 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: dart_algorithms
2 | description: A Very Good Project created by Very Good CLI.
3 | version: 0.1.0+1
4 | publish_to: none
5 |
6 | environment:
7 | sdk: ">=2.18.0 <3.0.0"
8 | dependencies:
9 | collection: ^1.17.1
10 |
11 | dev_dependencies:
12 | mocktail: ^1.0.0
13 | path: ^1.8.3
14 | test: ^1.19.2
15 | very_good_analysis: ^4.0.0+1
16 |
17 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/chore.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Chore
3 | about: Other changes that don't modify src or test files
4 | title: "chore: "
5 | labels: chore
6 | ---
7 |
8 | **Description**
9 |
10 | Clearly describe what change is needed and why. If this changes code then please use another issue type.
11 |
12 | **Requirements**
13 |
14 | - [ ] No functional changes to the code
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/documentation.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Documentation
3 | about: Improve the documentation so all collaborators have a common understanding
4 | title: "docs: "
5 | labels: documentation
6 | ---
7 |
8 | **Description**
9 |
10 | Clearly describe what documentation you are looking to add or improve.
11 |
12 | **Requirements**
13 |
14 | - [ ] Requirements go here
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/style.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Style Changes
3 | about: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
4 | title: "style: "
5 | labels: style
6 | ---
7 |
8 | **Description**
9 |
10 | Clearly describe what you are looking to change and why.
11 |
12 | **Requirements**
13 |
14 | - [ ] There is no drop in test coverage.
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/test.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Test
3 | about: Adding missing tests or correcting existing tests
4 | title: "test: "
5 | labels: test
6 | ---
7 |
8 | **Description**
9 |
10 | List out the tests that need to be added or changed. Please also include any information as to why this was not covered in the past.
11 |
12 | **Requirements**
13 |
14 | - [ ] There is no drop in test coverage.
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/refactor.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Refactor
3 | about: A code change that neither fixes a bug nor adds a feature
4 | title: "refactor: "
5 | labels: refactor
6 | ---
7 |
8 | **Description**
9 |
10 | Clearly describe what needs to be refactored and why. Please provide links to related issues (bugs or upcoming features) in order to help prioritize.
11 |
12 | **Requirements**
13 |
14 | - [ ] There is no drop in test coverage.
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/performance.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Performance Update
3 | about: A code change that improves performance
4 | title: "perf: "
5 | labels: performance
6 | ---
7 |
8 | **Description**
9 |
10 | Clearly describe what code needs to be changed and what the performance impact is going to be. Bonus point's if you can tie this directly to user experience.
11 |
12 | **Requirements**
13 |
14 | - [ ] There is no drop in test coverage.
15 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/revert.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Revert Commit
3 | about: Reverts a previous commit
4 | title: "revert: "
5 | labels: revert
6 | ---
7 |
8 | **Description**
9 |
10 | Provide a link to a PR/Commit that you are looking to revert and why.
11 |
12 | **Requirements**
13 |
14 | - [ ] Change has been reverted
15 | - [ ] No change in test coverage has happened
16 | - [ ] A new ticket is created for any follow on work that needs to happen
17 |
--------------------------------------------------------------------------------
/.github/workflows/main.yaml:
--------------------------------------------------------------------------------
1 | name: ci
2 |
3 | concurrency:
4 | group: ${{ github.workflow }}-${{ github.ref }}
5 | cancel-in-progress: true
6 |
7 | on:
8 | workflow_dispatch:
9 | pull_request:
10 | branches:
11 | - main
12 |
13 | jobs:
14 | semantic_pull_request:
15 | uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1
16 |
17 | build:
18 | uses: ./.github/workflows/dart_package.yml
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature Request
3 | about: A new feature to be added to the project
4 | title: "feat: "
5 | labels: feature
6 | ---
7 |
8 | **Description**
9 |
10 | Clearly describe what you are looking to add. The more context the better.
11 |
12 | **Requirements**
13 |
14 | - [ ] Checklist of requirements to be fulfilled
15 |
16 | **Additional Context**
17 |
18 | Add any other context or screenshots about the feature request go here.
19 |
--------------------------------------------------------------------------------
/test/src/quick_select_test.dart:
--------------------------------------------------------------------------------
1 | import "package:dart_algorithms/dart_algorithms.dart";
2 | import "package:test/test.dart";
3 |
4 | void main() {
5 | setUp(() {});
6 | group("Check ", () {
7 | test("", () {
8 | expect(quickSelect([3, 2, 1, 5, 6, 4], 2), 5);
9 | expect(quickSelect([3, 2, 3, 1, 2, 4, 5, 5, 6], 4), 4);
10 | expect(
11 | quickSelect(
12 | [3, 2, 1, 5, 6, 4, 0],
13 | compare: (a, b) => b.compareTo(a),
14 | 2,
15 | ),
16 | 1,
17 | );
18 | });
19 | });
20 | }
21 |
--------------------------------------------------------------------------------
/test/src/binary_search_test.dart:
--------------------------------------------------------------------------------
1 | import "package:dart_algorithms/src/binary_search.dart";
2 | import "package:test/test.dart";
3 |
4 | void main() {
5 | test("Binary Search", () {
6 | final arr = [1, 2, 3, 4, 5, 5, 5, 99, 101];
7 |
8 | expect(binarySearch(arr, 5), 4);
9 | expect(binarySearch(arr, 99), 7);
10 | expect(binarySearch(arr, 101), 8);
11 | expect(binarySearch(arr, 1), 0);
12 | expect(binarySearch(arr, 0), -1);
13 | expect(binarySearch([], 42), -1);
14 |
15 | expect(
16 | () => binarySearch([1, 3, 9, 0], 42),
17 | throwsA(isA()),
18 | );
19 | });
20 | }
21 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug Report
3 | about: Create a report to help us improve
4 | title: "fix: "
5 | labels: bug
6 | ---
7 |
8 | **Description**
9 |
10 | A clear and concise description of what the bug is.
11 |
12 | **Steps To Reproduce**
13 |
14 | 1. Go to '...'
15 | 2. Click on '....'
16 | 3. Scroll down to '....'
17 | 4. See error
18 |
19 | **Expected Behavior**
20 |
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 |
25 | If applicable, add screenshots to help explain your problem.
26 |
27 | **Additional Context**
28 |
29 | Add any other context about the problem here.
30 |
--------------------------------------------------------------------------------
/lib/src/utils.dart:
--------------------------------------------------------------------------------
1 | int defaultCompare(Object? value1, Object? value2) => (value1 as Comparable