w1d5 Flashcards
High-level: Binary Search
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
Why do sorts always take a proc?
To control the sort order (and to sort objects by attribute values).
How do you move selected text up/down/left/right in Atom?
cmd + ctrl + arrows
What does cmd + ctrl + arrows do in Atom?
moves selected text around
Methods that do not reference an instance variable should be written as what type of method?
Class method
Outline basic 4-step git workflow
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
What’s a more condensed version of git log?
git log –oneline
What does git log –oneline do?
Shows a more condensed version of the git log
What’s a shortcut to create and switch into a new branch?
git checkout -b newbranch
How to see the diff before merging a branch?
git checkout branch
git diff branch-to-merge
How do bring a remote repo locally
git clone url
What are some abstract data types?
7: 5 star
5-6: 4 star
1-4: 1 star
set map queue tree binary tree ternary tree nary-tree/polytree
What is a map ADT?
a set of key/value pairs
What two ops exist within a Queue ADT?
High-level: how would you implement one?
enqueue, dequeue
Array
unshift and pop
Elegant way to explain the depth of a tree?
Longest path to a leaf node
What are two ways to traverse a tree?
DFS, BFS
What are DFS and BFS for?
Traversing a tree
High-level: How do you perform a BFS?
Add the root to a queue
until the queue is empty, we want to:
- shift a node off the queue
- process that node
- enqueue all of that node’s children into the queue
Why would you use BFS over DFS?
If you think the result will be found nearer to the top of the tree, BFS will be much faster.
If you think the result will be found nearer to the top of the tree, what type of traverse should you use?
BFS
What 3 things make a decent commit message?
present tense capitalized verb
explains the commit
no trailing punctuation
What’s wrong with this code:
Class Foo
private
def some_priv_method
end
def initialize
self.some_priv_method
end
end
private method cannot be called with an explicit receiver.
instead, use a relative receiver.