![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Programming Guru
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
How did you keep the tree balanced? AVL tree rotations?
I would assume that's only necessary, no? I had to do that too. |
|
|
|
|
|
#22 |
|
Expert Programmer
|
Re: Challenging Programming Problem - "Pinball Ranking"
|
|
|
|
|
|
#23 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
No, it was just a simple binary tree - I didn't see anything in the problem requirements in the PDF about O(nlogn), just Sane's assertion that a N^2 algorithm can't finish it. Clearly, that is not the case.
|
|
|
|
|
|
#24 |
|
Programming Guru
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
Really? Well there were a few other data files that I haven't bothered to upload. I guess the one I did upload wasn't the one that exploits the worst case. At least one of them must be able to hit it. The professor told me that
|
|
|
|
|
|
#25 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
Quote:
I am trying it out with a worst case - sorting the s5.txt file. So far it just crashes with a stack overflow, due to my simple recursive program structure. Edit: I see you have changed your original post to be a bit less aggressive, thank you. |
|
|
|
|
|
|
#26 |
|
Programming Guru
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
I was talking about the data file doing the exploiting. Not you exploiting anything. lol
But I'm pretty sure N^2 can't make it. N = 100,000 N^2 = 10000000000 NlogN = 1660964 N^2/NlogN = 6021 So it's 6000 times slower with worst case. Doesn't seem likely that it can finish it in less than an hour or so. |
|
|
|
|
|
#27 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
Is a sorted list the worst case? Here is my (crappy) output from the sorted version for a non-recursive binary tree:
Count : 100000 Sum : 100000 Average: 1 Time : 22106 (ms) Depth : 99999 and for reverse sorted : Count : 100000 Sum : 5000049999 Average: 50000.5 Time : 19110 (ms) Depth : 99998 Obviously a bigger input file would get worse exponentially, but it still only took 22 seconds for 100,000 objects. The original PDF did say that that would be the maximum. |
|
|
|
|
|
#28 |
|
Programming Guru
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
That's wild. I need to rethink why that is for a moment. Even the professor acknowledged that N^2 couldn't finish it.
Why is your sum different? Edit: Nevermind. Of course it should be different. Last edited by Sane; Jan 2nd, 2008 at 5:45 PM. |
|
|
|
|
|
#29 |
|
Programming Guru
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
I gave it a bit closer examination. I had forgotten that N grows as the tree progresses. So that has to be taken into account.
Python Syntax (Toggle Plain Text)
N^2 5000050000
NlogN 1516704
x3296That reduces the speed factor to 3,000. But that's still an hour, if the balanced tree takes one second. Of course Big Oh is imprecise, but that can't possibly make the difference between a factor of 3,000 and a factor of 20. What else do you think is going on here? Last edited by Sane; Jan 2nd, 2008 at 6:14 PM. |
|
|
|
|
|
#30 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
Re: Challenging Programming Problem - "Pinball Ranking"
I think, of the 1 second (1.1 with the non-recursive code), a significant portion is reading the file and writing the output.
I split the input and sort loops up and put the timer only counting the sort loop. I ended up with 670ms for the normal input and 18000 ms for the sorted input. Note that the original input is far from best case, giving a binary tree depth of 8468. I think that they probably designed it that way. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| programming or virus problem | mukul | C++ | 3 | Sep 30th, 2007 3:53 AM |
| need advice on problem with wireless network programming | dark_omen | C++ | 2 | Mar 13th, 2007 8:46 PM |
| programming problem | mcl1008 | Java | 6 | Nov 6th, 2006 1:59 PM |
| C programming problem | mmmm_strawberries | C++ | 3 | Mar 1st, 2005 3:48 PM |
| SPIM Assembly Programming Simulation Problem | tsgrimey | Assembly | 1 | Feb 9th, 2005 2:21 AM |