Closed faame closed 2 years ago
Good analysis. I re-ran the experiments with that update and M = 10^9 had a 96.26% insertion percentage for me. I updated the exercise here: https://github.com/reneargento/algorithms-sedgewick-wayne/commit/64793c56c70c7857db6ad596c7db9fe9667e3089 Thanks!
In 3.1.15
It shows then N=10^9, the insertion time is 5.92% of the overall time.
This is incorrect. It should be close to 100%
we can use the existing conclusion that for
BinarySearchST
Assuming insert inserts distinct keys. There are M insertions, for M distinct keysM Search is conducted on N keys, thus
Per the question, M = N*1000
So
The insertion percentage is
I think the idea is that the N^2 is the high-order item here. Thus when N become asymptotic, P should approach 100%.
In the example, largest M=10^9, so largest N=10^6
In that case the percentage should be
Yet your program experiment is
5.92%
far from 100% I think one issue is here:In 3.1.15 source code
when number of insertions is N=10^6, you are drawing random number from [0, 10^5]. Thus you will have significant number of duplicate numbers, resulting a much shorter symbol table (I..e effective N << 10^6)
I printed out the size of the symbol table after N-10^6 insertions, and the size is less than 10^4, which is far from the expected 10^6 size.
So I think the correct anwswer for 3.1.15 is to use formulas
Using N=10^9 as upper bound of random number generator
I can see the program getting closer to 100%