Sorting Algorithms Demo We all know that Quicksort is one of the fastest algorithms for sorting. It's not often, however, that we get a chance to see exactly how fast Quicksort really is. The following applets chart the progress of several common sorting algorithms while sorting an array of data using in-place algorithms. This means that the algorithms do not allocate additional storage to hold temporary results: they sort the data in place. Some of these sorts are very stupid or very slow and should not be used in code. In-Place Mergesort is yet another abomination. New: Radix sort by Alvin Raj, August 13, 2002. Click on each applet to see the algorithm run.Click on the name of the algorithm to see the source. Bubble Sort (by James Gosling and Jason Harrison) Bi-Directional Bubble Sort (by James Gosling) Selection Sort (by Jason Harrison) Shaker Sort (by Jason Harrison) Insertion Sort (by Jason Harrison) In-Place Merge Sort (by Jason Harrison) Double Storage Merge Sort (by Jack Snoeyink) Heap Sort (by Jason Harrison)
Free Java Tutorials & Guide | Java programming source code Finding a Loop in a Singly Linked List Motivation A singly linked list is a common data structure familiar to all computer scientists. A singly linked list is made of nodes where each node has a pointer to the next node (or null to end the list). A singly linked list is often used as a stack (or last in first out queue (LIFO)) because adding a new first element, removing the existing first element, and examining the first element are very fast O(1) operations. When working with singly linked list, you are typically given a link to the first node. If a linked list has a cycle: The malformed linked list has no end (no node ever has a null next_node pointer)The malformed linked list contains two links to some nodeIterating through the malformed linked list will yield all nodes in the loop multiple times A malformed linked list with a loop causes iteration over the list to fail because the iteration will never reach the end of the list. Incorrect "Solutions" Traverse the List Until the End Mark Each Node Detect Only Full Loops
The Evolution of a Programmer High School/Jr.High First year in College program Hello(input, output) begin writeln('Hello World') end. Senior year in College (defun hello (print (cons 'Hello (list 'World)))) New professional #include <stdio.h> void main(void) { char *message[] = {"Hello ", "World"}; int i; for(i = 0; i < 2; ++i) printf("%s", message[i]); printf("\n"); } Seasoned professional Master Programmer Apprentice Hacker Experienced Hacker Seasoned Hacker % cc -o a.out ~/src/misc/hw/hw.c % a.out Guru Hacker New Manager Middle Manager mail -s "Hello, world." bob@b12 Bob, could you please write me a program that prints "Hello, world."? Senior Manager % zmail jim I need a "Hello, world." program by this afternoon. Chief Executive % letter letter: Command not found. % mail To: ^X ^F ^C % help mail help: Command not found. % damn! Anonymous If you enjoyed this, you might like:
Three Lists problem Skip this if you don't like my toy-algorithm posts. What I call the "three lists problem" is presented in AdUni's Algorithms course, lecture number five by Prof. Shai Simonson: Given three lists of numbers A, B and C, find if there exists a triplet x in A, y in B and z in C such that x+y+z=0. Prof. Simonson describes in general three ways of doing this, the brute force method in O(n^3), a slighly smarter method in O(n^2 log n), and finally a neat method in O(n^2). The numbers need to be distributed normally between some number X and -X. First the brute force method, which is useful for comparison, and to check the correctness of the other results. (defun three-lists-problem-n3 (a b c) "O(n^3) solution, aka the brute force method." ;; n^3 (loop named destiny for x of-type fixnum in a do (loop for y of-type fixnum in b do (loop for z of-type fixnum in c do (when (= (+ x y z) 0) (return-from destiny (list x y z))))))) Next is the roughly O(N^2 N Log N) method.
Compilers: Principles, Techniques, and Tools (Dragon Book) Collected Algorithms of the ACM Open IT Online | View your documents online