Python Libraries for DSA Interviews Flashcards
What are all of the functions and import statements for heaps?
import heapq
heapq. heappop(heap_list)
heapq. heappush(heap_list, val)
heapq. heapify(list)
heapq. nlargest(k, iterable, key)
heapq. nsmallest(k, iterable, key)
heapq. heappushpop(heap, elem)
heapq. heapreplace(heap, elem)
What are the Python functions to create a heap and it’s basic functionality?
- heapq. heappop(heap_list)
- heapq. heappush(heap_list, val)
- heapq. heapify(list)
What are the Python functions to find the k largest or k smallest of a heap?
- heapq. nlargest(k, iterable, key)
- heapq. nsmallest(k, iterable, key)
What are some useful methods in the “collections” library?
- defaultdict
- Counter
- deque
What is the import statement for generating permutations and combinations?
- from itertools import permutations
- from itertools import combinations
What import statement do you use when you want a data structure with the following properties?
* unique values
* ordering
from collections import OrderedDict