Giter VIP home page Giter VIP logo

guide_to_algorithms's People

Contributors

andyttran avatar brent-leavitt avatar emmaem avatar h3xar0n avatar mikeyao avatar tabithahsia avatar wjin0352 avatar zubair avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

guide_to_algorithms's Issues

found for loop has 14 operations and map method has 9 operations

hello,

  • i am trying to understand the complexity of map method in js.
  • can you tell me which one is better one.
  • since in some of my react code I see people using map method http://jsfiddle.net/jhudson8/135oo6f8/.
  • not sure when to use map method and for loop.
  • I am providing two codes below.
  • using this example I calculated complexity https://github.com/andyttran/guide_to_algorithms#1c-analyze-line-by-line
  • and found for loop has 14 operations and map method has 9 operations.
  • in the coments below I have given value one for e ch operation.
  • can you tell me whether I have done it correctly

for loop

var cars =[
{'toyota' : 'corolla', 'honda' : 'civic'},
{'toyota' : 'corolla1', 'honda' : 'civic1'},
{'toyota' : 'corolla2', 'honda' : 'civic2'},
{'toyota' : 'corolla3', 'honda' : 'civic3'},
];
var names = []; //names = 1, [] = 1
for(var i=0; i< cars.length; i++) { // for = 1 , var i = 1, =0 = 1, < = 1, cars.length = 1, i++ = 1
names.push(cars[i].toyota); //names = 1, push = 1, cars[i] = 1, toyota = 1
}
console.log(names); has an array access and then a printing to the console, so thats 2 operations
total = 14

map method js

var cars =[
{'toyota' : 'corolla', 'honda' : 'civic'},
{'toyota' : 'corolla1', 'honda' : 'civic1'},
{'toyota' : 'corolla2', 'honda' : 'civic2'},
{'toyota' : 'corolla3', 'honda' : 'civic3'},
];

var mapValues = cars.map(function(animal){ //mapvalues = 1, cars = 1, map= 1, function= 1
return animal.toyota; //return = 1, animal = 1, toyota = 1
});
console.log(mapValues); // has an array access and then a printing to the console, so thats 2 operations
total = 9

Time complexity error

In the solution to Problem Set 1 (the very last line of the README) it says:

  1. 300n^5 + 15002^n + 3n // O(n^5)

However doesn't the 15002^n term dominate (similarly to how 2^n dominates n^2)?

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.