CS | Priority Flashcards

(52 cards)

1
Q

What is the relationship between best/worst/expected case and big O/theta/omega?

algorithms big-O

A

Best/worst/expected case describe big O for particular inputs or scenarios. Big O/theta/omega describe the upper/lower/tight bounds for the runtime.

Cracking the Coding Interview 6E p.40

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

When the number of elements gets halved each time, this indicates big O of what?

algorithms big-O

A

O(log N)

Cracking the Coding Interview 6E p.44

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

When you have a recursive algorithm with multiple calls, what is the big O likely to be?

algorithms big-O

A

O(branches^depth). E.g. O(2^N).

Cracking the Coding Interview 6E p.45

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

Big O describes the __ __ . Draw a graph to depict this for some of the common big O times.

algorithms big-O

A

Rate of increase. (See source material.)

Cracking the Coding Interview 6E p.41-42

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

When do you add runtimes (simple phrase)? When do you multiply runtimes (simple phrase)?

algorithms big-O

A

Add: If your algorithm is in the form, “do this, then, when you’re all done, do that”. Multiply: If your algorithm is in the form, “do this for each time you do that”.

Cracking the Coding Interview 6E p.43

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

Steps of the problem-solving flowchart.

A

(See source material.) Listen: write the unique information down. Example: Draw a specific, large enough, not special case example. Brute force. Optimize with BUD; unused info, manually on an example, solve it incorrectly, make time vs space tradeoff, precompute. Walk-through. Implement: modularized, error checks, classes, var names. Test: conceptual, weird code, hot spots, small test cases, special cases.

Cracking the Coding Interview 6E p.62

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

What are 5 optimize and solve techniques?

A

BUD; DIY; simplify and generalize; base case and build; data structure brainstorm.

Cracking the Coding Interview 6E p. 67-72

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

What is great way to figure out the runtime of a recursive algorithm?

A

Draw the recursive calls as a tree.

Cracking the Coding Interview 6E p. 132

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

When you see an algorithm with multiple recursive calls, what is the likely runtime?

Cracking the Coding Interview 6E p. 53

A

exponential

Cracking the Coding Interview 6E p. 53

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

What is the ordering property of a binary search tree?

Cracking the Coding Interview 6E p. 101

A

all left descendants <= n < all right descendants

Cracking the Coding Interview 6E p. 101

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

Can a binary search tree have duplicates?

Cracking the Coding Interview 6E p. 101

A

Clarify with the interviewer.

Cracking the Coding Interview 6E p. 101

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

Does balancing a tree mean that the left and right subtrees are the same size?

Cracking the Coding Interview 6E p. 101

A

No.

Cracking the Coding Interview 6E p. 101

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

What is a complete binary tree?

Cracking the Coding Interview 6E p. 102

A

Every level of the tree is fully filled except perhaps the last one, which is filled left to right.

Cracking the Coding Interview 6E p. 102

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

What is a full binary tree?

Cracking the Coding Interview 6E p. 102

A

Every node has either 0 or 2 children.

Cracking the Coding Interview 6E p. 102

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

What is a perfect binary tree? Should you assume a binary tree is perfect?

Cracking the Coding Interview 6E p. 102

A

Both full and complete. No.

Cracking the Coding Interview 6E p. 102

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

What is a min-heap?

Cracking the Coding Interview 6E p. 103

A

Complete binary tree where each node is smaller than its children.

Cracking the Coding Interview 6E p. 103

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

Basic idea of insertion into a min heap. Time complexity?

Cracking the Coding Interview 6E p. 104

A

Bottom, rightmost; bubble up. O(log n).

Cracking the Coding Interview 6E p. 104

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

Basic idea of extracting min element from a min-heap?

Cracking the Coding Interview 6E p. 104

A

Remove root; swap root with last element; bubble down.

Cracking the Coding Interview 6E p. 104

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

Runtime of a prefix check in a trie?

Cracking the Coding Interview 6E p. 105

A

O(K) where K is the length of the string

Cracking the Coding Interview 6E p. 105

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

If a problem involves a list of valid words, or searching on related prefixes repeatedly, use a ?

Cracking the Coding Interview 6E p. 105

A

Trie.

Cracking the Coding Interview 6E p. 105

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

If you want to visit each node in a graph, what method is simplest?

Cracking the Coding Interview 6E p. 107

A

DFS.

Cracking the Coding Interview 6E p. 107

22
Q

If you want to find the shortest path in a graph, what method is preferred?

Cracking the Coding Interview 6E p. 107

A

BFS.

Cracking the Coding Interview 6E p. 107

23
Q

What is the preferred method to find the shortest path between a source and destination node?

Cracking the Coding Interview 6E p. 108

A

Bidirectional search.

Cracking the Coding Interview 6E p. 108

24
Q

How are stacks sometimes used in recursive algorithms?

Cracking the Coding Interview 6E p. 97

A

To push temporary data, then remove as you backtrack (e.g. if recursive check fails).

Cracking the Coding Interview 6E p. 97

25
What part of a queue implementation is easy to mess up? ## Footnote Cracking the Coding Interview 6E p. 98
Updating the first and last nodes. ## Footnote Cracking the Coding Interview 6E p. 98
26
What situations are queues used for? ## Footnote Cracking the Coding Interview 6E p. 98
BFS or cache. ## Footnote Cracking the Coding Interview 6E p. 98
27
What is a denormalized database? ## Footnote Cracking the Coding Interview 6E p169
(See source material.) ## Footnote Cracking the Coding Interview 6E p169
28
What are examples of problems heaps / priority queues can help solve?
scheduling periodic tasks and merging log files; top/bottom; best/worst; min/max; optimal; paths ## Footnote [Source](https://realpython.com/python-heapq-module/)
29
In the context of OO design for a game piece, what is a lesson to keep in mind?
Discuss if a Piece class should be subclassed or keep state composed with it. ## Footnote Cracking the Coding Interview 6E Chapter 7 p325
30
In the context of OO design for a game with a board, what is a lesson to keep in mind?
Discuss if Board and Game classes should be separate. ## Footnote Cracking the Coding Interview 6E Chapter 7 p325
31
In the context of OO design for a game, what is a lesson to keep in mind about the score?
Discuss which class should keep the score. ## Footnote Cracking the Coding Interview 6E Chapter 7 p325
32
In the context of OO design for a game, what is a lesson to keep in mind about how to treat the Game class?
Discuss if the game should be a singleton. ## Footnote Cracking the Coding Interview 6E Chapter 7 p325
33
In the context of OO design for a game, what is a lesson about what concepts need objects?
Objects for abstract concepts like Hand in a card game. ## Footnote Cracking the Coding Interview 6E Chapter 7
34
In the context of OO design for a game, what is a lesson about how to get user input?
Function to get user input. ## Footnote Cracking the Coding Interview 6E Chapter 7
35
In the context of OO design for a game, what is a lesson about representing enumerations?
Enum class for any enumeration. ## Footnote Cracking the Coding Interview 6E Chapter 7
36
In the context of OO design for a game, what is a lesson about collections of objects?
Are there any collections of objects that will be used as an exhaustible resource? E.g. deck of cards. If, so both the collection and the objects need to keep state about the objects' availability. E.g. deck tracks number of cards used, card tracks if available. ## Footnote Cracking the Coding Interview 6E Chapter 7
37
In the context of OO design for a game, what is a lesson about abstraction for related objects?
When objects have different state/behaviors, as an optimization, consider abstraction to create a small hierarchy of objects. E.g. Card, BlackjackCard; Hand, BlackjackHand. Can represent complicated logic about specific types of cards, e.g. Ace, without creating objects for individual types of cards. ## Footnote Cracking the Coding Interview 6E Chapter 7
38
In the context of OO design for a game, what is a lesson about types of abstraction for behaviors?
When using abstraction, consider abstract adjectives describing behaviors. E.g. Movable, Drawable. ## Footnote Cracking the Coding Interview 6E Chapter 7
39
In the context of OO design for a game, what is a lesson about how to run the game?
For a game, conside an Automator class with high-level methods to run the game, e.g. dealInitial(), playAllHands(). https://github.com/careercup/CtCI-6th-Edition/blob/master/Java/Ch%2007.%20Object-Oriented%20Design/Q7_01_Deck_of_Cards/BlackJackGameAutomator.java ## Footnote Cracking the Coding Interview 6E Chapter 7
40
In the context of OO design for a game, what is a lesson about how to set up the game initially?
Do high-level methods to initialize data structures. ## Footnote Cracking the Coding Interview 6E Chapter 7
41
In the context of OO design for a game, what is a lesson about how to run a game with an exhaustible resource like cards?
For a game with an exhaustible resource like cards, to run the game, can use functions that return booleans: false is returned when the cards are exhausted. ## Footnote Cracking the Coding Interview 6E Chapter 7
42
8 tips for handling system design questions.
(See source material.) ## Footnote Cracking the Coding Interview 6E Chapter 9 p137
43
5 steps for system design questions.
(See source material.) ## Footnote Cracking the Coding Interview 6E Chapter 9 p138
44
4 steps for scalability in system design questions.
(See source material.) ## Footnote Cracking the Coding Interview 6E Chapter 9 p139
45
Define horizontal and vertical scaling.
## Footnote Cracking the Coding Interview 6E Chapter 9 p140
46
3 ways of doing data partitioning.
(See source material.) ## Footnote Cracking the Coding Interview 6E Chapter 9 p141
47
3 important networking metrics.
bandwidth, throughput, latency ## Footnote Cracking the Coding Interview 6E Chapter 9 p141
48
4 main considerations.
failures, availability and reliability, read-heavy vs. write-heavy, security ## Footnote Cracking the Coding Interview 6E Chapter 9 p142
49
Find kth largest element: What is the runtime for a heap-based algorithm? For a quick-select-based algorithm? ## Footnote LC/NC https://www.youtube.com/watch?v=XEmy13g1Qxc&ab_channel=NeetCode
O(N+klogN). O(N) in average case (O(N^2) in worst case).
50
Powers of 2 up through 2^9. ## Footnote Cracking the Coding Interview 6E p.61
4=16, 5=32, 6=64, 7=128, 8=256, 9=512
51
What are the exact values / approximate values / approximation of those bytes to MB, GB, etc.? 2¹⁰ 2²⁰ 2³⁰ 2⁴⁰ ## Footnote Cracking the Coding Interview 6E p.61
"2¹⁰ = 1024 ≈ 1 thousand ≈ 1K 2²⁰ = 1,048,576 ≈ 1 million ≈ 1MB 2³⁰ = 1,073,741,824 ≈ 1 billion ≈ 1GB 2⁴⁰ = 1,099,511,627,776 ≈ 1 trillion ≈ 1TB"
52
What are the exact values / approximate values / approximation of those bytes to MB, GB, etc.? 2^16 2^32 ## Footnote Cracking the Coding Interview 6E p.61
"2¹⁶ = 65,536 ≈ 64K 2³² = 4,294,967,296 ≈ 4GB"