Lesson: Algorithms
The polymorphic algorithms described here are pieces of reusable functionality provided by the Java platform. All of them come from the Collections
class, and all take the form of static methods whose first argument is the collection on which the operation is to be performed. The great majority of the algorithms provided by the Java platform operate on List
instances, but a few of them operate on arbitrary Collection
instances. This section briefly describes the following algorithms:
Sorting
The sort
algorithm reorders a List
so that its elements are in ascending order according to an ordering relationship. Two forms of the operation are provided. The simple form takes a List
and sorts it according to its elements' natural ordering. If you're unfamiliar with the concept of natural ordering, read the Object Ordering section.
The sort
operation uses a slightly optimized merge sort algorithm that is fast and stable:
-
Fast: It is guaranteed to run in
n log(n)
time and runs substantially faster on nearly sorted lists. Empirical tests showed it to be as fast as a highly optimized quicksort. A quicksort is generally considered to be faster than a merge sort but isn't stable and doesn't guarantee n log(n)
performance.
-
Stable: It doesn't reorder equal elements. This is important if you sort the same list repeatedly on different attributes. If a user of a mail program sorts the inbox by mailing date and then sorts it by sender, the user naturally expects that the now-contiguous list of messages from a given sender will (still) be sorted by mailing date. This is guaranteed only if the second sort was stable.
http://docs.oracle.com/javase/tutorial/collections/algorithms/index.html
分享到:
相关推荐
Your goal is to simply focus on a lesson at a time (they only a take few minutes to read). The lessons start right from the beginning, covering the basics of Java and building up from there. We ...
9. **FT1_FROG algorithms.pdf** - 这份文档可能深入探讨了FROG算法,这是一种常用的超快脉冲特性恢复技术,它可以提供完整的脉冲幅度和相位信息。 10. **FT4_MIFA.pdf** - 可能介绍了一种名为“多级互相关傅立叶...
2. **算法与数据结构**(algorithms):这部分可能包括排序算法(如冒泡、选择、插入、快速、归并排序)、查找算法、图算法、树算法等,这些都是编程能力提升的重要部分,对于解决实际问题至关重要。 3. **框架**...
2. **algorithms**:这个目录很可能包含了各种数据结构和算法的实现,如排序、查找、图论等,这对于提升编程能力,尤其是解决问题的效率至关重要。 3. **tool**:可能是工具类或者实用工具的集合,例如日志记录、...
2. **algorithms**:这部分内容专注于算法和数据结构,是任何编程学习的基础。可能包含了经典的排序、搜索算法实现,如冒泡排序、快速排序、二分查找等,以及链表、树、图等数据结构的Java实现。 3. **tool**:这...
2. algorithms(算法):这部分可能包含了各种经典的排序、搜索和其他算法的Java实现,如冒泡排序、快速排序、二分查找等。学习这部分可以帮助你理解算法的基本概念和提升代码的效率。 3. tool(工具):可能包含...
─algorithms 算法 ├─database 数据库 ├─distributed 分布式系统 ├─framework 一些常用类库 ├─java-advance 高级类库和jsr规范等 ├─java-basic Java基础 ├─lesson-code 一些课程代码 ├─mvc mvc框架 ...
Lesson 1: Index Concepts 3 Lesson 2: Concepts – Statistics 29 Lesson 3: Concepts – Query Optimization 37 Lesson 4: Information Collection and Analysis 61 Lesson 5: Formulating and Implementing ...