algorithm - find the smallest e1-e2 in a set of many elements in Java language -


i have problem is: given set of integers (e1,e2,e3....) , determine smallest ex-ey (the smallest result of subtraction of 2 elements in set). know has algorithm have no knowledge that. can me giving logics or code in java. many thanks!

the optimal solution can think of sort set ( o(n log n) ) , perform pairwise comparison on each consecutive pair in set ( o(n) ).

the "naive" algorithm compares every element against every other element o(n^2).


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -