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.
Consider the following text as a test for regular expressions: It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. During the battle, Rebel spies managed to steal secret plans to the Empire’s ultimate weapon, the...
Due to the large number of I/O classes in java.io.Files, there is a class called: java.nio.Files This class consists of several static function calls that cater to common use cases. You should look in this class before looking elsewhere. Reading from File A classic approach to reading from a text...
Streams are an endless flow of data from a source to a destination: graph LR Source -->|write| 010010 010010 -->|read| Destination Streams are objects. There are different classes for various types of sources and destinations. Streams as Object The standard library java.io implements streams in an object-oriented way. The InputStream...
File Handles This is an object that represents a file on the disk (a path in the file system). java.io.File is used to represent files and provides methods to interact with the file system. You can call the following methods on a File: Deleting Renaming Check if it exists: Check...
This method extends the example in the last lecture. Java uses the American spelling: synchronized. Synchronised Method class Buffer { private int v; private volatile boolean empty = true; public synchronized void insert (int x) { while (!empty) ; // null loop empty = false; v = x; } public...
A producer process and a consumer process communicate via a buffer. Producer Cycle: Produce item. Deposit in buffer. Consumer Cycle: Extract item from buffer. Process the item. There can be many producers and consumers, sometimes in a chain. Issues We have to ensure that: Producer cannot put items in a...
An image can be represented as a matrix where each cell used 24 bits to encode the colour as RGB. To compress it we can use the following method: Given an $H\times W$ image $P$, let $M$ be the corresponding matrix. $M$ will not typically be a square matrix. Exploiting...
Consider that web-pages form a directed graph. There is a directed edge from one node to another if that page links to it. We should order these nodes such that the most important is at the top. If a node is pointed to by a lot of other pages then...
Single-Source Shortest Paths Consider a directed/undirected connected graph $G$: The edges are labelled by weight. Given a particular vertex called the source: Find shortest paths from the source to all other vertices. Example Undirected connected graph $G$: graph LR a ---|2| b b ---|3| c a ---|3| c b ---|2|...
Minimum Spanning Tree (MST) Given an undirected connected graph $G$: The edges are labelled by weight Spanning tree of $G$: A tree containing all vertices in $G$. Minimum spanning tree of $G$: A spanning tree of $G$ with minimum weight. Example Undirected connected graph $G$: graph LR a ---|2| b...