merge sort and a binary search are what types of algorithms?
divide-and-conquer algorithms
explain the purpose of the special attribute __slots__?
limits the class states
provide a list operation that is constant time and linear time.
constant = pop(end) or insert(end+1)
linear = creating a new list or concatenating
What is the main difference between tuples and lists?
tuples are immutable while lists are mutable
Explain how Dictionaries are different from Sets.
Explain how Sets are different from Lists.
Dictionaries map a key to a particular value while Sets simply holds elements.
Sets guarantee all elements are unique, while Lists cannot guarantee this.
how would you go about converting a string to an interger?
can all integers be strings? can all strings be integers?
casting int() str() float()
what makes dictionaries and sets unique data structures?
constant lookup time
name a major difference between arrays and lists.
arrays have a fixed length while lists are dynamic
given an array with a fixed length of 10, where every index has an element, how will you go about adding a new element to the array without creating a new one? is it possible? why or why not?
you can't lol
what will you go about changing the value of an index?
if we are given an unsorted array, should we perform a linear search or a combination of binary search and insertion sort?
linear search - O(n)
binary + insertion = O(n2 + logn)
define ranges(start, stop, k)
does ranges(5) == ranges(1,5)?
list of numbers, which start at 0 if not specified and end at stop-1. k equals the steps that the range should take.
they do not equal.
if you append an element to the middle of a list, with length k, what will be its time complexity?
what about appending to the end?
What about appending to the start?
O(n)
O(c)
O(n)
DOUBLE POINTS
What are the characteristics of a good hash function?
Name one difference between a stack and queue.
Stack is LIFO / FILO. Queue is FIFO / LILO.
explain the difference between shallow and deep equality
deep = compares content
shallow = memory location / reference type
What algorithm performs better in a worst-case scenario, Quick Sort or Merge Sort?
Merge Sort because the time complexity remains O(nlogn) throughout all cases. Quick Sort becomes O(n^2) if the array is sorted or in reverse order.
What does it mean for a data structure to be heterogeneous?
provide an example of a heterogenous data structure.
It can hold any/all types.
Example: ["a", 1, 4.0]
if a function takes in a list as an argument and modifies it by adding one to every element, does the list have to be returned? why or why not?
the list was passed by reference, so no it does not need be returned
what is the purpose of handling exceptions?
If a runtime error occurs while executing a python program, we would want to handle the exception to ensure the program does not crash.
Name the algorithm
Linear Search Algorithm
Explain the quick sort algorithm.
Recursively obtain the pivot (index zero) and create three distinct arrays (less_than, equal, more_than).
Once everything is a pivot, it is sorted. Simply concatenate/add to an array.
False
Explain the concept of encapsulation
The idea of putting everything associated with an object in one place. For example, a rank, suit, name and short_name will be attributes for the Card class.
In what ways does a collision influence a hash function?
It maps two distinct inputs to the same output (hash code).
The time complexity can increase to O(n) when too many elements map to the key.
Name three special methods for python classes.
__init__
__str__ | __repr__ - string representation of object
__eq__ | __ne__ - equality and inequality
__lt__ | __le__ | __gt__ | __ge__ - relational operators