Python Data Structures + Algorithms Flashcards
(69 cards)
What is an array?
an ordered collection of elements
What is the time complexity of insertion/deletion of an array?
O(1)
What is the time complexity of searching an array?
O(n)
How do I create a list?
list() or my_list = [1, 2, 3]
How do i add elements to a list?
append, insert(num, idx)
How do I remove the last element of a list?
my_list.pop()
How do I deleted an element from a list?
del my_list[2]
What is unique about arrays in Python?
it is dynamic
What is a string?
an immutable sequence of characters
What is the time complexity of access on a string?
O(1)
What is the time complexity of concatenation on a string?
O(n)
How do I slice a string?
s[1:4]
How do I concatenate a string?
“a” + “b”
What is another name for a dictionary?
a hash map
What is a dictionary?
a collection of key-value pairs
Why do we choose dictionaries?
they provide efficient lookups based on keys
What is the access/insertion/deletion time complexity of a dictionary?
O(1)
How do I create a dictionary?
{} or {“apple”: 1}
How do I insert a new value to my dictionary?
dictionare[“banana”] = 2
What are arrays used for in leetcode?
problems involving sequences, searching, sorting, and dynamic programming
What are dictionaries used for in leetcode?
problems involving frequency, counting, lookings, and storing mapping between elements
What is a set?
unordered collection of unique elements
What is the time complexity for a set?
O(1)
How do I create a set?
s = (1, 2, 3) or s = set([1, 2, 3])