Week 5 Test Flashcards
what is complexity analysis?
reading code and determining the rate of growth through analysis instead of manually testing the code
what is big o notation used for
to express complexity analysis
what is Big o’s main concern
the general shape of the growth curve when a function is passed in a large value
why is big O not concerned with small values?
computers are so fast that even inefficient code returns almost immediately for a small number
what is the correlation between code beginning to behaving slowly and the steep of efficiency curve
the steeper the code, the faster the performance will degrade
what does it mean for a function to have constant growth
the runtime remains constant whether the input os large or small
what does space complexity describe?
how much memory the function requires
what are the space and time complexities of arr.push
time: 1*
space: 1*
requires no shifting and happens in place
what are the space and time complexities of arr.pop
Time: 1
space: 1
requires no shifting and happens in place
what are the space and time complexities of arr.shift
time: n
space: 1
requires all elements shift to the left by one, but happens in place
what are the space and time complexities of arr.unshift
time: n
space: 1
requires all elements shift to the right by one, but happens in place
what are the space and time complexities of arr.splice
time: n
space: n*
requires shifting to fill empty spaces and returns an array possibly of unknown length
what are the space and time complexities of slice
time: n
space: n
ceates a copy of the old array with some of all elements slice out; the values sliced have to be copied individually
what are the space and time complexities of arr.indexOf
time: n
space: 1
this will search and visit each node and the worst case is that the elemt is at the end of the array or not present at all, no space required
what are the space and time complexities of arr.map
time: n
space: n
creates a new array with some function applied to each element this is with the assumption that the cb is O(1)