This website houses notes from my studies at the University of Liverpool. If you see any errors or issues, please do open an issue on this site's GitHub.
Arrays An array consists of contiguous memory locations: The highest address corresponds to the last element. The lowest address corresponds to the first element. Declaring Arrays Arrays can be declared like so: float income[3]; This will create an array called income of type float that can hold three elements. Initialising...
Bucket Sort Bucket sort is not based on comparisons but on using keys as indices of a bucket array. Initially all items of the input sequence $S$ are moved to appropriate buckets. An item with key $k$ is moved to bucket $B[k]$. Then move all items back into $S$ according...
Standard Directory Names Directory Name Description src Source Files build/classes or bin Intermediate Output dist Distributeable Files All files apart from src are generated and can be deleted. Packages This is a method of grouping files together with their scope. The package is named using a reverse fully qualified name:...
A fragment of code that accepts zero of more argument values, produces a result value and has zero or more side effects. Arguments By default arguments are passed by value: int main (void) { putInFridge(eggs) return 0; } This means that if the variable changes in the function, the change...
Counting Inversions - Divide & Conquer The standard approach for counting inversions takes: \[\Omega(n^2)\] we can speed this up by using the following method. Divide the permutation into two fairly equal parts. Sort each sub-list and merge them into a single sorted list. Then count the inversions again. This is...
Conditional Statements In addition to the standard curly brace notation we can also use the following notation: if (condition): statement endif This must be ended with the statement endif. It also supports conditional expressions: condition ? if_true_expr : if_false_expr Other conditional statements such as: Switch-Case If While & Do-While Break...
Priority Queues A priority queue is a container of elements, each having an associated key: The key determines the priority used in picking elements to be removed. A priority queue has these fundamental methods: insertItem(k, e) - Insert an element $e$ having key $k$ into the PQ. removeMin() - Remove...
To compile our source code with Ant we need the source file: public class Main { public static void main(String args[]) { for(int i=0;i<args.length;i++) { System.out.println(args[i]); } } } This should be placed in a folder called src to match the srcdir variable in the build file. and an Ant...
Comparison Operators Type juggling affects the way that comparisons work in PHP, consequently there are some additional competitors: Expression Name Description expr1 == expr2 Equal TRUE if expr1 is equal to expr2 after type juggling. expr1 != expr2 Not Equal TRUE if expr1 is not equal to expr2 after type...
while This checks the statement before running the statements: while (<expression>) { <statements> } Be aware of the limits of the data-types you are using if you are including counters in your while loops. limits.h has information regarding maximum values. do while This checks the statement after running the statements:...