Giter Club home page Giter Club logo

challenge-cs02-07's Introduction

PS07: Designing a dictionary

Complete the implementation of the Dictionary data structure without using built-in set or dict.

The Dictionary class must expose the following methods.

  • Dictionary() constructor that takes no arguments.
  • set(k, v) sets the item with key k to the value v.
  • get(k) returns the value of item with key k if exist, else returns -1.
  • remove(k) removes the item with key k from the dictionary if exist, else do nothing.

Remember that dictionary operations must be efficient in space and time.

The following is a usage example of the Dictionary class:

data = Dictionary()
data.set(1, 1)
data.set(2, 1)
data.set(3, 3)
data.get(2)  # Returns 1
data.get(4)  # Returns -1
data.set(3, 5)
data.set(3, 2)
data.get(3)  # Returns 2
data.remove(1)
data.get(1)  # Returns -1

Constraints

Your dictionary is expected to:

  • Support up to 10^5 operations
  • Keys and values are integers in the range [0, 10^9]

How to submit.

  • Implement the methods listed above under solution.py.
  • All code will be checked for readability using pylint.
  • A grader is included, and all test cases must pass.
  • DO NOT modify the grader!
  • DO NOT use built-in set or dict!

Debugging

  • You can run the grader with the command python3 grader.py < test_cases/a.txt where a is the test case you want to run.
  • Yo can run all test cases with the command: for f in test_cases/*.txt; do python3 grader.py < "$f"; done

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.