简体   繁体   中英

Efficient implementations of Searching & Sorting Algorithms in Java

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!

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

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.

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.

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".

https://intelligentjava.wordpress.com/2014/07/05/sorting-algorithms/对性能比较的实现和基准进行了很好的评估。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM