sorting algorithm

Sorting algorithm

Selection sort



This method is called selection sort because it works by repeatedly selecting the smallest remaining item。

Selection sort uses ~N2/2 compares and N exchanges to sort an array of length N.

  1. First, find the smallest item in the array, and exchange it with the first entry。
  2. Then, find the next smallest item and exchange it with the second entry。
  3. Continue in this way until the entire array is sorted。

source code: Selection.java

结论:

  • 算法运行时间和输入无关。这意味着即使输入的数组有序,也要进行一趟扫描。
  • 数据的移动最少。交换次数和数组大小是线性关系。

insert sort



sorting algorithm

时间: 2024-08-24 15:38:54

sorting algorithm的相关文章

Design and Analysis of Algorithms_Fundamentals of the Analysis of Algorithm Efficiency_Pseudocode

This pseudocode from the book: <<Introduction to the Design and Analysis of Algorithms_Second Edition>> _ Anany LevitinNote that throughout the paper, we assume that inputs to algorithms fall within their specified ranges and hence require no

普林斯顿大学算法课 Algorithm Part I Week 3 快速排序 Quicksort

发明者:Sir Charles Antony Richard Hoare 基本思想: 先对数据进行洗牌(Shuffle the array) 以数据a[j]为中心进行分区(Partition),使得a[j]左侧的数据都小于等于a[j],a[j]右侧的数据都大于等于a[j] 分区完后递归排序 演示(Quicksort partitioning demo) 重复操作指导i和j指针相遇 当a[i] < a[lo]时,令i从左往右扫描 当a[j] > a[lo]时,令j从右往左扫描 交换a[i]和a[

Summary: sorting Algorithms

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. Time Complexity: O(N^2) f

Algorithm | Sort

Bubble sort Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wron

[Algorithms] Quicksort algorithm using TypeScript

Quicksort (also called partition sort and pivot sort) is arguably the most used sorting algorithm. It is the one commonly implemented internally in language runtimes. In this lesson we cover the quick sort algorithm, why is it called quick and how to

排序算法(sorting)

对COMP20003中排序部分进行总结,图片来自COMP20003 有部分内容来自http://www.cnblogs.com/eniac12/p/5329396.html 演示动画:https://www.cs.usfca.edu/~galles/visualization/ComparisonSort.html 概念: stable sort: 相同的值排序后相对顺序不变. Comparison-based sorting is Ω(nlogn). Hash function --- 用数对

Sorting Algorithms

Reference [1] https://www.geeksforgeeks.org/stable-quicksort/ Stability A sorting algorithm is said to be stable if it maintains the relative order of records in the case of equality of keys. Some sorting algorithms are stable by nature like Insertio

Java中常见的排序算法

这是我摘取的一段英文资料,我觉得学习算法之前,对各种排序得有个大致的了解: Sorting algorithms are an important part of managing data. At Cprogramming.com, we offer tutorials for understanding the most important and common sorting techniques. Each algorithm has particular strengths and w

ZOJ-2386 Ultra-QuickSort 【树状数组求逆序数+离散化】

Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input seque