Python Data Structures and Algorithms Drill

Table of Contents

Data Structures and Algorithms Drill

Data Structures

What is a list in Python?   drill python_data_structures_algorithms

Answer
  • A mutable sequence of values.

What is a tuple in Python?   drill python_data_structures_algorithms

Answer
  • An immutable sequence of values.

What is a dictionary in Python?   drill python_data_structures_algorithms

Answer
  • A mutable mapping of keys to values.

What is a set in Python?   drill python_data_structures_algorithms

Answer
  • An unordered collection of unique values.

What is a stack in Python?   drill python_data_structures_algorithms

Answer
  • A last-in, first-out (LIFO) data structure.

What is a queue in Python?   drill python_data_structures_algorithms

Answer
  • A first-in, first-out (FIFO) data structure.

Algorithms

What is the time complexity of the bubble sort algorithm?   drill python_data_structures_algorithms

Answer
  • O(n2)

What is the time complexity of the quicksort algorithm?   drill python_data_structures_algorithms

Answer
  • O(n log n) on average

What is the time complexity of the merge sort algorithm?   drill python_data_structures_algorithms

Answer
  • O(n log n)

What is the time complexity of the binary search algorithm?   drill python_data_structures_algorithms

Answer
  • O(log n)

What is the time complexity of the linear search algorithm?   drill python_data_structures_algorithms

Answer
  • O(n)

Searching and Sorting

What is the purpose of the `sort` method in Python?   drill python_data_structures_algorithms

Answer
  • Sorts a list in-place.

What is the purpose of the `sorted` function in Python?   drill python_data_structures_algorithms

Answer
  • Returns a new sorted list.

What is the purpose of the `index` method in Python?   drill python_data_structures_algorithms

Answer
  • Returns the index of the first occurrence of a value.

What is the purpose of the `find` method in Python?   drill python_data_structures_algorithms

Answer
  • Returns the index of the first occurrence of a value, or -1 if not found.

Graphs and Trees

What is a graph in Python?   drill python_data_structures_algorithms

Answer
  • A non-linear data structure consisting of nodes and edges.

What is a tree in Python?   drill python_data_structures_algorithms

Answer
  • A hierarchical data structure consisting of nodes and edges.

What is the purpose of the `DFS` algorithm?   drill python_data_structures_algorithms

Answer
  • Traverses a graph or tree depth-first.

What is the purpose of the `BFS` algorithm?   drill python_data_structures_algorithms

Answer
  • Traverses a graph or tree breadth-first.

Dynamic Programming

What is dynamic programming?   drill python_data_structures_algorithms

Answer
  • A method for solving complex problems by breaking them down into smaller sub-problems.

What is the purpose of memoization?   drill python_data_structures_algorithms

Answer
  • Stores the results of expensive function calls to avoid redundant computation.

What is the purpose of tabulation?   drill python_data_structures_algorithms

Answer
  • Stores the results of sub-problems in a table to avoid redundant computation.

Author: Jason Walsh

j@wal.sh

Last Updated: 2024-10-30 16:43:54