Enter size of tree to create [1000]: Enter # of random trees to create[100000]: Enter # trees per heartbeat [10000]: Shuffle values before adding [true]?: Verify searches work [false]?: Show 1st tree [false]?: Collecting Statistics: Processed: 10000 20000 30000 40000 50000 60000 70000 80000 90000 100000 Done Height | #Trees | ---------------------------------------------------------------------- 16 | 43 | 17 | 966 | ** 18 | 5579 | ************* 19 | 14661 | ********************************** 20 | 21314 | ************************************************** 21 | 21134 | ************************************************* 22 | 16082 | ************************************* 23 | 9845 | *********************** 24 | 5486 | ************ 25 | 2761 | ****** 26 | 1215 | ** 27 | 561 | * 28 | 220 | 29 | 83 | 30 | 36 | 31 | 9 | 32 | 5 | Minimum Possible Height = 8.96723 Minimum Actual Height = 16 Average Actual Height = 21.0394 Maximum Actual Height = 32 Maximum Possible Height = 999 Avg Compares for Search = 11 (truncated) Time = 29.479 seconds; processing speed = 3392 trees/second ------------------------------------------------------------------------------ Enter size of tree to create [1000]: 10000 Enter # of random trees to create[100000]: 1000000 Enter # trees per heartbeat [10000]: 100000 Shuffle values before adding [true]?: Verify searches work [false]?: Show 1st tree [false]?: Collecting Statistics: Processed: 100000 200000 300000 400000 500000 600000 700000 800000 900000 1000000 Done Height | #Trees | ---------------------------------------------------------------------- 24 | 18 | 25 | 949 | 26 | 12208 | *** 27 | 57676 | ************** 28 | 134769 | ********************************* 29 | 193509 | ************************************************ 30 | 198608 | ************************************************** 31 | 160151 | **************************************** 32 | 108700 | *************************** 33 | 65271 | **************** 34 | 35518 | ******** 35 | 17801 | **** 36 | 8356 | ** 37 | 3771 | 38 | 1604 | 39 | 682 | 40 | 267 | 41 | 95 | 42 | 36 | 43 | 7 | 44 | 1 | 45 | 2 | 46 | 1 | Minimum Possible Height = 12.2879 Minimum Actual Height = 24 Average Actual Height = 30.2145 Maximum Actual Height = 46 Maximum Possible Height = 9999 Avg Compares for Search = 16 (truncated) Time = 3063.72 seconds; processing speed = 326 trees/second ------------------------------------------------------------------------------ Some data taken from previous versions of ICS-46 in Java Enter size of tree to create : 10000 Enter # of random trees to create : 1000000 Collecting Statistics: Height | #Trees | ---------------------------------------------------------------------- 24 | 18 | 25 | 906 | 26 | 12360 | *** 27 | 57584 | ************** 28 | 135007 | ********************************** 29 | 193358 | ************************************************ 30 | 198349 | ************************************************** 31 | 160260 | **************************************** 32 | 109076 | *************************** 33 | 65045 | **************** 34 | 35396 | ******** 35 | 17637 | **** 36 | 8549 | ** 37 | 3703 | 38 | 1643 | 39 | 665 | 40 | 282 | 41 | 97 | 42 | 41 | 43 | 16 | 44 | 5 | 45 | 2 | 46 | 1 | Minimum Possible Height = 12.287856641840545 Minimum Actual Height = 24 Average Actual Height = 30.214161 Maximum Actual Height = 46 Maximum Possible Height = 9999 Avg Compares for Search = 16 (truncated) Time = 1341.13 seconds; processing speed = 745 trees/second ------------------------------------------------------------------------------ Enter size of tree to create : 10000 Enter # of random trees to create : 3000000 Collecting Statistics: Height | #Trees | ---------------------------------------------------------------------- 24 | 48 | 25 | 2816 | 26 | 36641 | *** 27 | 173110 | ************** 28 | 404628 | ********************************* 29 | 580334 | ************************************************ 30 | 596070 | ************************************************** 31 | 479814 | **************************************** 32 | 326389 | *************************** 33 | 194708 | **************** 34 | 106582 | ******** 35 | 53511 | **** 36 | 25438 | ** 37 | 11558 | 38 | 5032 | 39 | 1998 | 40 | 838 | 41 | 314 | 42 | 105 | 43 | 42 | 44 | 16 | 45 | 6 | 46 | 2 | Minimum Possible Height = 12.287856641840545 Minimum Actual Height = 24 Average Actual Height = 30.21550166666667 Maximum Actual Height = 46 Maximum Possible Height = 9999 Avg Compares for Search = 16 (truncated) Time = 4135.146 seconds; processing speed = 725 trees/second ------------------------------------------------------------------------------ Enter size of tree to create : 10000 Enter # of random trees to create : 5000000 Collecting Statistics: Height | #Trees | ---------------------------------------------------------------------- 24 | 67 | 25 | 4707 | 26 | 61134 | *** 27 | 289110 | ************** 28 | 674927 | ********************************* 29 | 965701 | ************************************************ 30 | 992753 | ************************************************** 31 | 800114 | **************************************** 32 | 544052 | *************************** 33 | 325608 | **************** 34 | 177491 | ******** 35 | 89025 | **** 36 | 42452 | ** 37 | 19076 | 38 | 8282 | 39 | 3347 | 40 | 1332 | 41 | 554 | 42 | 177 | 43 | 61 | 44 | 19 | 45 | 5 | 46 | 4 | 47 | 2 | Minimum Possible Height = 12.287856641840545 Minimum Actual Height = 24 Average Actual Height = 30.2152332 Maximum Actual Height = 47 Maximum Possible Height = 9999 Avg Compares for Search = 16 (truncated) Time = 6786.836 seconds; processing speed = 736 trees/second ------------------------------------------------------------------------------ I actually figured out a formula that computes the number of sequences that yield a binary search tree with N values and of height H. From this formula I computed the exact average height of a tree with N nodes. N Average Height 1 0.0 2 1.0 4 2.3333333333333335 8 4.017460317460317 16 6.039095184259206 32 8.280329890049611 64 10.67962444037314 128 13.190811301631685 This was a far as I was able compute: with N = 128, there are 128! sequences generated, beyond which swammped my computer. Note that 128! is 3856204823625804217356770659234636406174931095902235902788284032763734025751655 4356068616858850736153403005183305891634759217293226249885776611495524503935776 0034644709279247692495585280000000000000000000000000000000 The average height is approximated by 2*Log2(N)-1. The best bst with N nodes has height Log2(N)-1. So the average height is about 2 * the best (+1).