introspectiveSort: (History -- it is a lot newer than the others) Sorters.h
Is like quickSort, but use insertionSort for the smaller parts and revert to heapSort if recursion depth gets too deep.
Pseudocode:
introspectiveSort(a, n)
Sorter | in place | asymptotics | pragmatics |
---|---|---|---|
insertionSort | yes | awful:(O(n2)) | fast for small n |
mergeSort | no | worst case O(n log(n)) | near best, has special uses |
quickSort | yes | expected case O(n log(n)) | best in practice, give or take |
heapSort | yes | worst case o(n log(n)) | factor of two or three worse than best |
introspectiveSort | yes | worst case O(n log(n)) | best in practice, give or take |
Graphs have vertices and edges. Each edge connects two vertices.
For example a road network is a graph with intersections as vertices and road segments between intersections as edges.
For example a social network is a graph, with people as vertices and "friend" or "like" relationships represented by edges.
For example the internet itself is a graph with devices and routers as vertices and connecting links as edges.
Sometimes edges are given weights (or costs), think for example of the length of a road segment in a road network as the edge weight.
Sometimes graphs are directed (edge (a,b) represents a link from a to b, and not vice versa), and sometimes graphs are undirected ( where (a,b) and (b,a) denote the same bidirectional edge). As is commonly done, we will represent undirected graphs by incorporating both directions of an edge in the data structure.
The most common data structures used to represent graphs are the adjacency matrix and the (array of) adjacency lists. See ODS chapter 12.1, 12.2.
Graphs are ubiquitous --- they represent all binary relationships for starters --- and there are many, many important computational problems concerning graphs. They are the core subject of CISC 320 Algorithms. We will consider one fundamental problem: distance between vertices.
How can one determine the shortest path between vertex s and vertex d in a graph?
(s is for "source", d for "destination".)
It turns out the best general method is to learn the shortest path from s to every vertex in the graph. This is called the single source shortest path, SSSP, problem.
A breadth first traversal of the graph starting at s in which we learn the distances of vertices from s.