RANDOM 1
RANDOM 2
RANDOM 3
RANDOM 4
RANDOM 5
100

merge sort and a binary search are what types of algorithms?

divide-and-conquer algorithms

100

explain the purpose of the special attribute __slots__?

limits the class states

100

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

100

What is the main difference between tuples and lists?

tuples are immutable while lists are mutable

100

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.

200

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()

200

what makes dictionaries and sets unique data structures?

constant lookup time

200

name a major difference between arrays and lists.

arrays have a fixed length while lists are dynamic

200

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?

200

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)

300

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.

300

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)

300

DOUBLE POINTS

What are the characteristics of a good hash function?

300

Name one difference between a stack and queue.

Stack is LIFO / FILO. Queue is FIFO / LILO.

300

explain the difference between shallow and deep equality

deep = compares content

shallow = memory location / reference type

400

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.

400

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]

400

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


400

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.

400

Name the algorithm


Linear Search Algorithm

500

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.

500


False

500

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.

500

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.

500

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