DATA STRUCTURES AND
ALGORITHMS PYTHON
Name Every Data Structure (There are 8 Main Ones) - Correct Answers -1. Array
2. Stack
3. Queue
4. Linked Lists
5. Hash Table
6. BST
7. B-Tree, Red Black Trees
8. Heaps
Name Every Python Super Basic Datastructure - Correct Answers -1. List
2. Tuples
3. Sets
4. Strings
5. Arrays (you must use numpy)
Strings - Correct Answers -1. They are immutable
2. Access characters in strings like you do for arrays/lists
3. empty strings are false, non empty are true.
4. | and & don't work on strings
Slicing - Correct Answers -string_name[beginning:end:step]
*end is not inclusive
*works for strings, lists, and tuples
Useful String Methods - Correct Answers -1. s[3]
2. s + t
3. len(s)
4. s in t
5. s.strip()
6. s.startswith(prefix)
7. s.endswith(suffix)
8. s.find(substring, beg, end) - returns the first position where substring is found.
9. s.rfind(substring, beg,end) - returns the position of the last occurrence of string
10. s.lower() - changes case
11. s.upper() - changes case
12. s.swapcase() - changes to other case
Python List - Correct Answers -1. not always homogenous
2. mutable
, 3. used to implement stacks and queues
Runtime and Space-Time of Selection Sort - Correct Answers -Runtime: theta(N^2)
Space-Time: Big O(1)
Runtime and Space-Time of Heap Sort - Correct Answers -Runtime: Omega(N) if all
elements are equal, Big O(NlogN)
Space-Time: Theta(N)
Runtime and Space-Time of In-place Heap Sort - Correct Answers -Runtime: O(NlogN)
Space-Time: Theta(1)
Python List Methods - Correct Answers -1. append(x)
2. extend(x)
3. insert(i, x)
4. min(list)
5. max(list)
6. del a[i:j]
7. a.reverse()
8. a.sort()
9. B = copy.deepcopy(A)
10. b = copy.copy(A)
11. remove(index)
Tuples - Correct Answers -1. collection of python objects separated by commas
2. immutable
3. use () to create
Tuples Methods - Correct Answers -1. len(tuple_name)
2. tuple(list_name)
3. cmp() - returns 0 if matched. 1 when not matched and longer, -1 when not matched
and shorter
4. max() - returns max el
5. min() - returns min el
Python Sets - Correct Answers -1. unordered collection data type that is iterable,
mutable, and has no duplicate elements
2. based on datastructure known as hash table
3. highly optimized for checking contains
4. to create a set you need to use set(list)
*Only instances of immutable types can be added to python set
Methods - Correct Answers -1. add(x)
2. union(other)
3. intersect(other)
4. difference(other)
5. clear()
ALGORITHMS PYTHON
Name Every Data Structure (There are 8 Main Ones) - Correct Answers -1. Array
2. Stack
3. Queue
4. Linked Lists
5. Hash Table
6. BST
7. B-Tree, Red Black Trees
8. Heaps
Name Every Python Super Basic Datastructure - Correct Answers -1. List
2. Tuples
3. Sets
4. Strings
5. Arrays (you must use numpy)
Strings - Correct Answers -1. They are immutable
2. Access characters in strings like you do for arrays/lists
3. empty strings are false, non empty are true.
4. | and & don't work on strings
Slicing - Correct Answers -string_name[beginning:end:step]
*end is not inclusive
*works for strings, lists, and tuples
Useful String Methods - Correct Answers -1. s[3]
2. s + t
3. len(s)
4. s in t
5. s.strip()
6. s.startswith(prefix)
7. s.endswith(suffix)
8. s.find(substring, beg, end) - returns the first position where substring is found.
9. s.rfind(substring, beg,end) - returns the position of the last occurrence of string
10. s.lower() - changes case
11. s.upper() - changes case
12. s.swapcase() - changes to other case
Python List - Correct Answers -1. not always homogenous
2. mutable
, 3. used to implement stacks and queues
Runtime and Space-Time of Selection Sort - Correct Answers -Runtime: theta(N^2)
Space-Time: Big O(1)
Runtime and Space-Time of Heap Sort - Correct Answers -Runtime: Omega(N) if all
elements are equal, Big O(NlogN)
Space-Time: Theta(N)
Runtime and Space-Time of In-place Heap Sort - Correct Answers -Runtime: O(NlogN)
Space-Time: Theta(1)
Python List Methods - Correct Answers -1. append(x)
2. extend(x)
3. insert(i, x)
4. min(list)
5. max(list)
6. del a[i:j]
7. a.reverse()
8. a.sort()
9. B = copy.deepcopy(A)
10. b = copy.copy(A)
11. remove(index)
Tuples - Correct Answers -1. collection of python objects separated by commas
2. immutable
3. use () to create
Tuples Methods - Correct Answers -1. len(tuple_name)
2. tuple(list_name)
3. cmp() - returns 0 if matched. 1 when not matched and longer, -1 when not matched
and shorter
4. max() - returns max el
5. min() - returns min el
Python Sets - Correct Answers -1. unordered collection data type that is iterable,
mutable, and has no duplicate elements
2. based on datastructure known as hash table
3. highly optimized for checking contains
4. to create a set you need to use set(list)
*Only instances of immutable types can be added to python set
Methods - Correct Answers -1. add(x)
2. union(other)
3. intersect(other)
4. difference(other)
5. clear()