Code Monkey home page Code Monkey logo

Comments (2)

joowani avatar joowani commented on May 15, 2024 2

Hi @crazywkb,

Your cycle function seems to have a bug (it will never terminate if the input is not falsy), but I get your point. I prefer option 2 as it doesn't try to hide anything from the users. The earlier the users discover that their tree has a problem the better. I will look into adding a circular dependency check in the next release. Thanks for bringing this up!

from binarytree.

joowani avatar joowani commented on May 15, 2024 1

There is already a way to validate the tree (including circular dependency checks) via binarytree.Node.validate. After some thought, I decided to leave it up to the user to call this validate method explicitly rather than calling it in all methods like len.

The reasoning is as follows:

  1. I've seen this library being used to teach students. The teacher, for example, may want to intentionally trigger an infinite loop or a break the binary tree for educational/demonstration purposes. A far-fetched example, but the point is that I'd rather give the users the freedom of choice.
  2. Extra computation required for every method.

from binarytree.

Related Issues (20)

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.