PDA

View Full Version : can someone please explain to me the point of a binary tree/hashing?



obstaclez
07-27-2018, 11:09 AM
not sure if this is the right place to ask or if i should be in homework help, but i am working on some homework and apparently our teacher thought it was beneficial to skip the original chapter on binary trees, so reading about AVL trees and hashing, i am extremely confused. what's the point of them? what would they be used for? (if it matters, this is in java)

j03
07-27-2018, 12:31 PM
not sure if this is the right place to ask or if i should be in homework help, but i am working on some homework and apparently our teacher thought it was beneficial to skip the original chapter on binary trees, so reading about AVL trees and hashing, i am extremely confused. what's the point of them? what would they be used for? (if it matters, this is in java)

A Binary Tree is similar to an array, list, but it's more of a hierarchical data structure... So instead of a list which is made up like this:



Item 1
Item 2
Item 3
Etc.

The Binary Tree will look like this:



Item
|....item 1
. |....item 1.1
|....item 2
. |....item 2.1
|....item 3
. |....item 3.1

Edit: Damn it, the formatting messed up when I hit submit. It's supposed to show the ".1" items branching out from "1", "2", "3". And those ones branching out from "item", like a tree. And the last elements are called leaves.

I got lazy doing this on my phone, could have added more elements but you get the idea... It's basically a tree. Sometimes it'll be needed for you to break down your data into categories like this instead of having one list. I think if you google or YouTube, you'll get a better explanation. Typically this makes data easier to search and manipulate.

Hashing is also pretty simple to understand. It's similar to the list above, except what if this list was massive and you didn't know all of the item names? You could use an ID, call the ID an index number, or key, which will point to the item name in the list. Google this too as it doesn't take a lot of reading. :)


Sent from my iPhone using Tapatalk

obstaclez
07-27-2018, 02:00 PM
i'm really just not understanding how to do this assignment. is there someone i can pm about it?

j03
07-29-2018, 07:27 PM
i'm really just not understanding how to do this assignment. is there someone i can pm about it?

Edited my post so it should look like how I was trying to explain it. You can share the questions in a spoiler tag like [ spoiler] question here [ /spoiler] (but no space after '[')so it's not picked up by Google or any other search engines... if not, you could PM me and I'll try to help.

omg.UFOs
09-03-2018, 08:59 AM
A Binary Tree is similar to an array, list, but it's more of a hierarchical data structure... So instead of a list which is made up like this:



Item 1
Item 2
Item 3
Etc.

The Binary Tree will look like this:



Item
|....item 1
. |....item 1.1
|....item 2
. |....item 2.1
|....item 3
. |....item 3.1

Edit: Damn it, the formatting messed up when I hit submit. It's supposed to show the ".1" items branching out from "1", "2", "3". And those ones branching out from "item", like a tree. And the last elements are called leaves.

I got lazy doing this on my phone, could have added more elements but you get the idea... It's basically a tree. Sometimes it'll be needed for you to break down your data into categories like this instead of having one list. I think if you google or YouTube, you'll get a better explanation. Typically this makes data easier to search and manipulate.

Hashing is also pretty simple to understand. It's similar to the list above, except what if this list was massive and you didn't know all of the item names? You could use an ID, call the ID an index number, or key, which will point to the item name in the list. Google this too as it doesn't take a lot of reading. :)


Sent from my iPhone using Tapatalk

you see the world in ones and zeros, dont you joe.

j03
09-04-2018, 05:00 PM
you see the world in ones and zeros, dont you joe.

I mean, you could. I try and think of everything differently if I'm looking for a solution or for something to make more sense.

Tyler Durden
12-18-2018, 04:06 PM
not sure if this is the right place to ask or if i should be in homework help, but i am working on some homework and apparently our teacher thought it was beneficial to skip the original chapter on binary trees, so reading about AVL trees and hashing, i am extremely confused. what's the point of them? what would they be used for? (if it matters, this is in java)

I'll just add to what Infamous Joe pointed out.
A binary tree is a hierarchical data structure where in you have a root node followed by its children followed by children of its children. The word binary is because at each node you can have a max of 2 children (binary) if you want 3 it's ternary and so on.
The advantage is in a height balanced binary tree ( AVL tree or Red Black tree) the left child is always less than the parent, where as right child is always greater than or equal to the parent.
Now imagine you want to find an element, in a regular array search you need to check every element, whereas Ina a binary tree you've gotta just check left or right node, so your max search would be log(n)base2. OK big deal, but I can do binary search on an array and still get it in same time complexity, so why trees? The answer is if you gotta insert an element into the array you've gotta shift the array upto n elements, whereas in a binary tree simply add it as a child to a node in log(n) base2 time, same for removal :)
The real advantage comes in large data sets, imagine you need to search a user in a database consisting of 1 million records, conventionally you will have to iterate through each element to get the result, that means parse through 1 million users, whereas in a binary tree you need to just check log of 1 million = 20 users approx.
Hashing to put simply, take a value and generate a value of constant bits based on it. You can use any of the plenty algorithms present.
If you need any help feel free to ask, competitive programming is one of my hobbies :)
Here's a link I suggest.
[Only registered and activated users can see links]

Ps. Wrote on my tab so bare with typos :p