Home

Awesome

JavaScript Algorithm And Data Structure

This is an attempt to implement all kind of widely used Algorithms and Data Structures in the programming world using JavaScript. Thus the term AlgoDS is used as a name of this repository. Anyone can use it as a reference to implement those problems. If you have any suggestion, then please make an issue or contact me, I will be grateful to you.

The Solutions

Most of the implementations are done using pure functions so that anyone can use them as well if they want. index.js files are made for testing purpose. Besides, you will find README file in every problem that will illustrate the problem so that you can understand them easily.

Basic Terms

Big O

It allows us to calculate how the runtime of an Algorithm grows as the inputs grow

Some Mostly Used Big O

Run Time Complexity

Describe the performance of an algorithm. How much processing power or time is required to run an algorithm if we double the amount of input

       O(n^2)
|       / / O(nlogn)/ O(n)
|      / /        /
|     / /       /
|    / /      /
|   / /     /
|  / /    /
| / /   /
|/ /  /----------------------- log(n)
| / /_________________________ O(1)
|//___________________________

Identifying Runtime Complexity

Space Complexity

The amount of space in the memory required by that particular Algorithm. How much more memory is required by doubling the problem set.

123 => 321 => n times
123456 => 654321 n times

Some Mostly Used Space Complexity

Logarithm

Logarithmic values often can be very confusing. But there also very easy to understand. Like if we explain what does log2(8) = 3 means:

log2(8) = 3
=> 2^3 = 8
log(2)(value) = exponent => 2^exponent = value

And also log2 and log is same. We can omit 2 in this case

Performance of Objects

We can analyze the JavaScript's built-in objects to find out its various complexity to accomplish various task

const anObj = {
  name: 'Zonayed Ahmed',
  age: 22,
  gender: 'Male'
}

Complexity

Performance of Arrays

We can analyze the performance of JavaScript's built-in array

const anArr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ..., 1000]

Complexity

Problem Solving

Problem Solving Pattern

Some problem solving patterns are widely used to simplify the solution like:

Frequency Counter

This pattern uses objects or sets to collect values/frequency of values. Thus most of time nested loops or O(n^2) time complexity can be avoided

Multiple Pointers

Creating pointers or values that correspond to an ndex or position and move towards beginning, end or middle based on a certain condition

Data Structure

Ways of organizing information with optimal runtime complexity for adding, removing and some basic operations in the record. Some example of mostly used Data Structure