Question

Trying to come up with the simplest way to create binary tree, so i read alot of code online from different sources.

how is it theres so many different ways to create a working binary tree? This is what i dont understand about programming syntax/language... the logic i get.. but i believe there should be a set , uniform foundation to create the same things in the simplest way. Am I wrong?

create tree
create node
create node root
Was it helpful?

Solution

Ok,

I will try to answer your question.

Let's take a big box. You want to put inside some things. Few days after, you will have to find something and use it. Someday, maybe you will want to throw something away.

So, what is your approach, if you are sure, that you will never use any object of them? Probably you will not care where and how you put this object. It is fast and easy to do.

What, if someday, you will want to use some objects? You keep this way and you will be loosing a lot of time for searching or maybe you will try to keep some order inside and easily find an object?

Exactly the same story is with the Binary Trees.

Each of alghoritms has some properties f.e. a lot of algos keep your tree balanced. Before you choose an implementation for your code, think about how you will use it and take a proper one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top