GithubHelp home page GithubHelp logo

code-shoily / algorithms-in-dart Goto Github PK

View Code? Open in Web Editor NEW
219.0 11.0 119.0 269 KB

Implementation of data structures and algorithms in Dart programming language.

Dart 100.00%
dart data-structures algorithms graph trees sorts

algorithms-in-dart's Introduction

Algorithms in Dart

Build Status

Implementation of several algorithms with Dart programming language.

Use dartdoc to generate documentation.

Lists

List data structures are implemented under the package lists.

SinglyLinkedList

lib/lists/singly_linked_list.dart

DoublyLinkedList

lib/lists/doubly_linked_list.dart

CircularLinkedList

lib/lists/circular_singly_linked_list.dart and lib/lists/circular_doubly_linked_list.dart

Stack

lib/lists/stack.dart

Queue

lib/lists/queue.dart

Heaps

BinaryHeap

All base classes are in lib/heaps/base.dart

lib/heaps/binary_heap.dart - BinaryHeap, MinHeap and MaxHeap

Sorts

lib/sorts/common.dart contains helper functions and typedefs for sorting algorithms.

lib/sorts/exchange.dart - Bubble Sort, Odd-Even Sort, Gnome Sort, Quick Sort

lib/sorts/insertion.dart - Insertion Sort

lib/sorts/selection.dart - Heap Sort, Selection Sort

lib/sorts/distribution.dart - Pigeonhole Sort, Counting Sort, Radix Sort

lib/sorts/merge.dart - Merge Sort

Searching

lib/search/sequential.dart - Linear Search

lib/search/interval.dart - Binary Search

Trees

Binary Search Tree

lib/trees/binary_search_tree.dart

AVL Tree

lib/trees/avl_tree.dart

Red Black Tree

lib/trees/red_black_tree.dart

Math

lib/math/common.dart - GCD, LCM, Factorial

Graph

ADT

lib/graph/graph.dart - Graph ADT

lib/graph/vertex.dart - Vertex

lib/graph/traversal.dart - Traversal ADT to represent graph traversal results.

Traversals

lib/graph/dfs.dart - Algorithm for DFS traversal on graphs.

lib/graph/bfs.dart - Algorithm for BFS traversal on graphs.

Graph Paths

lib/graph/topological_sort.dart - Topological sort on acyclic digraphs.

lib/graph/bellman_ford.dart - Bellman Ford Algorithm

lib/graph/dijkstra.dart - Dijkstra's algorithm

algorithms-in-dart's People

Contributors

code-shoily avatar happy-san avatar mafinar-cmb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

algorithms-in-dart's Issues

Refactor Vertex Tests

The test/graph/vertex_test.dart has variables bleeding throughout the codebase. We need to clean those up in spirit of other files. We should extract all local var declarations in the top level and lock/unlock them on setUp. Also, we can add lockAll, unlockAll, _initializeVertex etc functions to keep setUp uncluttered. We can test/graph/graph_test.dart for inspiration.

Implement Sorted Linked List.

This will be similar to SinglyLinkedList. The differences would be:

  • fromList() constructor will sort the elements of the list before inserting them.

  • append() won't be implemented.

  • insert() will not take position as parameter, since we'll decide where the newNode goes.

Enhance Graph ADT

  • Convert to and from matrix representation
  • Review the adjacency matrix implementation and refactor if necessary

Refactor Graph ADT

  • Add inComing and outGoing fields on Vertex to include connections
  • Remove Connection and replace it with LinkedHashMap with num as values (weight)
  • Refactor Graph as abstract class
  • Remove Settings

Radix Sort

I am watching dsa js tutorial and implementing in on dart currently on radix sort

//radix sort
import 'dart:math' as Math;

main() {
}

getDigitNum(int n, int i) {
// return ((n / 100).round() %10);
// var cal = (n.abs() / Math.pow(10, =i)) % 10;
var cal = (n.round().abs() / Math.pow(10, i)) % 10;
// var cal = (n / 100)%10;

return cal.round();
}

digitCount(int number) {
if (number == 0) {
return 1;
}
return (number.abs().toString().length);
}

mostDigits(List number) {
var maxDigits = 0;
for (var i = 0; i < number.length; i++) {
maxDigits = Math.max(maxDigits, digitCount(number[i]));
}
return maxDigits;
}

radixSort(List nums) {
var maxDightCount = mostDigits(nums);
for (var k = 0; k < maxDightCount; k++) {
List digitBuckets = List.from({});//confused here
}
}

//here is the js codefunction getDigit(num, i) {
return Math.floor(Math.abs(num) / Math.pow(10, i)) % 10;
}

function digitCount(num) {
if (num === 0) return 1;
return Math.floor(Math.log10(Math.abs(num))) + 1;
}

function mostDigits(nums) {
let maxDigits = 0;
for (let i = 0; i < nums.length; i++) {
maxDigits = Math.max(maxDigits, digitCount(nums[i]));
}
return maxDigits;
}

function radixSort(nums){
let maxDigitCount = mostDigits(nums);
for(let k = 0; k < maxDigitCount; k++){
let digitBuckets = Array.from({length: 10}, () => []);
for(let i = 0; i < nums.length; i++){
let digit = getDigit(nums[i],k);
digitBuckets[digit].push(nums[i]);
}
nums = [].concat(...digitBuckets);
}
return nums;
}

radixSort([23,345,5467,12,2345,9852])

//i just want help this part below js code

let digitBuckets = Array.from({length: 10}, () => []);

//dart code
List digitBuckets = List.from({});//confused here

Convert tree algorithms to not nullable

Some ground-works have been done to make the process easier such as tighter generics types (Please look into the ADTs and nil on RedBlackTree). The process should start with removal of // @dart=2.9 on the files (module + test) and start addressing the errors by adding punctuations. The pattern for converting tests is to first append a ? on the pre-setUp variables and then append ! to all test cases (to ensure the value isn't null and are initialized, which is ensured since setUp initializes them any way). Only files that are NNBDed are tree_adt.dart and binary_tree_adt.dart.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.