Efficient implementations of Searching & Sorting Algorithms in Java

纵饮孤独 提交于 2019-12-23 17:27:03

问题


Does anyone have a good reference for a set of Java code implementations of common searching and sorting algorithms.

There are many ways to skin a cat (its easy to find Java code of various algos on the net), however is there a list of the most efficient ways in Java to implement these various algorithms?

There is for example the http://www.algorithmist.com but most implementations are in C/C++.

Cheers!


回答1:


I'd suggest looking at the Java Standard Library source code itself.

The Collections and Arrays classes have binary search and binary sort implementations which you can study.

Here's the source for Collections.java from openjdk: http://www.docjar.com/html/api/java/util/Collections.java.html




回答2:


I found the book "Algorithms in Java (parts 1-4)" by Sedgewick useful. The code is available online, but it might be hard to understand without the book.




回答3:


Some standard Algorithms for Maps, Sets, Lists etc. are available. You have to download the src.zip from the Oracle-Java homepage, where it is available.

For common use cases, the algorithms should be pretty efficient, but of course, for every algorithm there is a worst-case scenario for the data, to be provided. So in exceptional cases, you will be able to find or produce better ones.




回答4:


The runtime complexity of an algorithm is indifferent to the programming language it's implemented in - so you shouldn't really care too much. But since you ask, I would consider using grepcode. For example, look what I found when i searched "java quicksort".




回答5:


https://intelligentjava.wordpress.com/2014/07/05/sorting-algorithms/ has good review with implementations and benchmark for performance comparison.



来源:https://stackoverflow.com/questions/10159834/efficient-implementations-of-searching-sorting-algorithms-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!