w1d5 Flashcards

1
Q

High-level: Binary Search

A

base case:
return nil if empty array

gen case:
probe mid element with probe_index

return index if probe == target

bsearch(left) if target < probe

if target > probe
answer = bsearch(right)

answer.nil? ? nil : probe_index + 1 + answer

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

Why do sorts always take a proc?

A

To control the sort order (and to sort objects by attribute values).

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

How do you move selected text up/down/left/right in Atom?

A

cmd + ctrl + arrows

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

What does cmd + ctrl + arrows do in Atom?

A

moves selected text around

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

Methods that do not reference an instance variable should be written as what type of method?

A

Class method

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

Outline basic 4-step git workflow

A
new file in working dir
git add file
file now in staging
git commit
file now in repo
git push
file now in remote repo
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s a more condensed version of git log?

A

git log –oneline

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

What does git log –oneline do?

A

Shows a more condensed version of the git log

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

What’s a shortcut to create and switch into a new branch?

A

git checkout -b newbranch

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

How to see the diff before merging a branch?

A

git checkout branch

git diff branch-to-merge

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

How do bring a remote repo locally

A

git clone url

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

What are some abstract data types?

7: 5 star
5-6: 4 star
1-4: 1 star

A
set
map
queue
tree
binary tree
ternary tree
nary-tree/polytree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a map ADT?

A

a set of key/value pairs

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

What two ops exist within a Queue ADT?

High-level: how would you implement one?

A

enqueue, dequeue

Array
unshift and pop

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

Elegant way to explain the depth of a tree?

A

Longest path to a leaf node

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

What are two ways to traverse a tree?

A

DFS, BFS

17
Q

What are DFS and BFS for?

A

Traversing a tree

18
Q

High-level: How do you perform a BFS?

A

Add the root to a queue

until the queue is empty, we want to:

  1. shift a node off the queue
  2. process that node
  3. enqueue all of that node’s children into the queue
19
Q

Why would you use BFS over DFS?

A

If you think the result will be found nearer to the top of the tree, BFS will be much faster.

20
Q

If you think the result will be found nearer to the top of the tree, what type of traverse should you use?

A

BFS

21
Q

What 3 things make a decent commit message?

A

present tense capitalized verb
explains the commit
no trailing punctuation

22
Q

What’s wrong with this code:

Class Foo
private
def some_priv_method
end

def initialize
self.some_priv_method
end
end

A

private method cannot be called with an explicit receiver.

instead, use a relative receiver.