Python Flashcards
Data Structure: deque
import
from collections import deque
Data Structure: deque
method(s): append & appendleft
usage with space & time complexity
append(val) & appendleft(val) - adds item
Time: O(1)
Space: O(1)
Data Structure: deque
method(s): pop & popleft
usage with space & time complexity
pop() & popleft() - removes and returns item
Time: O(1)
Space: O(1)
Data Structure: deque
method(s): index
usage with space & time complexity
index(ele, beg, end) - returns first index of value
Time: O(n)
Space: O(1)
Data Structure: deque
method(s): insert
usage with space & time complexity
insert(i, a) - This function inserts the value mentioned in arguments(a) at index(i) specified in arguments.
Time: O(n)
Space: O(1)
Data Structure: deque
method(s): remove
usage with space & time complexity
remove(val) - This function removes the first occurrence of the value mentioned in arguments.
Time: O(n)
Space: O(1)
Data Structure: deque
method(s): count
usage with space & time complexity
count(val) - This function counts the number of occurrences of value mentioned in arguments.
Time: O(n)
Space: O(1)
Data Structure: deque
method(s): extend & extendleft
usage with space & time complexity
extend(iterable):- add multiple values at the right end of the deque.
extendleft(iterable):- add multiple values at the left end of the deque. Order is reversed as a result of left appends.
Time: O(K)
Space: O(1)
Data Structure: deque
method(s): reverse
usage with space & time complexity
reverse():- This function is used to reverse the order of deque elements.
Time: O(n)
Space: O(1)
Data Structure: deque
method(s): rotate
usage with space & time complexity
rotate():- This function rotates the deque by the number specified in arguments. If the number specified is negative, rotation occurs to the left. Else rotation is to right.
Time: O(K)
Space: O(1)
Data Structure: OrderedDict
import
from collections import OrderedDict
Data Structure: OrderedDict
method(s): get item
usage with space & time complexity
dict[key] - returns value
Time: O(1)
Space: O(n)
Data Structure: OrderedDict
method(s): set item
usage with space & time complexity
dict[key] = value
Time: O(1)
Space: O(n)
Data Structure: OrderedDict
method(s): popitem
usage with space & time complexity
popitem() - used to delete an item from the beginning
popitem(last=True) - used to delete an item from the end
Time: O(1)
Space: O(n)
Data Structure: OrderedDict
method(s): move_to_end
usage with space & time complexity
move_to_end(key, last = True) - move an existing key of the dictionary in the end or beginning
Time: O(1)
Space: O(1)