RowlandOti / es6-data-structures-and-algorithms

This repository contains some popular Data Structures and Algorithms done in JavaScript, ES6.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EcmaScript 6 Algorithms and Data Structures

Build Status codecov Codacy Badge Codacy Badge license Commitizen friendly semantic-release

This repository contains some popular Data Structures and Algorithms done in JavaScript ES6.

Data Structures

According to Wikipedia:

In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

The following terms are the foundation terms of a data structure.

  • Interface - This represents the set of operation supported by a data structure
  • Implementation - This provides the definition of algorithms used in the operations of the data structure i.e. it provides the internal representation of the data structure

Characteristics of a Data Structure

  1. Correctness - a data structure should implement its interface correctly
  2. Time Complexity - execution time of operations of a data structure should be as small as possible
  3. Space Complexity - memory usage of a data structure operation should be as little as possible

Data Structure Operations Complexity

Data Structure Access Search Insertion Deletion
Array 1 n n n
Stack n n 1 1
Queue n n 1 1
Linked List n n 1 1
Hash Table - n n n
Binary Search Tree n n n n
B-Tree log(n) log(n) log(n) log(n)
AVL Tree log(n) log(n) log(n) log(n)

DS Operations

Shown below are the data structures covered here:

Algorithms

This is a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.

The following are the algorithms covered here:

Algorithms by Topic

Algorithms by Paradigm

An algorithmic paradigm is a generic method or approach which underlies the design of a class of algorithms. It is an abstraction higher than the notion of an algorithm, just as an algorithm is an abstraction higher than a computer program.

Array Sorting Algorithms Complexity

Name Best Average Worst Memory Stable
Bubble sort n n2 n2 1 Yes
Insertion sort n n2 n2 1 Yes
Selection sort n2 n2 n2 1 No
Heap sort n log(n) n log(n) n log(n) 1 No
Merge sort n log(n) n log(n) n log(n) n Yes
Quick sort n log(n) n log(n) n2 log(n) No
Shell sort n log(n) depends on gap sequence n (log(n))2 1 No
Counting sort n + r n + r n + r n + r Yes
Radix sort n * k n * k n * k n + k Yes

Big-O Notation

This is a theoretical measure of the execution of an algorithm, usually the time or memory needed, given the problem size n, which is usually the number of items. Informally, saying some equation f(n) = O(g(n)) means it is less than some constant multiple of g(n).

It is used in Computer Science to describe the performance or complexity of an algorithm. Big-O specifically describes the worst-case scenario, and can be used to describe the execution time required or the space used (e.g. in memory or on disk) by an algorithm.

The most optimum algorithm scales in constant time and space. This means it does not care at all about the growth of its inputs. Next best is logarithmic time or space, then linear, linearithmic, quadratic, and exponential. The worst is factorial time or space. In Big-O notation:

  1. Constant: O(1)
  2. Logarithmic: O(log n)
  3. Linear: O(n)
  4. Linearithmic: O(n log n)
  5. Quadratic: O(n²)
  6. Expontential: O(2^n)
  7. Factorial: O(n!)

Below is the list of some of the most used Big O notations and their performance comparisons against different sizes of the input data.

Big O Notation Computations for 10 elements Computations for 100 elements Computations for 1000 elements
O(1) 1 1 1
O(log N) 3 6 9
O(N) 10 100 1000
O(N log N) 30 600 9000
O(N^2) 100 10000 1000000
O(2^N) 1024 1.26e+29 1.07e+301
O(N!) 3628800 9.3e+157 4.02e+2567

Installation

Clone this repo:

$ git clone https://github.com/akhenda/es6-data-structures-and-algorithms.git

Navigate to the es6-data-structures-and-algorithms directory:

$ cd es6-data-structures-and-algorithms

Install the required dependencies:

$ yarn install

Testing

To run both tests and linting, run:

yarn run validate

To run the tests alone:

yarn run test

To run ESLint:

yarn run lint

Usage

...

Resources

License

The MIT License (MIT)

Copyright (c) 2016 Joseph Akhenda.

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.

About

This repository contains some popular Data Structures and Algorithms done in JavaScript, ES6.

License:MIT License


Languages

Language:JavaScript 100.0%