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.
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....
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...
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...
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...
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...
Dynamic programming is similar to divide-and-conquer however, recursive calls are replaced by looking up pre-computed values. We can use it to compute optimisation problems where a brute force search is infeasible. A typical approach to solve a problem using dynamic programming is to first find a recursive solution to the...
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...
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...
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...
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...