fave77 / Mathball

A JavaScript library for Competitive Programming
https://fave77.github.io/Mathball-Docs/
MIT License
99 stars 49 forks source link

Implement Tree data structure #158

Closed Shubhayu-Das closed 5 years ago

Shubhayu-Das commented 5 years ago

Do the checklist before filing the issue:

NOTE: Provide a clear and concise description of the feature that needs to be added! Or if its a bug, then provide the necessary steps to reproduce it along with screenshots.

Tree data structure is widely used in competitive programming owing to it's nature of reducing O(n) problems to O(log n) problems. I suggest we implement a data structure names BinaryTree, which can be further built up on in the future.

We can can further implement Binary Search Trees, Balanced Binary Search Trees, Segment Trees etc in the future, using this basic Binary Tree implementation.

The Binary Tree will have the following functions:

  1. insert(data)
  2. remove(data)
  3. search(data)
  4. inorder()
  5. preorder()
  6. postorder()
  7. findMin(node)
  8. findMax(node)
  9. update(data, new_val)
Shubhayu-Das commented 5 years ago

I would like to work on this if you accept the issue.

fave77 commented 5 years ago

@sateslayer you're assigned.

Shubhayu-Das commented 5 years ago

I've have some doubts regarding the validation which I'm supposed to provide:

  1. How do I check whether a node actually exists in the tree or not? - In a binary tree this is simply a matter of going left or right. Here there might be unknown number of nodes which makes traversal much harder

This is why I thought of changing this issue to the implementation to only binary trees instead of generic trees. This would be much easier to implement and useful too in programming. Raw trees are hardly ever used; implementing binary trees using a generic tree code is very troublesome

Waiting for your reply so that I can proceed accordingly.

fave77 commented 5 years ago

Okay, make it a binary tree!

Shubhayu-Das commented 5 years ago

I'll make the requisite changes in the issue above?

fave77 commented 5 years ago

okay