- Notifications
You must be signed in to change notification settings - Fork31
Algorithm-archive/Learn-Data_Structure-Algorithm-by-Javascript
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
You need to have basic understanding of the JavaScript programming language to proceed with the codes from this repository.
- Linked List
- Stack
- Queue
- Binary Search Tree (BST)
- Heap
- Hash Table
- Disjoint Set Union (Union Find)
- Trie
- Suffix Array
- Segment Tree
- Binary Indexed Tree (BIT)
- Heavy Light Decomposition
- Graph Representation
- Breadth First Search (BFS)
- Depth First Search (DFS)
- Topological Sort
- Strongly Connected Components (SCC)
- Minimum Spanning Tree (MST)
- All Pairs Shortest Path (Floyd Warshall's Algorithm)
- Single Source Shortest Path Algorithm
- Djkastra's Algorithm
- Bellman Ford Algorithm
- Directed Acyclic Graph
- Bipartite Matching
- Articulation Point, Bridge
- Euler Tour/Path
- Hamiltonian Cycle
- Stable Marriage Problem
- Chinese Postman Problem
- 2-satisfiability
- Flow Algorithms
- Maximum Flow
- Minimum Cut
- Min-Cost Max Flow
- Maximum Bipartite Matching
- Vertex Cover
Dynamic Programming
- Rod Cutting
- Maximum Sum (1D, 2D)
- Coin Change
- Longest Common Subsequence
- Longest Increasing Subsequence
- Matrix Multiplication
- Edit Distance (Levenshtein distance)
- 0/1 Knapsack
- Travelling Salesman Problem
- Optimal Binary Search Tree
Greedy Algorithms
- Activity Selection/Task Scheduling
- Huffman Coding
- Knapsack Problem (Fractional Knapsack)
String Algorithms
- Rabin-Karp Algorithm
- Knuth-Morris-Pratt Algorithm
- Z Algorithm
- Aho-Korasick Algorithm
- Manachers Algorithm
- Boyr-Moore Algorithm
Number Theory
- Greatest Common Divisor (GCD)
- Longest Common Multiplier (LCM)
- Euler Totient (Phi)
- Primality Testing
- Prime finding(Sieve of Eratosthenes)
- Prime factorization
- Factorial
- Fibonacci
- Counting, Permutation, combination
- Exponentiation
- Big Mod
- Euclid, Extended euclid
- Josephus Problem
- Farey Sequence
- Catalan numbers
- Burnside's lemma/circular permutation
- Modular inverse
- Probability
- Chinese Remainder Theorem
- Gaussian Elimination method
- Dilworth's Theorem
- Matrix Exponentiation
Computational Geometry
- Pick's Theorem
- Convex hull
- Line Intersection
- Point in a polygon
- Area of a polygon
- Line Sweeping
- Polygon intersection
- Closest Pair
Game Theory
- Take Away Game
- Nim's Game
- Sprague-grundy Number
Others
- BackTracking
- N-Queen's Problem
- Tower of Hanoi Problem
- BackTracking
JavaScript is aloosely typed or adynamic language. That means you don't have to declare the type of a variable ahead of time. The type will get determined automatically while the program is being processed. That also means that you can have the same variable as different types:
varfoo=42;// foo is now a Numbervarfoo='bar';// foo is now a Stringvarfoo=true;// foo is now a Boolean
The latest ECMAScript standard defines seven data types:
Six data types that are primitives:
- Boolean (
true
andfalse
) - Null (invalid object or address has the value
null
) - Undefined (a variable that has not been assigned a value has the value
undefined
) - Number (integer and floating point values ranging from -(253 -1) to (253 -1), +Infinity, -Infinity and NaN(not-a-number) )
- String (Sequence of textual characters. Strings are immutable in JavaScript)
- Symbol (new in ECMAScript 6)
- Boolean (
JavaScriptArrays are regular objects for which there is a particular relationship between integer-key-ed properties and the 'length' property. Additionally, arrays inherit from Array.prototype which provides to them a handful of convenient methods to manipulate arrays like indexOf (searching a value in the array) or push (adding an element to the array), etc. This makes arrays a perfect candidate to represent lists or sets.
More details about data types in #"Permalink: More details about data types in JavaScript:" href="#more-details-about-data-types-in-javascript">
Algorithms in plain English: time complexity and Big-O notationBig-O Cheat Sheet LinkA beginner's guide to big-O notation
The easiest way to run and test the codes from this repository is to usenodejs (I have checked my code using nodejs v6.5.0 in an Windows machine).
Install it in your machine and add it to your environment path so that it is accessible in terminal commands.
Then you can run a JavaScript file like this:
nodefile.js
There are ES6 implementations of the Data Structures and Algorithms in their respective folders within a separate folder namedes6
.Couple of things to notice here:
- There are no trueprivate properties available in ES6 yet. So, in classes noworkarounds or hacks used to implement private properties. There are severalproposals and initiative ongoing to introduce it in ECMAScript. Hoping that would be done soon and we will then add it in our code.
- We tried to implement the data structures and some algorithms in separate modules so that they can be used independently in any other codes. While
import
is indeedpart of ES6, it is unfortunately not yet supported by any native environments, Node or browser. Until the native support introduced the easy workaround is to stick with the oldCommonJS Module format(Which is supported in NodeJS and as weadvised earlier to test our codes in NodeJS, so we are sticking with it). The modules will beexported using CommonJS Module format and imported by 'require'.Though there are other ways likeBabel
,Rollup
etc., but that need some build configurations(And we don't want to make our codes more complicated). And at the end babel will convert the code torequire
andmodule.exports
anyway.
Why you didn't use prototype methods in Objects?
=> Well, we could've. But before argue on that, you might want to readthis nice article. We chose to follow the philosophy described on that article. But still, you can easily rewrite the codes of this repository using 'prototypal methods' for your own use.
About
Data Structure and Algorithm explanations with Implementations by Javascript
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.