QuickSort is a sorting algorithm developed by Tony Hoare that, on average, makes
O(n log n) comparisons to sort n items. It is also known as partition-exchange
sort because of its use of the partition
algorithm. In the worst
case, it makes O(n2) comparisons, though this behavior is rare. QuickSort is
often faster in practice than other O(n log n) algorithms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; add line numbers | |
(global-linum-mode 1) | |
;; display line numbers and column numbers | |
(setq line-number-mode t) | |
(setq column-number-mode t) | |
;; make sure the line numbers don't touch the text | |
(setq linum-format "%d ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Armstrong { | |
public static void main(String[] args) { | |
for (int a = 0; a < 9; a++) { | |
for (int b = 0; b < 9; b++) { | |
for (int c = 0; c < 9; c++) { | |
int n = a * 100 + b * 10 + c; | |
int a3 = a * a * a; | |
int b3 = b * b * b; | |
int c3 = c * c * c; | |
if (a3 + b3 + c3 == n) System.out.println(n); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A disjoint sets data structure. | |
* | |
* @author Michael E. Cotterell <[email protected]> | |
* @param n the number of initial disjoint sets | |
*/ | |
class OldDisjointSets (n: Int) { | |
// make sure we're using mutable sets | |
import scala.collection.mutable.{ BitSet, Set } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Search { | |
public static <T extends Comparable<T>> int binarySearch(T[] array, T value, int lo, int hi) { | |
if (lo < hi) { | |
int mid = (lo / 2) + (hi / 2); | |
int cmp = array[mid].compareTo(value); | |
if (cmp < 0) return binarySearch(array, value, lo, mid - 1); | |
if (cmp > 0) return binarySearch(array, value, mid + 1, hi); | |
return mid; | |
} // if |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalation.linalgebra.VectorD | |
import scalation.random.Normal | |
object NaiveBayes extends App { | |
val miles = VectorD(1300, 900, 2000, 1450, 2190, 1600, 300, 3100, 1521, 1786) | |
val mean = milel.sum / miles.dim.toDouble | |
val variance = ((miles - mean) ~^ 2).sum / (miles.dim.toDouble - 1) | |
def PrMiles (x: Double) = Normal(mean, variance).pf(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.Random | |
// print unshuffled range | |
(1 to 10) foreach { i => println(i) } | |
// print shuffled range | |
val r = new Random() | |
r.shuffle(1 to 10 toIterable) foreach { i => println(i) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOT TESTED YET | |
import scala.reflect.runtime.universe._ | |
class Schema[T : TypeTag](val attributes: String*) extends Dynamic { | |
val length = attributes.length | |
def selectDynamic[A: TypeTag](field: String): A.tpe = null | |
def updateDynamic[A: TypeTag](field: String)(value: A.tpe) { } | |
} // Schema |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<http://johnson.cs.uga.edu/triplify/index.php/actor> <http://www.w3.org/2000/01/rdf-schema#comment> "Generated by Triplify V0.7.1 (http://Triplify.org)" . | |
<http://johnson.cs.uga.edu/triplify/index.php/actor> <http://creativecommons.org/ns#license> <http://creativecommons.org/licenses/by/3.0/us/> . | |
<http://johnson.cs.uga.edu/triplify/index.php/actor/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Actor> . | |
<http://johnson.cs.uga.edu/triplify/index.php/actor/2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Actor> . | |
<http://johnson.cs.uga.edu/triplify/index.php/actor/3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Actor> . | |
<http://johnson.cs.uga.edu/triplify/index.php/actor/4> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Actor> . | |
<http://johnson.cs.uga.edu/triplify/index.php/actor/5> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Actor> . | |
<http://jo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
google.load('visualization', '1', {'packages': ['geochart']}); | |
google.setOnLoadCallback(drawMarkersMap); | |
function drawMarkersMap() { | |
var data = new google.visualization.DataTable(); | |
data.addColumn('string', 'City'); | |
data.addColumn('number', 'Population'); | |
data.addColumn('number', 'Area'); | |
data.addRows([ | |
['Rome', 2761477, 1285.31], |