How can you create a decorator that takes arguments?

  • By modifying the Python interpreter.
  • By using the @decorator syntax with argument values.
  • Decorators in Python cannot take arguments.
  • Using a function that takes the decorator arguments and returns the actual decorator function.
To create a decorator that takes arguments, you can define a function that accepts those arguments and returns a decorator function. This allows you to customize the behavior of the decorator based on the arguments provided.

How can you create a generator in Python?

  • Using a class with __iter__ and __next__ methods
  • Using a for loop
  • Using a while loop
  • Using the yield keyword in a function
You can create a generator in Python by defining a function with the yield keyword. When the function is called, it returns an iterator that generates values one at a time when you iterate over it. This is a fundamental feature for working with large datasets efficiently.

How can you create a generator that produces values infinitely?

  • JavaScript doesn't support infinite generators.
  • Use a for loop and return values endlessly.
  • Use a while loop with a condition that never becomes false.
  • Use the function* syntax and an infinite while (true) loop, yielding values within the loop.
To create a generator that produces values infinitely, you can use the function* syntax and an infinite while (true) loop, yielding values within the loop. This allows you to generate an endless sequence of values efficiently.

How can you create class methods that cannot be overridden by subclasses?

  • By defining the method inside the constructor.
  • By making the method static.
  • By marking the method as final.
  • By using the const keyword.
In many object-oriented programming languages, including JavaScript and Java, you can create methods that cannot be overridden by subclasses by marking them as final. This keyword indicates that the method is the final implementation and cannot be further overridden.

A ____ sort is a highly efficient sorting algorithm based on partitioning of an array of data into smaller arrays.

  • Bubble
  • Merge
  • Quick
  • Selection
A Merge sort is a highly efficient sorting algorithm that uses a divide-and-conquer approach to sort an array. It repeatedly divides the array into smaller sub-arrays until each sub-array is sorted, then merges them back together to achieve the final sorted order.

A ____ tree is a tree in which each node has at most two children, which are referred to as the left child and the right child.

  • Binary
  • Octal
  • Quad
  • Ternary
A Binary Tree is a tree data structure where each node has at most two children, a left child and a right child. This data structure is commonly used in computer science and is fundamental to many algorithms and data structures.

A decorator in Python is a design pattern used to add new functionality to an object without altering its ____.

  • attributes
  • class
  • methods
  • structure
In Python, decorators are typically used to add new functionality to methods of a class without changing the method's name or signature. This is commonly used for tasks like logging, authorization, and caching.

A ____ algorithm guarantees to run in the same time (or space) for any input of the same size.

  • Deterministic
  • In-Place
  • Non-Deterministic
  • Stable
A Deterministic algorithm guarantees to run in the same time (or space) for any input of the same size. It is predictable and has consistent performance.

A ____ in Python is a collection of key-value pairs, where the keys must be immutable.

  • Dictionary
  • List
  • Set
  • Tuple
In Python, a dictionary is a collection of key-value pairs, where the keys must be immutable (and usually unique). Tuples are immutable, making them suitable for use as dictionary keys.

A ____ is a data structure that stores elements in a linear sequence but allows additions and removals only at the start.

  • Array
  • Linked List
  • Queue
  • Stack
A Stack is a data structure that follows the Last-In-First-Out (LIFO) principle, meaning the last element added is the first to be removed. It allows additions and removals at the start, making it suitable for managing function calls, undo functionality, and more.