Jump to content

Hello everyone,

 

So I have this exercise about avl trees and I am not too sure how to go about it. The point is to feed a number to the function and having it return the name of the type of polygon. For example, if I send 32 then it returns triacontadi polygon.

 

I have 3 AVL trees, each one with a polygon. A polygon has an int and a String, the number of sides and the name you give the amount of sides he has, like so:

image.png.d7073f1a041982d6095881573b3c427c.png

 

Now, the first tree has the "ones" meaning, 1 to 9. The second one has the Tens 10 90. And the third one has the hundreds

 

I started out by trying to devide each search by group, meaning if the wanted number was less than 10 then the search would be on the ones tree. If the search was between 10 and 99 then it would be on the first and second tree and so on. But my approach isn't making a lot of sense in the 21 to 29 cases. I would like to find a general approach to this but so far haven't managed to do so.

 

Link to comment
https://linustechtips.com/topic/867792-avl-tree-polygon-search/
Share on other sites

Link to post
Share on other sites

Do you only need to find values in that table or also any other polygon name that can be build using that table (ie  42)?

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
https://linustechtips.com/topic/867792-avl-tree-polygon-search/#findComment-10772159
Share on other sites

Link to post
Share on other sites

10 hours ago, mathijs727 said:

Do you only need to find values in that table or also any other polygon name that can be build using that table (ie  42)?

Other polygon from one, two or the three tables

2 -> first table

34 -> 1st and 2nd

935 -> the 3 tables

Link to comment
https://linustechtips.com/topic/867792-avl-tree-polygon-search/#findComment-10773823
Share on other sites

Link to post
Share on other sites

31 minutes ago, ShatteredPsycho said:

Other polygon from one, two or the three tables

2 -> first table

34 -> 1st and 2nd

935 -> the 3 tables

So build seperate trees for 0-10, 10,20,30...100 and 100,200,300,...,1000.

Split your input query into seperate digits (935 -> 9, 3, 5) and look them up in the trees?

 

And if you need, build an AVL with exceptions.

Look up the query in that tree and if it fails then use the normal naming scheme (described above).

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
https://linustechtips.com/topic/867792-avl-tree-polygon-search/#findComment-10773870
Share on other sites

Link to post
Share on other sites

2 hours ago, mathijs727 said:

So build seperate trees for 0-10, 10,20,30...100 and 100,200,300,...,1000.

Split your input query into seperate digits (935 -> 9, 3, 5) and look them up in the trees?

 

And if you need, build an AVL with exceptions.

Look up the query in that tree and if it fails then use the normal naming scheme (described above).

Well ofc, that was my intent but my doubt wasn't there.

But I guess I don't really have to be concerned. I can just take the digit, place a 0 after and look them up on three trees

Link to comment
https://linustechtips.com/topic/867792-avl-tree-polygon-search/#findComment-10774112
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×