• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/116

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

116 Cards in this Set

  • Front
  • Back
What is a data structure?
A data structure is a way of organzing data in a computer so it can be used effectively to retrieve data. It consists out of a pointer and a data record.
What is a stack?
Data structure where elements are ordered by insertion order. Can only be removed and added to the top. Analogy: Stack of books. Ex: Undo button
What is a queue?
Data structure where elements are ordered by insertion order. Can only be removed from the front and added to the back. Analogy: Line in theater. Ex: Printer
What's the difference between a stack and a queue?
The point which can be added upon (queue = back and stack = top) and the point from which can be taken from (queue = front and stack = top)
What's the best way to implement stacks and queues in Ruby?
Use an array and limit yourself to the required behavior. Using push / pop gives LIFO(last in first out) behavior (stack), while using push / shift gives FIFO behavior (queue)
Why bother having many different search algorithms?
It can make a big difference in performance depending on the dataset you’re using.
What is breadth-first-search (BFS)?
A way of navigating a dataset (tree) by level first

What is depth-first-search (DFS)? And which types can you use?

A way of navigating a dataset (tree) by traversing the nodes and their respective children first. Data,left,right (preorder). Left,data,right (inorder). Left,right,data (postorder)

What situations would you want to use BFS?
If the tree is very deep and search nodes are rare. depth first search (DFS) might take an extremely long time. If you know a search node is not far from the root of the tree, a breadth first search (BFS) might be better. (get oldest deceased people from family tree & friend suggestions in facebook)
What situations would you want to use DFS instead?
If the tree is very wide, a BFS might need too much memory, so it might be completely impractical. (youngest still alive person from family tree).
When would BFS be impractical?
If nodes are frequent but located deep in the tree, BFS could be impractical.
What is recursion?
Recursion is the idea that a function calls itself. Pretty simple, right? It's used to take a big problem and start breaking it down into smaller and smaller pieces ("Divide and Conquer") and continuing to feed their solutions back into the original function until some sort of answer is achieved and the whole chain unwinds.
What are the limitations of using recursive solutions?
It uses overall more memory than looping since each recursion copies the result of the previous calculation.
What types of problems are more suited for simple loops than recursion?
Generally speaking, All. Loops may achieve a performance gain for your program. Recursion may achieve a performance gain for your programmer since the code is shorter and ‘cleaner’.
What is meant by "recursive depth?"
The distance from the required solution compared to the end case.
What is a "stack overflow”?
A process going outside of the allotted memory to the task.

Why is 'stack overflow' relevant to a recursive problem?

Recursion without end case cause infinite loops, which drains memory really quickly.

What is an algorithm?
A set of consecutive instructions to reach a predefined outcome. Commonly used in sorting and searching data. Ex: pathfinding, querying,
What is pseudo-code?
Written down steps which logically depict the coding steps in human language. Ex: “Let grandma ask for the time until you shout in all caps”

How do you issue an HTTP request in Ruby?

What is REST
Represential state transfer is used to map http actions (get, post, patch and delete) to database actions (create, read, update, delete)
What's the difference between a GET and a POST request?
A get request asks for a file from the server whilst a post request tries to modify/create a file on the server

How do you create, read, update and delete normal files from your computer as a ruby object (and csv’s) and how do you make new files/change/make directories?

Why do we serialize data?
Saving any file as flat data so it can be transferred over the internet.
What is JSON?
JSON (JavaScript Object Notation) is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML.
What is YAML?
YAML is a flexible, human readable file format that is ideal for storing object trees. YAML stands for “YAML Ain't Markup Language”. It is easier to read (by humans) than JSON, and can contain richer meta data. It is far nicer than XML

How do you turn a Ruby object into JSON and back? Difference between generate/to_json/pretty_generate?

to_json accepts also non-json objects whilst generate is more strict. Pretty print includes newlines to debug in the command line

What is an implicit return?
The last evaluation of a function is automatically returned

What is a class and what is an instance?

A class is an object “mold” for creating similar instances of the class. They predefine the similar functionality and starting variables. An instance is an object based on the class type. Example: Post class and post1 = Post.create(title: “title”, author: “simon”). Like the mold of a sword and a cast

When should you use a class?
A class should be used when objects need to be instantiated. If it’s just stand-alone functionality, you should use a module.

How do you create a class in your script file and what should happen in the initialize method?

What is a class method and how does it differ from an instance method?
A class method is a function which is called on the class itself (ex: self.all = Post.all). An instance method is called on the instance of the class (post1.change_title(“title”)

What are the four types of variables in ruby?

What are "getter" and "setter" methods used for?
It means some instance variables can be read and set after instantiation with attr_accessor, attr_reader and attr_writer.

How does inheritance work?

Allows to inherit functionality and variables. class Dog < Animal

Why is inheritance really useful?
It allows DRY and create different objects with similar functionality and properties without re-writing everything.

How do you require, include and extend a module? How do you extend a class? What does that mean?

What does #super do?

returns the output of the inherited class method

What is a "boolean"?
true or false operator
What are "truthy" values?
values that evaluate to true
Are nil, 0, "0", "", 1, [], {} and -1 considered true or false?
Only nil and false are evaluated to false in ruby

When do you use unless?

When you want the code to run only if the condition evaluates to false

What does <=> do?
It compares the first value with the second. It return 0 if equal and 1 if the first one is greater and -1 if the first one is smaller.
What do || and && and ! do?
Or, and & not
What is returned by puts("woah") || true?
“woah” Only the first parts gets evaluated in an OR statement. If this returns true, the second isn’t checked.
What is ||=?
Conditional assignment. It’ll only evaluate the function if the assigned element doesn’t already exist
What is the ternary operator?
Shorthand version of an if-else statement (condition ? Case if true : case if false)
When should you use a case statement?
When you have multiple, nested if-else statements

What does loop, while, for, each and times do?

A for x in @collection is the same as an each loop, but the last x variable persists after the loop. A loop do is the same as while(true). Used when unsure how long it will last but clear when it should end

How do you stop a loop?
break or exit
How do you skip to the next iteration of a loop?
next
How would you start the loop over again?
retry restarts the entire loop. Redo restarts the current loop.

What is a block, proc, lambda and what does yield do. How do you call a proc (2 ways)?

What does #each do?
Executes code for each element in argument. Returns one element each iteration.
What does #map do?
Returns an array where code has been executed for each element in argument.
What is the difference between #map and #collect?
None
What does #select do?
Returns an array for each element in argument which matches criteria.

What does #inject do?

Adds element to index. arr = [a,b,c] arr.inject(1, q). Inserts q at index 1.

What does #shift (n) do?
Removes first n elements from collection and returns it.
What does #pop(n) do?
Removes last n elements from collection and returns is.
what does #divmod do?
Returns quotient and modulus 8.divmod(3) => [2,2]
What does #join(separator) do?
Returns a string created by converting each element of the array to a string, separated by the given separator
What does #split(pattern) do?
Divides str into substrings based on a pattern, returning an array of these substrings. If pattern is a String, then its contents are used as the delimiter when splitting str. If pattern is a single space, str is split on whitespace, with leading whitespace and runs of contiguous whitespace characters ignored.
What does .include? Do?
check if array includes a value.
What does #index do?
arr.index(“simon”) => returns index of element in array

what does #send do?

send sends a message to an object instance and its ancestors in class hierarchy until some method reacts (because its name matches the first argument). Ex: 1.send('+') 2 => 3

How do you check if every item, at least one or no item in a collection fulfills a certain criteria?
collection.all?{|k,v| code } , any? and none?. Returns true or false.
What does require do?
Adds functionality from module, class or library to current code. Loads only once.
What does load do?
Same thing as require but is loaded in every time load is called.
What's the difference between an Integer and a Float?
Numbers after the comma. Dot notation converts integers into floats. 1.0 + 2 = 3.0.
What's the difference between =, ==, and ===?
Assignment, comparison and comparison with type.
How do you do exponents in Ruby?
3**2
What is a range?
an interval between two values

How do you create a range (2 ways)? And what is the difference between .. and ...

[1..10].to_a includes 10, [1...10].to_a excludes 10, [“a”..”z”].to_a, 1.upto(10), 10.downto(1).to_a

What is string interpolation?
Evaluating a variable inside a string #{variables}
What are escape characters?

(newline), \t (horizontal tab)
How do you concatenate strings?
“simon” + “ is cool” or “simon” << “ is cool”
How are strings and arrays similar?
They are both objects and can be accessed like string[0..3]
What is a symbol?
A pointer which is used as a record locator for a value/object. This saves memory since it’s only created once and stays the same. Mystring = :symbol

What is a Regular Expression (RegEx). How do I select (all) numbers, characters, certain types, do exclusions, use ranges of letters/numbers, one character multiple times, several characters multiple times with range?

a sequence of symbols and characters expressing a string or pattern to be searched for within a longer piece of text. "test123"[/\d+/] => 123.

What are three ways to create an array?
arr = Array.new(0), arr = [], arr = %w(1 2 3)
How do you combine arrays (3 ways)?
array1 + array2, array1.push(array2), array1 << array2
How do you find the values in one array that aren't in another?
array1 - array2
How do you find values in both arrays?
Use the intersection operator &. x = [1, 2, 4] y = [5, 2, 4] x & y # => [2, 4]
What is the difference between push/pop and shift/unshift?
Push/pop adds/removes to back and shift/unshift removes/adds to front.
How is pushing or shoveling another array into your array different from just adding them together?
The shovel only accepts 1 element.
How do you delete items in an array (two methods)?
arr.delete(8) or arr - [8]
How do you find the biggest/smallest item in an array?
arr.minmax
How do you remove any duplicates from your array?
arr.uniq!
How do you find out how big an array is?
.length / .size / .count
How do you put an array in order?
.sort!
What is a hash?
A Hash is a collection of key-value pairs like this: "employee" => "salary". It is similar to an Array, except that indexing is done via arbitrary keys of any object type, not an integer index. hash[“employee”] => “salary”
What are keys and values?
keys are the pointers which point to the values in the hash.
How is a hash similar to an Array?
It’s also a collection of different object types
How is a hash different from an Array?
indexing is done via arbitrary keys of any object type, not an integer index.

What are 2 ways to create a hash?

hash = Hash.new, hash = {}

What is the hash rocket?
The equals and greater than sign which connects the key to the value.
How do you access data in a hash?
hash[“employee”] => “salary”
How do you change data in a hash?
hash[“employee”] = “salary”
What are options hashes, splat arguments and double splat arguments?
Options hashes are used a lot when need to pass optional arguments to method. function(arg, options={}), these can also be writtes as function(arg, **options) and passed in as function(1, a: “this”, b: “second”}. function(arg, *other) returns an array of other arguments.
How do you delete data from a hash?
hash.delete(key)
How do you add hashes together?
hash.merge(secondhash)
How do you list out all the keys or values?
hash.keys OR hash.values
How do you see if the hash contains a key or value?
hash.has_value?(value_you_seek) OR hash.key(key)
How do you get the current date and time, Year? Month? Hour? Second? Weekday?
require “time” and type Time.now (.second, .hour, .year, .month)
How do you create a Time specifically for 12/25/2013?
Time.mktime( year, month, day, hour, min, sec, usec )
How do you find how many days have passed between two Time's?
Time1 - Time2
How would you find out the time that was 100 seconds ago? 10 days ago?
Time.now – 60*60*24*10 (s*m*h*days)
How do you check if something is nil?
.nil?

What's the difference between nil and blank and empty?

Only nil is nil, empty? is a standard Ruby method on some objects like Arrays, Hashes and Strings. Its exact behaviour will depend on the specific object, but typically it returns true if the object contains no elements. Blank is rails only method

What's the difference between puts and p and print?
print executes to_s on object, puts does the same but adds newline and p calls inspect instead of to_s but also includes newline
What do +=, -=, *= and /= do?
return variable after calculation is done.
What is parallel assignment?
Multiple assignment. A,b = 1, 2 or a, b, c, d = 1
What's the easiest way to swap two variables?
x,y = y, x
What’s a linked list?
A linked list is a linear data structure where each node has a value and pointer to the next node. The last node point to nil.
What are trees? (tree, binary tree, binary search tree, red-black tree)
a group of data items and turn them into a tree full of nodes where each left node is "lower" than each right node. The tree starts with the "root node" and any node with no children is called a "leaf node".