Alg Qs Flashcards
1
Q
Fastest way to sum up number 1 to n
A
n * ( n + 1 ) / 2
2
Q
Sum for the first n terms in an arithmetic series
A
n(a1 * a2) / 2 where a1 is the starting number and a2 is the finishing number
3
Q
What is a JavaScript object?
A
A JS object is a collection of properties, where a property consists of a key value pair. The value can be data or a function.
4
Q
When to use objects?
A
When order doesn’t matter.
When you need fast access /insertion / removal
Constant time O(n) for access, insertion, and removal
5
Q
What is the Big O of searching an object?
A
O(N)
6
Q
What is the Big O of getting an array of entries, keys or values?
A
O(N)
7
Q
What is the Big O of checking if a property exists?
A
O(1)