• Stars
    star
    106
  • Rank 315,428 (Top 7 %)
  • Language
    JavaScript
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🛠🛠🛠 Widely used Algorithms and Data Structures using JavaScript 🛠🛠🛠

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

  • Arithmetic operations are always constant
  • Assignment of a variable is also constant
  • Accessing elements in an object by its key is constant
  • Accessing elements in an array by its index number is constant
  • The complexity of a loop is the amount of iteration it takes to complete the loop. How many time the loop runs again and again is the total complexity.

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

  • Constant Time => O(1) The algorithms will always take the same amount of time no matter how large our input data is or small. It is always the same. Thus it is called as constant time.
  • Logarithm Time => log(n) Doubling the inputs will not double the amount of work required
  • Linear Time => n Iterating over all the elements in a collection once. Usually if any program has one for loop, it can have linear time complexity
  • Quasilinear Time => n * log(n) Doubling the elements will double the amount of work required
  • Quadratic Time => n^2 Every element in a collection has to be compared to every other element
  • Exponential Time => 2^n Adding a single element will double the work required.
       O(n^2)
|       / / O(nlogn)/ O(n)
|      / /        /
|     / /       /
|    / /      /
|   / /     /
|  / /    /
| / /   /
|/ /  /----------------------- log(n)
| / /_________________________ O(1)
|//___________________________

Identifying Runtime Complexity

  • Iterating through a collection using a single for loop => O(n)
  • Iterating through half of a collection using a single for loop => O(n)
  • Iterating through two different collection using separate for loop => O(n + m)
  • Two nested loop iterating over same collection => O(n^2)
  • Two nested loop iterating over different collection => O(n * m)
  • Most of the Sorting Algorithm => O(n * log(n))
  • Searching on a Sorted Collection => O(logn)

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

  • Boolean, Numbers, undefined, null including most of the primitives are constant
  • String takes the amount of character, means the length is its required space. Thus it is O(n)
  • Objects takes the number of keys it has. Thus it is O(n)
  • Arrays are also same. It takes the total number of elements it has(its own length). This it is also O(n)

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

  • Insertion will take O(1)
  • Removal will also take O(1)
  • Accessing anything will also take 0(1)
  • Searching anything will take 0(n)

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

  • Accessing an element by its index number will take O(1)
  • push() and pop() methods also take O(1)
  • But shift() and unshift() will take O(n) as all the element's index number has to be changed in order to remove or add any element from the front
  • Searching will take O(n)

Problem Solving

  • Understand the main problem very clearly at First
  • Try to find out some example, what type and amount of data it will take and also what it will return. Try to understand them.
  • Now breaks them down. How this type of input can give that type of output. Break them out one by one
  • Now solve those problem one by one, simply
  • Now take a look at the solution and try to refactor it maintaining DRY Principal

Problem Solving Pattern

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

  • Frequency Counter
  • Multiple Pointers
  • Sliding Window
  • Divide and Conquer
  • Dynamic Programming
  • Greedy Algorithms
  • Backtracking ...and more to come

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

  • Array
  • Object
  • Stack
  • Queue
  • Linked List
  • Tree
  • Graph
  • Set
  • Hash Table

More Repositories

1

js.zonayed.me

সম্পূর্ণ বাংলায় হাতেকলমে জাভাস্ক্রিপ্ট শিখুন(ওয়েবসাইট রিপো)
JavaScript
329
star
2

zonayed.me

Repo for my personal portfolio website.
JavaScript
80
star
3

DevTop

An essential desktop 🖥️ tool for the developers 👨‍💻. Easy access to the necessary tools 🛠️ like copy-paste 📋 history, gist 👨 💻 manager , short-link 🔗 manager, todos 📝, bookmarks 🔖 and many more to come ⌛, just one click 🖱️ away! Supported in all the major platform. ⬇Download Now
JavaScript
55
star
4

electron-gatsby-boilerplate

Simple Minimal Electron Gatsby Boilerplate. Create new BrowserWindow easily and speed up your development experience. Also included Automatic Linting, Redux, TravisCI Configuration and GitHub Release.
JavaScript
39
star
5

HolyQuranReact

Read Holy Quran, cleaner, simpler and clutter free application. May peace be upon you.
JavaScript
34
star
6

react-mini-blog

See Live Demo Here
JavaScript
32
star
7

old.js.zonayed.me

📖📖📖 Learn Complete JavaScript and Most Useful Techniques 🎉 in Bangla 📖📖📖
JavaScript
30
star
8

react-micro-blog

🛠🛠🛠 A Simple Front-end React Application which Acts as a Complete Blog 🛠🛠🛠
JavaScript
29
star
9

react.zonayed.me

📖📖📖 Learn React JS and Useful Techniques 🎉 in Bangla 📖📖📖
JavaScript
23
star
10

web-workers

Demonstration of the power of Web Worker in the Simplest way. Live demo at:
JavaScript
14
star
11

electron-webview-boilerplate

Quickly turn your Website, Web Application, Webpage into a usable Cross-platform, downloadable Desktop Application. Zero Configuration needed.
CSS
9
star
12

node-movie-pocket

🛠🛠🛠 A Complete Web Application with Login/Register and Database 🛠🛠🛠
HTML
9
star
13

react-native-welcome

Simple way to add interactive user instruction to let your user know about your app before start using it...
JavaScript
9
star
14

nodeMySQLPhonebookClient

The Main Project is Live here:
JavaScript
8
star
15

talk.js

JavaScript
8
star
16

nodeMySQLPhonebook

A Simple Phonebook App with MySQL, Node and Express JS
JavaScript
8
star
17

react-web-workers

Simplest way to include web workers with your React Application and get smoother experience
JavaScript
8
star
18

BengaliPrayerTimings

See Live Demo Here
JavaScript
7
star
19

500Taka-scam-bomber

JavaScript
7
star
20

nasa-rocket-launch

✈✈✈Next Rocket Launch. Live Demo Here:
JavaScript
7
star
21

todo-react-hooks

JavaScript
7
star
22

Basic-Electron-App

JavaScript
5
star
23

ReactPress

Create WordPress Theme using React Only! Demo: { username: 'user', password: 'user' }
PHP
5
star
24

react-starter-pack

JavaScript
5
star
25

css-dark-mode

A Simple React App showing Dark Mode Tricks using CSS only
JavaScript
4
star
26

with-zonayed

JavaScript
4
star
27

ReactToDo

See Live Demo Here
JavaScript
3
star
28

learning-git

3
star
29

react-cart

See Live Demo Here
JavaScript
3
star
30

faithful-muslim-data

3
star
31

next-starter-jamstack

JavaScript
2
star
32

pretty-copy-paste

JavaScript
2
star
33

nextjs-netlify-blog-demo

2
star
34

react-weather-station

The Main Project is Live here:
JavaScript
2
star
35

learnReactWithZonayed

Hands On Tutorial on React JS
2
star
36

gatsbyJSONBlog

🎉🎉🎉 A Simple Blog 🖊 Made from JSON Data with Gatsby 🎉🎉🎉
CSS
2
star
37

my-roadmap

2
star
38

docker-react-app

JavaScript
2
star
39

Project-Based-Learning-JAVA-

Java
2
star
40

old.zonayed.me

JavaScript
2
star
41

banglaCalculator

JavaScript
2
star
42

learnC

C
2
star
43

johnny-five-led-blinking

JavaScript
2
star
44

vue-todo

See Live Demo Here
JavaScript
2
star
45

node-web-server

The Main Project is Live here:
HTML
2
star
46

old.react.zonayed.me

The Main Project is Live here:
JavaScript
2
star
47

learning-git-ntsu

2
star
48

react-project-setup

JavaScript
1
star
49

gtk2-first-gui

C
1
star
50

node-simple-web-server

HTML
1
star
51

johnny-five-keypad-feedback

1
star
52

travis-demo

JavaScript
1
star
53

inTheEndPiano

HTML
1
star
54

Shortcut-Virus-Recovery

Visual Basic
1
star
55

gatsby-starter-netlify-cms

JavaScript
1
star
56

AlgoDS.c

C
1
star
57

node-authentication

The Main Project is Live here:
JavaScript
1
star
58

wasm-hello-world

A Simple Hello World with Web Assembly
JavaScript
1
star
59

learnCPlusPlus

C++
1
star
60

test-merge

1
star
61

gulp-demo

JavaScript
1
star
62

node-basic-express-website

HTML
1
star
63

react-fake-poll

See Live Demo Here
JavaScript
1
star
64

prayerTimeRange

The Main Project is Live here:
JavaScript
1
star
65

zonayedpca

1
star
66

learn-javascript-with-zonayed

JavaScript
1
star
67

reduxSimpleApp

🛠🛠🛠 A Simple App to Demonstrate Redux 🛠🛠🛠
JavaScript
1
star
68

datocms-react-recipes-blog-demo

JavaScript
1
star