I need to find the element of a list, with the highest weight.
Example:
{{1, 3.80737}, {2, 4.48538}, {3, 2.64947}, {4, 1.06387}, {5,
5.07804}, {6, 1.33265}, {7, 9.11426}, {8, 6.90628}, {9,
5.34919}, {10, 3.90156}}
the program should pick {7, 9.11426}.
I've done the following working example:
n=50;
tabint = Table[{i, RandomReal[{1, n}]}, {i, 1, n}] (*to generate a random table. This command does not matter for the efficiency of my programme. It's only for this example*)
tabsort = Sort[tabint, (#1[[2]] >= #2[[2]]) &];
initialvls = tabsort[[1]];
The thing that bothers me with my code is the sort. It seems that I lose time in sorting the whole list than those I would need to if just looking for the maximum weight. I bet there is a faster way to do this.
Any help would be appreciated.
P.S.: I've tried to find other questions similar to this one, but the answers don't seems to be applicable to my problem. May be wrong though...
MaxByhere andMaximalByintroduced in version 10. – Szabolcs Dec 02 '14 at 19:21