r/CircleProgramming • u/Illuminatesfolly • Mar 21 '13
How do I make this code faster without loosing the function?
http://pastebin.com/ie9XTrc7
3
Upvotes
r/CircleProgramming • u/Illuminatesfolly • Mar 21 '13
View all comments
Show parent comment
2
u/cokeisahelluvadrug Mar 21 '13
Ok, so clicking on a node essentially bisects its subtree?
It seems to me that most of the program's processing time can be split into 2 categories: sorting the trees, and rendering the nodes. Swing is actually pretty bad at rendering because it's not hardware accelerated, but that doesn't really seem to be the problem here. If you want rendering performance to increase just only render the things that change every frame, don't wipe the screen and re-render everything.
The sort that you're doing is not very efficient:
"Bubble sort" is generally known to be a poor sorting algorithm because it's pretty slow for large sets. For example, sorting 100 items with bubble sort would take ~10,000 steps, whereas sorting 100 items with one of the "good" sorting algorithms would take less than 1,000 steps (compare n2 average steps to nlogn average steps). There is a common sorting algorithm called "merge sort" that works by combining two sorted trees into a single larger sorted tree, and I think it might be relevant to your interests. Additionally, since your tree is subdivided (and therefore you're not sorting the entire tree, just different subtrees), you're going to get some efficiency boosts there.