Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an ordered map (BST) #11

Open
13 tasks
mwermelinger opened this issue Jan 6, 2024 · 0 comments
Open
13 tasks

Add an ordered map (BST) #11

mwermelinger opened this issue Jan 6, 2024 · 0 comments
Labels
effort: high These issues require the most work priority: medium type: feature New feature

Comments

@mwermelinger
Copy link
Member

mwermelinger commented Jan 6, 2024

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.
@mwermelinger mwermelinger added effort: high These issues require the most work priority: medium type: feature New feature labels Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: high These issues require the most work priority: medium type: feature New feature
Projects
None yet
Development

No branches or pull requests

1 participant