Giter Site home page Giter Site logo

javascript-datastructures-and-algorithms's Introduction

Data Structures and Algorithms in JavaScript

Implementing Data Structres and Algorithms in JavaScript โญ

Table Of Contents


Big O

It is a standard measure to check how efficient our code or algorithm is. In other words it is used to determine the efficiency of an algorithm, to understand Big O more clearly you must be familiar with Time Complexity

Time Complexity

Time Complexity is nothing but the amount of time taken by a function/algorithm to complete it's task.

O(n)

O(n), it means that as the number of inputs grow, the number of operation also increases. Hence, it is a linear process.

For example. if we are looping over an array of say n integers

let n = 5;
const inputArray = new Array(n).fill('hello');
for ( let i=0; i < inputArray.length; i++){
    console.log(inputArray[i]);
}

console.log(inputArray);

if n is say a very large number then it would take a lot more time. Because the number of inputs has grown. Therefore it will take O(n) time to complete those operetions depending on the value of n

O(1)

O(1) denotes that the number of operations will remain the same even if the number of inputs grows. Hence, it is constant time.

For example, we are asked to print the first value of an array of size n

let n;
const largeArray = new Array(n).fill(200);
console.log(largeArray[0]);

since we are printing the 1st value of the array it is always doing a single operation, regardless the size of our input size.

javascript-datastructures-and-algorithms's People

Contributors

ayushbali avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.