fill in the gaps exercise - return second biggest element in list (7)

6 Name: #!/usr/bin/anonymous : 2011-04-04 00:23 ID:BSO72EOy

>>5
You should be putting your highest m numbers in a binary search tree. Then for each number: 1. you insert it in the BST. and 2. remove the (m+1)th smallest element in the tree.

So you would get a O(n log m) algorithm instead of a O(nm) algorithm, where n is the number of elements in the array, and m is from the mth largest element that you want.

This thread has been closed. You cannot post in this thread any longer.