Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Data Structure and Algorithm explanations with Implementations by Javascript

NotificationsYou must be signed in to change notification settings

Algorithm-archive/Learn-Data_Structure-Algorithm-by-Javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

You need to have basic understanding of the JavaScript programming language to proceed with the codes from this repository.

Table of Contents

  • Introduction to JavaScript

  • Data Structure

  • Searching

  • Sorting

  • Graph Algorithms

    • 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


Introduction

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

Data Types in JavaScript

The latest ECMAScript standard defines seven data types:

  • Six data types that are primitives:

    • Boolean (true andfalse)
    • Null (invalid object or address has the valuenull)
    • Undefined (a variable that has not been assigned a value has the valueundefined)
    • 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)
  • Object

Arrays

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">

Object Oriented Programming in JavaScript

Algorithms in plain English: time complexity and Big-O notationBig-O Cheat Sheet LinkA beginner's guide to big-O notation

How to Use

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

ES6/ES2015 implementations

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. Whileimport 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.

FAQ

  • 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.

Useful Links:

About

Data Structure and Algorithm explanations with Implementations by Javascript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp