CARVIEW |
Python DSA libraries
This quiz checks what you know about Python DSA (Data Structures and Algorithms) libraries. These libraries help you solve problems faster and write cleaner, more efficient code!
Question 1
What is the primary feature of a min-heap created using heapq in Python?
The largest element is always at index 0
All elements are sorted
The smallest element is always at index 0
The elements are stored in a dictionary
Question 2
What does heapq.heappushpop(heap, elem) do?
Removes the largest element
Pushes then pops the largest element
Pushes elem, then pops and returns the smallest element
Sorts the heap
Question 3
What will the following code output?
import heapq
h = [3, 2, 1]
heapq.heapify(h)
print(heapq.heappop(h))
1
2
3
Error
Question 4
Which function will return the 2 largest elements from a heap?
heapq.heappop()
heapq.heappushpop()
heapq.nlargest(2, heap)
heapq.popmax()
Question 6
What is the difference between bisect_left() and bisect_right()?
bisect_left() inserts at end
bisect_right() inserts before equal elements
bisect_left() inserts before equal elements, bisect_right() after
No difference
Question 7
What does the following code do?
import bisect
arr = [1, 2, 4, 5]
bisect.insort(arr, 3)
print(arr)
[1, 2, 3, 4, 5]
[1, 2, 4, 5, 3]
[3, 1, 2, 4, 5]
Error
Question 8
What is the output of the following array code?
import array
a = array.array('i', [1, 2, 3])
a.append(4)
print(a.tolist())
[1, 2, 3]
[1, 2, 3, 4]
[4, 3, 2, 1]
Error
Question 9
What does arr.remove(1) do in an array?
Removes all 1s
Removes last element
Removes the first occurrence of 1
Throws an error
Question 10
Which collections container retains key insertion order?
defaultdict
deque
OrderedDict
Counter
There are 15 questions to complete.