I have the memoization fibonacci code and I am having trouble figuring out what the time complexity is of it:  function fibMemo(index, cache) {   cache = cache || [];   if (cache[index]) return cache[index];   else {     if (index < 3) return 1;...
I am having trouble understanding how the following solution is O(1) space and not O(n) space.  The coding challenge is as follows:  Write a solution that only iterates over the string once and uses O(1) additional memory, since this is what you woul...
In modern, v8 Javascript, what is the algorithmic complexity of String.prototype.slice?  To be clear, I'm looking for real-world, practical figures or rules of thumb.  Quick Tests  I tried to get a rough estimate by running two quick tests in the...
I'm trying to better understand how the space and time complexity of reading and writing values changes as the number of entries in an object grows....
I'm using _.uniqWith in Lodash to remove duplicate objects from an array of ~6,000 objects:  let uniqColors = _.uniqWith(colorCollection, _.isEqual);   Where a sample object in the array looks like:  {   r: 122,   g: 44,   b: 216 }   It takes abo...
I am trying to determine the time complexity for the following function.  The function reverses the order of words in a string and then reverses the order of letters in a word.  For example:  “the sky is blue” => “eulb si yks eht”  var rev...
What is the time complexity of Map.prototype.get if properties of map are objects?  const o1 = {v: 1}; const o2 = {v: 2}; const m = new Map();  m.set(o1, 'o1'); m.set(o2, 'o2');  m.get(o1) // Time complexity O(1)? m.get(o2) // Time co...
So let's say I had a program that looked like this:  var foo = 10;  for(var i = 0; i < foo; i++){     console.log('first loop'); }  for(var j = 0 j < foo; j++){     console.log('second loop'); }   Now, from what I understand...
Here I have two solutions to find if a srting is a Palindrome. The first one uses Recursion and the second one uses for loop. I am little confused how my code with Recursion would perform vs. the code without recursion. Does the code with Recursion r...
Update:    - Wikipedia says o(n) not O(n) so this algorithm isn't an in-place solution.   - Debating whether this solution runs in O(n) or O(1).   This is my solution for LeetCode question Flatten Binary Tree to Linked List. In terms of time a...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.