Frontend Prep Flashcards

1
Q

What’s the difference between i++ and ++i?

A

i++ returns the value before it’s incremented
++i returns the value after it’s incremented

let num = 1;
console.log(‘value before incremented: ‘,num++); // 1
let num2 = 1;
console.log(‘value after incremented: ‘,++num2); // 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are data structures?

A
  • A way to organize and manage data.
  • They’re a bunch of data values put together that have relationships between them that you can manipulate by applying certain functions and manipulations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is time complexity?

A

A measure of how fast an algorithm runs. It’s expressed using Big O notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s space complexity?

A

A measure of how much auxiliary memory an algorithm takes up. It’s expressed using Big O notation.It’s a measurement of how fast the space taken by a program grows, if the input increases

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How will your program save a memory slot?

A

Your program will save a memory slot or series of memory slots that’s free

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens if you need to save multiple memory slots?

A

If your program needs more than one memory block to store into, it would store it in back to back memory slots

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How’s memory represented?

A

0’s and 1’s (binary)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s considered constant space complexity?

A
variable declarations (ex. let i = 0)
O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s considered linear space complexity (generally)?

A

When we create new arrays. Where the array will take n slots of space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s considered quadratic space complexity (generally)?

A

when pushing to different elements into an array.

ex. const arr = [];
for (let i = 0; i < n; ++i) {
    for (let j = 0; j < n; ++j) {
        arr.push(i + j);
    }
}

Here, i and j are two unique elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s considered an O(log n space complexity)?

A

when you iterate through a series of numbers up to n and increment by multiplying and adding that i value into the array

ex. 
const arr = [];
for (let i = 1; i < n; i *= 2) {
    arr.push(i);
}

Here the array will take (log n) - 1 space

Space complexity: O(log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s the worst case time complexity of inserting into an array?

A

O(n), this is b/c when we insert we need to shift n number of elements over to be able to insert at a given index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s the worst case time complexity of inserting into a linked list?

A

O(1), this is b/c we’re just reassigning the pointers to the element before where we want to insert to the new node and assigning the new node’s next to be the following node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why use bigInt (primitive type)?

A

BigInt gives us the ability to work with large numbers without having to worry about potentially losing precision (digits) or weird representation issues that hamper accuracy and create bugs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does Number and + (unary plus) differ?

A

They both convert strings to numbers, but + is the fastest way of converting a string to a number b/c it doesn’t perform any operations on the value if it’s ALREADY a number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s the DOM?

A

When the HTML loads on the browser, it’s basically like a tree. And we can interact with the nodes on this tree by updating or editing it.