In recursive functions, what is the specific programming term for the condition (like if n <= 1:) that prevents the function from calling itself infinitely?
The base case.
In Matplotlib, what visual attribute does passing the string argument 'r' to the plt.plot() function change?
It turns the plotted line red.
In Python, what is the fundamental difference between the = operator and the == operator?
= assigns a value, while == checks for equality.
If you have a DataFrame of fantasy characters, what method allows you to separate them by their "Race" to compute summary statistics like mean height or age?
.groupby()
Under what specific circumstance would a programmer have a strong preference for using a while loop instead of a for loop?
Ex: When prompting a user repeatedly until their input is valid.
Any situation you don't know the number of repetitions.
What is the output of the recursive function mystery(n) when called with mystery(4), given that it returns n if n≤1, and otherwise returns mystery(n-1) + mystery(n-2)?
3
By definition, what constraint makes a set of nodes a valid tree structure?
Each node can have up to one parent.
What is a primary difference between a list and a tuple when it comes to modifying their contents?
Lists are mutable (you can assign to their elements), but tuples are immutable.
What exactly does the command df.iloc[0,:] retrieve from a DataFrame?
The very first row of the DataFrame.
In natural language processing, what is the definition of "tokenization"?
The process of converting text into a sequence of tokens, such as words and punctuation symbols.
Suppose you have a recursive function power(x) that returns 2**x for all positive integers x. If the base case is if x == 0: return 1, what should the recursive return statement be?
power(x-1) * 2
If you run plt.plot(x, y, 'r') where x is [1, 2, ..., 9] and y is the square of x, what is the final y value plotted on the graph?
81.
Why is checking if an item exists inside a large dataset faster if the dataset is a Set rather than a List?
Sets use a hash function, which makes lookup faster than checking each item one by one.
What does the boolean indexing syntax df[df['id'] >= 1000] return?
A DataFrame consisting of all rows where the column "id" is at least 1000.
In machine learning, what is the primary purpose of cross-validation?
To ensure that the model generalizes well to unseen data by evaluating it on different subsets.
Consider a recursive function that takes an integer n as an input. If its base case is written exactly as if n <= 1: return n, what will the function immediately return if it is called with the integer -10?
-10.
Which of these problems is the least suited to applying a graph algorithm: Finding a central person in a social network, pathfinding in a video game, or finding the average value of a list?
Finding the average of a list.
If you have a list containing three strings, L = ['A', 'B', 'C'], and you write a nested loop structure starting with for i in L: and immediately followed inside by for j in L:, how many total combinations will the code execute?
9.
When performing an outer join on two DataFrames based on ID, what does Pandas put in the columns for an ID that exists in the first table but is missing from the second?
NaN (Not a Number).
What does the term "broadcasting" mean in the context of NumPy?
The way NumPy arrays perform arithmetic when the operands have different dimensions.
If you are writing a recursive function designed to process a Python list by passing a slightly smaller version of the list into each recursive call, what is the base case to stop the recursion?
When the list is empty (or has a length of 0).
In Scikit-Learn, the DecisionTreeClassifier object uses a tree-like data structure to categorize data. What is considered a major real-world advantage of using this specific model compared to other complex machine learning algorithms?
It makes explainable decisions.
You have a try block that attempts to divide 5 by 0, which triggers an except block that prints "Something bad happened", followed by a finally block that prints "Done". What is actually printed to the screen?
"Something bad happened", followed by "Done"
Suppose you have a DataFrame df with rows for 'Compound A' and 'Compound B', and columns for 'salinity' and 'acidity'. Which command would throw an error or fail to retrieve the salinity scores: df['salinity'] or df.loc['salinity']?
df.loc['salinity'] would fail because .loc looks for row labels first, not columns.
If you write a function containing a single for loop that searches through an unsorted list L one item at a time to see if an element is greater than a certain value, what is the worst-case run time complexity as the length of the list increases?
O(n) / linear time