How would you optimize a Python function that is found to be CPU-bound during profiling?

  • a) Use a Just-In-Time (JIT) compiler like PyPy.
  • b) Increase the number of threads to parallelize the code.
  • c) Optimize the algorithm or use data structures that are more efficient.
  • d) Use a faster computer for running the code.
When a Python function is CPU-bound, the most effective optimization is usually to optimize the algorithm or use more efficient data structures. JIT compilation (a) can help in some cases, but it may not be as effective as algorithmic improvements. Increasing the number of threads (b) might help if the code can be parallelized, but this is not always the case. Using a faster computer (d) is generally not a solution to CPU-bound code as it doesn't address the underlying inefficiencies.

If multiple base classes have methods with the same name, method resolution in a derived class follows the _______ rule.

  • FIFO (First In, First Out)
  • LIFO (Last In, First Out)
  • LOO (Last Out, Out)
  • MRO (Method Resolution Order)
In Python, when multiple base classes have methods with the same name, the method resolution follows the Method Resolution Order (MRO) to determine which method to call.

How would you optimize the performance of a deep learning model in TensorFlow or PyTorch during the inference stage?

  • A. Quantization
  • B. Data Augmentation
  • C. Gradient Clipping
  • D. Model Initialization
Option A, Quantization, is a common optimization technique during the inference stage. It involves reducing the precision of model weights and activations, leading to smaller memory usage and faster inference. Option B, Data Augmentation, is typically used during training, not inference. Option C, Gradient Clipping, is a training technique to prevent exploding gradients. Option D, Model Initialization, is essential for training but less relevant during inference.

How would you optimize the performance of a RESTful API that serves large datasets?

  • A. Use HTTP GET for all requests
  • B. Implement pagination and filtering
  • C. Remove all error handling for faster processing
  • D. Use a single, monolithic server
B. Implementing pagination and filtering allows clients to request only the data they need, reducing the load on the server and improving performance. Options A, C, and D are not recommended practices and can lead to performance issues.

How would you implement a dequeue (double-ended queue) data structure?

  • Array
  • Linked List
  • Queue
  • Stack
A dequeue can be efficiently implemented using a doubly linked list, where you can add or remove elements from both ends in constant time. While arrays are also used, they may not provide the same level of efficiency for both ends' operations.

In NumPy, the ____ function is used to compute the inverse of a matrix.

  • np.inverse()
  • np.invert()
  • np.linalg.inv()
  • np.transpose()
In NumPy, the np.linalg.inv() function is used to compute the inverse of a matrix. This function is essential for various linear algebra operations in NumPy, such as solving linear equations.

In object-oriented programming in Python, ____ refers to the class that a class inherits from.

  • base class
  • parent class
  • subclass
  • superclass
In Python, the term "base class" refers to the class that a class inherits from. It's also commonly called a "parent class" or "superclass."

In object-oriented programming, ____ refers to the bundling of data and methods that operate on that data into a single unit.

  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism
In object-oriented programming, encapsulation refers to the concept of bundling data (attributes) and methods (functions) that operate on that data into a single unit, known as a class. This helps in data hiding and controlling access to an object's internals.

In Pandas, ____ is used to concatenate two or more DataFrames along a particular axis.

  • combine
  • concat
  • join
  • merge
In Pandas, the concat function is used to concatenate (combine) two or more DataFrames along a specified axis (either rows or columns). It is a powerful tool for combining data in various ways.

In Pandas, how can you filter the rows of a DataFrame where the value in a specific column is greater than a threshold?

  • df.apply('column_name > threshold')
  • df.filter('column_name > threshold')
  • df.select('column_name').where('value > threshold')
  • df[df['column_name'] > threshold]
To filter rows in a Pandas DataFrame where the value in a specific column is greater than a threshold, you can use boolean indexing. This is achieved by specifying the condition inside square brackets.