You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Map ADT can be implemented with a binary search tree (BST) if keys are ordered.
You may copy and adapt code from Sections 16.1 and 16.4 of the M269 book. You may work with others on this issue, to reduce the workload, e.g. you write the code and someone else adds the docstrings afterwards.
In subfolder paddles, create a file map.py:
The module imports Iterable from collections.abc.
Create a class BinarySearchTreeMap with an appropriate docstring.
The class has one creator method __init__:
It has an optional parameter with type annotation Iterable[tuple]: a collection of key-value pairs that are added to the map with a for-loop, using the first modifier method listed further below.
The class has these inspector methods:
return the size of the map (number of key-value pairs)
return the key-value pairs one by one, in in-order, pre-order or post-order (3 separate methods)
return the value associated to a given key (raise ValueError if the key doesn't exist)
check if the given key exists (return a Boolean)
check if two maps are equal (same key-value pairs)
The class has these modifier methods:
associate a given key with a given value (add the pair if the key doesn't exist, otherwise replace the value)
remove a given key (and its value) from the map; raise ValueError if the key doesn't exist
Add a docstring to each method, including the method's complexity.
Add a docstring at the start of the file, explaining the Map ADT. (See stack.py for the structure of the explanation.)
In subfolder tests, add a file test_map.py:
Write tests for the modifier methods, using the inspectors. Follow the structure described in CONTRIBUTING.md and illustrated in stack.py.
The text was updated successfully, but these errors were encountered:
The Map ADT can be implemented with a binary search tree (BST) if keys are ordered.
You may copy and adapt code from Sections 16.1 and 16.4 of the M269 book. You may work with others on this issue, to reduce the workload, e.g. you write the code and someone else adds the docstrings afterwards.
In subfolder
paddles
, create a filemap.py
:Iterable
fromcollections.abc
.BinarySearchTreeMap
with an appropriate docstring.__init__
:Iterable[tuple]
: a collection of key-value pairs that are added to the map with a for-loop, using the first modifier method listed further below.ValueError
if the key doesn't exist)ValueError
if the key doesn't existstack.py
for the structure of the explanation.)In subfolder
tests
, add a filetest_map.py
:stack.py
.The text was updated successfully, but these errors were encountered: