Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Python library for learning binarytrees (github.com/joowani)
112 points by juwani on June 5, 2018 | hide | past | favorite | 15 comments



Minor suggestion: I would replace 'learning' with 'studying' for clarity, since "learning trees" instantly associates with gradient boosting (e.g. xgboost/lightgbm) in machine learning.


Done!


Or you could learn algorithms properly

https://algs4.cs.princeton.edu/home/

https://algs4.cs.princeton.edu/30searching/

and write your own trees.

There is a free coursera course that goes along with the princeton algorithm website. Also this website has tons of exercises to help you master the subject. Not to mention all their code is freely available ( though it is in Java, not python ).

I'm a believer of learning by doing. Using something others have built for you isn't an optimal way of learning anything. Especially binary trees and the more encompassing subject of algorithms.


It was clear to me as well as some other commenters here that the point in this library is to practice algorithms on binary trees and pretty print their output.

Studying algorithms while using a library for the implementation of the underlying data structure is still very much "learning by doing." This assumption being that you already understand how to implement that data structure and would like to concentrate on studying algorithms on that data structure.

It's very odd that you have chosen to declare this "improper" and discredit it as a result of your own misunderstanding. The documentation clearly states the author's intentions:

"It allows you to skip the tedious work of setting up test data, and dive straight into practising your algorithms."[1]

[1] https://binarytree.readthedocs.io/en/latest/index.html


Setting up the test data and pretty printing the tree is part of the learning process. I'd say it is essential.

Writing pretty printers for trees is one of the best ways to verify you actually know how a tree works rather than having a superficial understanding of it.

> It's very odd that you have chosen to declare this "improper" and discredit it as a result of your own misunderstanding.

Because that's not the proper way to learn binary trees. I felt I gave good reasons for why. You learn binary trees by building one yourself. That's the best way.

So you use data provided by others. You use pretty printers provided by others. You use implementation provided by others. So what have you learned?

Part of the learning process, especially in algorithms, is creating your own data ( to test edge cases, speed, etc ). Part of learning is setting up your own pretty printer because it sure isn't trivial the first time you do it.

Something as fundamental like binary trees and algorithms should be taught/learned properly.


> You learn binary trees by building one yourself. That's the best way.

Sure - do it once, but if you're trying to wrap your head around a new algorithm or just trying to focus on one particular problem, it's very de-motivating to not have quality debug-printers, random-data-generators, etc.

Story: I was once trying to wrap my head around heap.remove() (and the associated sift-up) and I had my own tree class and various ways to print and inspect it. I couldn't for the life of me figure out why my sift wasn't working. Wasted like an hour on it. Turns out it was working, it was just my printing/test-harness stuff that was flawed. Sure that was a useful hard-knock, but it really served as a distraction from what I was trying to do at the moment. Made me stop doing tree katas for a few weeks out of frustration.

> Something as fundamental like binary trees and algorithms should be taught/learned properly.

"Properly" is pejorative here. I would say this class/lib is an extremely useful part of learning more advanced tree/algo concepts properly.

Having a helper class that solves some of the basics well and sets you up for success lets you focus on the larger problems without having to constantly re-visit the basics. It's how abstractions are made and learned.


> I couldn't for the life of me figure out why my sift wasn't working. Wasted like an hour on it. Turns out it was working, it was just my printing/test-harness stuff that was flawed. Sure that was a useful hard-knock, but it really served as a distraction from what I was trying to do at the moment.

What you think is an unnecessary distraction is in my opinion a very important experience and part of the learning process. Everything you hand-code for your own data structure be it pretty-print, test-harness, etc. are all important while learning.

> Having a helper class that solves some of the basics well and sets you up for success lets you focus on the larger problems without having to constantly re-visit the basics.

Once you have built the data structures bottom-up from scratch along with all the additional utilities to pretty-print it, test it, etc. you have your helpers ready already. There is no need to use someone else's helpers at that point.


> "It allows you to skip the tedious work of setting up test data, and dive straight into practising your algorithms."

Setting up your own test data and pretty-printing your trees with your own code are important in my opinion.


Exactly this! If you are learning algorithms, you should be implementing your own trees rather than relying on a library like this that does the work for you.

The real benefit of learning algorithms comes when you put the hard work into it to build the data structures in a bottom up manner. Using someone else's tree generating library eliminates this experience which is a vital experience in the journey of learning algorithms.


Except the use case for this is not meant as a substitution for "hard work." It's a convenience library.

This is no different than importing the Python's standard library's queue, dequeue, hash etc for use in studying algorithms that use those data structure after you understand how to implement them by hand.


I really like the idea of libraries that make it easy to learn a data structure/algorithm/general concept. Thank you for publishing this! It will certainly make CS concepts easier to teach.


Semi-off topic, but I recently had a binary tree interview question and it made me think about if I ever implemented a binary tree aside from a college course.

Has anyone ever used a binary tree in production code somewhere? The closest thing I used was a linked list



I was just thinking of writing something like this to practice algorithms. Glad to see it exists already.


Thank you




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: