Python Libraries for DSA Interviews Flashcards

1
Q

What are all of the functions and import statements for heaps?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the Python functions to create a heap and it’s basic functionality?

A
  • heapq. heappop(heap_list)
  • heapq. heappush(heap_list, val)
  • heapq. heapify(list)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the Python functions to find the k largest or k smallest of a heap?

A
  • heapq. nlargest(k, iterable, key)
  • heapq. nsmallest(k, iterable, key)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some useful methods in the “collections” library?

A
  • defaultdict
  • Counter
  • deque
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the import statement for generating permutations and combinations?

A
  • from itertools import permutations
  • from itertools import combinations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What import statement do you use when you want a data structure with the following properties?
* unique values
* ordering

A

from collections import OrderedDict

How well did you know this?
1
Not at all
2
3
4
5
Perfectly