Skip to content
UoL CS Notes

Home

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.

JavaScript - Functions, Libraries & Objects

COMP284 Lectures

Functions A basic JavaScript function takes the following form: function identifier(param1, param2,...) { statements } We can also assign a function to a variable like so: var identifier = function(param1, param2, ...){ statements } identifier.length can be used inside the body of the function to determine the number of parameters....

Read More

C++ Overloading Continued & Templates

COMP282 Lectures

Overloading Types of Operators There are three types of operator in C++: Prefix Unary - --counter Postfix Unary - counter++ Binary - num1 - num2 Unary Operators To overload prefix unary operators we write: returntype operator-(); This will override -. To overload postfix unary operators we write: returntype operator++(int); The...

Read More

Numeric Testing

COMP285 Lectures

To test numeric functions we should use cases like so: | Fcalc(x) - Ftrue(x) | < tolerance We can calculate Ftrue using an arbitrary precision maths package. This is as there are inherent losses with floating point numbers so our calculated value may be off (within reason). Tolerance We can...

Read More

C++ Inheritance & Overloading

COMP282 Lectures

Inheritance c++ has access modifiers on inheritance. There are no interfaces like in Java. Basic inheritance has the following syntax: class Dog : public Animal(); which represents the following: classDiagram Animal <|-- Dog The access modifiers change the access modifiers of inherited methods etc. public makes no change. Polymorphism #include...

Read More

JavaScript Control Structures & Arrays

COMP284 Lectures

Control Structures Conditional Statements Conditional statements can take the following forms: if (condition) statement else if (condition) statement else statement condition ? if_true_expr : if_false_expr Switch Statements We can use switch statements like so: switch (expr) { case expr1: statements break; case expr2: statements break; default: statements break; } while...

Read More

JavaScript Introduction

COMP284 Lectures

JavaScript is a language for client-side programming. Hello, world! <!DOCTYPE html> <html lang="en-GB"> <head> <title>Hello, world!</title> </head> <body> <script> document.writeln("<p><b>Hello, world!</b></p>"); </script> <noscript> <p><b>Please enable JavaScript to see the super secret message!</b></p> </noscript> </body> </html> Script is enclosed in script tags. Alternative HTML is enclosed in noscript tags. Types JavaScript...

Read More

Classes in C++

COMP282 Lectures

The nice thing about C++ being compatible with C is that you don’t have to use classes if you don’t want to. Classes A basic example of a class looks like so: #include <string> class Animal { int weight; std::string name; }; Remember to include the semicolon ; at the...

Read More

Greedy Algorithm Applications - Knapsack, Scheduling, Clustering

COMP202 Lectures

The greedy method solves optimisation problems by going through a sequence of feasible choices. The sequence starts from a well-understood configuration and then iteratively makes the decision that seems best from all those that are currently possible. Problems that have a greedy solution possess the greedy-choice property. Fractional Knapsack Problem...

Read More

Divide & Conquer Applications

COMP202 Lectures

Fast Multiplication of Integers A logical multiplication algorithm will take $\Theta(n^2)$ time to complete. We can do better by doing a fast multiplication. Consider that we have two numbers, $I$ and $J$, to multiply together. Pad the numbers with zeros, at the beginning, so that the length of each number...

Read More