Quick Sort Implementation in C

Quicksort is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order. Developed by Tony Hoare in 1959, published in 1961, it is still a commonly used algorithm for sorting. When implemented well, it can be about two or three times faster than its main competitors, merge sort and heapsort. Quicksort is a comparison sort, meaning that it can sort items of […]

Sort a Scrambled Itinerary

This algorithm problem is from Google Code Jam. Here is the description of the problem. Once upon a day, Mary bought a one-way ticket from somewhere to somewhere with some flight transfers. For example: SFO->DFW DFW->JFK JFK->MIA MIA->ORD. Obviously, transfer flights at a city twice or more doesn’t make any sense. So Mary will not do that. Unfortunately, after she received the tickets, she messed up the tickets and she […]

Sieve of Eratosthenes

In mathematics, the sieve of Eratosthenes, one of a number of prime number sieves, is a simple, ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite (i.e. not prime) the multiples of each prime, starting with the multiples of 2. The multiples of a given prime are generated starting from that prime, as a sequence of numbers with the same […]

Mapped Memory

Mapped memory permits different processes to communicate via a shared file. To map an ordinary file to a process’s memory, use the mmap (“Memory MAPped,” pronounced “em-map”) call. The first argument is the address at which you would like Linux to map the file into your process’s address space; the value NULL allows Linux to choose an available start address. The second argument is the length of the map in bytes. The third […]