<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Brandon Skerritt on Medium]]></title>
        <description><![CDATA[Stories by Brandon Skerritt on Medium]]></description>
        <link>https://medium.com/@brandonskerritt?source=rss-2480a7e35749------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JCIg513S9nUkaPVA2vXb2w.jpeg</url>
            <title>Stories by Brandon Skerritt on Medium</title>
            <link>https://medium.com/@brandonskerritt?source=rss-2480a7e35749------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 06:04:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@brandonskerritt/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[This publication has moved!]]></title>
            <link>https://medium.com/@brandonskerritt/this-publication-has-moved-bdf8ea1af644?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdf8ea1af644</guid>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Sun, 20 Oct 2019 10:14:41 GMT</pubDate>
            <atom:updated>2019-10-20T10:14:41.081Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://skerritt.blog/">Brandon&#39;s Blog</a></p><p>This publication has moved to:</p><p><a href="https://skerritt.blog/">Brandon&#39;s Blog</a></p><p>Please check it out. Subscribe via RSS or email!</p><p><a href="https://skerritt.blog/">Brandon&#39;s Blog</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdf8ea1af644" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Is Dynamic Programming With Python Examples]]></title>
            <link>https://medium.com/@brandonskerritt/what-is-dynamic-programming-with-python-examples-c6af920fb179?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6af920fb179</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Wed, 05 Jun 2019 16:03:32 GMT</pubDate>
            <atom:updated>2019-06-26T12:04:54.394Z</atom:updated>
            <content:encoded><![CDATA[<p>Dynamic programming is breaking down a problem into smaller sub-problems, solving each sub-problem and storing the solutions to each of these sub-problems in an array (or similar data structure) so each sub-problem is only calculated once.</p><p>It is both a <a href="https://en.wikipedia.org/wiki/Mathematical_optimization">mathematical optimisation</a> method and a computer programming method.</p><p><em>Optimisation problems</em> seek the maximum or minimum solution. The general rule is that if you encounter a problem where the initial algorithm is solved in O(2 n) time, it is better solved using Dynamic Programming.</p><h3>Why Is Dynamic Programming Called Dynamic Programming?</h3><p><a href="https://en.wikipedia.org/wiki/Richard_E._Bellman">Richard Bellman</a> invented DP in the 1950s. <a href="https://en.wikipedia.org/wiki/Dynamic_programming#History">Bellman named it Dynamic Programming</a> because at the time, RAND (his employer), disliked mathematical research and didn’t want to fund it. He named it Dynamic Programming to hide the fact he was really doing mathematical research.</p><p>Bellman explains the reasoning behind the term Dynamic Programming in his autobiography, Eye of the Hurricane: An Autobiography (1984, page 159). He explains:</p><blockquote><em>“I spent the Fall quarter (of 1950) at RAND. My first task was to find a name for multistage decision processes. An interesting question is, Where did the name, dynamic programming, come from? The 1950s were not good years for mathematical research. We had a very interesting gentleman in Washington named Wilson. He was Secretary of Defense, and he actually had a pathological fear and hatred of the word research. I’m not using the term lightly; I’m using it precisely. His face would suffuse, he would turn red, and he would get violent if people used the term research in his presence. You can imagine how he felt, then, about the term mathematical. The RAND Corporation was employed by the Air Force, and the Air Force had Wilson as its boss, essentially. Hence, I felt I had to do something to shield Wilson and the Air Force from the fact that I was really doing mathematics inside the RAND Corporation. What title, what name, could I choose? In the first place I was interested in planning, in decision making, in thinking. But planning, is not a good word for various reasons. I decided therefore to use the word “programming”. I wanted to get across the idea that this was dynamic, this was multistage, this was time-varying. I thought, let’s kill two birds with one stone. Let’s take a word that has an absolutely precise meaning, namely dynamic, in the classical physical sense. It also has a very interesting property as an adjective, and that is it’s impossible to use the word dynamic in a pejorative sense. Try thinking of some combination that will possibly give it a pejorative meaning. It’s impossible. Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it as an umbrella for my activities.”</em></blockquote><h3>What are Sub-Problems?</h3><p>Sub-problems are smaller versions of the original problem. Let’s see an example. With the equation below:</p><p>$$1 + 2 + 3 + 4$$</p><p>We can break this down to:</p><p>$$1 + 2$$</p><p>$$3 + 4$$</p><p>Once we solve these two smaller problems, we can add the solutions to these sub-problems to find the solution to the overall problem.</p><p>Notice how these sub-problems breaks down the original problem into components that build up the solution. This is a small example but it illustrates the beauty of Dynamic Programming well. If we expand the problem to adding 100’s of numbers it becomes clearer why we need Dynamic Programming. Take this example:</p><p>$$6 + 5 + 3 + 3 + 2 + 4 + 6 + 5$$</p><p>We have $6 + 5$ twice. The first time we see it, we work out $6 + 5$. When we see it the second time we think to ourselves:</p><blockquote><em>“Ah, 6 + 5. I’ve seen this before. It’s 11!”</em></blockquote><p>In Dynamic Programming we store the solution to the problem so we do not need to recalculate it. By finding the solutions for every single sub-problem, we can tackle the original problem itself.</p><p><em>Memoisation </em>is the act of storing a solution.</p><h3>What is Memoisation in Dynamic Programming?</h3><p>Let’s see why storing answers to solutions make sense. We’re going to look at a famous problem, <a href="https://www.mathsisfun.com/numbers/fibonacci-sequence.html"><em>Fibonacci sequence</em></a>. This problem is normally solved in Divide and Conquer.</p><p>There are 3 main parts to <a href="https://skerritt.blog/divide-and-conquer-algorithms/">divide and conquer</a>:</p><ol><li><strong>Divide </strong>the problem into smaller sub-problems of the same type.</li><li><strong>Conquer </strong>— solve the sub-problems recursively.</li><li><strong>Combine </strong>— Combine all the sub-problems to create a solution to the original problem.</li></ol><p>Dynamic programming has one extra step added to step 2. This is memoisation.</p><p>The Fibonacci sequence is a sequence of numbers. It’s the last number + the current number. We start at 1.</p><p>$$1 + 0 = 1$$</p><p>$$1 + 1 = 2$$</p><p>$$2 + 1 = 3$$</p><p>$$3 + 2 = 5$$</p><p>$$5 + 3 = 8$$</p><p>In Python, this is:</p><pre>def F(n): if n == 0 or n == 1: return n else: return F(n-1)+F(n-2)</pre><p>If you’re not familiar with recursion I have a <a href="https://skerritt.blog/divide-and-conquer-algorithms/">blog post written for you that you should read first.</a></p><p>Let’s calculate F(4). In an execution tree, this looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*zeA5Wgnq1mnnCrWh.png" /></figure><p>We calculate F(2) twice. On bigger inputs (such as F(10)) the repetition builds up. The purpose of dynamic programming is to not calculate the same thing twice.</p><p>Instead of calculating F(2) twice, we store the solution somewhere and only calculate it once.</p><p>We’ll store the solution in an array. F[2] = 1. Below is some Python code to calculate the Fibonacci sequence using Dynamic Programming.</p><pre>def fibonacciVal(n): memo[0], memo[1] = 0, 1 for i in range(2, n+1): memo[i] = memo[i-1] + memo[i-2] return memo[n]</pre><h3>How to Identify Dynamic Programming Problems</h3><p>In theory, Dynamic Programming can solve every problem. The question is then:</p><blockquote><em>“When should I solve this problem with dynamic programming?”</em></blockquote><p>We should use dynamic programming for problems that are between <em>tractable </em>and <em>intractable </em>problems.</p><p><a href="https://www.britannica.com/technology/tractable-problem"><em>Tractable problems</em></a> are those that can be solved in polynomial time. That’s a fancy way of saying we can solve it in a fast manner. Binary search and sorting are all fast. <a href="https://www.umsl.edu/~siegelj/information_theory/classassignments/Lombardo/04_intractableproblems.html"><em>Intractable problems</em></a> are those that run in exponential time. They’re slow. Intractable problems are those that can only be solved by bruteforcing through every single combination ( <a href="https://www.youtube.com/watch?v=YX40hbAHx3s">NP hard</a>).</p><p>When we see terms like:</p><blockquote><em>“shortest/longest, minimized/maximized, least/most, fewest/greatest, “biggest/smallest”</em></blockquote><p>We know it’s an optimisation problem.</p><p>Dynamic Programming algorithms proof of correctness is usually self-evident. Other algorithmic strategies are often much harder to prove correct. Thus, more error-prone.</p><p>When we see these kinds of terms, the problem may ask for a specific number ( “find the minimum number of edit operations”) or it may ask for a result ( “find the longest common subsequence”). The latter type of problem is harder to recognize as a dynamic programming problem. If something sounds like optimisation, Dynamic Programming can solve it.</p><p>Imagine we’ve found a problem that’s an optimisation problem, but we’re not sure if it can be solved with Dynamic Programming. First, identify what we’re optimising for. Once we realize what we’re optimising for, we have to decide how easy it is to perform that optimisation. Sometimes, the <a href="https://brilliant.org/wiki/greedy-algorithm/">greedy approach</a> is enough for an optimal solution.</p><p>Dynamic programming takes the brute force approach. It Identifies repeated work, and eliminates repetition.</p><p>Before we even start to plan the problem as a dynamic programming problem, think about what the brute force solution might look like. Are sub steps repeated in the brute-force solution? If so, we try to imagine the problem as a dynamic programming problem.</p><p>Mastering dynamic programming is all about understanding the problem. List all the inputs that can affect the answers. Once we’ve identified all the inputs and outputs, try to identify whether the problem can be broken into subproblems. If we can identify subproblems, we can probably use Dynamic Programming.</p><p>Then, figure out what the recurrence is and solve it. When we’re trying to figure out the recurrence, remember that whatever recurrence we write has to help us find the answer. Sometimes the answer will be the result of the recurrence, and sometimes we will have to get the result by looking at a few results from the recurrence</p><p>Dynamic Programming can solve many problems, but that does not mean there isn’t a more efficient solution out there. Solving a problem with Dynamic Programming feels like magic, but remember that dynamic programming is merely a clever brute force. Sometimes it pays off well, and sometimes it helps only a little.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*CjX9LYRnEgl3USaK.png" /></figure><h3>How to Solve Problems using Dynamic Programming</h3><p>Now we have an understanding of what Dynamic programming is and how it generally works. Let’s look at to create a Dynamic Programming solution to a problem. We’re going to explore the process of Dynamic Programming using the <a href="https://courses.cs.washington.edu/courses/cse521/13wi/slides/06dp-sched.pdf"><em>Weighted Interval Scheduling Problem</em></a>.</p><p>Pretend you’re the owner of a dry cleaner. You have <em>n</em> customers come in and give you clothes to clean. You can only clean one customer’s pile of clothes (PoC) at a time. Each pile of clothes, <em>i</em>, must be cleaned at some pre-determined start time $s_i$ and some predetermined finish time $f_i$.</p><p>Each pile of clothes has an associated value, $v_i$, based on how important it is to your business. For example, some customers may pay more to have their clothes cleaned faster. Or some may be repeating customers and you want them to be happy.</p><p>As the owner of this dry cleaners you must determine the optimal schedule of clothes that maximises the total value of this day. This problem is a re-wording of the <em>Weighted Interval scheduling problem</em>.</p><p>You will now see 4 steps to solving a Dynamic Programming problem. Sometimes, you can skip a step. Sometimes, your problem is already well defined and you don’t need to worry about the first few steps.</p><h3>Step 1. Write the Problem out</h3><p>Grab a piece of paper. Write out:</p><ul><li>What is the problem?</li><li>What are the subproblems?</li><li>What would the solution roughly look like?</li></ul><p>In the dry cleaner problem, let’s put down into words the subproblems. What we want to determine is the maximum value schedule for each pile of clothes such that the clothes are sorted by start time.</p><p>Why sort by start time? Good question! We want to keep track of processes which are currently running. If we sort by finish time, it doesn’t make much sense in our heads. We could have 2 with similar finish times, but different start times. Time moves in a linear fashion, from start to finish. If we have piles of clothes that start at 1 pm, we know to put them on when it reaches 1pm. If we have a pile of clothes that finishes at 3 pm, we might need to have put them on at 12 pm, but it’s 1pm now.</p><p>We can find the maximum value schedule for piles $n — 1$ through to n. And then for $n — 2$ through to n. And so on. By finding the solution to every single sub-problem, we can tackle the original problem itself. The maximum value schedule for piles 1 through <em>n</em>. Sub-problems can be used to solve the original problem, since they are smaller versions of the original problem.</p><p>With the interval scheduling problem, the only way we can solve it is by brute-forcing all subsets of the problem until we find an optimal one. What we’re saying is that instead of brute-forcing one by one, we divide it up. We brute force from $n-1$ through to n. Then we do the same for $n — 2$ through to n. Finally, we have loads of smaller problems, which we can solve dynamically. We want to build the solutions to our sub-problems such that each sub-problem builds on the previous problems.</p><h3>2. Mathematical Recurrences</h3><p>I know, mathematics sucks. If you’ll bare with me here you’ll find that this isn’t that hard. <a href="https://en.wikipedia.org/wiki/Recurrence_relation">Mathematical recurrences</a> are used to:</p><blockquote><em>Define the running time of a divide and conquer (dynamic programming) technique</em></blockquote><p>Recurrences are also used to define problems. If it’s difficult to turn your subproblems into maths, then it may be the wrong subproblem.</p><p>There are 2 steps to creating a mathematical recurrence:</p><h3>1: Define the Base Case</h3><p>Base cases are the smallest possible denomination of a problem.</p><p>When creating a recurrence, ask yourself these questions:</p><blockquote><em>“What decision do I make at step 0?”</em></blockquote><p>It doesn’t have to be 0. The base case is the smallest possible denomination of a problem. We saw this with the Fibonacci sequence. The base was:</p><p>It’s important to know where the base case lies, so we can create the recurrence. In our problem, we have one decision to make:</p><p>or</p><p>If n is 0, that is, if we have 0 PoC then we do nothing. Our base case is:</p><blockquote><em>if n == 0, return 0</em></blockquote><h3>2: What Decision Do I Make at Step n?</h3><p>Now we know what the base case is, if we’re at step n what do we do? For each pile of clothes that is compatible with the schedule so far. Compatible means that the start time is after the finish time of the pile of clothes currently being washed. The algorithm has 2 options:</p><ol><li>Wash that pile of clothes</li><li>Don’t wash that pile of clothes</li></ol><p>We know what happens at the base case, and what happens else. We now need to find out what information the algorithm needs to go backwards (or forwards).</p><blockquote><em>“If my algorithm is at step i, what information would it need to decide what to do in step i+1?”</em></blockquote><p>To decide between the two options, the algorithm needs to know the next compatible PoC (pile of clothes). The next compatible PoC for a given pile, p, is the PoC, n, such that $s_n$ (the start time for PoC n) happens after $f_p$ (the finish time for PoC p). The difference between $s_n$ and $f_p$ should be minimised.</p><p>In English, imagine we have one washing machine. We put in a pile of clothes at 13:00. Our next pile of clothes starts at 13:01. We can’t open the washing machine and put in the one that starts at 13:00. Our next compatible pile of clothes is the one that starts after the finish time of the one currently being washed.</p><blockquote><em>“If my algorithm is at step i, what information did it need to decide what to do in step i-1?”</em></blockquote><p>The algorithm needs to know about future decisions. The ones made for PoC <em>i</em> through <em>n</em> to decide whether to run or not run PoC <em>i-1</em>.</p><p>Now that we’ve answered these questions, we’ve started to form a recurring mathematical decision in our mind. If not, that’s also okay, it becomes easier to write recurrences as we get exposed to more problems.</p><p>Here’s our recurrence:</p><p>$$ OPT(i) = \begin{cases} 0, \quad \text{If i = 0} \\ max{v_i + OPT(next[i]), OPT(i+1)}, \quad \text{if n &gt; 1} \end{cases}$$</p><p>Let’s explore in detail what makes this mathematical recurrence. OPT(i) represents the maximum value schedule for PoC <em>i</em> through to <em>n</em> such that PoC is sorted by start times. OPT(i) is our subproblem from earlier.</p><p>We start with the base case. All recurrences need somewhere to stop. If we call OPT(0) we’ll be returned with 0.</p><p>To determine the value of OPT( <em>i</em>), there are two options. We want to take the maximum of these options to meet our goal. Our goal is the <em>maximum value schedule</em> for all piles of clothes. Once we choose the option that gives the maximum result at step <em>i,</em> we memoize its value as OPT( <em>i</em>).</p><p>Mathematically, the two options — run or not run PoC <em>i</em>, are represented as:</p><p>$$v_i + OPT(next[n])$$</p><p>This represents the decision to run PoC <em>i</em>. It adds the value gained from PoC i to OPT(next[n]), where next[n] represents the next compatible pile of clothing following PoC <em>i</em>. When we add these two values together, we get the maximum value schedule from <em>i</em> through to n such that they are sorted by start time if <em>i</em> runs.</p><p>Sorted by start time here because next[n] is the one immediately after v_i, so by default, they are sorted by start time.</p><p>$$OPT(i + 1)$$</p><p>If we decide not to run <em>i</em>, our value is then OPT(i + 1). The value is not gained. OPT(i + 1) gives the maximum value schedule for i+1 through to n, such that they are sorted by start times.</p><h3>3. Determine the Dimensions of the Memoisation Array and the Direction in Which It Should Be Filled</h3><p>The solution to our Dynamic Programming problem is OPT(1). We can write out the solution as the maximum value schedule for PoC 1 through n such that PoC is sorted by start time. This goes hand in hand with “maximum value schedule for PoC i through to n”.</p><p>From step 2:</p><p>$$OPT(1) = max(v_1 + OPT(next[1]), OPT(2))$$</p><p>Going back to our Fibonacci numbers earlier, our Dynamic Programming solution relied on the fact that the Fibonacci numbers for 0 through to n — 1 were already memoised. That is, to find F(5) we already memoised F(0), F(1), F(2), F(3), F(4). We want to do the same thing here.</p><p>The problem we have is figuring out how to fill out a memoisation table. In the scheduling problem, we know that OPT(1) relies on the solutions to OPT(2) and OPT(next[1]). PoC 2 and next[1] have start times after PoC 1 due to sorting. We need to fill our memoisation table from OPT(n) to OPT(1).</p><p>We can see our array is one dimensional, from 1 to n. But, if we couldn’t see that we can work it out another way. The dimensions of the array are equal to the number and size of the variables on which OPT(x) relies. In our algorithm, we have OPT( <em>i</em>) — one variable, <em>i</em>. This means our array will be 1-dimensional and its size will be n, as there are n piles of clothes.</p><p>If we know that <em>n</em> = 5, then our memoisation array might look like this:</p><p>memo = [0, OPT(1), OPT(2), OPT(3), OPT(4), OPT(5)]</p><p>0 is also the base case. memo[0] = 0, per our recurrence from earlier.</p><h3>4. Coding Our Solution</h3><p>When I am coding a Dynamic Programming solution, I like to read the recurrence and try to recreate it. Our first step is to initialise the array to size (n + 1). In Python, we don’t need to do this. But you may need to do it if you’re using a different language.</p><p>Our second step is to set the base case.</p><p>To find the profit with the inclusion of job[i]. we need to find the latest job that doesn’t conflict with job[i]. The idea is to use Binary Search to find the latest non-conflicting job. I’ve copied the code from <a href="https://www.geeksforgeeks.org/weighted-job-scheduling-log-n-time/">here </a>but edited.</p><p>First, let’s define what a “job” is. As we saw, a job consists of 3 things:</p><pre># Class to represent a job class Job: def __init__(self, start, finish, profit): self.start = start self.finish = finish self.profit = profit</pre><p>Start time, finish time, and the total profit (benefit) of running that job.</p><p>The next step we want to program is the schedule.</p><pre># The main function that returns the maximum possible # profit from given array of jobs def schedule(job): # Sort jobs according to start time job = sorted(job, key = lambda j: j.start) # Create an array to store solutions of subproblems. table[i] # stores the profit for jobs till arr[i] (including arr[i]) n = len(job) table = [0 for _ in range(n)] table[0] = job[0].profit;</pre><p>Earlier, we learnt that the table is 1 dimensional. We sort the jobs by start time, create this empty table and set table[0] to be the profit of job[0]. Since we’ve sorted by start times, the first compatible job is always job[0].</p><p>Our next step is to fill in the entries using the recurrence we learnt earlier. To find the next compatible job, we’re using Binary Search. In the full code posted later, it’ll include this. For now, let’s worry about understanding the algorithm.</p><p>If the next compatible job returns -1, that means that all jobs before the index, i, conflict with it (so cannot be used). Inclprof means we’re including that item in the maximum value set. We then store it in table[i], so we can use this calculation again later.</p><pre># Fill entries in table[] using recursive property for i in range(1, n): # Find profit including the current job inclProf = job[i].profit l = binarySearch(job, i) if (l != -1): inclProf += table[l]; # Store maximum of including and excluding table[i] = max(inclProf, table[i - 1])</pre><p>Our final step is then to return the profit of all items up to n-1.</p><pre>return table[n-1]</pre><p>The full code can be seen below:</p><pre># Python program for weighted job scheduling using Dynamic # Programming and Binary Search # Class to represent a job class Job: def __init__(self, start, finish, profit): self.start = start self.finish = finish self.profit = profit # A Binary Search based function to find the latest job # (before current job) that doesn&#39;t conflict with current # job. &quot;index&quot; is index of the current job. This function # returns -1 if all jobs before index conflict with it. def binarySearch(job, start_index): # https://en.wikipedia.org/wiki/Binary_search_algorithm # Initialize &#39;lo&#39; and &#39;hi&#39; for Binary Search lo = 0 hi = start_index - 1 # Perform binary Search iteratively while lo &lt;= hi: mid = (lo + hi) // 2 if job[mid].finish &lt;= job[start_index].start: if job[mid + 1].finish &lt;= job[start_index].start: lo = mid + 1 else: return mid else: hi = mid - 1 return -1 # The main function that returns the maximum possible # profit from given array of jobs def schedule(job): # Sort jobs according to start time job = sorted(job, key = lambda j: j.start) # Create an array to store solutions of subproblems. table[i] # stores the profit for jobs till arr[i] (including arr[i]) n = len(job) table = [0 for _ in range(n)] table[0] = job[0].profit; # Fill entries in table[] using recursive property for i in range(1, n): # Find profit including the current job inclProf = job[i].profit l = binarySearch(job, i) if (l != -1): inclProf += table[l]; # Store maximum of including and excluding table[i] = max(inclProf, table[i - 1]) return table[n-1] # Driver code to test above function job = [Job(1, 2, 50), Job(3, 5, 20), Job(6, 19, 100), Job(2, 100, 200)] print(&quot;Optimal profit is&quot;), print(schedule(job))</pre><p>Congrats! 🥳 We’ve just written our first dynamic program! Now that we’ve wet our feet, let’s walk through a different type of dynamic programming problem.</p><p>Imagine you are a criminal. Dastardly smart. You break into Bill Gates’s mansion. Wow, okay!?!? How many rooms is this? His washing machine room is larger than my entire house??? Ok, time to stop getting distracted. You brought a small bag with you. A knapsack — if you will.</p><p>You can only fit so much into it. Let’s give this an arbitrary number. The bag will support weight 15, but no more. What we want to do is maximise how much money we’ll make, $b$.</p><p>The greedy approach is to pick the item with the highest value which can fit into the bag. Let’s try that. We’re going to steal Bill Gates’s TV. £4000? Nice. But his TV weighs 15. So… We leave with £4000.</p><pre>TV = (£4000, 15) # (value, weight)</pre><p>Bill Gates’s has a lot of watches. Let’s say he has 2 watches. Each watch weighs 5 and each one is worth £2250. When we steal both, we get £4500 with a weight of 10.</p><pre>watch1 = (£2250, 5) watch2 = (£2250, 5) watch1 + watch2 &gt;&gt;&gt; (£4500, 10)</pre><p>In the greedy approach, we wouldn’t choose these watches first. But to us as humans, it makes sense to go for smaller items which have higher values. The Greedy approach cannot optimally solve the {0,1} Knapsack problem. The {0, 1} means we either take the item whole item {1} or we don’t {0}. However, Dynamic programming can optimally solve the {0, 1} knapsack problem.</p><p>The simple solution to this problem is to consider all the subsets of all items. For every single combination of Bill Gates’s stuff, we calculate the total weight and value of this combination.</p><p>Only those with weight less than $W_{max}$ are considered. We then pick the combination which has the highest value. This is a disaster! How long would this take? Bill Gates’s would come back home far before you’re even 1/3rd of the way there! In Big O, this algorithm takes $O(n²)$ time.</p><p>You can see we already have a rough idea of the solution and what the problem is, without having to write it down in maths!</p><h3>Maths Behind {0, 1} Knapsack Problem</h3><p>Imagine we had a listing of every single thing in Bill Gates’s house. We stole it from some insurance papers. Now, think about the future. What is the optimal solution to this problem?</p><p>We have a subset, L, which is the optimal solution. L is a subset of S, the set containing all of Bill Gates’s stuff.</p><p>Let’s pick a random item, N. L either contains N or it doesn’t. If it doesn’t use N, the optimal solution for the problem is the same as ${1, 2, …, N-1}$. This is assuming that Bill Gates’s stuff is sorted by $value / weight$.</p><p>Suppose that the optimum of the original problem is not optimum of the sub-problem. if we have sub-optimum of the smaller problem then we have a contradiction — we should have an optimum of the whole problem.</p><p>If L contains N, then the optimal solution for the problem is the same as ${1, 2, 3, …, N-1}$. We know the item is in, so L already contains N. To complete the computation we focus on the remaining items. We find the optimal solution to the remaining items.</p><p>But, we now have a new maximum allowed weight of $W_{max} — W_n$. If item N is contained in the solution, the total weight is now the max weight take away item N (which is already in the knapsack).</p><p>These are the 2 cases. Either item N is in the optimal solution or it isn’t.</p><p>If the weight of item N is greater than $W_{max}$, then it cannot be included so case 1 is the only possibility.</p><p>To better define this recursive solution, let $S_k = {1, 2, …, k}$ and $S_0 = \emptyset$</p><p>Let B[k, w] be the <em>maximum total benefit</em> obtained using a subset of $S_k$. Having total weight at most w.</p><p>Then we define B[0, w] = 0 for each $w \le W_{max}$.</p><p>Our desired solution is then B[n, $W_{max}$].</p><p>$$ OPT(i) = \begin{cases} B[k — 1, w], \quad \text{If w &lt; }w_k \\ max{B[k-1, w], b_k + B[k — 1, w — w_k]}, \; \quad \text{otherwise} \end{cases}$$</p><h3>Tabulation of Knapsack Problem</h3><p>Okay, pull out some pen and paper. No, really. Things are about to get confusing real fast. This memoisation table is 2-dimensional. We have these items:</p><p>Where the tuples are (weight, value).</p><p>We have 2 variables, so our array is 2-dimensional. The first dimension is from 0 to 7. Our second dimension is the values.</p><p>And we want a weight of 7 with maximum benefit.</p><p>The weight is 7. We start counting at 0. We put each tuple on the left-hand side. Ok. Now to fill out the table!</p><p>The columns are weight. At weight 0, we have a total weight of 0. At weight 1, we have a total weight of 1. Obvious, I know. But this is an important distinction to make which will be useful later on.</p><p>When our weight is 0, we can’t carry anything no matter what. The total weight of everything at 0 is 0.</p><p>If our total weight is 1, the best item we can take is (1, 1). As we go down through this array, we can take more items. At the row for (4, 3) we can either take (1, 1) or (4, 3). But for now, we can only take (1, 1). Our maximum benefit for this row then is 1.</p><p>If our total weight is 2, the best we can do is 1. We only have 1 of each item. We cannot duplicate items. So no matter where we are in row 1, the absolute best we can do is (1, 1).</p><p>Let’s start using (4, 3) now. If the total weight is 1, but the weight of (4, 3) is 3 we cannot take the item yet until we have a weight of at least 3.</p><p>Now we have a weight of 3. Let’s compare some things. We want to take the max of:</p><p>$$MAX(4 + T[0][0], 1)$$</p><p>If we’re at 2, 3 we can either take the value from the last row or use the item on that row. We go up one row and count back 3 (since the weight of this item is 3).</p><p>Actually, the formula is whatever weight is remaining when we minus the weight of the item on that row. The weight of (4, 3) is 3 and we’re at weight 3. 3–3 = 0. Therefore, we’re at T[0][0]. T[previous row’s number][current total weight — item weight].</p><p>$$MAX(4 + T[0][0], 1)$$</p><p>The 1 is because of the previous item. The max here is 4.</p><p>$$max(4 + t[0][1], 1)$$</p><p>Total weight is 4, item weight is 3. 4–3 = 1. Previous row is 0. t[0][1].</p><p>I won’t bore you with the rest of this row, as nothing exciting happens. We have 2 items. And we’ve used both of them to make 5. Since there are no new items, the maximum value is 5.</p><p>Onto our next row:</p><p>Here’s a little secret. Our tuples are ordered by weight! That means that we can fill in the previous rows of data up to the next weight point. We know that 4 is already the maximum, so we can fill in the rest.. This is where memoisation comes into play! We already have the data, why bother re-calculating it?</p><p>We go up one row and head 4 steps back. That gives us:</p><p>$$max(4 + T[2][0], 5)$$.</p><p>Now we calculate it for total weight 5.</p><p>$$max(5 + T[2][1], 5) = 6$$</p><p>We do the same thing again:</p><p>$$max(5 + T[2][2], 5) = 6$$</p><p>Now we have total weight 7. We choose the max of:</p><p>$$max(5 + T[2][3], 5) = max(5 + 4, 5) = 9$$</p><p>If we had total weight 7 and we had the 3 items (1, 1), (4, 3), (5, 4) the best we can do is 9.</p><p>Since our new item starts at weight 5, we can copy from the previous row until we get to weight 5.</p><p>We then do another max.</p><p>Total weight — new item’s weight. This is $5–5 = 0$. We want the previous row at position 0.</p><p>$$max(7 + T[3][0], 6)$$</p><p>The 6 comes from the best on the previous row for that total weight.</p><p>$$max(7 + 0, 6) = 7$$</p><p>$$max(7 + T[3][1], 6) = 8$$</p><p>$$max(7+T[3][2], 9) = 9$$</p><p>9 is the maximum value we can get by picking items from the set of items such that the total weight is $\le 7$.</p><h3>Finding the Optimal Set for {0, 1} Knapsack Problem Using Dynamic Programming</h3><p>Now, what items do we actually pick for the optimal set? We start with this item:</p><p>We want to know where the 9 comes from. It’s coming from the top because the number directly above 9 on the 4th row is 9. Since it’s coming from the top, the item (7, 5) is not used in the optimal set.</p><p>Where does this 9 come from?</p><p>This 9 is not coming from the row above it. <strong>Item (5, 4) must be in the optimal set.</strong></p><p>We now go up one row, and go back 4 steps. 4 steps because the item, (5, 4), has weight 4.</p><p>4 does not come from the row above. The item (4, 3) must be in the optimal set.</p><p>The weight of item (4, 3) is 3. We go up and we go back 3 steps and reach:</p><p>As soon as we reach a point where the weight is 0, we’re done. Our two selected items are (5, 4) and (4, 3). The total weight is 7 and our total benefit is 9. We add the two tuples together to find this out.</p><p>Let’s begin coding this.</p><h3>Coding {0, 1} Knapsack Problem in Dynamic Programming With Python</h3><p>Now we know how it works, and we’ve derived the recurrence for it — it shouldn’t be too hard to code it. If our two-dimensional array is i (row) and j (column) then we have:</p><p>If our weight j is less than the weight of item i (i does not contribute to j) then:</p><pre>if j &lt; wt[i]: T[i][j] = T[i - 1][j] else: // weight of i &gt;= j T[i][j] = max(val[i] + t[i - 1][j-wt(i), t[i-1][j]) // previous row, subtracting the weight of the item from the total weight or without including ths item</pre><p>This is what the core heart of the program does. I’ve copied some code from <a href="https://www.geeksforgeeks.org/0-1-knapsack-problem-dp-10/">here </a>to help explain this. I’m not going to explain this code much, as there isn’t much more to it than what I’ve already explained. If you’re confused by it, leave a comment below or email me 😁</p><pre># Returns the maximum value that can be put in a knapsack of # capacity W def knapSack(W , wt , val , n): # Base Case if n == 0 or W == 0: return 0 # If weight of the nth item is more than Knapsack of capacity # W, then this item cannot be included in the optimal solution if (wt[n-1] &gt; W): return knapSack(W , wt , val , n-1) # return the maximum of two cases: # (1) nth item included # (2) not included else: return max(val[n-1] + knapSack(W-wt[n-1] , wt , val , n-1), knapSack(W , wt , val , n-1)) # To test above function val = [60, 100, 120] wt = [10, 20, 30] W = 50 n = len(val) print(knapSack(W , wt , val , n)) # output 220</pre><h3>Time Complexity of a Dynamic Programming Problem</h3><p><a href="https://skerritt.blog/you-need-to-understand-big-o-notation-now/">Time complexity</a> is calculated in Dynamic Programming as:</p><p>$$Number \;of \;unique \;states * time \;taken \;per\; state$$</p><p>For our original problem, the Weighted Interval Scheduling Problem, we had n piles of clothes. Each pile of clothes is solved in constant time. The time complexity is:</p><p>$$O(n) + O(1) = O(n)$$</p><p><a href="https://skerritt.blog/you-need-to-understand-big-o-notation-now/">I’ve written a post about Big O notation </a>if you want to learn more about time complexities.</p><p>With our Knapsack problem, we had n number of items. The table grows depending on the total capacity of the knapsack, our time complexity is:</p><p>$$O(nw)$$</p><p>Where n is the number of items, and w is the capacity of the knapsack.</p><p>I’m going to let you in on a little secret. It’s possible to work out the time complexity of an algorithm from its recurrence. You can use something called the Master Theorem to work it out. This is the theorem in a nutshell:</p><p>Now, I’ll be honest. The master theorem deserves a blog post of its own. For now, I’ve found this video to be excellent:</p><h3>Dynamic Programming vs Divide &amp; Conquer vs Greedy</h3><p>Dynamic Programming &amp; <a href="https://skerritt.blog/divide-and-conquer-algorithms/">Divide and Conquer</a> are similar. Dynamic Programming is based on Divide and Conquer, except we memoise the results.</p><p>But, Greedy is different. It aims to optimise by making the best choice at that moment. Sometimes, this doesn’t optimise for the whole problem. Take this question as an example. We have 3 coins:</p><p>1p, 15p, 25p</p><p><a href="https://en.wikipedia.org/wiki/Change-making_problem">And someone wants us to give a change of 30p</a>. With Greedy, it would select 25, then 5 * 1 for a total of 6 coins. The optimal solution is 2 * 15. Greedy works from largest to smallest. At the point where it was at 25, the best choice would be to pick 25.</p><h3>Tabulation (Bottom-Up) vs Memoisation (Top-Down)</h3><p>There are 2 types of dynamic programming. Tabulation and Memoisation.</p><h3>Memoisation (Top-Down)</h3><p>We’ve computed all the subproblems but have no idea what the optimal evaluation order is. We would then perform a recursive call from the root, and hope we get close to the optimal solution or obtain a proof that we will arrive at the optimal solution. Memoisation ensures you never recompute a subproblem because we cache the results, thus duplicate sub-trees are not recomputed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*dyJCx079RVzLCv5X.png" /></figure><p>From our Fibonacci sequence earlier, we start at the root node. The subtree F(2) isn’t calculated twice.</p><p>This starts at the top of the tree and evaluates the subproblems from the leaves/subtrees back up towards the root. <strong>Memoisation is a top-down approach.</strong></p><h3>Tabulation (Bottom-Up)</h3><p>We’ve also seen Dynamic Programming being used as a ‘table-filling’ algorithm. Usually, this table is multidimensional. This is like memoisation, but with one major difference. We have to pick the exact order in which we will do our computations. The knapsack problem we saw, we filled in the table from left to right — top to bottom. We knew the exact order of which to fill the table.</p><p>Sometimes the ‘table’ is not like the tables we’ve seen. It can be a more complicated structure such as trees. Or specific to the problem domain, such as cities within flying distance on a map.</p><h3>Tabulation &amp; Memosation — Advantages and Disadvantages</h3><p>Generally speaking, memoisation is easier to code than tabulation. We can write a ‘memoriser’ wrapper function that automatically does it for us. With tabulation, we have to come up with an ordering.</p><p>Memoisation has memory concerns. If we’re computing something large such as F(10⁸), each computation will be delayed as we have to place them into the array. And the array will grow in size very quickly.</p><p>Either approach may not be time-optimal if the order we happen (or try to) visit subproblems is not optimal. If there is more than one way to calculate a subproblem (normally caching would resolve this, but it’s theoretically possible that caching might not in some exotic cases). Memoisation will usually add on our time-complexity to our space-complexity. For example with tabulation we have more liberty to throw away calculations, like using tabulation with Fib lets us use O(1) space, but memoisation with Fib uses O(N) stack space).</p><h3>Conclusion</h3><p>Most of the problems you’ll encounter within Dynamic Programming already exist in one shape or another. Often, your problem will build on from the answers for previous problems. <a href="https://en.wikipedia.org/wiki/Dynamic_programming#Algorithms_that_use_dynamic_programming">Here’s a list of common problems that use Dynamic Programming.</a></p><p>I hope that whenever you encounter a problem, you think to yourself “can this problem be solved with ?” and try it.</p><p><em>Originally published at </em><a href="https://skerritt.blog/dynamic-programming/"><em>https://skerritt.blog</em></a><em> on June 5, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6af920fb179" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Get Any Job You Want — A Guide to Employability Skills]]></title>
            <link>https://medium.com/@brandonskerritt/how-to-get-any-job-you-want-a-guide-to-employability-skills-d835f8076b2f?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/d835f8076b2f</guid>
            <category><![CDATA[job-hunting]]></category>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[internships]]></category>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Wed, 10 Apr 2019 21:18:46 GMT</pubDate>
            <atom:updated>2019-04-28T16:20:37.830Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Get Any Job You Want — A Guide to Employability Skills</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-WUCwYf2owKVFk1h.jpg" /></figure><p>This is a book I wrote on job applications. It’s now available for free right here, with no catches. Seriously. You do not have to buy anything or sign up for anything. This is the entire book, for free, with 0 content taken away and 0 added. It’s really long.</p><p>If you like this blog post, but don’t want to buy it, sign up to my email list below to get this book in a PDF.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb5d02f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fb5d02f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252Fb5d02f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/69b18ef75e89f36fffa0002a2c51ee64/href">https://medium.com/media/69b18ef75e89f36fffa0002a2c51ee64/href</a></iframe><p>Also, this was automatically converted using Pandoc. There may be some visual errors in this blog post. Please ignore them, they’re not in the book itself.</p><p>Found an error or want to contribute to this resource? The GitHub repo is <a href="https://github.com/brandonskerritt/HowToGetAnyJobYouWant/tree/master">here</a>. If you make an edit, you’ll get your name in the acknowledgements of the book (when I next update it). Many thanks to <a href="https://www.linkedin.com/in/elicastro1/">Elizabeth Castro</a> for her feedback on this book.</p><p>Professional skills, Just the mere murmur of the word makes me want to fall asleep. It’s such a boring topic, there’s no getting around that. So many people fall asleep in professional skills classes or never take the time to learn these vital skills.</p><p>This makes a large difference between the people who took the boring class and the people who didn’t. So many people apply for graduate jobs every single year, I’m willing to bet around 95% of them have no experience with professional skills. Because of this, there is a gap in the market. If you have even basic professional skills, you’re going to look better than the 95% of the candidates that have applied.</p><p>Professional skills are vital. Even if you do not wish to learn much about it. To the nerds out there, like me, who have studied professional skills we know this to be true. It is a boring subject, but if you study this boring subject, you’re going to look like the best thing since sliced bread to employers.</p><p>Degrees don’t matter. Unless you don’t have one. If you have one, it doesn’t matter. 99% of the people applying for graduate junior positions have degrees. A degree will not make you stand out, no matter how hard you work towards that degree. You need to differentiate yourself, by showing that you are more than just a degree title. One of the ways you could do this is by learning professional skills.</p><p>This book is written for everyone who understands that this is a vital skill but does not have the knowledge or means to study it. This book is written for everyone who desperately wants to learn these skills but falls asleep in the lectures on them.</p><p>If you have no interest in getting an increase in salary before you start, or no interest in being the best intern a company has ever had, then put this book down. Do not read it. This is not for you.</p><p>One of the people who read the original draft on this got a promotion before they started. Their CV was “the best thing we had ever seen” and because of this, the person was deemed a god amongst everyone who didn’t have basic knowledge of constructing a CV.</p><p>Let me tell you a secret. For a select few who are obsessed with professional skills, getting internships is a game. I am not joking. One of my friends got 36 internships in his first year at the likes of Bank of America, Barclays, Royal Bank of Scotland, Amazon, Apple, and many more. I have more friends who have achieved similar feats.</p><p>For a select few, professional skills are a game. I’ve interviewed as many of them as I could to learn the secrets to the game, how to get any job you want. This book is a compilation of wisdom from that exclusive group and much more.</p><h3>Career vs Job</h3><p>Let’s get right into the business of the day. A job is something you do for money. Your part time Tesco work is a job. A career is what your life is, what you’re doing with your life. This is anything that can take over your life. A professor at University, for example.</p><p>With a job, you work a shift and that’s it. You don’t do anything else.</p><p>With a career, you work a shift, you go home, and you work some more. You may go to conferences, you may network, you may learn some things in order to improve yourself at your job. Here are the biggest differences:</p><p>Lots of growth and opportunities</p><p>Low or no growth</p><p>Earning experience</p><p>Earning money</p><p>Go above and beyond</p><p>Doing the bare minimum</p><p>Happy that you get to work</p><p>Angry or frustrated that you’re forced to work</p><p>Aligned with the core values of the company</p><p>Uninterested or doesn’t care about the core values</p><p>Looking to move up the corporate ladder</p><p>Looking for a new job that pays more</p><p>A career is a journey</p><p>A job is a grind</p><h3>The job cycle</h3><p>When you’re in university, there’s a certain cycle you normally have to follow in order to get a good graduate job. The cycle is:</p><p>Insight days &gt; Spring internships &gt; Summer internships &gt; Placement year &gt; Graduate job.</p><p>You don’t need to do all of these things. The typical way most people go around it is:</p><p>Summer internships (or a placement year) &gt; Graduate job.</p><p>The lower you start on this cycle, the more likely you are to get a job. This cycle doesn’t matter that much, unless you’re applying somewhere exclusive. If you want to work somewhere like Bank of America, you’ll need to follow this cycle.</p><p>Bank of America would rather hire someone who went through the whole cycle with them than someone who didn’t. It matters here, since they are such a big company even their insight days fill out quickly. They don’t need to bother with people who have only done an internship, if they have hundreds who have done insight days or are even campus ambassadors for them.</p><p>The lower levels (insight days, spring internships, sometimes summer internships) carry over from other companies in the same industry.</p><p>If you did insight days and a spring internship at BlackRock, Bank of America will think that’s really good as you’re in the industry. Of course, they’ll always pick someone who has worked for their company over someone who’s just worked at a competitor, but you can’t expect to do 20 insight days / 20 spring internships just to get a chance at a company.</p><p>Most insight days / spring internships are just advertisements for a company.</p><h3>Landing that job</h3><p>It’s better to focus on 5 companies than it is to apply to 100. I’m willing to bet that the person who applies to 5 companies, who has researched every company and knows them all will get more graduate job offers, than the person who has applied for 100 but doesn’t know a thing about the companies they have applied for.</p><p>If you have an internship, here’s some good advice from a recruiter on how to turn that internship into a graduate job.</p><p>This advice comes from Andrew Osayemi.</p><p>“So, you are fortunate to have a spring or summer internship &amp; are looking for 1 piece of unconventional advice, to help increase your chances of being offered a full-time graduate job?</p><p>Well the advice is very simple — Ask everyone on your team if they would like a tea or coffee every 2–3 hours each day</p><p>Do it with a warm smile.</p><p>If they say no — still smile &amp; politely say “no problem, please let me know if you need anything!”</p><p>And if they say yes, write down their order carefully so you don’t mess it up including any special requests (soya milk, 10 sugars etc)</p><p>When you return with their beverage of choice, again make sure you give it to them with a warm smile!</p><p>Now the next 10 seconds is crucial</p><p>You have an opening to ask how their day is going, if they have any work for you to do, if you can book a convenient time to work shadow them, did they watch the latest reality show etc.</p><p>Very soon your likeability factor will be increased which greatly impacts your chances of being offered a full-time graduate offer!</p><p>I’ve given this advice to countless students whom I have coached via Rare Recruitment &amp; the feedback is “It works”!</p><h3>Your university’s careers team</h3><p>Your university’s careers team is an elite squad of experts whose entire jobs are to get you great jobs. This book isn’t meant to be a replacement for them, it goes hand in hand with them. They can interview you, look at your CV &amp; more to help you get prepared.</p><p>You can find out how to access your university’s careers team by Googling “[University name] careers team”.</p><h3>My university’s careers team is bad</h3><p>It happens. The good news is that you’re already on your way to becoming an expert in employability skills. By reaching out and reading this book, you’re already doing 90% more than anyone else applying for that job — learning more about employability skills.</p><p>For practice with interviews — go to as many as possible. Apply to companies you’ll likely never work at just to get interview experience. The more you do, the better. When you’re at an interview, make friends with the other candidates and work together to achieve greatness. To get great jobs. They’ll likely be able to help you with your CV &amp; other things.</p><h3>One last thing before Chapter 1</h3><p>This book isn’t a one size fits all book. The recruitment industry is large. So large in fact, that it’s impossible to cover every single titbit. In some industries, a nicely designed CV is essential. In others, anything other than black and white is seen as a monstrosity. While I try my best in this book to guide you along this path, know that you need to research yourself. I can’t possibly cover every single industry here.</p><p>A Curriculum Vitae (CV) or a resume is one of the most vital parts of job hunting. Put simply, it is a piece of paper you give to a recruiter. This recruiter decides if you are worth the time to interview based on this bit of paper.</p><p>Every job requires a CV. Sometimes, the job will force you to rewrite your entire CV on their website. Even if it does, you’ll still need a CV.<br><br> As such, writing a good CV is the key to getting a good job.<br><br> The CV is a summary of your professional life so far. It features your education, your work experience, skills and more.</p><p>Most times a person reads the CV, but sometimes machines can also read it. Recently artificial intelligence is being used to read CVs. When a human reads your CV, they don’t exactly read it. Estimations say that they spend 7 seconds on your CV, but this isn’t true. If you were in the position of looking at CVs and you saw something that looked spiritless, would you bother reading it? I know you wouldn’t. That’s why your CV needs to catch their eyes. It needs to make them curious and interested in you within the first second or two. First impressions matter here, A lot.</p><h3>Personalising your CV</h3><p>Your CV will impress the person reading it if it’s customised to them. Everyone likes a customised birthday cake more than a regular Tesco own brand birthday cake.<br> Make it look like you’re perfect for the job because the employer only wants the perfect candidate. The thing with applying for a very large organisations is that they have no shortage of candidates. Why settle on someone mediocre when 2 weeks later you’ll have someone perfect for the role? You need to act perfect and believe you are perfect for the role.</p><h3>Keywords is the keyword of this section</h3><p>An AI looks for keywords. They do not have an average time of looking at your CV.<br> A recruiter will insert a bunch of keywords into a computer program. The program will scan each CV and give the CV a score on how many keywords the CV has. This is why it is important to know what keywords to put into your CV. But, having an A4 piece of paper with font size 2 to fill it to the brim of keywords might not work. You don’t know whether they will use a human or a machine — or even both. Machines can rank your CV depending on how ‘clean’ it is too.</p><p>To insert keywords, you need to know what job you are applying for and what company.<br> Let’s say you apply to Barclays for a summer analyst position.<br> First you would Google around. Search for terms like “Barclays CV keywords” and “Summer analyst keywords CV”. If these do not return anything then read the description.<br> A part of the description in 2018 states this:</p><blockquote><em>“ </em>We are looking for bright, personable individuals who have the ambition to succeed and an impetus to learn and make the most of this fantastic opportunity within a competitive environment.”</blockquote><blockquote><em>From </em><a href="https://joinus.barclays/eme/internships/banking-summer-analyst"><em>https://joinus.barclays/eme/internships/banking-summer-analyst</em></a></blockquote><p>Barclays are looking for people who love learning. Who want to make a difference to themselves and to the world and are above all, kind.</p><p>You should customise your CV to show that you love learning. You are kind hearted (volunteering work can prove this, for example) and understand that it is a competitive position. Try to use the keywords themselves. Barclays say you need “an impetus to learn”, you can write in your CV profile that you have an impetus to learn. You should show that you need this position.</p><p>To customise your CV, analyse the job description. Obsessively read it and highlight keywords that come up. They say that they want someone with strong self-motivation? Find something you’ve done that proves this and put it on to your CV. Just like with the Barclays example earlier, it’s all about matching your CV up to the job description as much as possible.</p><p>By inserting keywords into the CV you’ll be able to pass the keyword test performed by machines, as discussed earlier. But please do not puke keywords onto your CV, it has to look natural.</p><p>Read the job description, the responsibilities, the specific requirements, the location. If you see a word you don’t know, Google it. That word you don’t know is likely a keyword. Remember the Barclays example from earlier? It’s like they’ve grabbed a thesaurus and randomly inserted words into the job description. These words are keywords.</p><p>Some keywords come up and up again in many jobs such as:<br> * Teamwork<br> * Time management<br> * Microsoft Office<br> * Leadership skills<br> * Computer literacy</p><p>Let’s say a job description has this sentence in it:</p><blockquote>“Required — Advance knowledge of Microsoft Applications (Word, Excel, PowerPoint).”</blockquote><p>Then instead of writing “Microsoft Office” on your CV you write:</p><blockquote>“Advance knowledge of Microsoft Software (Word, Excel, PowerPoint).”</blockquote><p>If the machine reads your CV, you’ll pass the keyword test. If a human reads your CV, they may not remember the job description exactly, which is good. When they read “Advance knowledge of Microsoft Software…” something will click in their head which makes you stand out. That something is that their subconscious memory recalls the keywords used in the job description.</p><h3>Making the CV fit around you, not you trying to fit into a CV template</h3><p>If you’re applying for a job that requires programming, have a “languages” section on your CV that talks about all the languages you know. Or if you know other languages, include them. There isn’t a one size fits all CV that’s perfect for you. You need to make the perfect CV for you.</p><p>It’s also best to rate your skills. If you’re fluent in German, say you’re fluent. If you’re not fluent but still quite good, write intermediate. Be honest, don’t lie that you’re fluent in Mandarin as the job might need that you are.</p><p>Most people fire off blankets of CV’s to every single recruiter on their LinkedIn or job recruiters like it’s the last thing you’ll ever do. Do not do this. Customisation per job is vital.</p><h3>Lie about your Location</h3><p>Want to get a job in London? Then write “London” on your CV.<br> This won’t work well if you write “London” and you live in Scotland unless you plan to move.<br> If you get called up on it say you’re going to relocate, or you enjoy commuting.</p><p>You need the employer to think that if they hire you, they won’t come into any problems like you living an hour away.</p><h3>How to research an organisation</h3><p>You need to know about an organisation before you apply for a job there. You can’t apply to an organisation you know nothing about and expect to get the job. In order to be the perfect candidate, you need to be an expert on this organisation.</p><p>Some of the things you want to find out are:</p><p>Once you’ve researched about them, add the things you’ve found to a word document and print it out. Go over this document on the way to the interview. You do not need to memorise every company you apply for. Use this information in your cover letter and learn the information the day before your interview.</p><p>You could Google most of these. Just Google “[Companies name] [thing you want to find out]”. ` When you research a company, the best website you should concentrate on is the company’s own website. For history, you should look at the company’s Wikipedia page. For current news, you can Google search the company and click the “news” tab.</p><p>For most companies, Bloomberg contains a “snapshot” of the company. This includes the key executives for the company, their age, their annual compensation, a company overview, how many employees they have and more. The key thing about these snapshots are the “key developments” section whereby Bloomberg lists the most important news and developments for a company.</p><p>To find a Bloomberg snapshot of a company, Google “[company name] Bloomberg snapshot”.</p><p>If the company is especially big, chances are that the Economist has written an article about them at some point. Find sources you like &amp; trust, and search to see if that company has come up in these sources.</p><h3>Writing a CV</h3><p>Now we know about customising a CV, let’s get into how to write a CV. The first most important rule is that your CV should be 1 page. Not double sided but one page. If you have 15+ years of experience then 2 pages is okay, but 1 page is always preferable.</p><h3>Choosing the right CV Template</h3><p>Choosing the right CV template is always important. You could try to create your own template, but I don’t suggest you do this unless you’re good at design. The simplest and easiest way to find a good template is to Google “CV Template” and pick one you like.</p><p>Make sure the template is well designed and it has to be visually appealing. The template should be slightly sparse of information. A CV with little information on it looks more appealing than a CV full of information. The recruiter is used to CVs with paragraphs upon paragraphs of information. If you have little information, it will catch their eye. Try not to disclude stuff that’s directly relevant to the position, you want to be the best person for the job.</p><p>If you know a little tiny bit about computers, you can Google “LaTeX CV templates” to get some nice templates for free. If it’s on Overleaf or ShareLaTeX then it’s easier to use. LaTeX is like a programming language but for writing.</p><p>A well-designed CV is more important than most people think. Well designed does not have to equal “pretty colours and nice shapes”.</p><p>In some industries, a well designed CV is a burden. Employers can hate them with a burning rage. The recruitment industry is less “this one tip works for everyone” and more “this one tip is really cool for a specific part of the industry”. Well designed CVs may be appreciated at tech start-ups or design companies, but at other places like law firms they can be hated. While in this book I advocate for colour CVs, know that you need to perform your own research and find out if its appropriate for your industry.</p><p>Another downside to using well designed CVs is that Applicant Tracking Software can’t read them. This is the software / AI used to determine whether or not you are the right candidate.</p><p>Instead of reading these chapters and thinking “this is perfect for my industry” I implore you to think “this is a good idea, but I wonder if my industry likes this?”</p><p>If you believe the answer to be “yes, my industry likes this” then go ahead.</p><p>But, the benefits for well designed CVs still exist. No one else will have a CV like yours, so you’ll stand out. Also, you can have a well designed CV and have a plain black / white layout. Whitespace is your friend here. Lots of space, sparse information.</p><p>You have to decide for yourself what is good and what is bad. All industries are different.</p><p>My friend Chris has so many internships he’s lost count. These include places like Bank of America, Google, Facebook and many, many more. His CV is black &amp; white and it worked pretty well for him. Try to find people in the industry you’re applying for like Chris who have a lot of experience applying to jobs. Ask them what the industry is like. You can use LinkedIn for this.</p><p>Your CV needs to be eye-catching, it needs to be designed well. It needs to look good and have the correct information in it.</p><p>Personally speaking, I use NovoResume.com for all of my CV needs. I have been using them for years, and they’ve never once let me down.</p><p>Your university careers team might also have templates for you to use, but I would recommend at least modifying this template. Thousands of people will use your universities careers template every year, try to make it unique and make it your CV. If you’ve found 2 or more templates you really like, and you don’t know which one to use, just ask your university careers team.</p><p>If your CV is visually stunning, the employer will love it. They read so many of the same black &amp; white PDF documents filled with information every day they’re desperate to find something that has a hint of graphic design.</p><p>Going hand in hand with a well-designed CV, don’t crinkle your CV or put folds in it if you print it out. It has to look like it just came out of a printer. Never, ever hand over a CV with a crinkle or fold in it.</p><h3>Achievements &amp; Jobs on a CV</h3><p>When writing out your CV, list your achievements at a job. Don’t list the duties you had to do. Everyone has to do stuff at a job, achievements are more impressive. Make sure the CV is visually appealing and sparse of information. You want to tell a story in as few words as possible. Put your jobs in reverse-chronological order so your most recent work appears at the top of the CV.</p><p>If I was to say that I was the best Student Union officer that would make me sound big headed. If I was to change that to “changed Student Union approval rating from 30% to 90%” it would sound even more impressive and not so egotistical.</p><p>Achievements are important too. Try to make your achievements in this format:</p><blockquote>“I did X by doing Y as proved by Q”</blockquote><p>As a general rule you need to have some sort of statistic related to the achievement. It makes the achievement sound so much more impressive. Mixing this achievement rule with statistics will go a long way for you.</p><p>Don’t include jobs if it’s not relevant. If you’re applying to be an investment banker and you worked at an ice cream shop for a week, it’s not really helpful for you to put that on. It’ll just make your CV look messy. If you have no experience, it will be more helpful to put your education on it. You want to balance your education and work experience. If you’ve never worked anywhere relevant before, you’ll want to include your A-levels and university modules with grades. If you’ve worked in industry, as an internship or whatnot then you might not want to include A-levels in order to write more about this experience.</p><p>Real world experience is always worth more than education, so try to disclude as much information of your education as possible. But make sure to put university on there. Don’t include primary / secondary school. The earliest you can go back to is A levels.</p><p>If you’re applying for a job in academia, your education matters a lot more than normal. If you have a perfect mix of work experience and education, try to list your education shortly. Only include the modules that are relevant to the job. If you’re applying for a job in game design and you’ve done modules on game design, include them.</p><p>The single most important thing you can do to make your CV stand out is to customise your CV per job.</p><h3>How to spell-check your CV</h3><p>You need to avoid spelling and grammar mistakes at all costs. It is the difference between you getting a job and you not getting the job. The simplest form of spell checking you can do is to run the Microsoft Word spell checker. But, this isn’t good enough. You actually need to read your CV, and then get someone else to read it for you.</p><p>Your university’s careers team is perfect for this. Almost every careers team will have some form of session or drop in clinic for them to read your CV and pick up on anything that’s wrong. When in doubt, visit your careers team.</p><p>Instead of Microsoft Word’s spell checker, I use Grammarly.</p><h3>To PDF or not to PDF</h3><p>Always send your CV as a PDF unless they absolutely specify it has to be sent in a format they require.</p><p>The PDF is designed to be readable on any machine. The way the PDF looks on your machine is the exact same way it’ll look on any other machine. Anyone can open a PDF. PDFs are supported in Internet Explorer or Chrome. With Microsoft Word, if they have a different Word version to you it may look different. It may actually look worse to them than it does to you. Also, not everyone has Microsoft Word; but everyone has a web browser like Firefox or Chrome.</p><p>If they need the CV in plaintext (copy and paste) you have to change the formatting. You can make sections using “ — — “. Like so:</p><blockquote><em>Achievements<br> — — — — — — — — — -</em></blockquote><blockquote><em>* Changed Student Union approval rating from 30% to 90%</em></blockquote><p>You can use an asterisk as a bullet point, as seen above.</p><h3>References</h3><p>No references available on request. No one I know that gets jobs does this. Make it as easy as possible for the recruiter. Contacting you to ask for references is another step to them, which makes it harder. Cut out the middleman and put the contact details for your reference on the CV itself.</p><p>I know that some references will write you letters, and that’s good. You should hand these in when they ask for qualifications (if they do) or letters of recommendation. Please do not copy and paste your references’ letters onto your CV or attach them to the other blank side. It’s just not good.</p><p>You’ll usually want 2 references, 1 academic and 1 work related. If you have never worked somewhere before, use another academic reference if you can or someone you have volunteered with. Or the head of a society you’re active in.</p><p>When you put the reference on your CV, it should look like this:<br> Name<br> How they know you (ex-boss, ex-co-worker)<br> Contact details (email, phone)</p><p>That’s it. No “I went drinking with him every Friday”. No stories or anything, short and sweet.</p><p>Make sure you ask the person if you can use them as a reference. Make sure they will only say good things about you. If they want to “be honest” about you, find someone else. Your references should gleam at the opportunity to talk about how amazing you are.</p><p>In a warm Starbucks once I was talking to a recruiter. They talked about how many people put references down without making sure the referencer is okay with it. Or they’ll put a reference down that isn’t too keen on the person. The recruiter would often call these references and get:</p><blockquote>“They were alright, they did the job”</blockquote><p>or even worse:</p><p>It’s important to make sure your references know you and love you. Be very careful with what information you put down too.</p><p>If you put down the references personal phone number and your CV gets shared around, you’ve shared personal information with people the reference doesn’t even know about. This is violating many Data Protection Act Regulations.</p><p>In some countries, you don’t even need to put references down on your CV. References are sometimes the very last thing a recruiter asks for. You could instead use that reference space for something more important.</p><p>Like with choosing a well designed CV or a plain CV, you need to decide for yourself. While in the UK it is traditional to put references down, you need to consider the benefits and downsides of it.</p><p><strong>Benefits</strong> <strong>Downsides</strong></p><h3>Make it as Easy for your Employer as Possible</h3><p>Referencing what I said earlier, make it as easy for your employer as possible. Think about who you are applying to. If you’re applying in the tech industry, chances are that they are reading your CV on a computer, so hyperlinks in CVs are cool. If not, don’t include them as they don’t look good when printed out.</p><p>Are you applying to be a graphic designer? The design of your CV matters the most. Are you applying to be a game developer? You could make your CV as a game, like Robbie Leonardi did here: <a href="http://www.rleonardi.com/interactive-resume/"><em>www.rleonardi.com/interactive-resume/</em></a></p><p>Really think about who you are applying for and how you can make your CV better for them.</p><h3>Have a “Profile” Section</h3><p>This profile is a small section of your CV that includes a brief summary of your skills, experiences and goals. It is your elevator pitch. Imagine you are in an elevator with the recruiter of a large company. You have 30 seconds to convince them to care about you enough to want to interview you. This is the elevator pitch. A good profile makes people interested in you. It gives them a reason to read on and pay attention to your CV.</p><p>This is truly customised to you. I really cannot tell you what to write. Your elevator pitch should talk about who you are, what you do, your education, and your goals in life. A good profile will break these rules. It’s one thing to follow the rules, but in order to stand out you need to break these rules. My profile is:</p><blockquote>“Obsessive learner and problem solver, always looking for the next big problem to solve”</blockquote><p>Your elevator pitch talks about your education &amp; experience, your CV profile talks about you as a person. If they want to know about your education &amp; experience, they’ll simply read on. Your principles and goals in life are discovered, not invented.</p><p>My friend’s profile says:</p><blockquote>“I love what I do — turning ideas into reality by coding. “</blockquote><p>It’s incredibly hard for me to describe this, since it has to be personalised to you. No one can tell you what to write here, but keep in mind that you’ll discover what you love if you keep it in the back of your head for long enough.</p><h3>Bullet points, paragraphs &amp; action verbs</h3><p>Bullet Points. Always try to have bullet points. You’re allowed to include paragraphs, but if everything in your CV is a paragraph it’ll look extremely dull. Bullet points are more readable.</p><p>Personally speaking, the only time I use paragraphs is for my achievements, when I want to tell a story. Everything else is bullet points. You should use action verbs in your bullet points to make it sound powerful. Instead of saying:</p><p>You can say:</p><blockquote>“I orchestrated a project”</blockquote><p>Here is a list of 185+ action verbs you can use, from the website The Muse</p><h3>Things to Include in a CV</h3><p>You have a template and you want to change a few things, here are some things you might want to include:</p><p>You can also put a language down that doesn’t relate to the job. If you know an Asian language like Chinese and you put that into your CV, the recruiter will instantly think you are some sort of super genius.</p><h3>What not to include in a CV</h3><p>Let’s just list all the things that the Equality Act of 2010 makes illegal for employers to ask you:</p><h3>Summary of this chapter</h3><h3>Personalising a CV</h3><p>☐ Have you used a CV template?</p><p>☐ Have you customised the CV template to fit around you?</p><p>☐ Does your CV have keywords in it?</p><p>☐ Is your CV clean &amp; minimalistic?</p><p>☐ Do you have special sections related to the job? IE languages, skills, achievements?</p><p>☐ Does your CV have contact details on it, and is the location where you want to be / where you are?</p><p>☐ Do you have achievements at a job on your CV?</p><p>☐ Have you spell checked you CV?</p><p>☐ Is your CV a PDF?</p><p>☐ Do you have references, without “references available on request” on your CV?</p><p>☐ Do you have a profile section?</p><p>☐ Do you have action verbs in your CV?</p><p>☐ Have you gotten rid of everything under the Equality Act of 2010, unless it benefits you in some way?</p><h3>Researching an organisation</h3><p>Do you know these things about the company:</p><p>☐ Mission statement of the company</p><p>☐ Who founded it &amp; why</p><p>☐ A brief history of the company</p><p>☐ Current CEO of the company</p><p>☐ products &amp; services</p><p>☐ Competitors</p><p>☐ Current issues</p><p>☐ News</p><p>☐ Culture</p><p>☐ Career development</p><p>The cover letter is a letter that goes with a CV that explains why you want a job. It can be the first chance you get to stand out to your potential employer.</p><p>What makes a cover letter so difficult is that there is no clear-cut formula to writing a cover letter.</p><p>Ultimately the goal of the cover letter is to draw attention to yourself. It should be clear, concise and display competent language skills.</p><p>It is important to note that not all jobs require a cover letter. It should state it in the job description if it does require a cover letter.</p><h3>Design of a cover letter</h3><p>Google “Cover letter templates” and find one you like. The exact same advice from the CV applies here too. Make sure it’s designed nicely. If you use Novoresume, they also have cover letter templates.</p><h3>Length of the cover letter</h3><p>Some people write entire novels as cover letters, well, almost. Your cover letter should be short. A full page at most.</p><p>The shorter a cover letter is, the better it will look. Don’t try to skimp on information to make it shorter. 4 paragraphs are around the perfect length since it will follow a typical story arc.</p><h3>General structure of a cover letter</h3><p>Start with an introduction. Make the reader aware of why you’re writing this. Include the job you’re applying for. We’ll go into each section soon.</p><p>The 2nd paragraph is your skills, what you can provide to the company.</p><p>The 3rd paragraph should be why you want to work for the company.</p><p>The 4th paragraph is the conclusion. Mention that you look forward to hearing back from them.</p><p>This follows a typical story arc. Start off with who you are, why they should care, why you care about them, summarise and end.</p><h3>Some general tips for the cover letter</h3><p>Don’t talk about how great the position would be to you. Talk about what you can bring the company, always have the company in mind. Show what you’re capable of within a cover letter. Try to tell a story. Stories illuminate the human mind and intrigues them. Try to push them to read more.</p><p>Do not make a one-size-fits-all cover letter. It’s the same as the CV, customise it per job. Job hunting is in itself a job.</p><p>As with a CV your cover letter may be keyword tested so try to include some keywords that the employer wants to see.</p><p>Always send your cover letter as a PDF for the same reason you would send a CV as a PDF.</p><p>Do not use weak or passive language. <a href="http://www.hemingwayapp.com/">http://www.hemingwayapp.com</a> is an online editor which will show you what is considered weak or passive. Instead of writing “I feel”, “I believe” write “I am confident that, “I am positive that”.</p><p>Try to limit the use of “I”. This is a letter about how you meet the employer’s needs, not why it would be good to you.</p><p>The formality depends on the company. If you are applying for a tech start-up formality likely isn’t something they do. An old-fashioned bank? Be as formal you can</p><h3>The start of the cover letter</h3><p>A cover letter should have your information at the start:<br> * First &amp; Last Name<br> * Street Address<br> * City<br> * Postcode<br> * Phone Number<br> * Email Address</p><p>Then comes your salutation. Dear Sir / Madam / Mrs / Mr / Ms / Dr. If you know the person’s name and their honorific, then you need to use this. The letter should feel addressed to that individual person, it should never feel like a blanket cover letter you’ve sent to everyone</p><p>“John Gribbin</p><p>171 Fake street ct9 9lr</p><p>+0174857389</p><p>google@google.com”</p><h3>First paragraph</h3><p>The first paragraph is where you introduce yourself. What you’re applying for.</p><p>“Dear Sir or Madam,</p><p>My name is Brandon Skerritt and I am applying for the position of Bookseller at Waterstones, please find enclosed my CV.”</p><p>In most cases they already know what your name is and what you’re applying for, so if you can don’t include this part. Always include the salutation. If you know the name of the person who will be reading this, use their name.</p><p>As stated in How to Win Friends and Influence People:</p><p>“Names are the sweetest and most important sound in any language.”</p><p>Use keywords. Keywords and statistics are the secret key to unlocking that first interview.</p><p>If you were referred to the job, mention that contact. Express excitement that you’ve applied. The reader should feel like you would die if you didn’t get the job. That you want this job more than anything.</p><p>“I have the pleasure of being acquainted with one of the Counsellors on your staff, Eleanor Seville. She let me know about the open position and recommended that I contact you.”</p><p>Recommendations are important. Some professionals state that they would never have gotten the job if not for a recommendation.</p><p>The first paragraph should flow into who you are and why you want this job. You can always say “I hope you are well” if you do not know what to write.</p><h3>Second Paragraph</h3><p>The second paragraph is where you talk about your skills and experience. Unlike a CV you do not use blunt bullet pointed language here but instead talk about your experience, like a story. You can also explain any gaps that might appear in a CV here.</p><p>Try not to regurgitate your CV in letter form. Think about what you’re writing and why you’re writing it. Make it into a story. You need to customise your cover letter per job, much like you’ll customise your CV per job.</p><p>This section should display that you have researched this position and know what it is about and how your skills match with the position.</p><p>“For as long as I can remember I’ve been an obsessive reader. I review books on GoodReads, I’ve written some fiction novellas in my spare time. I’ve been a bookseller for the last 2 years at [Bookshop name here] and have loved every second of it. As well as being a bookseller I’ve trained new employees and managed the general every day running of the store.”</p><p>Sometimes people will use bullet points, it’s entirely up to you. If this was bullet pointed it would look like:</p><p>“For as long as I can remember I’ve been an obsessive reader, having even written some fiction novellas in my spare time. I’ve been a bookseller for the last 2 years and in my role, I have achieved:</p><ul><li>Trained new employees although it wasn’t my job</li><li>Broke the record for most amount of money earnt in made in a day. Previous record was £400, my team and I made £1200</li><li>Located a class photo book from the 1980s by calling up every store in the area to check for it. Just to make the customer happy.”</li></ul><p>Bullet points make it shorter and easier to read but it also takes away the humanity of a normal paragraph.</p><h3>Third paragraph</h3><p>The third paragraph is why you’re applying. What do you like about the job or company you’re applying to? Any nice anecdotes about the company? After reading the last paragraph the recruiter should be curious. Why do you want to change jobs if you love it? What’s so special about this company? <strong>What can you do for the company?</strong></p><p>This is where you swing the bat and hit that ball out of the park. This is where you show your determination and undying love for the company. This is where the recruiter decides if you’re different from the others.</p><p>“Waterstones has always been my favourite bookstore. I’ve collected over 11 stamp cards and try to go to Waterstones weekly to see what new books have been released. Sometimes I cannot help myself as a fellow book seller to rearrange books that have been misplaced or recommended books for your store based on the shelves. One such instance is a book titled “how to read water”; this book would have looked good next to The Cloud Collectors guide — a book on reading clouds”</p><h3>Fourth Paragraph</h3><p>Fourth paragraph is the conclusion, where you wrap this all up. Reiterate why you want to work there and display that you are happy that you might have the opportunity to work there.</p><p>“Your store is my favourite among the many Waterstones I have been to, and I’ve been to nearly all of them. I hope I have the opportunity to work at this fantastic store.</p><p>I look forward to hearing back from you,</p><p>Brandon Skerritt”</p><p>Another way to end this is:</p><p>“Thank you for your time and consideration. I look forward to meeting with you to discuss my application further.</p><p>Yours sincerely,</p><p>Brandon Skerritt”</p><h3>Conclusion</h3><p>☐ Have you researched the company and you know what keywords to use?</p><p>☐ Have you discussed what you can bring the company, not what the company can bring you?</p><p>☐ Have you customised it per job?</p><p>☐ Is your cover letter a PDF?</p><p>☐ Are you using active language (and not passive)?</p><p>☐ Does the formality of the cover letter match the formality of the job?</p><p>“What are you doing?”</p><p>“I’m googling them” responded my friend with CVs strewn across her table.</p><p>“This one’s bad” she stated with authority. The CV itself looked good enough for an interview but her research online showed she wasn’t right for the job.</p><p>One by one, she Googled them all. Education didn’t matter, their experience — for the most part, didn’t matter.</p><p>Although this was a part-time waitressing job at a small local café, their online portrayal mattered. It mattered so much that people with amazing academical backgrounds and lots of experience were being tossed to the side.</p><p>This is why personal branding is important. It is not only for the entrepreneurs out there but for every single person. Most people believe that personal branding doesn’t affect them since they are not a celebrity. The truth is, everyone has a personal brand. It’s up to you to decide when and how you’ll take control of it. Your personal brand exists, whether you like it or not.</p><p>A personal brand isn’t makeup you’re selling or being featured in magazines. It is everything about your public life. Your Twitter, Facebook, Instagram.</p><p>You do not have to be an entrepreneur to care about your personal brand. When you apply for a job the recruiter will Google you. They’ll want to know:</p><p>If you tick some of these boxes, you’ll stand out from the rest.</p><p>There is often a quote given out in running circles:</p><p>“It’s okay to run slowly. You’re still running laps around the people sitting on the sofa.</p><p>The same can be said for a personal brand. It’s okay if your personal brand doesn’t have years of posts or tweets. It’s okay if you only started today. You’re still doing better than those who have not started.”</p><p>Your personal brand will bring you more riches in life than any job you could have. When we work somewhere, we say that thing is us. “I am a lawyer” instead of “I practice law”. “I am a programmer” instead of “I program at work”.</p><p>This way of thinking consumes your life. Your entire life rotates around this one job, this one title.</p><p>This should not be the case. If you quit or you lose your job, then your title goes away. If your title goes away, your entire life crumbles.</p><p>If you developed a personal brand and have friends and fans, then they will continue to be with you. It is a lot easier to switch jobs or find a new job when you have so many contacts on social media.</p><p>As an example, you have have two people:</p><p>Charlotte is a software engineer at Google. She regularly writes blog posts about software, goes to conferences, has a podcast. She does stuff outside of her job.</p><p>Emily is another software engineer at Google. Emily’s entire life is Google. She does not go to conferences, have a blog, or even cares about anything else. She is only a Googler.</p><p>Both of these people are fired. Emily struggles to find a job having to apply to every company that has a position. Charlotte writes a quick tweet about it, it gets reshared a couple hundred of times and she has a new job before the weeks over.</p><p>Your personal brand is like insurance for yourself and your job. Your personal brand, if you take it seriously, will transcend your career and will become your career.</p><h3>Making friends, not connections</h3><p>Do not act like you only added someone on LinkedIn to increase your professional network. Try to become friends with them instead.</p><p>A connection is just someone that acknowledges you exist at the best of times. Normally it’s when someone randomly connects with someone on LinkedIn to “increase their network”.</p><p>Connections are meaningless. If you wanted a job at a company and you have a connection there, asking them to help you likely won’t work as they won’t know you.</p><p>If you are friends with this person however, you are kind, generous and have helped them they are more likely to help you get the job.</p><p>Friendships formed over social media are worth 100 times more than a simple connection to someone. This brings us into the second point, you need to care about them in order for them to care about you.</p><p>One of the first rules of Dale Carnegie’s book “How to win friends and influence people” states:</p><p>“Become genuinely interested in other people”</p><p>If you don’t care about or celebrate someone’s achievements, then when it is time for you to celebrate your achievements they likely won’t care.</p><p>Not too long ago when I got into university, I posted about it on social media. No one cared because I didn’t care about their achievements. Now I regularly celebrate my friends’ achievements, small or big because I care about them and they celebrate mine.</p><p>People will only care about you if you care about them. You need to make friends. Connecting with someone just isn’t enough anymore.</p><p>We’re now in the thank you economy. You used to fake being big until you got big, now you have to be small; even if you are as big as Google. Do not pretend like your schedule is too big, treat the other person as a friend.</p><p>Back in the day, you used to be able to fake being big. If you owned a company, you could play some background noise when on the phone to make it sound like you’re busy. Now we have public follower counts, you cannot fake being big. You need to be human.</p><h3>Creating content</h3><p>Content creation is the only way to build a personal brand. Whether that content is via tweets, Instagram points or blog posts.</p><p>You are not going to make friends if you only ever like or retweet stuff. You need to produce content. Content is like seeds you plant in the ground. The more seeds you plant, the more likely they’ll grow into a beautiful garden.</p><p>The content does not have to be blog posts. It can be reviews, answers on Quora, open source software. As long as it is preferably free, online, and provides value to people it’s good content.</p><p>You may be able to get by without content creation if you are a big-name celebrity. Elon Musk rarely creates online content but is still famous. The likely chance of you not needing to create content online is slim.</p><p>Content creation is what draws crowds, it’s what you can show your employer. People who look at your profile and see you are passionate about your cause will like you.</p><p>The majority of your posts on social media should be about what you love. They should also show a side to you, have emotion in it. Nobody likes a re-posting Twitter bot.</p><p>Your content has to be great content. Bad content is not good enough. If you have to take time to create good content instead of posting every day than do so. But great content always trumps mediocre content, even if the mediocre content is posted every day or even every hour.</p><h3>Creating content from other content — the pillars of content creation</h3><p>This is a method that allows you to create a lot of content from one piece of content. You need to decide on your main content pillars. Let’s use YouTube or Medium (a blog) as an example.</p><p>Once you’ve created this large piece of content, a large 5000-word article or a YouTube video you pick out things to repost to your relevant social media channels. Often your readers / watchers will point out the exact moments they loved about your content.</p><p>On Medium, readers highlight what they loved about your article. On YouTube, watchers post video timestamps in your comments.</p><p>Once you know what they loved, you can post this specific line or clip of a video to your relevant social media. With content creation, you don’t need to make content for every single platform. Focus on your main pillar of content creation, make that as best as you can. Using this strategy, you can create amazing content from amazing content without straining yourself.</p><h3>Blogging</h3><p>Blogging is the easiest way to create a personal brand. You can write about anything on a blog. Most bloggers who care for their personal brand will write about their industry. It’s a way to show employers that you are enthusiastic about the industry.</p><p>Starting a blog is easy, the hardest part is knowing what to write. Read lots, look at the news and wait. Ideas will come to you. Even if you think the ideas are stupid or insignificant, they’re still better than the people who don’t have a blog.</p><p>The platform doesn’t matter as much — as long as you write. Medium.com is an amazing platform for getting your voice out there. Although it isn’t the best to write on and you’re restricted no other blogging platform provides as much value as Medium does.</p><p>Many bloggers start out on Medium and move their way to another platform overtime.</p><p>If you build an entire business or brand on someone else’s platform you don’t get much control over what happens to your business. The platform could fail, it could die like Vine did.</p><p>There isn’t much on blogging here, as you can find so much content on starting a blog online.</p><h3>GitHub</h3><p>If you write code and you’re not on GitHub, what are you doing? GitHub is a social network with its core functionality being that it is a version control system. You upload code, and friends or fans can see your code.</p><h3>Green boxes</h3><p>GitHub has a section on everyone’s profile called “contributions”. It has a number on top of the green boxes, that number is how many contributions you have made in the last year. Every single day on GitHub, you get a new box. If you contribute on that day, you get a green box. The more contributions on a day, the darker the shade of green.</p><p>A contribution is defined as doing something. You upload some code, you edit some code, you write some documentation. You leave comments on bugs software has. You create “issues” which are reports of bugs you have encountered on other people’s code.</p><p>The more you interact and support the open source community, the more green boxes you get. The more green boxes, the more it looks like you’re passionate about coding.</p><h3>Bio</h3><p>Nothing special here. Just copy and paste the bio you use on Twitter / Instagram here.</p><h3>Stars</h3><p>Think of stars as likes. You can star a project you find interesting and others can see them.</p><h3>Repositories</h3><p>Repositories are projects of code. If you’ve created a cool coding project, create a repository for it.</p><h3>Facebook</h3><p>There’s no point in me trying to explain what Facebook is, you already know.</p><h3>Facebook Groups</h3><p>Facebook groups are just like LinkedIn groups (discussed later). Find groups that interest you. There are groups for Women in Tech, LGBT+ groups, People of Colour and more. Find professional groups that appeal to you and join them.</p><p>I’ve seen hackathons advertised where winners get a guaranteed interview at Apple in Facebook tech groups before, so it’s worth joining Facebook groups just in case.</p><h3>Facebook Targeted adverts</h3><p>I have friends that <strong>love</strong> their Facebook adverts. If you go to a lot of tech events, read a lot on tech and regularly interact with the tech world — you’ll get adverts targeted at you. Some of these adverts are useful. Some of them could be hackathons, or events you can go to. Whenever you see an advert that is useful to you, click “see more of this” to let Facebook know that this is relevant to you.</p><p>The idea is to get adverts that can directly improve your life.</p><h3>Following Influencers</h3><p>Just like you can follow Richard Branson on Twitter, you can also follow him on Facebook. Follow as many influencers in your field as possible and interact with them or with people in the comments.</p><h3>Facebook stories</h3><p>Facebook stories is another way you can build your personal brand. Not many people use Facebook stories, so when you do use it, you’ll stand out amongst your peers. Facebook groups also have a story function, so you can post stories to Facebook groups.</p><h3>Community Facebook pages</h3><p>Make sure to follow &amp; like Facebook pages that interest you. Be aware that others can see what pages you have liked, so don’t go liking anything too silly that may jeopardise your future career.</p><h3>Facebook events</h3><p>Facebook events are ways to find out about events happening near you. From society’s or companies posting events, you could find an event for anything.</p><p>Facebook will also display “related” events in the sidebar. If you find an event you like make sure to check out related events.</p><p>Lastly, there is a wealth of information out there about upcoming tech events. Companies are trying to get their events known and get more personal with their potential customers and attendees. Hackathons and workshops are very frequently posted on Facebook too, so keep an eye out for events by looking at posts in Facebook groups, and using the Facebook search bar.</p><p>On top of that, to see even more you might be interested in, look at the Related Events in the sidebar.</p><h3>URL</h3><p>This is the first thing you will want to do to brand yourself, a vanity URL is your customised domain on Facebook. Instead of facebook.com/e2434h394oij you can get facebook.com/joeshmoe. Go to the Customized URL page on Facebook and set yours now. If you can’t find out how to do it, just Google “Facebook customised URL”. I’m not including instructions here, in case they change it after I’ve published this.</p><h3>Photo</h3><p>Upload the same one you use on LinkedIn. Some people will disagree with me on this and say that you should give visitors a unique Facebook experience — this is fine, just as long as it’s not harmful to your brand.</p><p>As a rule, I would say the picture should be related to what type of person you are, being an authentic representation of your personal brand. If you are on the summit of Kilimanjaro in your profile picture, you had better be into your mountaineering in other words.</p><h3>Twitter</h3><p>Twitter is a microblogging platform allowing users to upload “tweets” which are 280 characters long. The user can comment on, like, or retweet a tweet.</p><h3>Handle</h3><p>You need to have a professional Twitter handle. This is often your name such as: “@brandonskerritt” or @brandon_skerritt”.</p><p>If someone else is using a Twitter handle you want and they’re not using it (no tweets or activity), then you can submit a request to get that handle.</p><p>To do this, you need to have your own domain and email address. Let’s say you want the handle “@skerritt”. To claim this handle, you need to own an email address, such as: brandon@skerritt.tech and own a website or domain similar to skerritt.com.</p><p>Once you own those, you can file for impersonation on the Twitter handle you want. To get a customised email, just Google it.</p><h3>Twitter Engagement</h3><p>Your Twitter engagement score is a key performance indicator (KPI) of how a tweet has performed.</p><p>Twitter engagement is calculated using:</p><p>In short: It’s a popularity score for each of your tweets.</p><p>Here are some statistics directly from Twitter on how to improve your engagement:</p><ul><li>Photos average a 35% boost in Retweets</li><li>Videos get a 28% boost</li><li>Quotes get a 19% boost in Retweets</li><li>Including a number receives a 17% bump in Retweets</li><li>Hashtags receive a 16% boost</li></ul><p>Twitter polls are a good way to gain engagement. Most people want to find out the result of a poll, so they’ll vote on it just to see the result.</p><h3>Getting people to care about you</h3><p>Know what industry you’re in. Find a hashtag that relates to this industry. If you’re a programmer, #100daysofcode is a good hashtag.</p><p>If you don’t know of any hashtags, just search your industry and see what hashtags others are using.</p><p>Once you’ve found a hashtag, interact with people. Congratulate people, answer questions they may have, just talk to them. Do this, day in and day out and you’ll eventually get more followers who care about your content.</p><p>Another way to do this is to post content that helps others. If you help someone through your content, they will want to follow you as you could help them even more.</p><p>Reply to every mention you get, and any tweets that you can relate to.</p><p>Twitter’s new feed is non-chronological. An algorithm selects what tweets a user may want to see, even if they don’t want to see that tweet. The more you interact with a user, the more likely your tweets will appear in their feed.</p><h3>To tweet or not to tweet</h3><p>Like any social network, Twitter rewards users who engage with other users. You need to reply to, like, and retweet other user.</p><p>If you don’t, Twitter won’t show your tweets to people.</p><h3>Twitter Spam Rules</h3><p>Twitter is incredibly strict with spammers. If you spam follow, like or retweet Twitter won’t show your tweets to many people.</p><p>In fact, Twitter’s rules are so strict that you could get flagged for spamming even if you don’t mean to spam. If you like, follow, or retweet too much in a certain time period — you’re classed as a spammer. The exact rules and timing of the spam rules aren’t available to the public as spammers could use them to their advantage. Just be extremely careful when interacting with many people on Twitter.</p><h3>Instagram</h3><p>Instagram is a social network for sharing photos. I’m not going over how to take good photos, since there are millions of photography guides available on the web.</p><h3>Knowing if your Instagram will grow or not</h3><p>Sometimes, it can feel like a lottery. Will your Instagram grow ridiculously large after 3 months? Or will it not grow at all for many months. There are a few tell-tale signs to watch out for.</p><h4>The number of instagrammers in your niche</h4><p>How many other Instagram accounts are creating &amp; talking about the content like you are? The more there is, the harder it is for you to penetrate this community. Think about your niche, what are you targeting? Search Instagram for other accounts in this niche and see whether or not it’ll be harder for you to grow here.</p><p>You can measure how many people are in a niche from hashtags. This method isn’t perfect, but it’s the best we have. Search your niche like “#Yoga” and see how many posts are under that hashtag. #Yoga has 60 million posts, so it’s a very hard community to penetrate into and grow.</p><p>If you search ‘#BuildUpDevs’ you’ll find out this hashtag has a small amount of posts in it, but it’s still an active hashtag. This is an easy hashtag to penetrate into.</p><h4>How unique your Instagram account is</h4><p>The uniqueness of your account within its content category has a direct correlation with the likelihood of growing an engaged audience fast. How are you going to make your account different from all of the other accounts in your niche?</p><p>Your unique selling point could be that you post the most visually appealing photos, or you include dogs in your photos. You have to be unique, so you can grow in your chosen niche.</p><p>No one wants to follow another account that just posts the same images as everyone else does. You need to be unique, stand out and attract attention.</p><h3>Picking your niche</h3><p>The simplest way to pick your niche is to just pick something that makes you happy to look at. That’s it. Just being happy is all that matters.</p><p>You may choose to pick a niche that relates to the area you want to work in the future. As a computer scientist, I post about coding on Instagram.</p><p>As a general rule, the more specific your niche is the more potential you have to grow. Remember there has to be a want for your niche. Dogs in cute jumpers is an example of a specific niche that has a large demand.</p><h3>When to post</h3><p>Knowing when to post is unique per Instagram account. If you’re running a business and want extremely high growth, you may be posting up to 5 or 7 times a day. You should experiment to see how many posts you should post per day.</p><p>Start out posting once on 3 separate days in a week. Then go up to 5, then up to 7. Try posting X per week, record how many followers you gain. Do this for a couple of weeks until you find out how many posts your niche wants. I try to post daily in my coding Instagram.</p><p>Hashtags are what gets you noticed in the community. Hashtagging is important and vital for your instagram posts. On Instagram, you have communities. These communities communicate and are built around hashtags. In order to join a community, you need to post regularly to hashtags and follow those who also post to those hashtags.</p><p>Users can now follow hashtags, so they can see your posts in that hashtag even if they don’t follow you. Hashtags can also be featured in Instagram stories, to get your story seen by people who follow that hashtag.</p><p>You can add hashtags to your profile’s bio. You’ll appear in searches for the hashtags you select. It’s a good idea to use hashtags in your bio to attract a larger audience.</p><p>The easiest way to get the best hashtags for your niche is to find top posters in that niche and copy their hashtags. They’ve done all the hard work for you — by finding the hashtags that work.</p><p>One of the problems with this approach is that the larger accounts already have a large following — whereas you’re just starting out. Let’s assume the poster with the large account is posting in #Yoga, with 16 million posts in it. This poster has 20,000 followers — so when their fans see the photo, they like it. This boosts it through the other posts in #yoga and makes it appear at the top — where it gets more likes.</p><p>If someone with little to no followers tried to post under #Yoga, their photo would be lost in the hundreds of photos posted to that hashtag every day.</p><p>When starting out, you want a mix of popular hashtags and not so popular hashtags. You want those popular, big hashtags so just in case your photo blows up it can blow up more. You want those smaller hashtags, so others can find you. You’re allowed a maximum of 30 hashtags, so 25 of those should be smaller and 5 should be larger.</p><p>The smaller hashtags have to actually exist. You can’t just make your own hashtags, as no one will discover them. Once you become a bigger account you may choose to make your own hashtags.</p><p>The easiest way to find smaller hashtags is to look for smaller creators in your niche and check through the hashtags they use. Knowing what hashtags are “small” and which are “big” depends entirely on the niche, only you can decide that.</p><p>When you search a hashtag, Instagram will show you related hashtags to the hashtag you have searched. Click through these and see if you can find any good hashtags you can include in your posts.</p><p>When I started my own coding Instagram, I copied someone else’s hashtags and pasted them into my notes app. Now I just copy and paste every time I post something.</p><p>When posting hashtags, it’s better to include them in a comment on your post rather than having them in the description of the post. This makes it look cleaner. When posting in a comment, write 5 full stops:</p><p>“</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>#hashtags #go #here</p><p>“</p><p>This will make your hashtags hidden in a comment, so the post looks cleaner overall.</p><h3>Interactions</h3><p>You should see by now that the most important aspect of social media is to be social. Reply to every comment you get, talk to people. Be sociable. These apps reward people for using them. They want you to be social. Make the algorithm work for you by being sociable and interacting with others.</p><h3>Tagging reposters</h3><p>Reposters are some of the biggest players in the Instagram game. You tag them in a photo related to the niche, and they repost it. They give you credit, and you get hundreds of thousands of follows / likes / comments.</p><p>Usually the biggest posters in a hashtag are reposters. Click on a post. Are they giving credit, like “Photo by @brandon.codes”? If the profile is not of a person, they might be a reposter.</p><p>When you tag a reposting account in your posts, you have the chance of being reposted. These reposting accounts are usually the biggest in the niche, so your post will be seen by thousands of followers. This increases your own visibility and will enable you to get a larger follower.</p><h3>Location</h3><p>As well as tagging your photos with hashtags &amp; people, you can also tag your photos with a location. Just like with hashtags, each location has its own Instagram feed. It’s worth tagging your photos with a location, simply because it puts you in one more feed.</p><h3>Grid Visuals</h3><p>How your grid looks is important to your brand. Your grid has to be consistent, neat, and aesthetically pleasing. People will follow you if you keep a consistent theme in your grids. Here are some simple grid systems you can use.</p><h4>Normal</h4><p>Just post the same type of content — without worrying how it looks in the bigger picture. Stick to the same colour combination and the same theme, you’ll do well.</p><h4>Diagonals</h4><p>With diagonals, you’re aiming to match the same type of photo diagonally. Think Connect Four, but with photos. With diagonal photos you should stick to the same overall niche, such as “Yellow” or “Coffee” but each diagonal should be different from the other diagonals. One diagonal could be yellow cars, another could be yellow coats.</p><h4>Tiles</h4><p>Much like a black &amp; white tiled floor, you’ll want to tile your photos here. Your tiles need to look different in order for the effect to take place.</p><h4>Row by row</h4><p>Every row has its own unique style. Much like diagonal, each row has to differentiate itself from the others.</p><h4>Lines</h4><p>You can place a column of photos down the middle that all follow a theme, or down one of the sides.</p><h4>Rainbow feeds</h4><p>The colour of your feed gradually changes over time — giving the impression of a rainbow. This is quite hard to pull off, but it makes your feed look amazing.</p><h4>Borders</h4><p>Having white borders around your photos can give more space in the feed to each item, making it look that much cooler.</p><p>From December 2017, you can now follow hashtags. This is monumental, since you can see the posts of people you don’t follow in your Instagram feed. Follow as many hashtags as you can and engage with everyone on Instagram. The more you engage, the more you’ll grow.</p><h3>Creating unique content &amp; series</h3><p>In order to stand out, you may wish to create a unique series of content. My friend, Sasha, has a weekly Instagram stories series called “Colour Tuesday”. Every Tuesday, people send her their favourite colours and she posts them into her story.</p><p>This interaction with her fan base strengthens their liking for her. When Instagram sees all these hundreds of people interacting with her, they reward her by putting her posts higher up in the Instagram feed.</p><p>You can interact with your followers via polls, question &amp; answer sessions, live sessions and much, much more. Instagram is adding more features to enable users to interact more. If you interact more, the more Instagram will like you.</p><p>One of the series I have started recently is mini-blogs on topics that my followers suggest to me. They tell me to cover something, like the Turing Completeness of PowerPoint. Ok, I admit, this sounds boring. I can hear your eyes closing as I write this. But I’m a computer scientist, this is what people find fun in my field.</p><p>LinkedIn is a social network for professionals. It’s built for anybody and everybody that wants to become more professional. You can think of LinkedIn as the virtual version of going to a careers fair. You’ll be able to meet lots of people, make connections &amp; friends and more on LinkedIn.</p><p>Your LinkedIn profile is like a general CV. Your CV is customised per job &amp; position, your LinkedIn is generalised.</p><p>This is a general rule for all social media. It’s important to keep your profile updated. Whenever you get a new job or anything else professionally related, update your profile. If you do something cool, update your network.</p><h3>The headline</h3><p>The headline is the first thing someone sees when they see you on LinkedIn. At minimum, the headline should be your current job and company.</p><p>The headline has a 120-character maximum. Your headline helps people find you. When someone searches you in LinkedIn search, they get your profile picture, your name and your headline.</p><p>Most people on LinkedIn just have their job title(s) as the headline, but you should add much more to it. You can include your expertise, any awards you’ve won. Even include keywords in your header that you want to come up for in LinkedIn search.</p><p>You can include things such as:</p><p>If someone searches “freelance graphic designer” on LinkedIn and that’s your headline, you’ll appear in the search.</p><p>Instead of having:</p><p>“Student”</p><p>As your headline, you can instead have:</p><p>“Student specialising in mental health applications of VR”</p><p>You need to be creative. Don’t be cliché. Don’t have a headline like this:</p><p>“Student of life, school of hard knocks”</p><h3>The photo</h3><p>LinkedIn profiles which have a picture are 11 times more likely to be viewed, according to LinkedIn.</p><p>Your LinkedIn picture should be recent, and it should look professional. It shouldn’t be you in a nightclub or your Tinder profile picture. If you can, pay someone to take it for you. Do you know any photography students? Kindly ask them if they could take a photo of you.</p><p>It should be an ordinary, professional headshot of yourself. Another good tip is to have a photo of you doing something as your LinkedIn profile. If you’re a VR specialist, you in a VR headshet would work. You still need to look professional. Look ahead and smile.</p><p>If your industry doesn’t wear suits (technology), then don’t wear a suit in your profile picture.</p><p>The background of your photo matters a lot. It should be minimalistic, nothing going on in the background. Preferably a white background would be perfect.</p><p>Make sure to use the same profile picture across all of your professional social media. Your brand recognition matters. You don’t want people searching for you on Twitter and getting confused as to whether it’s really you or not.</p><p>Try to name the photo file “Firstname.Lastname.png”. Search engine optimisation means that you want to optimise your online presence to appear higher in search engines (Google) results. By naming your profile picture to this, you’ll appear higher in search engine results for your name.</p><p>You’ll also only want to use the .png file extension. The .jpeg or .jpg is a compressed version of .png, meaning it won’t look as good. Try to only take pictures on .png. If you have taken pictures on your phone or a camera, it’s likely that this file is a .png file. If your photo name ends in .png, it’s a png.</p><h3>The profile cover photo</h3><p>The background picture also needs to be professional. It can be you speaking to an audience or some code you’ve written. It should be clean and professional. If you’ve never done this than any photos of you at an event you’ve been to related to the industry will do.</p><p>If you’re still stuck, pick a nice landscape photo or something.</p><h3>Summary</h3><p>This is vital to your LinkedIn. The summary is a paragraph section about you. It includes your professional summary, any hopes or aspirations you have in your career.</p><p>Before you write your summary, it’s important to understand these things:</p><p>Your summary should be general enough to cover any job you may apply to but specific enough to let you appear in search results. If you want to include bullet points in your summary, Google “Ascii bullet point” then copy and paste it, it’ll look like this “*”.</p><p>To appear in search results, you must utilise keywords. Understand what industry you want to go into and Google the keywords relevant to that industry.</p><p>You can also find keywords from job postings.</p><p>On mobile, the first 92 characters of your LinkedIn summary are visible. For the user to see the rest they must click “show more”. This means that the first 92 characters matter the most, make sure every character counts.</p><p>Also, write in first person. It’s creepy and weird to read something that says:</p><p>“Brandon is a creative genius who loves ice cream”</p><p>On someone’s profile, when you know for a fact, they’ve written it themselves.</p><p>Your summary is going to let you expand on your headline, what problems you solve and why you love doing it. It should be a story and if possible, it should prove your credentials. If you claim to be knowledgeable in macroeconomics, why are you knowledgeable?</p><p>If you can, include a call to action. A call to action is you calling the user to take action on something. In your LinkedIn profile, this action is typically to connect with you. Give them a reason to connect and tell them to connect with you.</p><h3>Spellcheck</h3><p>This shouldn’t be said, but just in case, everything needs to be spell checked.</p><h3>Own a business or brand? Check out this cool trick</h3><p>Under your Contact Info, LinkedIn gives you the option to link to a website or blog. But by default, the text that shows in your profile is the extremely dull “Blog” or “Website.” Anyone visiting your profile has no clue where they’ll end up if they click on that.</p><p>Want to use your actual brand or business name? You can! Here’s a simple little trick.</p><p>When editing the Websites area of your profile, select the “Other” option. Now you can add your own website title and URL.</p><h3>Personalise your URL</h3><p>Not many people know this, but you can personalise your URL on LinkedIn to a vanity URL. Instead of pointing to LinkedIn/In/3857239 you can make it point to LinkedIn/In/FirstnameLastname instead. Here’s instructions directly from LinkedIn on how to do this:</p><ol><li>Click the <em>Me</em> icon at the top of your LinkedIn homepage.</li><li>On your profile page, click <em>Edit public profile &amp; URL</em> on the right rail.</li><li>Under <em>Edit URL</em> in the right rail, click the <em>Edit</em> icon next to your public profile URL.</li><li>Type the last part of your new custom URL in the text box.</li></ol><p>Note: these instructions might have changed since the publication of this book.</p><h3>Sections</h3><p>You can create sections in LinkedIn. We’re going to go over all of the sections available to you.</p><h4>Experience</h4><p>The experience section is a reverse-chronological listing of all of your professional experience. Typically, this will include jobs or work experience you have undertaken.</p><p>You’ll want to have descriptive job titles here in order to let any recruiters know exactly what you were doing. Keywords are always the key. If you include keywords in your job descriptions, you’ll appear higher in search results (SEO).</p><p>If you have done an internship at Barclays learning about investing, instead of having:</p><p>“Internship at Barclays”</p><p>You should put:</p><p>“Investment analyst internship at Barclays”</p><p>Like with a CV, we’ll want to include achievements in your descriptions of the job. Include any testimonials here, if you have them, and any promotions you have received in the description of your experience.</p><h4>Education</h4><p>LinkedIn has a 2000-word count on your education here, so go wild if you want. Include your achievements, modules, activities &amp; societies and anything else you can think of. You can also include “media” which lets people see a media attachment related to this education. With permission of my lecturers, I’ve included PowerPoints I’ve given.</p><p>The media attachments will let anyone look at your work, if they care. In reality it’s incredibly unlikely that someone will look at your work, but it makes your education stand out since LinkedIn gives you a pretty “Media” section on your education.</p><p>Here’s my own example of my education section:</p><p>“ <em>Activities and Societies: Duke of Edinburgh Gold, Free Code Camp Kent, Body Combat</em></p><p>Modules:</p><p>Unit 1 — Business Skills for e-Commerce (core module) — Level 4 (15 credits)</p><p>Unit 2 — Computer Systems (core module) — Level 4 (15 credits)</p><p>Unit 3 — Employability and Professional Development (core module) — Level 4 (15 credits)</p><p>Unit 7 — Research Skills — Level 4 (15 credits)</p><p>Unit 14 — Website Design — Level 4 (15 credits)</p><p>Unit 19 — Object Oriented Programming — Level 4 (15 credits)</p><p>Unit 23 — Mathematics for Software Developers — Level 4 (15 credits)</p><p>Unit 24 — Networking Technologies — Level 4 (15 credits)</p><p>As well as studying for the MTA certification scheme.</p><p>Alongside this, I am also undertaking Gold DofE</p><p>Achievements while here:</p><p>100% in mock interview for University with University of Kent</p><p>Amazon Web Services award at the University of Nottingham’s hackathon, HackNotts 2016, representing my college. <a href="http://bit.ly/2lo7NGO">http://bit.ly/2lo7NGO</a></p><p>Passport to Employment, twice.</p><p>60% increase in student voice representation”</p><h4>Volunteer experience</h4><p>This section is designed the exact same way that experience is, except your volunteer experience goes here. There isn’t much to say here, since most of it was covered in the previous section.</p><h4>Skills &amp; Endorsements</h4><p>In this section, you list skills you have, and your connections can endorse you for those skills. As an example, you could list “writing” as a skill and have 13 connections confirm that you’re a good writer.</p><p>You can physically move these skills up and down the list. I recommend having the most in-demand skills or most impressive skills at the top, to catch the eye of your employer.</p><p>Don’t try to have the same skill but worded differently. For example, you could have these skills:</p><p>But Microsoft Office covers them all. You’re only allowed 30 skills, use them wisely.</p><p>To get your connections to endorse you for skills, simply endorse them. Going back to what we said earlier, if you want people to care you need to care about them. If you want endorsements, you need to endorse them.</p><p>Another way to get endorsements is to ask for them. Create a message, copy and paste it to people you know on LinkedIn. Very few people actively use LinkedIn, so this is a good way to get endorsements.</p><p>While a little spammy, it works.</p><h4>Recommendations</h4><p>People will write you recommendations, and you can write other recommendations. These are testimonials that someone knows you and they think you’re good. It’s usually a short paragraph or two of why you are amazing.</p><p>Some recruiters don’t like recommendations so much, since it’s very much a case of you writing one for your friends and they write one for you.</p><p>The key to getting recommendations is the same as getting endorsements, you write one for them and they’ll write one for you. You can also request a recommendation from people by following these steps:</p><ol><li>Click the <em>Me</em> icon at the top of your LinkedIn homepage.</li><li>Scroll down to the <em>Recommendations</em> section and click <em>Ask to be recommended</em>.</li><li>Type the name of the connection you’d like to ask for a recommendation in the <em>Who do you want to ask?</em> field.</li><li>Select the name from the dropdown that appears.</li><li>Fill out the <em>Relationship</em> and <em>Position at the time</em> fields of the recommendations pop-up window and click <em>Next</em>.</li><li>You can include a personalized message with your request by changing the text in the message field.</li></ol><h4>Accomplishments</h4><p>This is a whole section dedicated to your accomplishments. We’re going to go over each sub-section here.</p><p>Languages</p><p>This is simple, what languages do you know? If you’re a computer programmer, you can include programming languages here too. Nothing so special here.</p><p>Qualifications</p><p>This is where all of your qualifications go. All of your GCSE’s, A levels and university degrees as well as more. If you have taken any online courses, include them here. If you have a first aid certificate from work or you have a DBS check, include them here. Unlike with a CV, there’s no set rule to having “too much” on LinkedIn.</p><p>Recruiters can filter searches by qualifications, so make sure to include as many of these as you can. Your National Citizen Service or Duke of Edinburgh award goes here too.</p><p>There are many new sections you can add to your LinkedIn profile. From awards to volunteer work, there’s a section for you.</p><p>Projects</p><p>Your projects section details any projects you’ve worked on. It’s designed like the experience section where you can have dates on the project, descriptions and titles.</p><p>The same advice from experience works here. You can also add the other people who have worked on the project with you.</p><p>Organisations</p><p>What organisations are you a part of? If your degree is accredited, include that here. For example, my computer science degree is accredited by the British Computing Society, so I have them listed here.</p><p>I’ve also listed the organisations I’ve volunteered with here.</p><p>Courses</p><p>What courses have you done? Any online courses? First Aid course? Your modules? Anything course related can go here.</p><h3>Connections</h3><p>On LinkedIn, you can connect with anyone you want. Kind of. If too many people report as not knowing you, you’ll no longer be able to connect with people. You need to connect with people you’ve met. But, even when you’ve met people, they still may not remember you.</p><p>This is why it’s important to include a personalised message to everyone you connect with. A simple “I met you at [place here]” or “I’m interested in your work on X, can we connect so I can stay up to date?”</p><p>When you get past 500 connections on LinkedIn, it’ll only show on your LinkedIn profile as “500+ connections”. It’s way more impressive if you have 500+ connections than 499. Even if you only have 501 connections. People on LinkedIn can’t tell the difference between 501 connections and 171,326 connections. It always shows as “500+ connections”.</p><h3>Blog Posts</h3><p>You can write blog posts and articles directly in LinkedIn. This feature isn’t used so well but can be used to increase your reach.</p><p>If you want to write one, click “write an article” under the “update your status” section of the LinkedIn homepage.</p><h3>Groups</h3><p>There are many groups on LinkedIn you can join. You should find groups that interest you. You can find a group for web development, investing, and much more.</p><p>Once you’ve joined a group, comment on things and post things in that group. Interact with people in the group, it’ll help you make friends in that industry.</p><p>Groups can be an easy way to make friends and increase the number of connections you have.</p><h3>Conclusion</h3><p>I’m not going to create a checklist for every single social media that was brought up here, it’ll be too long. Just go through each section that applies to you.</p><p>☐ Have you gone through each of your social media accounts and applied the recommendations laid out in this chapter?</p><p>☐ Have you decided what type of content you’re going to produce and how?</p><p>☐ Have you started to make friends, not connections?</p><p>Interviews are essential to job positions. Almost every single job will involve an interview of some kind. Most people believe that an interview is where the employer sees if you are the right candidate for the job. While that is true, an interview is also where you see whether the employer is right for you.</p><p>When it comes to interviews, practice makes perfect. Get as much practice as possible. Ask your university careers service if they do practice interviews. The more interviews you do, the better you’ll get at them.</p><p>Later on in this book, we’ll go over a lot of possible interview questions.</p><h3>Interview Formats</h3><p>These interview formats can be mix and matched or on their own. It depends on how the employer wants to do things.</p><h3>Face to Face</h3><p>The normal physical interview format. There will be 1 or 2 people at most interviewing you. They’ll ask you questions relating to the job. They might also make you solve puzzles in front of them, in order to understand your problem-solving process.</p><h3>Online Video Interview</h3><p>The interviewer will give you a set of questions and you’ll have to record yourself for 15 to 30 minutes answering the questions.</p><p>The interviewer loves this format because if you bore them after the first 15 seconds they can stop watching.</p><p>Some companies (such as Barclays) use Artificial Intelligence to read your face and use that to determine whether you go onto the next stage. If you know an AI is going to face read you then you need to have a good internet connection and camera quality, as the AI can’t read your face otherwise.</p><p>Like any interview, you’ll need to dress for the occasion. Even if it’s not a human interviewing you, they may still be able to detect what you’re wearing.</p><h3>Skype Interview</h3><p>The employer will Skype you and will ask you questions as if it is face to face. Whatever you do, make sure you’re in a quiet environment with good internet.</p><p>If you don’t want to approach your careers service and would rather ask friends for this, this is the easiest interview type to ask for help with.</p><p>Your friend could be in bed reading out a list of questions whilst on Skype. However, you must act professional. You cannot be in bed or not dressed for the occasion. This is interview practice, not question time practice. If you do not take practice interviews seriously, you’ll falter at the real interview.</p><p>When completing video interviews or Skype interviews, look behind you. What’s behind you? That’s what the interviewer will see. Try to interview with a boring, plain white background if you can. Your universities careers team may let you take video / Skype interviews in a nice, monotone office.</p><p>Don’t look sad, smile. Smiling is the key to interviews, even if they can’t physically see you. Don’t wear a headset or headphones, it makes you look unprofessional</p><p>You can have notes in front of you while doing this interview. Take this to your advantage. Place your CV, company information, questions you want to ask and any more right in front of you, so your interviewer can’t see them. Don’t Google things mid-interview.</p><h3>Phone Interview</h3><p>This is used to determine whether you are worth the time and effort to interview in person. This type of interview is almost always one employee interviewing you.</p><p>Just like with the Skype and video interviews, you can have things in front of you. Have your CV, questions and whatever else you think you may need. Just make sure not to play around with the paper too loudly.</p><p>You need to make sure it’s a high-quality phone call too. If you don’t get signal in your home, find somewhere that does have signal and is quiet. Your universities careers team would probably let you make a call in one of their offices, if you asked.</p><p>You’re allowed to quietly Google things this time, as long as it’s quiet and you don’t leave too much of a gap in your speech. Do not type directly onto your phone while calling someone, they’ll hear it.</p><p>It’s a good idea to disable phone notifications as well. You don’t want the recruiter to hear your phone buzzing from your Snapchat notifications.<br><br> When answering the phone, answer with:</p><p>“Hello, [YOUR NAME] here”.</p><p>I would answer as:</p><p>“Hello, Brandon here”</p><p>Smile. Even if they don’t see you. Smiling comes through on the phone, so smile a lot and be happy.</p><p>Assessment Centres</p><p>An assessment centre is a building or office designed to assess your criteria for the job. Assessment centres typically follow this schedule:</p><p>Most of the time you will be asked to give a presentation during the assessment centre. Your team will be assigned a problem and some reading material, to produce a presentation. More on presentations can be found on page 149</p><p>Very commonly you’ll be asked to retake the tests you’ve done online such as verbal reasoning and numerical reasoning. Sometimes people get their friends to do these online, so this is a test to make sure you know what you’re doing. More on these tests can be found on page 145.</p><p>You may do all of these things, you may do some of these things. If you have an assessment centre coming up and you know what will happen there, feel free to only read the parts that apply to you.</p><h4>Social events</h4><p>Social events are any part of the assessment centre that is said to be “informal”. This will typically be lunch. This can and will still affect your outcome. Use the time to ask lots of questions, make notes that may be useful in any future interviews with the company.</p><h4>In-Tray / e-Tray Exercises</h4><p>This is similar to a role-playing scenario. You will pretend to be a newly appointed manager with a bunch of tasks in a tray / inbox. You have to choose which tasks are the most important. You may also be asked to complete the tasks in the tray. The tray exercises will feature an abundance of sources. It could be emails, voicemails, letters or charts.</p><h4>Group Activities</h4><p>When undertaking group exercises one or two instructors will watch you. Don’t dominate the discussion, let everyone speak and if someone’s quiet ask them for their input. Try to present your idea as it’ll make you stand out from the group. Don’t worry if one person is seen as too dominating as it likely won’t impress the recruiter.</p><p>In group exercises you must be inclusive, you must include everyone in solving a problem. What they’re looking for here is someone who works well in a team. You do not have to be the “best” in the team. You’re not going to be knocked out of the process during the group problem for not being the “best”. You must display excellent communication skills and teamwork skills.</p><p>Normally you’ll encounter one of these problems:</p><p>Business scenarios</p><p>Often linked to the business. This can include coming up with new ideas for the company, setting a budget, planning a holiday, making a new product, case studies of charities.</p><p>Ranking exercises</p><p>As the name implies, you have to rank things. Whether this is your top 10 favourite songs or favourite prime ministers. The interviewer could give you a list of people and tell you only 5 or 10 can survive — who do you kill?</p><p>Physical tasks</p><p>This is anything that involves physical activity. It can be building a radio or building a tower of blocks in a weird fashion. It could also be things like Football or table tennis. It depends on how wacky the company is. If it’s a tech company, it’s a good indication that they might have something wacky such as table tennis.</p><p>Role plays</p><p>Your team will have to roleplay a scenario. This can involve selling an item to someone, management roles or pretending to fire an employee.</p><h3>Panel Interview</h3><p>You will be interviewed by a panel of people, as opposed to just 1 or 2 people. This is very similar to a face to face interview.</p><h3>Group Interview</h3><p>You will be interviewed as a group. As in multiple candidates will be interviewed by one interviewer (or panel). This is also normally a face to face style interview. It is unusual to have a group interview over Skype or the phone.</p><p>Employers do this type of interview because it is efficient, they can interview multiple candidates at once.</p><p>In this style you want to stand out. You can do this by:</p><h3>Styles of Interview</h3><p>There can be many different styles of interviews that match the formats of interviews. This section is designed to give a broad overview of the different styles of interview possible. Further on in this book we will discuss interview questions</p><h3>Competency Interview</h3><p>Competency interviews require candidates to talk about specific times they have solved problems. They want to see you are competent. This is where the project(s) comes into play as well, talked about on page 161. What better way to prove you’re good at something if you’ve actually done it?</p><p>Competency based interviews will usually have the interviewer read questions off of a bit of paper or their laptop. They will likely take notes throughout the interview.</p><p>The type of questions that come up here will be strictly formatted. None of those “what’s your favourite colour?” questions.</p><p>The best way to prepare for a competency interview is to read through the questions listed later in this book and try to answer them yourself.</p><p>Competency based interview questions can be found in the next chapter.</p><h3>Strength Based Interviews</h3><p>A strength-based interview focuses on what you enjoy doing, rather than what you can do like in a competency-based interview. Strength based interviews come from “positive” psychology. The theory states that by matching you with what you enjoy doing you’ll be happier in your role, will perform better and stay with the company for longer.</p><p>The interviewer will likely not have any questions written down for this, or not many. They may ask something like “tell me about your favourite day out” and they will ask questions based on your answers to really gage you as a person. These types of interviews will normally feel like a formal chat with a friend rather than a one on one interview.</p><p>More and more companies are switching to strength-based interviews. These companies publicly state they use them:</p><p>Strength based questions don’t have a binary “right or wrong” answer. But, do be a decent human being. Don’t talk badly about other people, don’t lie, just be nice.</p><p>Just like every other type of interview you’ll need to include examples to back up your responses.</p><p>Here are some examples of strength-based interview questions:</p><p>We’ll go over how to answer these in chapter 6.</p><h3>Stress Based Interviews</h3><p>A stress-based interview is designed to make you stressed, to put you under pressure to see how well you do.</p><p>The logic is that the way you respond under stress during the interview is indicative of the way you’ll handle similar situations on the job.</p><p>They can be problematic because it may make the applicant develop a negative attitude towards the company. Sometimes, even the most successful applicants will turn down an offer on account of the nature of the interview alone.</p><p>Here’s some stress-based interview questions:</p><p>Again, we’ll go over these questions in the next chapter.</p><h3>Technical Interviews</h3><p>A technical interview is used heavily in the technology industry. It usually involves coding.</p><p>There are so much out there about technical interviews ranging from 800-page books to entire video guides on how to pass technical interviews so I’m not going to cover this in detail here. Because of this, I’m not going to write about them here. I recommend the book “Cracking the Coding Interview”, a link to this book can be found at the end of this book.</p><h3>Structured Interview</h3><p>A structured interview is another describing word for a certain type of interview. A structured interview will usually follow a structure. The interviewer asks the questions in a standard pace and the questions are normally read off of a sheet of paper.</p><h3>Unstructured Interview</h3><p>Like above, an unstructured interview is another describing word.</p><p>There isn’t a strict structure to these types of interviews. Usually the interviewer will ask you 1 or 2 questions to start you off. The rest of the questions and the way the interview goes will depend on your answers to the first 1 or 2 questions.</p><h3>The Lunch Interview</h3><p>One of the more informal types of interviews. The interviewer will buy you lunch and will interview you over lunch.</p><p>Do some research on the restaurant you are going to. Try to decide what you will order in advance, before reaching the restaurant. Although a restaurant might feel more informal than an interview, make sure to dress the part.</p><p>If you’re applying for Google or something similar,, where everyone wears jeans and hoodies then wear jeans and a hoodie. Make sure you know what the company expects. Most businesses will require suits and formal wear.</p><p>If you’re not sure on the dress code, just take a step back and think for a second. Is the company some super serious fortune 100 bank or investment firm? It’s formal all the way. Are they a tech start-up? Likely informal. If you Google “[companies name] dress code” you might find them. When in doubt, dress smart.</p><p>Try to arrive 15 minutes before the time of the reservation and meet the employer outside the restaurant.</p><p>The best thing you can do here is to take the lead from your interviewers. When you sit down, casually ask if they’ve been to the restaurant before and what they think are good options. Hopefully their recommendations will give you a sense of an appropriate price range. If not, when the wait staff arrives, try to have your interviewer order first and choose something at that price point (or less).</p><p>Also, be sure to pick an option that will be easy to eat while you’re talking. (Hint: Forkfuls of Caesar salad are easier to manoeuvre than a massive, messy sandwich.)</p><p>Finally, no matter how casual your employer may be, you want to put forward your very, very best self. This means: Stay away from ordering alcohol, even if the interviewers do. If you get the job, you will have plenty of opportunities to share a drink with them — the interview is not the time or place to start.</p><p>There’s a couple stories going around about interviewers asking the waitressing staff to purposely get the interviewees order wrong. This is so the interviewer can see how the applicant behaves in this situation. This is an important example to talk about because while lunch interviews are informal — they are still interviews.</p><h3>Conclusion</h3><p>☐ Find out what interview you’re having</p><p>☐ Try to match the interview to the types listed in this chapter</p><p>☐ Read up on those types of interviews and practice them</p><p>☐ Practice those specific styles again (practice makes perfect)</p><p>☐ Find out the formality of the company</p><p>This chapter is all about interview questions. Before we get into them, let’s first go through some basics of answering interview questions.</p><h3>Answering Interview Questions</h3><p>The STAR method (see below) is appropriate to use for talking about examples and situations you have been in that are beneficial to talk about during the interview. As you’ll come to see, most interview questions require you to answer with an example.</p><p><strong>Situation</strong></p><p>What situation were you in? Give some background details. Were you at university? An internship?</p><p><strong>Task</strong></p><p>What was you tasked with? What were you asked to do, was there a team? Why did you have to do it?</p><p><strong>Action</strong></p><p>What actions did you take? What did you actually do to solve the task? This is the largest part of the STAR method, you should talk more here than any other part.</p><p><strong>Result</strong></p><p>What was the result? What happened because you took action?</p><h3>Know Yourself</h3><p>They will ask questions about your CV. People regularly forget what they have put on their CV. Make sure you understand the projects and work you’ve put on there.</p><p>If you’ve done any projects, I use this table to help me remember any projects I’ve worked on (shown on next page). I recommend you fill this out before an interview, as it will help you.</p><p>“If you know the enemy and know yourself, you need not fear the result of a hundred battles. If you know yourself but not the enemy, for every victory gained you will also suffer a defeat. If you know neither the enemy nor yourself, you will succumb in every battle.” — Sun Tzu, Art of War</p><p>If you’ve researched the company and you know yourself, you’ll come out on top most of the time.</p><p>I also use this table below to find out examples / projects that may be beneficial when answering interview questions. Replace project with example if you haven’t worked on projects. Pick 3 projects you want to really focus on, that you think will benefit you in the interview. Once you’ve picked 3, complete this table.</p><p>Once you’ve filled out these tables, you should have a really good idea of who you are and what you’ve done. Congratulations! You’re already better than 60% of the other applicants. Let’s make you better than 80% of the other applicants in our next section.</p><h3>15 Interview Questions</h3><p>Interview questions, loved by some, hated by many. These are often seen as the hardest part of the interview. What do you say? What do you do? What’s the “right” answer here?</p><p>Interview questions make up 95% of an interview. The whole purpose of an interview is to ask questions and be asked questions. Luckily for you and I, according to Reed, one of the largest recruitment agencies in the world, there are only 15 interview questions. All other interview questions stem from these magic 15.</p><p>The Pareto Principle states that 80% of the rewards comes from 20% of the work. We only need to know how to answer 20% of the interview questions to answer 80% of all the questions asked of you. The other 20%, well, that should come from your research on the company. Later on, in this book, we will discuss how to research a company.</p><p>Let’s get right into these interview questions.</p><h3>Tell me about yourself</h3><p>Don’t make the mistake of thinking this is about your personal life. They do not care about your personal life. It doesn’t matter whether you have a dog or a cat. They want to hear your professional life story.</p><p>Make sure to tell a story. Like previously discussed, humans are naturally prone to enjoying stories. Stories make the other person interested. Don’t give out a bullet pointed list, talk with them.</p><p>This question is a combination of these things: How well the candidate has prepared, their confidence, and what they’ve done in their professional life.</p><p>Even if you haven’t done something interesting in your professional life, you can spin any story to make it sound amazing. In the world of news, bad stories are often spun into a good light. You can spin something non-interesting into interesting.</p><p>Let’s say you work part-time at McDonalds. I chose this because this is the most mediocre thing I could think of. While working at McDonalds, you discovered that it’s faster to type in the order as the person says it rather than to type it at the end. This isn’t ground-breaking stuff, just a simple observation. We’re going to spin this story to make you sound mind-blowingly amazing.</p><p>“In my teenage years I worked at a rapid quickfire fast food chain. On average, we served around 400 customers an hour and during our peaks the store would get so busy the line would go out the door. In this environment, I learnt that I thrive under extreme amounts of pressure. Not only did I have to make sure that every single customer was over-joyous with their meals, but I had to do it fast.</p><p>Whilst working here, I created a new system that increased the speed and accuracy of processing information into an End Point of Sales system. This new system allowed us to serve twice as many customers per minute all whilst keeping the customer satisfaction levels high.</p><p>One time, my store ran out of milk. My manager chose me to partake on this critical mission. To refill our stock supplies and refill them fast. Not only did I achieve this mission within 5 minutes, but I managed to achieve it before any customers requested items containing milk. Considering this restaurant serves 10 people a minute, I’ll say that’s some achievement.”</p><p>The point I’m trying to make here is that no matter how mediocre of a job you think you had, you can always spin it to make you sound amazing.</p><p>Back to the question at hand. Businesses have elevator pitches. These are 30 second speeches that describe the business. The idea is if you are in an elevator with an investor, you have around 30 seconds to convince them to invest in the company. People can have elevator pitches too, and this is used to answer this question.</p><p>Your elevator pitch should be customised per job position. Hopefully you’ll understand that nearly everything should be customised per job position. I can’t tell you what to say, as I don’t know you.</p><p>Don’t make it sound like someone has never asked this question to you before. Act confident. Practice on your friends or in your mirror. Don’t “uhm” or “ehh” before answering. This makes you look like you haven’t prepared, that you’re not confident. Look them in the eye, smile, and say it out loud like you’ve rehearsed it every day of your life.</p><p>Always start your pitch with what you currently do (professionally). End that paragraph with something that leads the interviewer back in time. You want to tell a story. You also want to talk about your most recent things first.</p><p>“I’m a computer science student at the University of Liverpool. I’m aiming to get a first-class degree. Previously I was studying a level 4 diploma at a local college”</p><p>The next part leads back into your past. Notice how I ended the first part with “Previously I was”. This gently pushes you and the reader back into the past. I’m a student, and the likely chance is that you are a student. Education is the thing that defines us, but if you have any part time jobs working in industry you can put them here.</p><p>If you are a software engineer, you can say something like this:</p><p>“I’m a computer science student at the University of Liverpool. I’m aiming to get a first-class degree. I’m also a software engineer part-time.”</p><p>Make sure each section smoothly leads into the other.</p><p>The second section should talk about your achievements. Don’t talk about your responsibilities, what you had to do. Talk about what you have achieved.</p><p>In my case, it’ll look like this:</p><p>“While at college I became the student union’s higher education vice president. During this role I ran the collective college partnership’s Student Union consisting of 5 colleges. Towards the end of my role, every student was filling out the annual student survey. Every section for the student union in the survey had improved ten-fold. Most noticeably, the student union satisfaction rating went up from 30% to ~85%.</p><p>This role required me to be an effective leader and team player. I needed to communicate complex ideas to the board members within meetings. I had to learn to deal with fast paced deadlines and even how to interview and select an appropriate replacement candidate. I believe all of these skills I have obtained will come in very useful within this job.”</p><p>Remember earlier when I said it’s all about spinning a story? Make sure to include statistics if you can. This section is ripe for you to spin, to make yourself sound amazing. At the time, my job required me to go to a meeting once a month and pop into classrooms to discuss student issues. That doesn’t seem like much, but I can spin it to make it sound amazing. Also, the statistics help a lot.</p><p>When you end this, you have to make the interview aware that you have finished. With this question, sometimes there is a few awkward seconds of the interviewer wondering “did they finish?”</p><p>In my case, I like to end it with:</p><p>“If there is anything else you would like to know, feel free to ask me.”</p><p>Most candidates fail this question because they have not practiced. They do not know how to answer or what to talk about. This results in the candidate vomiting out positions and words until they are satisfied that they’ve covered the question.</p><p>Throughout all of these questions in this book, I urge you to practice them. It simply is not enough to read it and forget it, you need to write your own answer to these questions. This question especially. This question is asked in pretty much every interview, and normally right at the start of an interview. Because it’s asked at the start, it counts towards your first impression. If you do not answer this question confidently then the interviewer will likely not hire you, even if you answer every other question well.</p><p>The interviewer asks this question because it allows them to get a rough idea of your background and experience. Sure, they could read your CV. But the interviewer sees this as an “easy” question and it helps to calm your nerves.</p><h3>2. Why are you applying?</h3><p>This question helps the employer understand what you can do for them. You could rephrase this question as “What can you do that we need you to do?” They want to know what problems you can solve. They want to know if you have the determination and motivation to work for the.</p><p>In the Reed book “Why You?” they say that an answer to this question can be expressed in one single sentence:</p><p>“I’m applying because my skills, experience, and motivation are the best fit for the job.”</p><p>Like all interview questions, you have to customise it per job interview. Don’t give out a blanket answer here. Don’t mention these in your answer:</p><p>You want to work at this job because you love it. Even if you don’t love it, don’t let the interviewer know. The interviewer wants to hire someone who is in love with the company and the job, don’t give them any reason to doubt you.</p><p>You want to research the job role here to see how you can fit into the job role. Interviewing is all about making yourself look like the perfect candidate for the job. Here’s an example of an answer to this question:</p><p>“I want this job because it emphasises helping others and integrity, two things that make up the core of who I am. In my previous job, I helped fundraise over £5000 for charity in one month and always put the customer first. I know I could bring my 3 years of experience to this company, and continue your years of growth”</p><h3>3. What are your greatest strengths?</h3><p>To answer this question, you have to customise it to the job description. Reflect what the job description says here. It’s no use talking about how great you are at welding if you’re applying for an office job.</p><p>This question is giving you the opportunity to boast about yourself, but don’t come across as arrogant. This is not the time to be humble, you need to sell yourself like you’re absolutely perfect for the job.</p><p>There isn’t much I can say here to help you, since this question is customised per job. You need to think about how you’ll answer this question and write down your answer.</p><p>Instead, let’s go over what makes a great answer. Look at this answer:</p><p>“I’m an extremely hard worker. I often don’t pick up many projects but when I do, I go all in. Recently I’ve picked up blogging, managing to amass more than 80,000 monthly readers in less than 8 months.”</p><p>The statistics in this answer make it hit hard. 80,000 people read my blog every month, and I’ve achieved that in 6 months? Notice how I’ve managed to boast here without sounding too big-headed. You could rephrase this as:</p><p>“I’ve grown my blog to tens of thousands of readers every single month, and it has taken me less than a year!”</p><p>This one sounds like I’m obsessed with myself. If you add statistics, you’re allowed to boast about yourself without sounding obsessive or insane.</p><p>Another way to rephrase this is:</p><p>“My blog posts get twice as many people reading them as there are people in Lichtenstein”</p><p>This is using statistics. There are around 30,000 people in Lichtenstein and 80,000 people read my blog, but this sounds big headed. You have to say the numbers directly. Notice how if we change this to include numbers it doesn’t make sense:</p><p>“My blog posts get 80,000 readers per month. There are 30,000 people in Lichtenstein. My blog gets more than twice as many readers per month then there are people in Lichtenstein”.</p><p>Statistics and hard numbers are incredibly important.</p><p>Make sure the statistic is relevant to the job. If I’m applying for a job that has nothing to do with writing, I probably wouldn’t bring this up.</p><p>With statistics, you don’t have to be given one to use it. You can work out the statistic yourself. Let’s say you work in a bookshop and you regularly talk to customers. You could say:</p><p>“I regularly engage with customers and sell them more books then what they came in for. On average, every customer I serve buys more than £50 worth of books”.</p><p>Sometimes, it’s better to present something you’re only slightly good at then it is to present something you are amazing at. If the thing you are amazing at doesn’t match the job description, don’t mention it. If the thing you are slightly good at does, do mention it.</p><h3>4. What are your greatest weaknesses?</h3><p>Many people fail this question because they believe that the right answer is “I don’t have any weaknesses”. What? Are you human? Everyone has a weakness. Please do not answer with a weakness similar to these:</p><p>Yeah, sure it may have worked for your granddad but employers could see the lies from miles away. Use an actual weakness here, something that you suck at. But don’t admit to something insane such as:</p><p>“Sometimes I get really vivid thoughts of murdering people that interview me… :)”</p><p>The secret to answering this question is to use a real problem you’ve faced. But make sure you talk about how you’ve overcome this. If you’re still overcoming the problem, that’s okay. You can still talk about this. An example taken from myself would be:</p><p>“I used to be terrified of phone call I’m still overcoming this but I’m not as bad as I was a year or two ago.”</p><p>But don’t make the weakness a part of the job description. If the job description says</p><p>“you need to be really good at talking to people”</p><p>Never say</p><p>“I’m really bad at talking to someone”.</p><p>You have to say how you overcame your weakness and turn it into something positive. Mould it into a story.</p><p>Show that this won’t be a problem at your current company. Say something along the lines of:</p><p>“I believe this won’t be a problem in this company”</p><p>and then say why. Mine would be:</p><p>“I used to be terrified of phone calls. The idea of phoning someone was a no go for me. Having worked in a student’s union and at multiple events it was inevitable for me to phone people so I’ve gotten used to it. I’m still overcoming this but I’m not as bad as I was a year or two ago. I believe this won’t be a problem at this company because I’m passionate for the cause of this company which would allow me to talk more on the phone to people revolving around this company. That’s one of the reasons I want to join this company, because I get to do what I love, and I get to push my boundaries and get out of my comfort zone, to grow both personally and professionally.”</p><p>It has to be very clear that this question is as normal as giving your name and address, do not act like they are forcing information out of you. Whatever you do, under all circumstances, never ever reply with any of these:</p><h3>5. What will your skills and ideas bring to this company?</h3><p>To put it bluntly, this question is:</p><p>“Why should we care about you? What can you do that others can’t?”</p><p>This is one of the best questions that could possibly come up in an interview. This question is:</p><p>“What can you do that others can’t?”</p><p>The recruiter is asking you to mow down your competition. Do not show mercy to your competition, make it very clear that you are the best. If you’ve worked on a project (discussed later), now is the time to talk about it. If you’re a software developer, you might say something like:</p><p>“I saw your company used this Python package on GitHub, but that Python package is deprecated. I’ve actually made a Python package that works the same but uses all the conventions that Python requires now. It’s also a little bit faster.”</p><p>You have to customise this per job. There aren’t many interview questions that you can’t customise per job. Also, you want to beat your components but don’t talk badly about them. Focus on your strengths, not your components’ weaknesses.</p><p>If you haven’t completed a project, talk about what you’ve done in the past for other, but similar, companies. Make it sound like these past achievements are something that you can do for this company. An example might be:</p><p>“I turned a failing product from 30 sales a month to 10,000 a week, I want to sell as many of Product X as possible”.</p><p>Or here’s another example:</p><p>“I will bring my unique vision to your company. I can see your company achieving X in the future, and I want to help you achieve this. I am experienced in A, B, C related to [company’s goals]. For example, I helped improve student retention rates at my previous college by over 45%. My marketing background, along with my ability to see potential future problems, will help you grow.”</p><h3>6. What’s your preferred management style?</h3><p>This question is just the interviewer wanting to know if you are going to get along together.</p><p>There’s 3 main steps to this question.</p><h4>Define what good management is</h4><p>They obviously care about good management, so it’s important that you and the interviewer get on the same page about what good management is. Here’s an answer example answer:</p><p>“Management style is hard to describe, but I think a good manager gives clear directions and stays hands-off but is ready and available to jump in and offer expertise or help when needed.”</p><h4>2. Add your own take</h4><p>Now say something that makes you unique. You want to stand out, not appear to be another sheep in the candidate pool. Here’s a good response for the second part from Forbes</p><p>“In terms of what makes me unique, I go out of my way to fully understand a problem and try to solve it as best as I can before seeking help. When I do, it’s quite a short chat since I know exactly what the problem is, and I know what questions I need to ask in order to solve it.”</p><h4>3. Add an example</h4><p>Examples always work in interview answers. Back up what you’ve said. Here’s an answer to this part:</p><blockquote><em>“ </em>I remember one project at [previous company name here] where I had to work on achieving X in 2 weeks. I worked tirelessly to make it the best it can be, but I came across a problem. I researched for hours on the problem itself before seeking help from my manager. Because of my research, I knew exactly what the problem was. A quick 2- or 3-minute chat with my manager fixed everything for me. I realised this problem may be experienced by more new employees, so I created a text document containing common problems and fixes which allowed our manager to work less on helping others and more on making sure goals are met on time<em>.”</em></blockquote><h3>7. Where do you see yourself in five years’ time?</h3><p>The recruiter is asking this question because they want to know if you plan to work there for a long time. Every employer expects you to work there for a very long time, even if it’s a small part time job.</p><p>Brand loyalty is important here. Even if you don’t plan to work there forever, make it seem like it. You can say something along the lines of:</p><p>“I don’t know your company well enough, but I would like to think I would still be working here. In 5 years’ time I would have liked to learnt enough to be able to train people in future roles.”</p><p>What you want to do here is mix “I love your company and I want to work here forever” with “I’m quite ambitious and I would love to take on some bigger roles in my career”.</p><h3>8. How would you approach this job?</h3><p>This question is strange. It’s kind of a trick question. You will never completely know how a company works without working at that company. Don’t answer like you’re an expert on this but you do need to answer like you have a relatively good idea of what you’re doing.</p><p>An answer like this will work:</p><p>“Well, the best way to do this job won’t come clear to me until I start this job. But I’ll start by getting to know my colleagues and team, listening, taking notes, building relationships, and helping people out where I can. After all that, I’ll have a good idea of how to do this job in the best way possible. At my last job I did…”</p><p>Notice the example again. Talk about how you best undertook your last job but don’t go on forever about it. You don’t need to answer every question with a long-winded story. Most interviews have time constraints, so don’t answer every question like you did with the first.</p><h3>9. What have you achieved in other roles?</h3><p>This is quite similar to question 3. This questions is giving you permission to toot your own horn, to show off. This is not the time to be humble. Talk about your proudest achievement at another role. This is highly personal, but an example of mine would be:</p><p>“My role as Higher Education Vice President started off on a bad turn. There were supposed to be 5 student union officers, but only I wanted to do the job. Effectively leaving me in charge of the work of 5 people, all whilst the student union staff who work with us had left to go to another job.</p><p>Luckily this was perfect for me, as I stepped up when no one else would. I travelled to every campus as much as possible to make sure all students were listened to. When a group of students came to me telling me that their course isn’t being properly funded, I demanded a meeting with the principle of East Kent College to fix this.</p><p>As well as this I repeatedly represented the students in a democratic way at both a local (Kent) way and in a national way. I was chosen to attend the National Union of Student’s National Conference, where I elected the next NUS officer team and chose to represent my college on a national scale.</p><p>By the end of the year the students were asked to fill out a survey about their time at college. Student union approval ratings were previously laying around 30%, with about 5 questions about the student’s union. By the time I finished, it laid around 90% with comments from students saying about how amazing it was for their problems to be fixed so easily.</p><p>On top of this, I received a letter from the Chief Executive President of Student Welfare saying that I was the best Student Union’s Officer ever and rewarding me with a £50 Amazon voucher.</p><p>“</p><p>Talk about your achievements, talk about the statistics that back these achievements up. But make sure it’s in a story, humans really like stories. Make sure it’s about <strong>past</strong> achievements in previous roles and not current achievements, things that you are achieving right now.</p><h3>10. What did you like and dislike about your last job?</h3><p>When answering this question, you want to balance two things. On one hand, you don’t want to sound like a moaner who hated your last job. But you also want to be authentic. Since it’s easy to talk about what you liked about your last job, we’ll discuss how to talk about the negatives here.</p><p>The interviewer is asking you to say something negative about your last job. Don’t pretend there wasn’t anything negative, everyone doesn’t like something about their job. Even if it’s really small, be authentic and you’ll do fine.</p><p>Don’t discuss people. This will make you come off as cruel or bad of heart. Discuss the circumstances or tasks you had.</p><p>Here’s a good answer you can model your own answer on:</p><p>“I loved many things about my previous job. An environment where I was regularly challenged, amazing people and cool projects. But there was one thing I didn’t like. Expectations were sometimes unclear. I would complete a project with little to no guidelines and then told that parts of it were wrong. I’ve since learned that communication is key here. If I don’t understand something, I need to ask my manager for help on what they want me to do. Two people can look at the same guidelines and draw vastly different conclusions as to what to do. I’ll always be thankful for the learning opportunity at this company, as it helps me improve myself.”</p><p>This answer is good. It talks about a negative in your job and how you overcame it. The employer is trying to trick you up, by seeing if there is something negative about you. Give them what they want but talk about how you turned this negative into a positive.</p><h3>11. Tell me about a time you worked in a team</h3><p>You&#39;re very likely going to work in a team, so the interviewer wants to know how good you are at team work.</p><p>You need to talk about an experience and weave it into a story. You need to talk about what you did and the problems your team overcame. Don&#39;t badmouth your team, only talk well about them. And remember, the interview cares about your team. There&#39;s no &quot;I&quot; in team, so don&#39;t only talk about how you did everything in the team.</p><p>This is really personal and customised to you, so no examples from me here. You should form your own answers. Just make it a happy story, talk about a problem your team faced and how you overcame it.</p><h3>12. What do your co-workers say about you?</h3><p>If you have testimonials or reference letters, now is a good time to ask if you can show them. Never just pull out your phone or paper documents without asking if it&#39;s okay.</p><p>If you don&#39;t have testimonials, you need to talk about yourself from an outside perspective. An answer like this would work:</p><p>&quot;My colleagues have told me that I am extremely organized and excellent at time management. During one project, my team members praised me for developing and sticking to a timeline for all the phases of the project. (Give a brief summary of what the project was.) We ended up successfully completing it ahead of time, and it was a hit&quot;</p><p>Notice how we talked about a time in a team, and how we used a story to tell it. This is effective. Talking about what team members think about you is more authentic than talking about what you think people you only hang out with at lunch think about you.</p><h3>13. How do you deal with stress and failure?</h3><p>Don&#39;t pretend like you&#39;ve never experienced stress. Talk about how you deal with stress and failure. This is highly personal so again customise this to you. My answer would be:</p><p>&quot;I once was rejected by 5 universities. I had no idea what I would be doing come September.</p><p>This was a highly stressful time for me because I expected to get into at least one university. I went running, I took a few days off work and I decided on my options. I could either of been sad, moany and upset for the rest of that month or I could have manned up, accepted what had happened and decided on my next step. I chose the latter.&quot;</p><h3>14. How much money do you want?</h3><p>As well as how to answer this question, I&#39;m also going to show you how to increase your salary year on year.</p><p>What If I told you that you can get £25,000 by reciting a Shakespeare poem? You would say &quot;Sign me up!&quot;. You&#39;ll memorise the entirety of that poem, knowing every single thing about it. Now, what If I told you that anyone can get this money by reciting a poem? You&#39;ll want to tell everyone you know. What if you told your friends and they said:</p><p>&quot;Well.... I don&#39;t like poetry. I don&#39;t read books much either. That&#39;s a ridiculous proposition. I&#39;m an architect, not a poet. I don&#39;t know the first thing about poetry.&quot;</p><p>Sounds ridiculous. They&#39;re giving up £25,000 because they don&#39;t want to recite poetry for a couple of minutes. This example is exactly like salary negotiation. You can make thousands, sometimes even hundreds of thousands by just spending a few minutes negotiating. You don&#39;t need to be an expert or have studied it to negotiate. I&#39;m going to walk you through everything to make sure you get a well-paying graduate job.</p><p>Questions on salary are difficult. Once you give a number, you lose. They know that&#39;s your maximum, so don&#39;t try and be the first one to give a number. The interviewer might ask:</p><p>&quot;What&#39;s your current salary?&quot;</p><p>Which is just a trick to find out how much money you&#39;re okay with. Here&#39;s what a typical normal salary negotiation looks like:</p><p>And that&#39;s it. You&#39;re stuck there. You could be worth £60k a year and if you answer with &quot;£20k&quot; that&#39;s it. That&#39;s your salary now.</p><p>Here&#39;s what it looks like if you&#39;ve followed this book:</p><ul><li>Once you have established yourself in your field, post an &quot;I&#39;m looking for a job&quot; Tweet / LinkedIn post / any other site you use.</li><li>Loads of people message you, asking you to work at their companies or they can recommend you for company X.</li><li>While these people are working to get you hired at their company, you explore your options on recruitment sites. You find a few jobs you like the look of.</li><li>You reach out to friends that work at these companies and ask for recommendations (if you&#39;re really interested in applying).</li><li>Your recruiter asks you how much money you want. You tell them &quot;It&#39;ll be good if we can come to a mutually fulfilling offer, what were you thinking?&quot;</li><li>They reply back with X</li></ul><p>Boom. You got them. Once they say a number, they lose. The second you say a number you lose. Whoever says the number first is the loser. Let&#39;s explore this some more, including what to do if they refuse to give the number first.</p><p>You should avoid questions such as &quot;how much money do you want&quot;. Don&#39;t give them any numbers. If they ask one of these questions simply say:</p><p>&quot;I&#39;m not comfortable sharing that information at this point&quot;</p><p>At some point in the process you achieve something which I describe as &quot;Yes, if...&quot; rather than &quot;No, but...&quot;. &quot;Yes, we want to work with you, if we can come to a mutually satisfactory offer,&quot; which is distinguished from, &quot;No, we don&#39;t want to work with you, but we might work with you if it turns out that you&#39;re disgustingly cheap.&quot; After you have agreement in principle that, &quot;We want you to work here. What&#39;ll it take to make that happen?&quot; - then and only then do you start negotiating.</p><p>This is <strong>really</strong> important. Only when everything else is said and done do you negotiate salary. You do not have a foot to stand on until this part. If you try to negotiate off the bat, you&#39;ll be thrown out. The more interviews, forms and tests you&#39;ve taken for the company the better. It costs <strong>thousands</strong> for a company to get you this far. Some people think that companies just put out adverts and that&#39;s it, people apply and they get jobs filled quickly. This isn&#39;t the truth.</p><p>The truth is that the company has already paid hundreds of thousands just to find applicants. They have to put out adverts, advertise on job boards (which costs money), hire people to write tests and interview questions, hire people to conduct interviews with you, hire people to double check that you can legally work at the company. Sometimes employers will pay you to travel there for an interview. Some employers can conduct as many as 16 interviews over a period of 12 months (Palantir does this for each applicant, not 16 total. 16 interviews for one applicant).</p><p>If you&#39;re applying for a weapons company (BAE Systems) they have to pay to get you security clearance before you&#39;re even allowed to show up on site for an interview.</p><p>The point I&#39;m trying to make is that replacing candidates late in the process isn&#39;t cheap. In fact, it&#39;s incredibly expensive. If you ask for £25,000 more when they&#39;ve spent £100,000 just to get you to that final stage, they&#39;re likely to say yes, as getting someone to that same stage costs too much.</p><p>The sunk cost fallacy is an important economic principle to think about here. If you&#39;ve spent £5,000 on trying to fix a car and you haven&#39;t fixed it yet, you&#39;re more likely to carry on trying to fix that car rather than buy a new one due to the sunk cost fallacy. The same is for jobs. Once you get to the late stages, the company would rather close the deal than find someone new to replace you.</p><p>Do not feel like you owe the company a favour because they have selected you. If the deal makes economic sense, everything will be fine. If not, they&#39;ll replace you. They hold no feelings for you, why should you hold feelings for them?</p><p>When negotiating salary, try to get them to negotiate over email. It gives you time to think about what&#39;s being said and time to reply. You also have concrete proof of a salary in case they try to trick you.</p><p>It never hurts to negotiate, statistics show that 87% of companies won&#39;t pull a job offer if a candidate negotiate their salary (Why You? - James Reed).</p><p>You need to prepare for this question. You need to research what other employees are earning at this company. And what people with the same job title but at different companies are earning. You can use Google, Glassdoor, PayScale to find this information. The location of the job matters too and will affect salary.</p><p>Have 3 numbers in your head. The perfect amount which is the highest amount possible for this job. The lowest amount, at which point you may as well walk away from the job offer and the medium amount, which is the middle of the 2.</p><p>If the company offers you stock options, don&#39;t play around with that. Nothing beats cold hard salary. It&#39;s very unlikely the company you work at is going to be the next Facebook. Try to convert the stock options into cash as soon as you can.</p><p>When you get to the point of emailing the employer, ask &quot;what do you think I&#39;m worth?&quot; or &quot;How much were you thinking?&quot;. The first person to give a solid number loses. You know how in Pawn Stars they always haggle down? That&#39;s because the seller always gives the price first. They know that&#39;s their maximum, so they try to save themselves money.</p><p>Once you give a number the employer will do exactly the same. They&#39;ll haggle down. If the employer gives a salary number first, you can haggle up. You&#39;re in control.</p><p>However, in the real world this probably isn&#39;t going to happen. They&#39;ll likely offer you half of your highest maximum salary number. This is where you can haggle up. They&#39;re allowed to haggle you down, so why don&#39;t you haggle up?</p><p>If you have to fill out a form with the salary you want on it, make it as low as the form will allow you. Try £1, that ought to give them a laugh.</p><p>What if they object to your &quot;never give a number&quot; strategy with something like &quot;I really need a number to move the process forward&quot;?</p><p>Firstly, they&#39;re lying to you. They want you to compromise your negotiating position. You should answer with:</p><p>&quot;I&#39;m more concerned at the moment with talking to you about discovering whether we&#39;re a mutual fit. If we&#39;re a great fit, then I can be flexible on the numbers with you and you can be flexible on the numbers with me. If we&#39;re not a great fit, then the numbers are ultimately irrelevant, because your company only hires the best and I only work at roles I would be the best at.&quot;</p><p>If they object again, say:</p><p>&quot;No seriously, I&#39;m more interested in if we&#39;re a good mutual fit or not. Money is irrelevant if we&#39;re not a mutual fit.&quot;</p><p>If they call you out and say &quot;Great try at dodging, but seriously I need a number&quot; there&#39;s a myriad of ways to responded to this. If you&#39;re in STEM you can just say:</p><p>&quot;Well, I would hate to walk away from this company over this. Working at the company would have been great for both of us. But you know, I hear the hiring market is tight right now, would you like me to introduce you to other candidates? To save you a few months of you trying to find someone else for this position.&quot;</p><p>STEM has a tight hiring market. It&#39;s tough for companies to find the right employees. There&#39;s more STEM positions to fill than there are employees to take them. You have the advantage here, not them.</p><p>If you&#39;re not in STEM, you can say:</p><p>&quot;Well, I&#39;m looking for £[The maximum salary you found out from earlier]&quot;</p><p>Remember what things have been said in the process. If they said &quot;It&#39;s taken 6 months just to find someone to interview&quot; during the interview, use this to your advantage. Say:</p><p>&quot;I understand that this is a little more money than you might be thinking, but this is an opportunity to get this job position filled without delaying your company for 6 more months&quot;.</p><p>Always put the company&#39;s best interests first. Dale Carnegie&#39;s How to Win Friends and Influence People talks about why people often don&#39;t care about your problems. If you say &quot;we&quot;, and &quot;us&quot; a lot, it opens their mind a lot more to a mutual problem.</p><p>There&#39;s a story floating around about a man who had offers from Google, Apple, Airbnb and more. Over the course of a week, he pitted each company against each other. &quot;Hey Apple, Airbnb is offering me £88,000 and your offer is £80,000. I would like to work at Apple, but the offer from Airbnb is persuasive, what can you do about it?&quot;. Eventually, he got a starting salary of $250,000. Up from $120,000. Also, if you&#39;re not in STEM, yes Silicon Valley salaries are crazy high. Bear in mind that the average rent is around $2500 a week though.</p><p>What you have to keep in mind is that if you&#39;re applying to Fortune 100 companies, they have so much money that an extra £130,000 is peanuts. Apple is literally worth $1 trillion. £130,000 is absolutely nothing to them. Don&#39;t be afraid of negotiating.</p><h3>15. Show me your creativity</h3><p>This question can come out in many forms, but they all reference creativity.</p><p>Almost all employers look for creativity.</p><p>Creativity does not have to be you painting a picture or creating a sculpture.</p><p>You might decide to create a Google Sheets document so everyone on your course knows all the deadline dates for course work.</p><p>As with all interview questions it&#39;s important to provide examples here and I can&#39;t tell you what examples to include as I don&#39;t know you.</p><p>Here&#39;s a good answer from here:</p><p>&quot;While working at SalesCompany, I developed a lead generalization email that generated an unheard of 37% response rate - well above the previous record of 12%, using a friendly tone that made the email prepare casual and personally written, despite being a template.&quot;</p><h3>General Interview Tips</h3><h3>Change &quot;uhhhh&quot; to &quot; &quot;</h3><p>Instead of saying &quot;uhhhh&quot; and &quot;ehhhhhh&quot; just pause. Smile.</p><h3>Ask for a pause</h3><p>In Karate we have something called a Kata, which is like a dance of all the moves you&#39;re supposed to know at your level. It&#39;s perfectly okay that between moves you take a short pause, a little break to think about what your next move is but when you perform the next move you do it strongly and fast.</p><p>The same can be said for interviews. It&#39;s perfectly okay to say</p><p>&quot;Sorry, I&#39;m feeling a little nervous. Do you mind if I have a few seconds to myself, so I can calm down?&quot;</p><p>The interviewer knows your nervous. The difference here is that you&#39;ve recognised this, and you&#39;ve done something to try to mitigate it. Most people who are interviewed are nervous and they never stop being nervous. They just talk and talk and talk and rush through everything.</p><p>In Karate if you rushed through your Kata it would be extremely ugly and convoluted. The same holds for interviews. Do not rush through questions. Don&#39;t even worry about a time limit. If you&#39;re calm and careful the interviewer will keep track of time.</p><h3>Questions to ask your interviewer</h3><p>After an interview you want to make sure to ask questions to seem intrigued. Normally you&#39;ll generate questions when talking to the interviewer but if you can&#39;t think of any here are some useful questions to ask:</p><p>&quot;What skills and experiences would make an ideal candidate?&quot; This question makes the interviewer say out loud what they are looking for</p><p>&quot;How would you describe a typical day and week in this position?&quot; This question is just making sure that you are a good match for the position.</p><p>&quot;When can I expect to hear from you?&quot; This question is handy to prevent your nerves from getting the better of you.</p><p>&quot;Describe the culture of the company.&quot; This makes sure you are comfortable with the culture of the company.</p><p>&quot;What do you like most about working for this company?&quot; This lets you connect with the interviewer on a personal level.</p><p>&quot;Do you have an email address so If I have any questions, I can follow up with you?&quot; This question lets you send a thank you email after every interview.</p><h3>Small Hints for Asking Questions</h3><p>Avoid questions that are about you like the salary, vacation time, work hours etc.</p><p>Avoid questions that can be answered &quot;yes&quot; or &quot;no&quot;.</p><p>Like most things in job hunting you&#39;ll want to customise these questions per company. The ones above are general but a good specific question about something the interviewer said will show you are listening.</p><h3>Following up after an interview</h3><p>After the interview, email the interviewer to say thank you. Try to mention something specific so the interview will remember you. It doesn&#39;t even have to be an email. It can even be on a social network as long as it&#39;s professional.</p><p>Here&#39;s a direct message I sent to someone after going to one of their talks:</p><p>&quot;Dear Cain, I was at your NatWest talk at the University of Liverpool. I really enjoyed it and I noticed you talked about API&#39;s and Cryptocurrencies. Being a computer scientist, this really intrigued me! Do you happen to have any upcoming talks about fintech, cryptocurrencies, apps or maybe even personal brand development at NatWest?&quot;</p><p>Here&#39;s a message my friend Kunal sent to someone as a follow up:</p><p>&quot;Hello, I was at the technology showcase event in Manchester today and found your input in the panel very interesting. I have already secured a place on the spring week in Radbroke and look forward to potentially working with you.</p><p>Many thanks, Kunal Agarwala&quot;</p><p>The key here is to let the person reading the follow up know where they know you from. If you had just interviewed with them, and you talked about your love for cats you can follow up with:</p><p>&quot;Hello! I&#39;m Emma, you interviewed me today and we talked about cats. I just wanted to say thank you for this wonderful opportunity to have an interview at [companies name] and I look forward to potentially working with you.</p><p>Many thanks,</p><p>Emma Smith&quot;</p><h3>Interview Red Flags</h3><p>Here are some red flags of interviews, because an interview is a two-way process. The employer is looking for the perfect employee, you&#39;re looking for the perfect job:</p><ul><li>They haven&#39;t read your CV, at all.</li><li>They speak negatively about past employees. Again, if they disrespect past employees, they&#39;ll likely disrespect you.</li><li>They swear and cuss. Not professional. At all.</li><li>The company has high turnover, they repeatedly lose employees. There&#39;s a reason they lose a lot of employees.</li><li>The company&#39;s online reviews are bad.</li></ul><p>If any of these appear in the interview, you should think twice about working there.</p><h3>Conclusion</h3><p>☐ Have you read your own CV?</p><p>☐ Have you filled out the tables in this chapter?</p><p>☐ Create your own answers to each interview question</p><p>☐ Remember to take it slowly</p><p>☐ Prepare questions to ask your interviewer</p><p>☐ Re-read the answers to the possible interview questions, really get to know them.</p><p>☐ Keep in mind the interview redflags</p><p>☐ Follow up after the interview</p><p>All of these tests are strictly timed, usually giving you 30 minutes for 30 questions. Some companies do not care if you don&#39;t complete the entire test in time. One recruiter even told me that they make them harder to put people under stress, and it&#39;s not expected for applicants to complete the whole test on time.</p><p>Your employability team may have access to online psychometric tests for you to take. The only way to get good at these tests, is to practice them. I&#39;m not going to walk you through the top 15 most popular questions, as there are many tutorials found online that will allow you to do this.</p><p>If your employability team doesn&#39;t offer psychometric tests, Google &quot;numeracy test free&quot; or &quot;verbal reasoning test free&quot; to find some free ones online.</p><p>If you complete a psychometric test, it is common for them to make you complete another one during an assessment centre or interview. Sometimes, people get their friends to take the tests for them, so this is a way for them to be sure.</p><p>The way I practiced interviewing and psychometric tests is to apply for jobs that I had no interest in. For example, I applied for a technology internship at Tesco - even though I had no intention of actually taking it up. It was good practice. When I applied to companies I did want to work at, the interviews and psychometric tests were a lot easier since I had been through the process before.</p><h3>Numeracy Tests</h3><p>A numeracy test is a test designed to gauge how well your daily maths skills are and how well they can be applied to a company&#39;s situation. The test will feature a variety of questions. Some questions will involve reading graphs and charts. Other questions will involve calculating percentages or anything you may be expected to do in the job.</p><p>You should use your own calculator. Make sure to know how your calculator works. Most calculators can do amazing things these days, such as calculating percentages easily. There are loads of calculator videos on YouTube to teach you how to use your calculator. I use a Casio FX-991ESPLUS, it&#39;s one step down from a graphing calculator but without the cost.</p><p>Make sure to use rough paper for calculations. These psychometric tests are usually done online, even if you&#39;re in person. Bring a notebook along to any interviews to perform rough calculations.</p><p>Before you submit an answer, make sure to double check it. Sometimes the online test does not let you go back to a previous answer.</p><p>Also, check your units. These online tests can sometimes trick you, presenting you with data in one unit but asking for data in a different unit. Make sure you know exactly what you&#39;re calculating.</p><h3>Verbal Reasoning</h3><p>In the verbal reasoning test, you have to read a paragraph and answer questions about that paragraph. You will normally be able to re-read the paragraph when answering the questions.</p><p>When answering a verbal reasoning test, you should take every word literally. You are being asked a question and the answer is in the paragraph they have given you. Do not try to use outside knowledge to answer a question. The answer should be presented to you somewhere in the text.</p><p>For this reason, it is important to read the questions carefully. Since the answers are given to you in the text, quite often the questions will attempt to trick you.</p><p>Practice makes perfect. You can find verbal reasoning tests by Googling &quot;verbal reasoning test&quot;.</p><h3>Personality Test</h3><p>A personality test is used to gauge how you behave in different situations and to see if you will fit in with the company&#39;s culture.</p><p>A personality test is usually used to tell:</p><p>The good news is that in a personality test there isn&#39;t a clear-cut right or wrong answer. Although there is no right or wrong answer, you can still fail a personality test.</p><p>To do well in this test you need to understand what your employer wants. Once you do, answer accordingly to how you think the perfect employee will answer.</p><h3>Conclusion</h3><p>Practice the tests as much as you can in your own free time.</p><p>Presentations are difficult. People have written entire books about presentations. In this section, I&#39;m going to try and distil some of the knowledge I have learnt from reading these books.</p><h3>Passion</h3><p>Presentations without passion is just bad noise. Passion is what makes your presentation exciting and enjoyable. Science shows that passion is contagious. You will inspire others if you are passionate. Passion is defined as something profoundly meaningful to you as an individual.</p><p>If you do not have passion, it will be hard to generate enthusiasm for your presentation. You want people to love your presentation. How can they love your presentation if you don&#39;t love it?</p><p>People who are passionate about their subject make better speakers. They inspire their audience in a way that non-passionate people can never do. Ralph Waldo Emerson once said:</p><p>&quot;Nothing great has ever been achieved without passion.&quot;</p><p>You can have effective slides, amazing body language &amp; a good message, but none of that matters if you aren&#39;t passionate.</p><p>You can&#39;t fake passion. Simon Sinek, a world renowned TED speaker once said:</p><p>&quot;When it comes to presentations, I cheat. I never do a presentation on something I&#39;m not passionate about.&quot;</p><h3>Stories</h3><p>Throughout this book, you&#39;ll have seen that stories make the world go around. No exception to presentations. Stories are the single, most effective way to reach people&#39;s hearts and minds. You need to tell a story that emotionally connects you to your audience.</p><p>Your audience has to trust you. If you tell a story with something too esoteric and disconnected from the lives of normal people, it&#39;s harder for your audience to engage with you.</p><p>The audience has to seem like they are on your level. You need to relate to them somehow. Everyone has a family, tell a story about family. If you had to give a presentation on some monthly numbers for SanDisk, you can open up by talking about your love for SanDisk. You can talk about how all of your family photos are on SanDisk. Show them photos of your family on a SanDisk device. Talk about how you&#39;ll only trust SanDisk with your family photos.</p><p>The most effective way of delivering information is through the emotional; connection of a story.</p><p>When you hear:</p><p>&quot;The smell of lavender&quot;</p><p>The part of your brain associated with smell activates. When you hear:</p><p>&quot;It felt of velvet&quot;</p><p>The part of your brain associated with touch activates. You can make people use their 7 senses by speaking.</p><p>No story is complete without villains or heroes. Make the story have at least one person the audience can root for.</p><p>Start with the end in mind. It&#39;s easy to think about what you want to talk about, but think about what you want the audience to get out of your presentation. Start with the end in mind, or start with a story. These are the most authenticate ways to create stories. To start with the end in mind, deconstruct the final argument you want to give at the end.</p><p>Simon Sinek says don&#39;t start with facts &amp; figures. They don&#39;t attract people&#39;s attention, start with a story. Stories suck people in and get them to pay attention.</p><h3>Avoid overused buzzwords &amp; clichés</h3><p>These are empty, meaningless. Overused metaphors are boring. In a study, overused metaphors like &quot;a rough day&quot; are treated simply as words akin to &quot;and&quot;, &quot;hello&quot; and other boring words.</p><h3>Conversation, not lecture</h3><p>You don&#39;t want to sit at the front of a room and lecture to people, you want to have a conversation with the audience as if you were talking to a close friend. Practice relentlessly until you can give your presentation as if you were just having a normal conversation.</p><p>There are four elements to verbal delivery, these are:</p><ol><li>Rate - The speed at which you speak.</li><li>Pitch - The pitch at which you speak.</li><li>Volume - How loud or quiet you are.</li><li>Pauses - How many pauses you use.</li></ol><p>When you&#39;re forced to read a university textbook, it&#39;s natural to highlight import sentences. The verbal equivalent is to alter one of the four elements of verbal delivery.</p><p>Pace is how fast or slowly you talk. The perfect pace to use is always slower than your normal conversation rate. You want to be slow. You want everyone to understand each word you say. If you speak at a normal conversational rate, it may bore some people.</p><p>Alongside pace, the average TED talk length is 18 minutes. In fact, almost no TED talks are longer than 18 minutes. TED has found that 18 minutes is perfect, so it&#39;s best to stick to this rule. If your presentation has to be more than 18 minutes - switch it up and add some breaks in. Get some audience participation going.</p><p>You should switch up the four elements of verbal delivery in order to make your presentation interesting.</p><p>Don&#39;t be monotone. You&#39;ll bore the audience. A presentation is a form of entertainment, make sure to entertain the audience by acting excited and speaking well.</p><h3>Pictures</h3><p>Pictures attract people. Pictures are worth a thousand words. Ever watched an Apple / TED presentation? You&#39;ll notice that they barely have any words. Try to disclude as much text as possible in replacement for pictures. If you&#39;re talking at the same time as a wall of text on the presentation, the audience won&#39;t know what to read / listen to and will get confused.</p><p>Although don&#39;t be afraid to write. If you need some text on there to convey a message, put some text on there.</p><h3>Body Language</h3><p>Gestures make a strong argument even stronger. The world&#39;s most charismatic leaders use great body language.</p><p>Studies have shown that complex thinkers use gestures and that the gestures give the audience confidence in the speaker. Some people go as far to say that talking to someone is 80% body language, 20% talking.</p><p>The simplest fix for a presentation lacking effective body language is to use hand gestures. Many presenters have their hands by their sides when they present. This bores people to death. You want to use hand gestures to help convey your messages.</p><p>In a study published in the Journal of Experimental Science, Bob Fennis and Marielle Seel performed ground-breaking studies on hand gestures in supermarkets. 71% of people were more likely to buy a box of sweets when a sales representative displayed an eager-nonverbal style rather than one who had a more reserved style. The sales representative who had better body language and gestures had a higher sales rate.</p><p>Don&#39;t go overboard with hand gestures. Your gestures should be natural, if you force it it&#39;ll come across as ill-conceived.</p><p>Most speakers keep their hands in their pockets when talking. Don&#39;t do this. It makes you appear uninteresting and boring.</p><p>It&#39;s not enough to rehearse the words when you&#39;re practicing. The presentation is 80% body language, 20% speaking. Why only practice the speaking part when your body language is 4 times more important? You need to stand up and practice the movements, the motions of speaking.</p><h3>Novelty</h3><p>Novelty and interesting are almost synonyms. Novelty is defined as:</p><p>&quot;The quality of being new, original, or unusual&quot;</p><p>Reveal something new or unique. Or offer a new answer to an old problem to your audience. The human brain loves novelty much like how it loves stories.</p><p>Martha Burns, a neuroscience professor at the North-western University says that learning something new activates the same area in your brain as gambling does. When dopamine is present in the brain, we tend to remember more than when it is not. Novelty creates this dopamine effect in your brain. Burns says that the easiest way to create dopamine in your audience is to make information new and exciting. The very definition of novelty.</p><h3>Be emotional</h3><p>If you connect with an audience&#39;s emotional side, they will be more receptive and less distracted.</p><h3>Statistics</h3><p>Every single great presentation contains some kind of statistic. Whether that&#39;s information being portrayed in a new light or just a plain old statistic. The best statistics are jaw-dropping statistics. Take this quote from a TED talk as an example:</p><p>&quot;Why are we ignoring the oceans? If you compare NASA&#39;s annual budget to explore the heavens, that one-year budget will fund NOAA&#39;s budget to explore the oceans for 1600 years.&quot;</p><p>Persuasion occurs when you reach a person&#39;s head and heart. Make numbers meaningful. Don&#39;t just give them out as dull numbers, put life into them.</p><h3>Don&#39;t be too serious</h3><p>Humans love humour. Don&#39;t take your subject too seriously and learn to make a joke now and again. When we meet people with good humour, we are more likely to attribute other desirable traits to them - such as being smart or being beautiful. By being funny, it&#39;s more likely that your audience will trust you.</p><p>Most laughs in a presentation come from the audience relating to the speaker through a story. If something happened to you and you found it humorous, there&#39;s a good chance that others will also find it funny.</p><h3>Flow</h3><p>Your presentation slides need to flow from one another like the sea flows into rivers - natural. You don&#39;t find many people marking the exact spot where the sea becomes a river, because it&#39;s natural and flows well. Your presentation slides need to flow just as well.</p><h3>Standing</h3><p>Do not stand in front of the screen when presenting. Stand away from the screen. Your presentation shouldn&#39;t have so much text and images that you need to physically point to them.</p><p>The rule of 3 states that a list of 3 things is more interesting than a list of 2 things. Leverage this to engage your audience. A presentation is all about engaging and entertaining your audience. By limiting slides to a maximum of 3 items you limit the need to physically point at your slides.</p><p>Feel free to repeat points. You can use the rule of three to repeat a point twice or 3 times or to add humour to your presentation. As an example, a presentation slide could look to answer the question &quot;What&#39;s the most popular way people prepare to present?&quot;</p><h3>Templates templates templates</h3><p>Templates are what makes the world go around. Use a template. Templates can be leveraged to create nice looking presentations in a short period of time.</p><h3>Practicing your presentation</h3><p>Your presentation, although it looks amazing on your laptop, may look horrible on a larger screen. If you do not have access to a larger screen to test, use high quality images and graphics. Images ending in the &quot;.png&quot; file extension are high quality and can scale well.</p><p>You can become amazing at presentations by practicing. No one starts out naturally good at anything, with some practice you can be in the top 10% of presenters. In many cities around the United Kingdom there are presentation practice groups. I recommend finding one of these groups by Googling it. If you don&#39;t want to go to one of these events you can practice at home but try to make sure people are watching, you.</p><p>The most important key to public speaking is confidence. You can only build confidence by publicly speaking, not by reading a book on it. Your first presentations may not be the best, but with practice and time you&#39;ll get so much better.</p><p>Always record your presentations if you can and look back on them later on, correcting any issues and mistakes you may have had. Keep a log / diary of all the presentations you&#39;ve done and how you can improve. Self-improvement is the only improvement that matters. If you constantly seek to improve yourself, nothing can stop you.</p><p>&quot;If you are not willing to learn, no one can help you. If you&#39;re willing to learn, no one can stop you.&quot;</p><p>Know your audience before you create a presentation. You have to customise your presentation to your audience. Customisation. The number one key to anything in this book is customisation.</p><p>If you&#39;re talking to a very technical audience than a technical presentation will be good. If you&#39;re talking to a non-technical audience then it won&#39;t go so well.</p><p>Think about what idea do you want people to leave your presentation with. Your presentation should present one solid idea distilled through many slides. It can answer a question, it can present a question, it can give a new mental model. Once you understand the purpose of the presentation you can begin to tailor it and improve it.</p><p>Humour in the presentation is amazing. Your job is to distil an idea into the audience in an entertaining fashion. Humour helps you do this, and it keeps the audience engaged. No one likes being forced to listen / watch a boring presentation.</p><h3>Conclusion</h3><p>Next time you have to create a presentation, re-read this chapter and apply some of these rules. Practice it, a lot. You&#39;ll get better the more you do presentations.</p><p>Projects are vital to your university life. No one cares about your university degree, unless you get less than a 2:1. If you get a 2:1 or a first, congratulations. You&#39;re just like every other person that has applied to the job. Because of this, the company doesn&#39;t care.</p><p>Don&#39;t get me wrong, if you have less than a 2:1 then most large companies will just push you aside. If you do get a 2:1 or above, the companies don&#39;t care but will still give you a chance. It&#39;s mean, right? Because your university degree doesn&#39;t matter, you need to differentiate yourself. Thousands of other applicants all have the same degree, what do you have that others do not?</p><p>Projects are what will make you stand out. Whether it&#39;s a project in an internship or projects you&#39;ve taken on outside of university. Internships and projects in this day and age are just as necessary as a university degree to get a good job.</p><p>If you&#39;re a coder or designer, congratulations! All you need to do is design / code things in your spare time. That&#39;s it. Just pick problems and fix them, design things. In fact, if you&#39;re doing any technical degree, I would argue that you could easily do the technicalities in your spare time. Are you a chemist? You can start a YouTube channel about chemistry. If you&#39;re an engineer, just engineer things outside of your degree.</p><p>When in doubt, create content around your subject. Sure, sometimes you&#39;re an engineer of oil rigs. You can&#39;t just build an oil rig in your spare time. But what you can do is teach others, create content about oil rigs.</p><p>If you&#39;re doing a Bachelor of Arts, create things. Content creation is one of the easiest projects you can do and will make you stand out. Companies want to hire people who are so passionate about their subject that some of their free time is spent in the subject, rather than someone who only goes to university and that&#39;s it.</p><p>If no one else is creating content for your subject, perfect! No competition. You&#39;ll look even more amazing when you graduate. Don&#39;t be afraid to try new things. Failure is what it&#39;s called when you give up. If you never give up, you never fail. Learn from your mistakes and make great content.</p><h3>Preprojects</h3><p>A preproject is a project you work on prior to working at the company you have applied for. The project benefits the company. Let&#39;s see an example.</p><p>There&#39;s an engineer called Nina who wanted to work at Airbnb. She created Nina4AirBnB.com to display what Airbnb are doing wrong and how they can improve it. Nina also talked about emerging markets such as introducing Airbnb into Dubai.</p><p>Because Nina had worked on this pre-project, she got an interview straight away. A pre-project takes time, research and dedication, but what better way to show your interest in a company than providing this for free? Once you&#39;ve made a pre-project, you&#39;re almost guaranteed an interview.</p><p>The difference between you and everyone else applying is not much. Some of you may have gotten better grades, others may have interesting hobbies. But you&#39;re all graduate university students, you need a way to stand out. If you complete a pre-project, not only will you stand out, but you&#39;ll be one of the only people being interviewed who has worked on the company.</p><p>A pre-project will get you noticed, will make you unique and will get your foot in the door. At YCombinator&#39;s Startup school they talk about how all employees must be passionate and dedicated to the business. It is rumoured that at Airbnb they ask the question &quot;If you only have 1 year to live, would you still work here?&quot; to see how passionate someone is about their cause. You can represent how passionate you are about a company&#39;s cause by working on a pre-project.</p><p>Pre-projects don&#39;t only work for a technical role, they can work for any business that has projects. And all businesses have projects.</p><p>As an example, you wanted to work at an amusement park like Thorpe Park. You can research and suggest an event for them based on your research. As an example, you could suggest that around Easter time they create an Easter event, like Fright Nights. Of course, you&#39;ll be a lot more creative than I am.</p><p>To create a pre-project, you need to understand what the company can do better. Can they expand into emerging markets? Is their website accessible? How can this website cater to a younger audience? Once you know what they can do better, you can begin to work on the pre-project.</p><p>The exact style and method you use for this project depends on what you are aiming to achieve. Make sure the document is divided up into sections and each section contains a goal. For example, to appeal to a younger audience you can have this section:</p><p>&quot;Open a Snapchat account and regularly use it. 80% of millennials have a Snapchat account and thus this is a good platform to communicate with the younger generation.&quot;</p><p>If you do write something like this, make sure you write an &quot;engagement plan&quot;. How you plan on growing the Snapchat account, how you&#39;ll engage with people directly through it. I know these sucks, since everyone our age knows Snapchat but older people like having plans for everything to do with social media.</p><p>Once you&#39;ve written a section, clearly define how you are the right person for this job. For example:</p><p>&quot;Not only do I regularly use Snapchat, but I&#39;ve used Snapchat professionally for a business before.&quot;</p><p>The idea is to not only display what you think they can do better, how they can do better, but to show that you are the person to execute these things. If you do not show you are the right person for the job, they&#39;ll simply take your plan and give it to someone else.</p><p>It&#39;s all well and good creating a pre-project, but how are you going to get people to see your project? If no one sees it, then it would never have mattered. Nina created her website using Wix, which is a website designed to easily create an online website. You can use Squarespace, Wordpress or plain old HTML &amp; CSS to build a website. There are many, many guides out there on how to build your own website, so that won&#39;t be covered here. Just understand that creating a website can be as easy as creating a PowerPoint presentation.</p><p>If you don&#39;t want to create a website, you can create a PDF document or presentation to show off. It won&#39;t look as good as a website does, but it&#39;ll get the job done.</p><p>Once you&#39;ve created a nice website or document to show, you need to find the right people or person to show it to.</p><p>Log into your LinkedIn profile and search for the company you want to work for. Click on &quot;connections&quot; in the tab and select &quot;first and second connections&quot;. This will show you all your connections at the company, as well as connections of connections at the company. Go through the search and look for people in the appropriate department. If you found some cyber security bugs in their website, look for someone on their cyber security / networking team.</p><p>If you can&#39;t find anyone on LinkedIn, not to worry. Find an online forum about that company by searching &quot;[company] forum&quot;. Try to find a subreddit for the company if this doesn&#39;t work.</p><p>If you can&#39;t find any subreddits or forums, find an email address. Every company has some sort of email address you can send email to.</p><p>Once you&#39;ve found the person / place to target, here&#39;s how you want to write it out. You&#39;ll want to explain who you are, what you&#39;ve done, and tell them to pass it on if they aren&#39;t the right person.</p><p>Here&#39;s an example:</p><p>&quot;Dear Chris, I&#39;ve seen that Bank of America&#39;s website isn&#39;t accessible by everyone. I&#39;ve redesigned it and written about it here [link here]. I would be grateful if you or someone you know could have a read and improve Bank of America&#39;s website. Kind regards, Brandon&quot;</p><p>If you&#39;re posting into a forum, you can write:</p><p>&quot;Hey all! I really want to work for [company]. I&#39;ve noticed some things about [company] and written up an improvement proposal here. What do you think?&quot;</p><p>The important thing here is that in the first one, don&#39;t ask for a job position directly from the person. In How to Win Friends and Influence People, Carnegie talks about never directly asking someone for something but making them think about it first. The idea is to talk to them, to make them friends with you. Once you&#39;ve built up this position you may be offered a job, if not, you can ask. But never out-right ask for a job as your first message.</p><p>You want them to think that they decided to hire you on their own merit, not based off of something that you have said or done.</p><h3>Conclusion</h3><p>☐ Decide on what projects you&#39;re going to create</p><p>☐ Work on those projects</p><p>☐ Share those projects</p><p>☐ Repeat</p><p>Career Fairs. If you&#39;re a university student, it is likely this word has been shoved down your throat since the October you arrived. Truth is, career fairs aren&#39;t anything like how you imagined them. Some universities like to present career fairs as a way to get a job for graduation. Truth is, a careers fair is just a giant advertisement for hundreds of companies. No company will give you a job at a careers fair, instead they&#39;ll redirect you to their website, so you can apply.</p><p>What is the point of a careers fair then? Networking. Sure, you may not get a job directly from a careers fair, but meeting people &amp; networking - that&#39;s the reason you go. Your net worth is your network. Make friends with the people working at these companies. Ask them for tips on applying.</p><p>The easiest way to get a job at a large company is by knowing someone on the inside and getting recommended. The easiest way to know someone on the inside is to attend careers fairs.</p><h3>Should I bring business cards?</h3><p>Some people bring business cards to career fairs, but truth is outside of Asia they&#39;re not really much of a thing. You can have them, but it&#39;s unlikely that people will care about them as much as they might in other parts of the world.</p><h3>How do I research a company?</h3><p>Most career fairs will publish a list of companies that will be attending. Often, this is a form of advertisement to convince people to come as big companies will be there. Use this list to decide what companies are the most important for you to see.</p><p>Once you&#39;ve made this list, research the companies. Not extensive research like it&#39;s an interview, just some general knowledge about them - enough to be able to make a conversation about the company. Preferably reading their Wikipedia page &amp; checking the news for any mentions of them.</p><h3>Should I print out CVs?</h3><p>Print out copies of your CV and hand these out if companies don&#39;t have a webpage / spreadsheet where they want you to input you email address. Often, smaller companies will prefer physical CVs to an online application.</p><h3>What else should I be doing beforehand?</h3><p>Practice your elevator pitch. An elevator pitch is a 30 second pitch designed to let someone roughly know what you&#39;re about. It should feature your current positions, any important past positions and your general goals and life motto. Mine is:</p><p>&quot;Hi, I&#39;m Brandon. Obsessive Learner and Problem Solver. Future world changer. Currently a computer science student at the University of Liverpool and a journalist for Hacker Noon. Previously Higher Education Vice President of the East Kent Group.&quot;</p><p>Your elevator pitch needs to be persuasive, it should make the listener interested in you. It should detail some skills you know and what your future goals are.</p><p>Avoid rambling when giving an elevator pitch, don&#39;t frown or speak monotonal and don&#39;t restrict yourself to just one elevator pitch. You can have more than 1 depending on who you talk to.</p><p>It&#39;s best to make your elevator pitch more orientated to the company than to yourself. That&#39;s right customise it per company. By now, this phrase should be so ingrained in your mind you wake up in cold sweats at 4am screaming &quot;CUSTOMISE IT PER COMPANY&quot;.</p><p>As an example, from your research if you know a company is looking to implement artificial intelligence in their product you can approach the company at the careers fair and say &quot;Hey, my name&#39;s Brandon. I study artificial intelligence and I&#39;ve implemented different forms of AI in companies before. I know your company is looking to implement AI too, I would love to help you.&quot;</p><p>You need to find these problems that the company has, and you need to show them that you are the one that can solve this. If you can prove you are the right person for the job you will get further than someone who isn&#39;t proving themselves.</p><p>Imagine 2 people: James &amp; Eda.</p><p>James approaches the company and says:</p><p>&quot;Hi, my names James. I have a first-class degree in business management, I run a YouTube Channel with 250,000 subscribers and in my spare time I volunteer at Pilgrims hospice&quot;.</p><p>Eda approaches with:</p><p>&quot;Hey, I&#39;m Eda. I understand your company is having trouble getting younger people to sign on to your service. My dissertation was in marketing to young people and as a young person myself I know how to advertise to the new generations. Do you have any opportunities for someone like me to fix this problem at your company?&quot;</p><p>Eda would be the one who got hired, as she made it more about the company than about herself.</p><h3>What to wear</h3><p>Dress smart. Imagine it&#39;s like a job interview. Most of the other people at the careers fair will be dressed smartly.</p><h3>Best Questions to Ask at a Careers Fair</h3><p>The questions to ask can either be generic or tailored to the industry (which usually impresses recruiters but requires prior commercial awareness).</p><p>Some common generic questions to ask are:</p><h3>General Tips</h3><p>At the very end of every conversation always ask, &quot;can I contact you with further questions, do you have a business card?&quot; and if they don&#39;t write down their name, add their LinkedIn and add a customised message to the add so they know who you are.</p><h3>Conclusion</h3><p>☐ Know who will be at the careers fair</p><p>☐ Pick a small handful of companies you want to get into</p><p>☐ Become friends with the people running the stalls for these companies</p><p>☐ Ask lots of questions</p><p>☐ Follow up with the friends you&#39;ve made</p><p>Note: All links to Amazon in this section are Amazon Associate links. I will get a very small portion of what you pay if you use these links, at no extra cost to you.</p><h3>Cracking the Coding Interview</h3><p>Cracking the Coding Interview is a monstrous 900-page books on everything you could ever want to know about coding interviews. It&#39;s written by a recruiter for Amazon, Google, Microsoft, Apple. It features 200+ coding problems and walks you through the process for applying to the major tech companies.</p><h3>Why you? 101 interview questions you&#39;ll never fear again</h3><p>This book is written by Reed, who are a recruitment company. The 15 interview questions laid out in this book are answered more completely in this book by Reed.</p><h3>Crushing it!</h3><p>Good book on being a social media influence from social media influencer, Gary Vaynerchuk.</p><h3>How to Win friends and influence people</h3><p>If you interact with other humans, you need this book. If you have ever talked to someone or seen another human, this book is what you need. Everybody should read this book. No exceptions.</p><p><em>Originally published at </em><a href="https://skerritt.blog/employability-skills/"><em>https://skerritt.blog</em></a><em> on April 10, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d835f8076b2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Gentle Introduction to Divide and Conquer Algorithms]]></title>
            <link>https://medium.com/brandons-computer-science-notes/a-gentle-introduction-to-divide-and-conquer-algorithms-5398542d4067?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/5398542d4067</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Sun, 07 Apr 2019 10:11:34 GMT</pubDate>
            <atom:updated>2019-04-07T10:11:34.753Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*teOKqZu1yXM9_eYU.jpg" /></figure><p>Divide and conquer algorithms aren’t really taught in programming textbooks, but it’s something every programmer should know. Divide and conquer algorithms are the backbone of concurrency and multi-threading.</p><p>Often I’ll hear about how you can optimise a for loop to be faster or how switch statements are slightly faster than if statements. Most computers have more than one core, with the ability to support multiple threads. Before worrying about optimising for loops or if statements try to attack your problem at a different angle.</p><p>Divide and Conquer is one of the ways to attack a problem from a different angle. Throughout this article, I’m going to talk about creating divide and conquer solutions and what it is. Don’t worry if you have <strong>zero </strong>experience or knowledge on the topic. This article is designed to be read by someone with very little programming knowledge.</p><p>I’m going to explain this using 3 examples. The first will be a simple explanation. The second will be some code. The final will get into the mathematical core of divide and conquer techniques. (Don’t worry, I hate maths too).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb5d02f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fb5d02f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252Fb5d02f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/69b18ef75e89f36fffa0002a2c51ee64/href">https://medium.com/media/69b18ef75e89f36fffa0002a2c51ee64/href</a></iframe><h4>What is divide and conquer? 🌎</h4><p>Divide and conquer is where you divide a large problem up into many smaller, much easier to solve problems. The rather small example below illustrates this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*CObxyQnYrkla-91K.png" /></figure><p>We take the equation “3 + 6 + 2 + 4” and we cut it down into the smallest possible set of equations, which is [3 + 6, 2 + 4]. It could also be [2 + 3, 4 + 6]. The order doesn’t matter, as long as we turn this one long equation into many smaller equations.</p><p>Let’s say we have 8 numbers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*LQmPcR2y93AdKwPG.png" /></figure><p>And we want to add them all together. We first divide the problem into 8 equal sub-problems. We do this by breaking the addition up into individual numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/0*gU2rUvfOoFGjG2RE.png" /></figure><p>We then begin to add 2 numbers at a time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*MvcUnG1u85kVFDc8.png" /></figure><p>Then 4 numbers into 8 numbers which is our resultant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*iHpmXOCh22Ev5A5V.png" /></figure><p>Why do we break it down to individual numbers at stage 1? Why don’t we just start from stage 2? Because while this list of numbers is even if the list was odd you would need to break it down to individual numbers to better handle it.</p><p>A divide and conquer algorithm tries to break a problem down into as many little chunks as possible since it is easier to solve with little chunks. It typically does this with recursion.</p><p>Formally the technique is, as defined in the famous <a href="https://www.amazon.co.uk/Introduction-Algorithms-Thomas-H-Cormen/dp/0262033844/ref=as_li_ss_tl?keywords=Introduction+to+Algorithms&amp;qid=1551954553&amp;s=gateway&amp;sr=8-1&amp;linkCode=ll1&amp;tag=brandon0fe-21&amp;linkId=72a63dce0d8099988383cc3767340d40&amp;language=en_GB">Introduction to Algorithms</a> by Cormen, Leiserson, Rivest, and Stein, is:</p><ol><li>Divide</li></ol><p>If the problem is small, then solve it directly. Otherwise, divide the problem into smaller subsets of the same problem.</p><p>2. Conquer</p><p>Conquer the smaller problems by solving them recursively. If the subproblems are small enough, recursion is not needed and you can solve them directly.</p><p>Recursion is when a function calls itself. It’s a hard concept to understand if you’ve never heard of it before. This page provides a good explanation. In short, a recursive function is one like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74af0f09fa4bc05347b0907663b49c35/href">https://medium.com/media/74af0f09fa4bc05347b0907663b49c35/href</a></iframe><p>I’ll fully explain the code in a second.</p><p>3. Combine</p><p>Take the solutions to the sub-problems and merge them into a solution to the original problem.</p><p>With the code from above, some important things to note. The Divide part is also the recursion part. We divide the problem up at return n * recur_factorial(n-1).</p><p>Specifically, the recur_factorial(n-1) part is where we divide the problem up.</p><p>The conquer part is the recursion part too, but also the if statement. If the problem is small enough, we solve it directly (by returning n). Else, we perform return n * recur_factorial(n-1).</p><p>Combine. We do this with the multiplication symbol. Eventually, we return the factorial of the number. If we didn’t have the symbol there, and it was return recur_factorial(n-1) it wouldn&#39;t combine and it wouldn&#39;t output anything remotely similar to the factorial. (It&#39;ll output 1, for those interested).</p><p>We’re going to explore how divide and conquer works in some famous algorithms, Merge Sort and the solution to the Towers of Hanoi.</p><h4>Merge Sort 🤖</h4><p>Merge Sort is a sorting algorithm. The algorithm works as follows:</p><ul><li>Divide the sequence of n numbers into 2 halves</li><li>Recursively sort the two halves</li><li>Merge the two sorted halves into a single sorted sequence</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DUJ4UC8ZLqK4ZTOt.png" /></figure><p>In this image, we break down the 8 numbers into separate digits. Just like we did earlier. Once we’ve done this, we can begin the sorting process.</p><p>It compares 51 and 13. Since 13 is smaller, it puts it in the left-hand side. It does this for (10, 64), (34, 5), (32, 21).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vDJzg9fTsZoQUFAQ.png" /></figure><p>It then merges (13, 51) with (10, 64). It knows that 13 is the smallest in the first list, and 10 is the smallest in the right list. 10 is smaller than 13, therefore we don’t need to compare 13 to 64. We’re comparing &amp; merging two <strong>sorted </strong>lists.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bz6YwO24e6js6OJS.png" /></figure><p>In recursion we use the term <em>base case</em> to refer to the absolute smallest value we can deal with. With Merge Sort, the base case is 1. That means we split the list up until we get sub-lists of length 1. That’s also why we go down all the way to 1 and not 2. If the base case was 2, we would stop at the 2 numbers.</p><p>If the length of the list (n) is larger then 1, then we divide the list and each sub-list by 2 until we get sub-lists of size 1. If n = 1, the list is already sorted so we do nothing.</p><p>Merge Sort is an example of a divide and conquer algorithm. Let’s look at one more algorithm to really understand how divide and conquer works.</p><h4>Towers of Hanoi 🗼</h4><p>The Towers of Hanoi is a mathematical problem which consists of 3 pegs and in this instance, 3 discs. This problem is mostly used to teach recursion, but it does have some <a href="https://www.ibm.com/developerworks/community/blogs/jfp/entry/towers_of_hanoi_at_large1?lang=en">real world uses.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_x1B43X5WAJ-Hckn.png" /></figure><p>Each disc is a different size. We want to move all discs to peg C so that the largest is on the bottom, second largest on top of the largest, third largest (smallest) on top of all of them. There are some rules to this game:</p><ol><li>We can only move 1 disc at a time.</li><li>A disc cannot be placed on top of other discs that are smaller than it.</li></ol><p>We want to use the smallest number of moves possible. If we have 1 disc, we only need to move it once. If we have 2 discs, we need to move it 3 times.</p><p>The number of moves are powers of 2 minus 1. If we have 4 discs, we calculate the minimum number of moves as 2⁴ = 16–1 = 15.</p><p>To solve the above example we want to store the smallest disc in a buffer peg (1 move). See below for a gif on solving Tower of Hanoi with 3 pegs and 3 discs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tl_v1IGM9z3r2suc.gif" /></figure><p>Notice how we need to have a buffer to store the discs.</p><p>We can generalise this problem. If we have n discs: move n-1 from A to B recursively, move largest from A to C, move n-1 from B to C recursively.</p><p>If there is an even number of pieces the first move is always into the middle. If there are an odd number of pieces the first move is always to the other end.</p><p>Let’s begin to code the algorithm for ToH, in pseudocode.</p><pre>function MoveTower(disk, source, dest, spare):<br>	if disk == 0, then:<br>		move disk from source to dest</pre><p>We start with a base case, disk == 0. source is the peg you&#39;re starting at. dest is the final destination peg. spare is the spare peg.</p><pre>FUNCTION MoveTower(disk, source, dest, spare):<br>IF disk == 0, THEN:<br>    move disk from source to dest<br>ELSE:<br>    MoveTower(disk - 1, source, spare, dest)   // Step 1<br>    move disk from source to dest              // Step 2<br>    MoveTower(disk - 1, spare, dest, source)   // Step 3<br>END IF</pre><p>Notice that with step 1 we switch dest and source. We do not do this for step 3.</p><p>With recursion, we can be sure of 2 things:</p><ol><li>It always has a base case (if it doesn’t, how does the algorithm know to end?)</li><li>The function calls itself.</li></ol><p>The algorithm gets a little confusing with steps 1 and 3. They both call the same function. This is where multi-threading comes in. You can run steps 1 and 3 on different threads — at the same time.</p><p>Since 2 is more than 1, we move it down one more level again. So far you’ve seen what the divide and conquer technique is. You should understand how it works and what code looks like. Next, let’s learn how to formally define an algorithm to a problem using divide and conquer. This part is the most important in my opinion. Once you know this, it’ll be exponentially easier to create divide and conquer algorithms.</p><h4>Fibonacci Numbers 🐰</h4><p>The Fibonacci numbers can be found in nature. The way <a href="http://www.oxfordmathcenter.com/drupal7/node/487">rabbits produce </a>is in the style of the Fibonacci numbers. You have 2 rabbits that make 3, 3 rabits make 5, 5 rabits make 9 and so on.</p><p>The numbers start at 1 and the next number is the current number + the previous number. Here it’s 1 + 0 = 1. Then 1 + 1 = 2. 2 + 1 = 3 and so on.</p><p>We can describe this relation using a recursion. A recurrence is an equation which defines a function in terms of its smaller inputs. Recurrence and recursion sound similar and are similar.</p><p>With Fibonacci numbers if n = 0 or 1, it results in 1. Else, recursively add f(n-1) + f(n -2) until you reach the base case. Let’s start off by creating a non-recursive Fibonacci number calculator.</p><p>We know that if n = 0 or 1, return 1.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c73c74dc61e53f4eb3de60c0e78a9706/href">https://medium.com/media/c73c74dc61e53f4eb3de60c0e78a9706/href</a></iframe><p>The Fibonacci numbers are the last two numbers added together.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2243fd4e679e8395cc21b9e5aa3c9ccb/href">https://medium.com/media/2243fd4e679e8395cc21b9e5aa3c9ccb/href</a></iframe><p>Now we’ve seen this, let’s turn it into recursion using a recurrence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*at_stAMvUgbdzQ1rPZsaKw.png" /></figure><p>When creating a recurrence, we always start with the base case. The base case here is if n == 0 or 1, return n.</p><p>If we don’t return n, but instead return 1 this leads to a bug. For example, F(0) would result in 1. When really, it should result in 0.</p><p>Next, we have the formula. If n isn’t 0 or 1, what do we do? We calculate F(n — 1) + F(n — 2). In the end, we want to merge all the numbers together to get our final result. We do this using addition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*Xyk86oLoVhLLe3erCnP5Lw.png" /></figure><p>This is the formal definition of the Fibonacci numbers. Normally, recurrences are used to talk about the running time of a divide and conquer algorithm. My algorithms professor and I think it’s actually a good tool to create divide and conquer algorithms.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/550e27ab6643f38e5f534af3685d27b6/href">https://medium.com/media/550e27ab6643f38e5f534af3685d27b6/href</a></iframe><p>With knowledge of divide and conquer, the above code is cleaner and easier to read.</p><p>We often calculate the result of a recurrence using an execution tree. Computer overlords 🤖 don’t need to do this, but its useful for humans to see how your divide and conquer algorithm works. For F(4) this looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*HfAMMO11-M4KT-7l.png" /></figure><p>n is 4, and n is larger than 0 or 1. So we do f(n-1) + f(n-2). We ignore the addition for now. This results in 2 new nodes, 3 and 2. 3 is larger than 0 or 1 so we do the same. Same for 2. We do this until we get a bunch of nodes which are either 0 or 1. We then add all the nodes together. 1 + 1 + 0 + 0 + 1 = 3, which is the right answer.</p><h4>Conclusion 📕</h4><p>Once you’ve identified how to break a problem down into many smaller pieces, you can use concurrent programming to execute these pieces at the same time (on different <a href="https://www.wikiwand.com/en/Thread_(computing)">threads</a>) thereby speeding up the whole algorithm.</p><p>Divide and conquer algorithms are one of the fastest and perhaps easiest ways to increase the speed of an algorithm and are incredibly useful in everyday programming. Here are the most important topics we covered in this article:</p><ul><li>What is divide and conquer?</li><li>Recursion</li><li>MergeSort</li><li>Towers of Hanoi</li><li>Coding a divide and conquer algorithm</li><li>Recurrences</li><li>Fibonaccinumbers</li></ul><p>The next step is to explore multithreading. Choose your programming language of choice and Google, as an example, “Python multithreading”. Figure out how it works and see if you can attack any problems in your own code from this new angle.</p><p>You can also learn about how to solve recurrences (finding out the asymptotic running time of a recurrence), which is the next article I’m going to write. If you don’t want to miss it, or you liked this article do consider subscribing to my email list 😁✨</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb5d02f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fb5d02f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252Fb5d02f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/69b18ef75e89f36fffa0002a2c51ee64/href">https://medium.com/media/69b18ef75e89f36fffa0002a2c51ee64/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5398542d4067" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brandons-computer-science-notes/a-gentle-introduction-to-divide-and-conquer-algorithms-5398542d4067">A Gentle Introduction to Divide and Conquer Algorithms</a> was originally published in <a href="https://medium.com/brandons-computer-science-notes">Notes on Computer Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Public Key Cryptography Simply Explained]]></title>
            <link>https://medium.com/hackernoon/public-key-cryptography-simply-explained-e932e3093046?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/e932e3093046</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 11:31:00 GMT</pubDate>
            <atom:updated>2019-03-04T11:31:00.884Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sQEdHo9vxjnXWEjpaqNmvg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/te8hfiegpgo?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Liam Macleod</a> on <a href="https://unsplash.com/search/photos/city?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Public key cryptography seems magical to everyone, even those who understand it. In this post, I’m going to explain public key cryptography. Public Key Cryptography is based on asymmetric cryptography, so first let us talk about symmetric cryptography.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fec1a63%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fec1a63%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/c28f9fc84629b8f11d5c569ae4d99c81/href">https://medium.com/media/c28f9fc84629b8f11d5c569ae4d99c81/href</a></iframe><h3>Symmetric Cryptography</h3><p>Your front door is usually locked by a key. This key unlocks &amp; locks your front door. With symmetric cryptography, you have one key which you use to unlock and lock things.</p><p>Only people with the key or a copy of the key can unlock the door. Now, imagine you’re on holiday in Bali. You want to invite your friend around to look after your cat 😺 while you’re on the beautiful beaches 🏖️.</p><p>Before the holiday, you give your friend the key to your door. Your friend is then robbed, so someone else has your front door key now. Or your friend leaves it laying around and someone clones it. The problem with symmetric key cryptography is that this one key is easy to clone, it’s easy to attack your house in many different ways.</p><p>Let’s take this from an analogy to a real-life example of symmetric cryptography.</p><h3>Caeser’s Cipher</h3><p>Julius Caeser used a cipher to send messages that no one else could read other than the intended recipient. Mainly because no one could read back in 100 BC, and those that could wouldn’t understand a random string of letters. That’s the whole point of cryptography. To create ways to communicate without third parties listening in. This cipher is <em>Caeser’s Cipher</em>. Given an alphabet and a key (the key is an integer between 1 and 25), shift all of the alphabet letters by key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*PIIOrXblvDxuEi9-.png" /></figure><p>With a shift of 3, as seen in the image above, A becomes D, B becomes E and so on until it wraps around with X = A. The original message is called the <em>plaintext </em>and the encrypted message is called the <em>ciphertext</em>.</p><p>The easiest way to perform Caesar’s Cipher is to turn all of the letters into numbers, a = 1, b = 2, c = 3 and so on.</p><p>To encrypt, E, you calculate this for every letter (where s is the shift):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*2C8XGWFYrCIAw_RR7OB-hw.png" /></figure><p>This is called a <em>function. </em>You put an input into it, and an output comes out. A lot of functions are known as two-way functions. You can encrypt by using the function above, and it makes sense that to decrypt you just do the opposite. Given a function that doubles a number, if you have a doubled number and you want to reverse the function do the opposite of multiplying by 2, divide the number by 2.</p><p><em>mod </em>is the modulus operator. It’s the remainder of dividing. We do modulus because there isn’t a 27th letter in the alphabet, you just wrap around from “z” back to “a”. We’ll talk more about modular on in this article. Look at this small example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*WUaYwZfzt1FjLOa3FK90Mw.png" /></figure><p>Because 4 divided by 3 has a remainder of 1.</p><p>To decrypt Caesar’s cipher, D, you calculate this for every letter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*1p04owssRR8RwwO9CdZ7rA.png" /></figure><p>As you can tell, it’s not very secure. With 25 total shifts you just have to shift the text 25 times until you find the decrypted code, this is called a brute force attack. You take the encrypted text and shift it all 25 times until you find the decrypted text. But let’s imagine for a second that this was a hard cipher — that brute force isn’t feasible.</p><p>How do you tell your friend you’re using a shift of 9, for example? You have to communicate it to them somehow. Any and all forms of communication can be listened in on — whether that’s writing a letter or going to a hidden forest in Switzerland 30 miles from the nearest town and telling your friend.</p><p>The latter isn’t very feasible, but it is a lot more secure than telling your friend in Times Square, New York 🗽 what the shift is.</p><p>Now, imagine you brought your lunch to work in a special lunchbox — the same you’ve had since nursery school. Someone steals your food and your lunchbox. You don’t mind losing the food, but you do want the lunchbox back. You want a way for them to securely return your lunchbox without you knowing who took it — because that takes the pressure off of them.</p><p>You place a box in the staff room with a lock &amp; key. You give copies of keys to everyone in the office and hope for the best — that someone will return the lunchbox by placing it in the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/0*L967GhcV-NY6GWpM.png" /></figure><p>Unfortunately, the keys everyone has also unlocks the box as well as locks it. This means that someone could unlock the box and re-steal your lunchbox.</p><p>We need to find a way to get rid of this idea of sharing keys, get rid of the idea of ‘any key can lock and unlock’, and this is where asymmetric cryptography comes in.</p><h3>Asymmetric cryptography</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0vxWJd14iYJ98t80.jpg" /></figure><p>You install an extraordinary lock on this box, one that has two separate keys. The first key 🔑 can only turn clockwise, from <strong>A </strong>(locked) to <strong>B </strong>(unlocked) to <strong>C</strong> (locked).</p><p>The second key 🗝️ can only turn anti-clockwise, from <strong>C</strong> to <strong>B</strong> to <strong>A</strong>. You pick the first key and keep it to yourself. This is called a private key. The second key is called the public key. This key is given out to everyone in the office. You want everyone to have this key.</p><p>When someone returns your prized lunchbox, they can leave it in this box. All the public keys can do is lock the box. Your private key is the only one that can open it.</p><p>This is public key cryptography. Everyone knows that if they put something in the box and lock it, only you can open it with your private key.</p><p>With symmetric cryptography, everyone could open your box if they had the key. Now, no one apart from you can open the box.</p><p>Public key cryptography was first formulated by <a href="https://www.wikiwand.com/en/Diffie%E2%80%93Hellman_key_exchange">Whitfield-Diffie</a> or <a href="https://www.wikiwand.com/en/James_H._Ellis">James Ellis</a> (Ellis discovered first, but he didn’t publish it. Whitfield-Diffie published first). Both Ellis and Whitfield-Diffie enjoyed that public key cryptography could work in theory, but never managed to figure out how it would work in practice.</p><p>The production of a working Public Key Encryption system is attributed to <a href="https://www.wikiwand.com/en/RSA_(cryptosystem)">Rivest–Shamir–Adleman</a> (RSA) or <a href="https://www.wikiwand.com/en/Clifford_Cocks">Clifford Cocks</a>. Like above, Cocks discovered first, but he didn’t publish it. Rivest–Shamir–Adleman published first.</p><p>Let’s look at how this works mathematically.</p><h3>The maths behind public key cryptography</h3><p>While the box analogy was something physical, we’re going to go back to encrypting messages much like we did with Caeser Cipher.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*IuUfVi6osxGhN0VIIlK_RA.png" /></figure><p>When you apply the public key (K+) to the encrypted message, and then the private key (K-)to the encrypted message you get the plaintext message. We are also looking for these attributes:</p><p>It is computationally easy to:</p><ul><li>Generate a set of keys</li><li>Encrypt / Decrypt using these keys</li></ul><p>But it is also computationally infeasible to:</p><h3>Turning messages into numbers</h3><p>We want to turn a message into numbers. Previously we assigned a number to each letter, A = 1 and so on. The <em>American Standard Code for Information Interchange</em> (ASCII) is a table of all English letters and most symbols along with their associated ASCII code &amp; Binary output.</p><p>When you press a key on the keyboard, the keyboard converts this to Ascii as numbers are easier to work with than letters for a computer. If you want to learn more about ASCII, check out this <a href="https://www.youtube.com/watch?v=MijmeoH9LT4">video</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/0*OdQOex3Ht-iMnC9r.png" /></figure><p>Let’s encrypt the word “cats”. In binary, according to Ascii, this is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*hOKmJLYchdkpTbG2TuxT0g.png" /></figure><p>If you add them all together and convert to base 10, you get 4430123. For our example, we’re going to look at how Rivest–Shamir–Adleman (RSA), a public key cipher, calculates public &amp; private keys. We’re also going to use much smaller numbers, so the maths isn’t as hard to read.</p><p>Below is a calculator I created for turning ASCII into Binary. View it better on my website ( <a href="https://skerritt.blog/how-does-public-key-cryptography-work/">https://skerritt.blog/how-does-public-key-cryptography-work/</a> ).</p><p><a href="https://trinket.io/python/b72f370387">trinket: run code anywhere</a></p><h3>RSA</h3><ol><li>Choose 2 large prime numbers, p &amp; q.</li></ol><p>Prime numbers are numbers that only have 2 <a href="https://www.bbc.com/bitesize/topics/zfq7hyc">factors</a>, 1 and itself. We’re going to pick 5 &amp; 7, not large prime numbers but small for brevity.</p><p>2. Compute n = pq, z = (p-1)(q-1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*P-YOIAfDqQTNIrSmhM9kBg.png" /></figure><p>3. Choose e (with e &lt; z) such that e has no common factors with z.</p><p>e = 5</p><p>5 has no common factors with 24, and it is smaller than 24.</p><p>4. Choose d such that ed — 1 is exactly divisible by z.</p><p>The easiest way to do this would be to loop over all possible values of d in code. This code is written in <a href="https://skerritt.blog/learn-functional-python-in-10-minutes/">Functional Python</a>, but the language and paradigm doesn’t matter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87deb213e5de69816bfe6e430877b0bd/href">https://medium.com/media/87deb213e5de69816bfe6e430877b0bd/href</a></iframe><p>Since we’re using such small numbers, we have overlap. Both e and d are 5. Let’s set d to 29, just so we don’t have this overlap.</p><p>d = 29</p><p>5. The public key is (n, e). The private key is (n, d)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*4Ds-BOOLCPVt9WRnMovzmw.png" /></figure><p>Below is code to generate RSA keys. Note that we have overlap on d with p = 5 and q = 7, as discussed above.</p><p><a href="https://trinket.io/python/df05deacaf">trinket: run code anywhere</a></p><p>To send an encrypted message, Bob computes C = m^e mod n for message m and key e. To decrypt the message, Alice computes m = c^d mod n.</p><p>Encrypting “cats” gives us 42⁷⁵ mod 35 = 7.</p><p>Decrypting “cats” gives us 4430123.</p><p>Then to send a message m, Bob computes c=m^e (mod N) and sends it to Alice and Alice decrypts the message using her private key d with m=c^d (mod N)</p><h3>Why does it work?</h3><p>Prime factorisation. It’s easy to multiply two prime numbers together, but it’s incredibly hard to find out what prime numbers were used to make that number. You can easily multiply these two together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*QzroGYekr4b2W836pXlE6Q.png" /></figure><p>But if I gave you 992,474,117 and told you to find the prime numbers that were used to make this number, it’s not computationally feasible. Even more so when you realise the prime numbers used are very, very large.</p><p>This is known as a trap-door function or a one-way function. While it is easy to go through one way, it is computationally infeasible to go the other way. Boiling an egg is a one-way function because it is easy to boil an egg, but it is not possible to un-boil an egg. Let’s go deeper into the mathematics and explore modular arithmetic.</p><h3>Back to modular arithmetic</h3><p>Imagine a finite range of numbers, for example, 1 to 12. These numbers are arranged in a circle, much like a clock (modular arithmetic is sometimes called clock arithmetic because of this)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*PSgmS9Vbq5fOqCKS.png" /></figure><p>Count 13 around this clock. You get to 12 and then you need to count 1 more — so you go back to 1. Modular arithmetic is still defined as the remainder of division, however it can also be defined (and is more commonly defined) as a clock.</p><p>Functions using modular arithmetic tend to perform erratically, which in turn sometimes makes them one-way functions. Let’s see this with an example by taking a regular function and seeing how it works when it becomes a modular arithmetic function.</p><p>3^x</p><p>When we insert 2 into this function, we get ³² = 6. Insert 3 and we get ³³ = 9</p><p>This function is easy to reverse. If we’re given 9, we can tell that the function had an input of 3, because of ³³ = 9.</p><p>However, with modular arithmetic added, it doesn’t behave sensibly.</p><p>Image we had this formula:</p><p>3^x mod 7 = 1</p><p>How would you find out what x is? You can’t put the mod on the other side, because there isn’t really an inverse of modular arithmetic. What about guessing? Let’s input 5:</p><p>³⁵ mod 7 = 5</p><p>Okay, that was too big. You might want to go lower, maybe 4 or 3 but actually this is the wrong direction. When x is 6, it is equal to 1.</p><p>In normal arithmetic, we can test numbers and get a feel for whether we are getting warmer or colder, but this isn’t the case with modular arithmetic.</p><p>Often the easiest way to reverse modular arithmetic is to compile a table for all values of x until the right answer is found. Although this may work for smaller numbers, it is computationally infeasible to do for much larger numbers. This is often why modular arithmetic is known as a one-way function.</p><p>If I gave you a number such as 5787 and told you to find the function for it, it would be infeasible. In fact, if I gave you the ability to input any number into the function it would still be hard. It took me a mere few seconds to make this function, but it’ll take you hours or maybe even days to work out what x is.</p><p>RSA is a one-way function. While it is relatively easy to carry out this function, it is computationally infeasible to do the reverse of the function and find out what the keys are. Although, it is possible to reverse an RSA encryption if you know some numbers such as N.</p><h3>Let’s talk about N</h3><p>Recall earlier where I detailed how the RSA algorithm worked. There was one number, $n$. This n is special because under some circumstances n can make this one-way function reversible</p><p>N is a product of 2 prime numbers. As we saw earlier, if we take $5$ and $7$ and multiply them together, we get:</p><p>n = 35</p><p>In order for Bob to send Alice a message, he encrypts the message using Alice’s public key. Now that the message is encrypted, there has to be some way for Alice to decrypt it. There has to be some way for Alice to reverse this, but only for Alice to reverse it. You can’t have Eve or Niamh or Hannah reversing it — because that beats the point of encrypting it.</p><p>RSA is designed so the person who knows P and Q (the two prime numbers that are multiplied together to give N) can decrypt the message.</p><p>Although Alice has told the world her public key is n = 35, no one apart from Alice knows that P = 7, Q = 5. Note that the prime numbers are intentionally small for brevity.</p><p>You may be thinking “it’s easy to guess that 35’s prime factors are 5 and 7” and you would be right. But, with large enough numbers it is virtually impossible to find p and q.</p><p>In fact, with large enough numbers multiplying p and q are essentially one way functions. It is possible that in the future, perhaps the near future (with the invention of quantum computers) that factoring numbers becomes easy. Mathematicians have tried and failed for thousands of years to find an efficient way to factor numbers, so for now it is considered secure.</p><h3>Let’s look more into the maths</h3><p>Okay, let’s look at how modulus works in all of this. You understand why multiplication works, and how modulus works. But what about the other equations? What are they for?</p><p>Let’s demonstrate the deciphering algorithm using an identity due to Euler and Fermate:</p><blockquote><em>For any integer (M), M is relatively prime to n:</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*WOObVP5-x7F6UB3QGIaDLQ.png" /></figure><p>This is the Euler totient function giving the number of positive integers less than n which are relatively prime to n. Relatively prime is where 2 numbers only share the factor 1 with each other. In modern day we use <a href="https://www.wikiwand.com/en/Carmichael_function">Carmichael’s function</a> over Euler’s function, as Euler’s function can sometimes produce numbers too large to use. However, we’re using Euler’s totient function as it is what the original RSA paper used.</p><p>This sounds confusing, but let’s break it down. By elementary properties of the totient function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*RNP6NmkIgg3McisKdMz_XQ.png" /></figure><p>Since d is relatively prime to <strong>ϕ </strong>i (n), it has a multiplicative inverse e in the ring of integers modulo $<strong>ϕ</strong> (n). What this means is that the formula we used for RSA can be reversed (the trap door can be reversed) given some knowledge about the numbers used.</p><p>Without this special mathematical property it wouldn’t be possible to reverse the encryption and find out the ciphertext if you know some of the numbers used.</p><p>The <a href="https://www.wikiwand.com/en/Modular_multiplicative_inverse">modular multiplicative inverse</a> of the encryption algorithm c = m^e mod n is m = c^d mod n. All of this maths has built up to this. Modular arithmetic and one-way functions are heavily involved here. In order to encrypt, you calculate c. In order to decrypt, you calculate m. Both of these require knowledge of n, which is the special number we talked about earlier.</p><p>If you want to learn more about the maths of RSA, I highly reccomend the readable, <a href="https://people.csail.mit.edu/rivest/Rsapaper.pdf">origianl RSA paper</a>.</p><h3>Authentication</h3><p>How do you prove that a message sent by Bob was actually sent by Bob, and not sent by Eve? You need a way to authenticate them. In the real world, we authenticate using signatures. Although these can be forged, you can authenticate using a biometric scanner, but your fingerprints can be lifted and copied.</p><p>You can use a passcode, but again much like how Caeser cipher and its single key is useless, authentication methods that use single keys aren’t as perfect.</p><p>You can use a passcode, but again much like how Caeser’s cipher and its single key is useless, authentication methods that use single keys aren’t as perfect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*8U8mFD7hhMZn1ox4sd4LSQ.png" /></figure><p>Let’s say Bob wants to prove to Alice that Bob wrote the message he sent her. Bob sends his original message with an encrypted version of the message with his private key (K-). Alice uses Bob’s public key (K+)which, using the formula above, turns the encrypted message back into the normal message. Then Alice checks the message Bob sent with the message she got from the encrypted message. If they match, she can be sure that someone with Bob’s private key (probably Bob) sent it.</p><p>This method sucks for encrypting because if Bob encrypts his message with his private key, anyone can read it with his private key. Also, it’s computationally expensive to prove that Bob sent something. This is why we create a digest of the message and encrypt that instead to verify Bob. This digest of a message is done using a <em>hash function.</em></p><p>To learn more about hash functions, I wrote a sister article which explains them <a href="https://skerritt.blog/hash-functions/">here</a>.</p><h3>Back to cryptography</h3><p>By encrypting the hash of the message we speed up the process of encrypting it, which makes authentication a lot faster. Now, let’s play a prank on Bob.</p><p>We create an e-mail order to a pizza shop asking for 4 pepperoni pizzas. We sign this email with our private key. We send the pizza store our public key, but we tell them that Bob’s phone is dead and that our public key is actually Bob’s public key.</p><p>The pizza store verifies the signature and sends 4 pepperoni pizzas 🍕 to Bob. The worst part is, Bob doesn’t even like pepperoni. This is where a <em>certification authority </em>comes into play.</p><p>Certificate authorities (CA) bind a public key to a specific entity. This entity provides proof of identity to the CA, the CA then creates a certificate binding the entity to its public key. The idea is to take the trust out of trusting an individual for public keys. You still have to trust an organisation, but many people find trusting an organisation is better than trusting an individual.</p><p>The certificate containing the entities public key is digitally signed by the CA. This signing is the CA saying “this is the entities public key”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IyRwRnk7nKCA8fse.png" /></figure><p>When Alice want’s Bob’s public key, she gets Bob’s certificate. She then applies the CA’s public key to Bob’s certificate to get Bob’s public key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*d5Wu8E3olF_OpejF.png" /></figure><p>Cloudflare has an amazing article on certificate authorities <a href="https://blog.cloudflare.com/how-to-build-your-own-public-key-infrastructure/">here</a>.</p><h3>Secure Email with Pretty Good Privacy</h3><p><a href="https://www.wikiwand.com/en/Phil_Zimmerman">Phil Zimmerman</a> invented <a href="https://www.wikiwand.com/en/Pretty_Good_Privacy">Pretty Good Privacy</a> (PGP), the de facto standard for email encryption. Zimmerman used RSA in PGP. RSA is patented and he did not have permission from RSA inc (the company that holds the patent) to publish another cipher using RSA.</p><p>Zimmerman was also a target of a 3-year U.S federal investigation because at the time cryptography programs were considered munitions under U.S law. When asked whether all of the trouble was worth it to publish PGP, he <a href="https://philzimmermann.com/EN/essays/index.html">said </a>he had “no regrets”. Let’s look at how this used to be illegal algorithm works.</p><p>When Alice wants to send a confidential email to Bob, she:</p><ol><li>Generates random symmetric private key, K-.</li><li>Encrypts her email with K-(for efficiency)</li><li>Also encrypts K-with Bob’s public key.</li><li>Alice digitally signs the encrypted message.</li><li>Alice sends Bob both</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*doDEYrRO9h1W1CRxseUFtw.png" /></figure><p>and her digital signature.</p><p>In total, Alice uses three keys. Her private key, Bob’s public key, and the newly created symmetric key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DUNCAbU62a5Esr8H.png" /></figure><p>This idea of encrypting a symmetric key with a public key is called a <a href="https://www.wikiwand.com/en/Hybrid_cryptosystem">Hybrid Cryptosystem</a>. Some email messages can be incredibly large, encrypting these with a public key system would take a very long time.</p><p>Use a symmetric key system such as <a href="https://www.wikiwand.com/en/Advanced_Encryption_Standard">AES</a>, which is incredibly hard to break (but not as hard as RSA). Encrypt the AES key (and only the key, not the whole email) with the public key. This way, the receiver can apply their private key and find out the AES symmetric key to decrypt the email.</p><p>Not many people use PGP, because of how difficult it is to set up. At most, you need to download a program you trust to correctly implement PGP. In 2018 it was <a href="https://www.wired.co.uk/article/efail-pgp-vulnerability-outlook-thunderbird-smime">shown</a> that email clients such as Apple Mail, Thunderbird, and Outlook — who have settings to enable PGP can be forced to show the non-encrypted versions.</p><p>Not to mention how suspicious it looks for one person to send encrypted emails on a network of non-encrypted emails. The only email client (and address provider) which enables PGP by default is ProtonMail, but even then it’s only for Proton-to-Proton emails and you have to trust the company to implement it correctly.</p><h3>ProtonMail on Twitter</h3><p>@camfassett Most of them do a good job, but we understand your point. We built ProtonMail to make PGP encryption accessible to non-technical people. We will make sure this goal is reached 100%. ;) Thanks again!</p><h4>Conclusion</h4><p>Cryptography has been used for thousands of years, almost as long as mankind has held secrets. In our constant effort to keep our secrets secret to everyone apart from a select few we’ve found this magical algorithm that works pretty well. No doubt, in 300 or 400 years it will have been broken much like how Caeser thought his cipher would never be broken.</p><p>Hey 👋 Want to subscribe to my blog and stay up to date with posts similar to this one? Subscribe to my email list below. I won’t spam you. I will only send you posts similar to this one 😊✨</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fec1a63%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fec1a63%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/c28f9fc84629b8f11d5c569ae4d99c81/href">https://medium.com/media/c28f9fc84629b8f11d5c569ae4d99c81/href</a></iframe><p>If you’re feeling extra generous, I have a <a href="https://www.paypal.me/BrandonSkerritt">PayPal </a>and even a <a href="https://www.patreon.com/user?u=15993188">Patreon</a>. I’m a university student who writes these articles in my spare time. This blog is my full time job, so any and all donations are appreciated</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e932e3093046" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/public-key-cryptography-simply-explained-e932e3093046">Public Key Cryptography Simply Explained</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How does Tor actually work?]]></title>
            <link>https://medium.com/hackernoon/how-does-tor-really-work-5909b9bd232c?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/5909b9bd232c</guid>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Fri, 01 Mar 2019 22:40:00 GMT</pubDate>
            <atom:updated>2019-03-27T12:46:39.487Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*HKb_01cxi-GSUqQ_CbnhbA.png" /></figure><p>The United States Naval Research Laboratory developed The Onion Routing Protocol (T0r) to project U.S. intelligence communications online. Ironically, Tor has seen widespread use by everyone — even those organisations which the U.S. Navy fights against.</p><p>You may know Tor as the hometown of online illegal activities, a place where you can buy any drug you want, a place for all things illegal. Tor is much larger than what the media makes it out to be. According to <a href="https://www.tandfonline.com/doi/full/10.1080/00396338.2016.1142085">Kings College</a> much of Tor is legal.</p><p>This article doesn’t talk about what’s on Tor, or how to access Tor. This article gives a technical rundown of how the technology works, without speculation and without exaggeration of what Tor is.</p><p>The core principle of Tor is <em>onion routing</em> which is a technique for anonymous &amp; secure communication over a public network. In onion routing messages are encapsulated in several layers of encryption.</p><p>Onions have multiple layers to them, and so does a message going through Tor. Each layer in Tor is encryption, you are adding layers of encryption to a Tor message, as opposed to just adding 1 layer of encryption.</p><p>This is why it’s called The Onion Routing Protocol, because it adds layers at each stage.</p><p>The resulting onion (fully encapsulated message) is then transmitted through a series of computers in a network (called onion routers) with each computer peeling away a layer of the ‘onion’. Each layer contains the next destination — the next router the packet has to go to. When the final layer is decrypted you get the plaintext (non-encrypted message).</p><p>The original author remains anonymous because each node in the network is only aware of the preceding and following nodes in the path (except the first node that does know who the sender is, but doesn’t know the final destination).</p><p>This has led to attacks where large organisations with expansive resources run servers to attempt to be the first and last nodes in the network. If the organisation’s server is the first node, it knows who sent the message. If the organisation server is the last node, it knows the final destination and what the message says.</p><p>Now we have a basic overview of Tor, let’s start exploring how each part of Tor works.</p><h3>Overview</h3><blockquote>Onion Routing is a distributed overlay network designed to anonymise TCP-based applications like web browsing, secure shell and instant messaging.</blockquote><p>Clients <em>choose</em> a path through the network and build a <em>circuit</em> where each onion router in the path knows the predecessor and the successor, but no other nodes in the circuit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tlCJ2M3sTY-0oKSj.png" /></figure><p>The original author (the question mark on the far left) remains anonymous, unless you’re the first path in the node as you know who sent you the packet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*-H7JeKiPLCKGTvhf.png" /></figure><p>No one knows what data is being sent until it reaches the last node in the path; who knows the data but doesn’t know who sent it. The second to last node in the path doesn’t know what the data is, only the last node in the path does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uXkNMVe7ODepeEuS.png" /></figure><p>This has led to attacks whereby large organisations with expansive resources create Tor servers which aim to be the first and last onion routers in a path. If the organisation can do this, they get to know who sent the data and what data was sent, effectively breaking Tor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ezehs-JdxJ8HRRV5.png" /><figcaption>Oh no! Now large organisation knows you watch Netflix 🍿</figcaption></figure><p>It’s incredibly hard to do this without being physically close to the location of the organisations servers, we’ll explore this more later.</p><p>Throughout this article I’ll be using Netflix as a normal service (Bob) and Amazon Prime Video as the adversary (Eve). In the real world, this is incredibly unlikely to be the case. I’m not here to speculate on what organisations might want to attack Tor, so I’ve used 2 unlikely examples to avoid the political side of it.</p><p>Each packet flows down the network in <em>fixed-size cells</em>. These cells have to be the same size so none of the data going through the Tor network looks suspiciously big.</p><p>These cells are unwrapped by a symmetric key at each router and then the cell is relayed further down the path. Let’s go into Tor itself.</p><h3>Tor itself</h3><blockquote><em>There is strength in numbers</em></blockquote><p>Tor needs a lot of users to create anonymity, if Tor was hard to use new users wouldn’t adopt it so quickly. Because new users won’t adopt it, Tor becomes less anonymous. By this reasoning it is easy to see that usability isn’t just a design choice of Tor but a <em>security requirement</em> to make Tor more secure.</p><p>If Tor isn’t usable or designed nicely, it won’t be used by many people. If it’s not used by many people, it’s less anonymous.</p><p>Tor has had to make some design choices that may not improve security but improve usability with the hopes that an improvement in usability is an improvement in security.</p><h3>What Tor Isn’t</h3><p>Tor is not a completely decentralised peer-to-peer system like many people believe it to be. If it was completely peer to peer it wouldn’t be very usable. Tor requires a set of directory servers that manage and keep the state of the network at any given time.</p><p>Tor is not secure against end to end attacks. An end to end attack is where an entity has control of both the first and last node in a path, as talked about earlier. This is a problem that cyber security experts have yet to solve, so Tor does not have a solution to this problem.</p><p>Tor does not hide the identity of the sender.</p><p>In 2013 during the Final Exams period at Harvard a student tried to delay the exam by sending in a fake bomb threat. The student used Tor and Guerrilla Mail (a service which allows people to make disposable email addresses) to send the bomb threat to school officials.</p><p>The student was caught, even though he took precautions to make sure he wasn’t caught.</p><p>Gurillar mail sends an originating IP address header along with the email that’s sent so the receiver knows where the original email came from. With Tor, the student expected the IP address to be scrambled but the authorities knew it came from a Tor exit node (Tor keeps a list of all nodes in the directory service) so the authorities simply looked for people who were accessing Tor (within the university) at the time the email was sent.</p><p>Tor isn’t an anonymising service, but it is a service that can encrypt all traffic from A to B (so long as an end-end attack isn’t performed). Tor is also incredibly slow, so using it for Netflix isn’t a good use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f0ZHCDa5hYDs0QQj.png" /></figure><p>Now that we have a good handle on what Tor is, let’s explore <em>onion routing</em>.</p><h3>Onion Routing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GogMIiGnoKhRRouP.png" /></figure><p>Given the network above, we are going to simulate what Tor does. Your computer is the one on the far left, and you’re sending a request to watch <em>Stranger Things </em>on Netflix (because what else is Tor used for 😉). This path of nodes is called a <em>circuit. </em>Later on, we’re going to look into how circuits are made and how the encryption works. But for now we’re trying to generalise how Tor works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aZIB8j6LoEddgU7C.png" /></figure><p>We start off with the message (we haven’t sent it yet). We need to encrypt the message N times (where N is how many nodes are in the path). We encrypt it using AES, a symmetric key crypto-system. The key is agreed using Diffie-Hellman. Don’t worry, we’ll discuss all of this later. There is 4 nodes in the path (minus your computer and Netflix) so we encrypt the message 4 times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pKloSE851LTWhEI0.png" /></figure><p>Our packet (onion) has 4 layers. Blue, purple, orange, and teal. Each colour represents one layer of encryption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8uZRgXW2xeQKGETi.png" /></figure><p>We send the onion to the first node in our path. That node then removes the first layer of encryption.</p><p>Each node in the path knows what the key to decrypt their layer is (via <a href="https://skerritt.blog/diffie-hellman-merkle/">Diffie-Hellman</a>). Node 1 removes the blue layer with their symmetric key (that you both agreed on).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4JFKLDWli1_uqrma.png" /></figure><p>Node 1 knows you sent the message, but the message is still encrypted by 3 layers of encryption, it has no idea what the message is.</p><p>As it travels down the path, more and more layers are stripped away. The next node does not know who sent the packet. All it knows is that Node 1 sent them the packet, and it’s to be delivered to Node 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6qjaVbgGr7Sxbqho.png" /></figure><p>Now Node 3 strips away a layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BeWOysSPagdejb-S.png" /></figure><p>The final node knows what the message is and where it’s going, but it doesn’t know who sent it. All it knows is that Node 3 sent them the message, but it doesn’t know about anyone else in the path. One of the key properties here is that once a node decrypts a layer, it cannot tell how many more layers there are to decrypt. It could be as small as 1 or 2 or as large as 200 layers of encryption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WBSrOXoN58PHDEXF.png" /></figure><p>Now there’s no way Amazon can find out you watch Netflix! Netflix sends back a part of Stranger Things.</p><p>Let’s see how it works in reverse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d2Sh8SIMrybIbun9.png" /></figure><p>Node 4 adds its layer of encryption now. It doesn’t know who originally made the request, all it knows is that Node 3 sent the request to them so it sends the response message back to Node 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3AspKP_sG0dhI3EF.png" /></figure><p>And so on for the next few nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2n8h98txsDc4PQZ5.png" /></figure><p>Now the response packet is fully encrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4O76xZTm4W8x9i6G.png" /></figure><p>Now the packet is fully encrypted, the only one who still knows what the message contains is Node 4. The only one who knows who made the message is Node 1. Now that we have the fully encrypted response back, we can use all the symmetric keys to decrypt it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pGj9cONIbliUe0nY.png" /></figure><p>You might be thinking “I’ve seen snails 🐌 faster than this” and you would be right. This protocol isn’t designed for speed, but at the same time it has to care about speed.</p><p>The algorithm could be much slower, but much more secure (using entirely public key cryptography instead of symmetric key cryptography) but the usability of the system matters. So yes, it’s slow. No it’s not as slow as it could be. But it’s all a balancing act here.</p><p>The encryption used is normally <a href="https://www.wikiwand.com/en/Advanced_Encryption_Standard">AES</a> with the key being shared via Diffie-Hellman. I’ve written another article about Diffie-Hellman <a href="https://skerritt.blog/diffie-hellman-merkle/">here</a>.</p><p>The paths Tor creates are called circuits. Let’s explore how Tor chooses what nodes to use in a circuit.</p><h3>How is a circuit created?</h3><p>Each machine, when it wants to create a circuit, chooses the <strong>exit node first</strong>, followed by the other nodes in the circuit. Tor circuits are always 3 nodes. Increasing the length of the circuit does not create better anonymity. If an attacker owns the first and last nodes in the network, you can have 1500 nodes in the circuit and it still wouldn’t make you more secure.</p><p>When Tor selects the exit node, it selects it following these principles:</p><ol><li>Does the client’s torrc (the configuration file of Tor) have settings about which exit nodes not to choose?</li><li>Tor only chooses an exit relay which allows you to exit the Tor network. Some exit nodes only allow web traffic (HTTP/S port 80) which is not useful when someone wants to send email (SMTP port 25).</li><li>The exit node has to have the available capacity to support you. Tor tries to choose an exit node which has enough resources available.</li></ol><p>All paths in the circuit obey these rules:</p><ul><li>We do not choose the same router twice for the same path.</li></ul><p>If you choose the same node twice, it’s guaranteed that the node will either be the guard node (the node you enter at) or the exit node, both dangerous positions. There is a 2/3 chance of it being both the guard and exit nodes, which is even more dangerous. We want to avoid the entry / exit attacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uxqTXYvzFM_Pdata.png" /><figcaption>This isn’t okay. Node colour changes to show it’s the same.</figcaption></figure><ul><li>We do not choose any router in the same family as another in the same path. (Two routers are in the same family if each one lists the other in the “family” entries of its descriptor.)</li></ul><p>Operators who run more than 1 Tor node can choose to signify their nodes as ‘family’. This means that the nodes have all the same parent (the operator of their network). This is again a countermeasure against the entry / exit attacks, although operators do not have to declare family if they wish. If they want to become a guard node (discussed soon) it is recommended to declare family, although not required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n_Cb2ZgIf1phcDaq.png" /><figcaption>Not allowed</figcaption></figure><ul><li>We do not choose more than one router in a given /16 subnet.</li></ul><p>Subnets define networks. IP addresses are made up of 8 octets of bits. As an example, Google’s IP address in binary is:</p><pre>01000000.11101001.10101001.01101010</pre><p>The first 16 bits (the /16 subnet) is 01000000.11101001 which means that Tor does not choose any nodes which start with the same 16 bits as this IP address. Again, a counter-measure to the entry / exit attacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R34U_WHFADLjLH0F.png" /><figcaption>Not allowed</figcaption></figure><p>If subnets sound confusing, I’ve written this Python code to help explain them:</p><pre># have a play around with these<br># ip addresses are in binary, not the usual base 10<br># subnets are usually powers of 2, this is 2^4.<br>IP = &quot;01000000.11101001.10101001.01101010&quot;<br>subnet = 16</pre><pre># this will store the subnet address once we find it<br>subnet_ip = []</pre><pre>IP_list = list(IP)<br>counter = 0</pre><pre># for every number in the ip address<br>for i in IP_list:<br>  # we want to end the loop when we reach the subnet number<br>  if counter &gt;= subnet:<br>    break<br>  # the ip address segments each oclet of bits with full stops<br>  # we don&#39;t want to count a fullstop as a number <br>  # but we want to include it in the final subnet<br>  if i == &quot;.&quot;:<br>    subnet_ip.append(&quot;.&quot;)<br>    continue<br>  else:<br>    # else it is a number so we append and increment counter<br>    subnet_ip.append(i)<br>    counter = counter + 1<br>    <br>print(&quot;Subnet is &quot; + &#39;&#39;.join(subnet_ip))</pre><ul><li>We don’t choose any non-running or non-valid router unless we have been configured to do so. By default, we are configured to allow non-valid routers in “middle” and “rendezvous” positions.</li></ul><p>Non-running means the node currently isn’t online. You don’t want to pick things that aren’t online. Non-valid means that some configuration in the nodes torrc is wrong. You don&#39;t want to accept strange configurations in case they are trying to hack or break something.</p><ul><li>The first node must be a <strong><em>Guard node</em></strong>.</li></ul><p>A <strong><em>guard node</em></strong> is a privileged node because it sees the real IP of the user. It’s ‘expensive’ to become a guard node (maintain a high uptime for weeks and have good bandwidth).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OnBq4SGotzA0tENg.png" /></figure><p>This is possible for large companies who have 99.9% uptime and high bandwidth (such as Netflix). Tor has no way to stop a powerful adversary from registering a load of guard nodes. Right now, Tor is configured to stick with a single guard node for 12 weeks at a time, so you choose 4 new guard nodes a year.</p><p>This means that if you use Tor once to watch Amazon Prime Video, it is relatively unlikely for Netflix to be your guard node. Of course, the more guard nodes Netflix creates the more likely it is. Although, if Netflix knows you are connecting to the Tor network to watch Amazon Prime Video then they will have to wait 4 weeks for their suspicions to be confirmed, unless they attack the guard node and take it over.</p><p>Becoming a guard node is relatively easy for a large organisation. Becoming the exit node is slightly harder, but still possible. We have to assume that the large organisation has infinite computational power to be able to do this. The solution is to make the attack highly expensive with a low rate of success.</p><p>The more regular users of Tor, the harder is if for a large organisation to attack it. If Netflix controls 50/100 nodes in the network:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*O4La2xWz-XqdohPP.png" /></figure><p>The chance of you choosing a guard node from Netflix is 50%.</p><p>If suddenly 50 more normal user nodes join then that’s 50/150, reducing the probability of Netflix owning a guard node (and thus, a potential attack) and making it even more expensive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*Bgu1HbsGsINRJaQm.png" /></figure><p>There is strength in numbers within the Tor service.</p><h3>Tor Hidden Services</h3><p>Ever heard those rumours “there are websites on the dark-web, on Tor that when you visit them you’ll see people doing nasty things, selling illegal things or worse: watching The Hangover Part 3”</p><p>When people talk about these websites they are talking about <strong><em>Tor Hidden Services</em></strong>.</p><p>These are a wild concept and honestly deserve an entire blogpost on their own. Hidden services are servers, like any normal computer server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*jeZnMi3a_NHRZJTU.png" /></figure><p>Except in a Tor Hidden Service it is possible to communicate without the user and server knowing who each other are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/0*gR1-jmXjGTUbV9Mf.png" /></figure><p>The device (the question mark) knows that it wants to access Netflix, but it doesn’t know anything about the server and the server doesn’t know anything about the device that’s asked to access it. This is quite confusing, but don’t worry, I’m going to explain it all with cool diagrams. ✨</p><p>When a server is set up on Tor to act as a hidden service, the server sends a message to some selected Onion Routers asking if they want to be an introduction point to the server. It is entirely up to the server as to who gets chosen as an introduction point, although usually they ask 3 routers to be their introduction points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DCi41nUH380EOXhn.png" /></figure><p>The introduction points know that they are going to be introducing people to the server.</p><p>The server will then create something called a hidden service descriptor which has a public key and the IP address of each introduction point. It will then send this hidden service descriptor to a <a href="https://www.wikiwand.com/en/Distributed_hash_table">distributed hash table</a> which means that every onion router (not just the introduction points) will hold some part of the information of the hidden service.</p><p>If you try to look up a hidden service the introduction point responsible for it will give you the full hidden service descriptor, the address of the hidden service’s introduction points.</p><p>The key for this hash table is the onion address and the onion address is derived from the public key of the server.</p><p>The idea is that the onion address isn’t publicised over the whole Tor network but instead you find it another way like from a friend telling you or on the internet (addresses ending in .onion).</p><p>The way that the distributed hash table is programmed means that the vast majority of the nodes won’t know what the descriptor is for a given key.</p><p>So almost every single onion router will have minimal knowledge about the hidden service unless they explicitly want to find it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jCNjHQVUGgB2MKHU.png" /></figure><p>Let’s say someone gave you the onion address. You request the descriptor off the hash table and you get back the services introduction points.</p><p>If you want to access an onion address you would first request the descriptor from the hash table and the descriptor has, let’s say 4 or 5 IP addresses of introductory nodes. You pick one at random let’s say the top one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kYjZVFATLmTal7Px.png" /></figure><p>You’re going to ask the introduction point to introduce you to the server and instead of making a connection directly to the server you make a rendezvous point at random in the network from a given set of Onion Routers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vLfliAtvJuzL0E68.png" /></figure><p>You then make a circuit to that rendezvous point and you send a message to the rendezvous point asking if it can introduce you to the server using the introduction point you just used. You then send the rendezvous point a one time password (in this example, let’s use ‘Labrador’).</p><p>The rendezvous point makes a circuit to the introduction point and sends it the word ‘Labrador’ and its IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*92hWDR3k14lboDoq.png" /></figure><p>The introduction point sends the message to the server and the server can choose to accept it or do nothing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_lA3aSMiv4PCmojd.png" /></figure><p>If the server accepts the message it will then create a circuit to the rendezvous point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oJm03n-Yn4uASvfJ.png" /></figure><p>The server sends the rendezvous point a message. The rendezvous point looks at both messages from your computer and the server. It says “well, I’ve received a message from this computer saying it wants to connect with this service and I’ve also received a message from the service asking if it can connect to a computer, therefore they must want to talk to each other”.</p><p>The rendezvous point will then act as another hop on the circuit and connect them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0PmYsqZ6SrTQSBtW.png" /></figure><p>In short, a hidden service works like this, taken from <a href="https://tor.stackexchange.com/questions/672/how-do-onion-addresses-exactly-work">here</a>:</p><ol><li>A hidden service calculates its key pair (private and public key, asymmetric encryption).</li><li>Then the hidden service picks some relays as its <em>introduction points</em>.</li><li>It tells its public key to those <em>introduction points</em> over Tor circuits.</li><li>After that the hidden-service creates a <em>hidden service descriptor</em>, containing its public key and what its <em>introduction points</em> are.</li><li>The hidden service signs the <em>hidden service descriptor</em> with its private key.</li><li>It then uploads the <em>hidden service descriptor</em> to a <em>distributed hash table</em> (DHT).</li><li>Clients learn the .onion address from a hidden service out-of-band. (e.g. public website) (A $hash.onion is a 16 character name derived from the service’s public key.)</li><li>After retrieving the .onion address the client connects to the DHT and asks for that $hash.</li><li>If it exists the client learns about the hidden service’s public key and its <em>introduction points</em>.</li><li>The client picks a relay at random to build a circuit to it, to tell it a <em>one-time secret</em>. The picked relay acts as <em>rendezvous point</em>.</li><li>The client creates a <em>introduce message</em>, containing the address of the <em>rendezvous point</em> and the <em>one-time secret</em>, before encrypting the message with the hidden service’s public key.</li><li>The client sends its message over a Tor circuit to one of the <em>introduction points</em>, demanding it to be forwarded to the hidden service.</li><li>The hidden service decrypts the <em>introduce message</em> with its private key to learn about the <em>rendezvous point</em> and the <em>one-time secret</em>.</li><li>The hidden service creates a <em>rendezvous message</em>, containing the <em>one-time secret</em> and sends it over a circuit to the <em>rendezvous point</em>.</li><li>The <em>rendezvous point</em> tells the client that a connection was established.</li><li>Client and hidden service talk to each other over this <em>rendezvous point</em>. All traffic is end-to-end encrypted and the <em>rendezvous point</em> just relays it back and forth. Note that each of them, client and hidden service, build a circuit to the <em>rendezvous point</em>; at three hops per circuit this makes six hops in total.</li></ol><p>Tor is a fascinating protocol full of algorithms that have been refined over the years. I’ve come to appreciate Tor, and I hope you have to. Unfortunately, this article is far too long to summarise shortly. If you want to learn more, check out the paper on Tor titled “<a href="https://svn.torproject.org/svn/projects/design-paper/tor-design.pdf">Tor: The Second-Generation Onion Router</a>”.</p><p>If you liked this article and want more like it, sign up to my email list below ✨ I’ll only send you an email when I have something new, which is every month / 2 months or so.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff5c994%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Ff5c994%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/65f72cd88801451a00f5724000ab467b/href">https://medium.com/media/65f72cd88801451a00f5724000ab467b/href</a></iframe><p>If you’re feeling extra generous, I have a <a href="https://www.paypal.me/BrandonSkerritt">PayPal </a>and even a <a href="https://www.patreon.com/user?u=15993188">Patreon</a>. I’m a university student who writes these articles in my spare time. This blog is my full time job, so any and all donations are appreciated</p><p><em>Originally published at </em><a href="https://skerritt.blog/how-does-tor-really-work/"><em>skerritt.blog</em></a><em> on March 1, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5909b9bd232c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-does-tor-really-work-5909b9bd232c">How does Tor actually work?</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Algorithm for Finding Anagrams]]></title>
            <link>https://medium.com/hackernoon/an-algorithm-for-finding-anagrams-2fe7655de85b?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fe7655de85b</guid>
            <category><![CDATA[anagram-algorithm]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[computer-scienc]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Wed, 02 Jan 2019 12:56:00 GMT</pubDate>
            <atom:updated>2019-01-26T14:19:40.816Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U8AZbgD9wqF1IgVbOWlocg.png" /></figure><p>Finding anagrams of words does not look like a difficult problem but has an interesting solution.</p><p>This article has been updated. Find the updated version here:</p><p><a href="https://skerritt.blog/an-algorithm-for-finding-anagrams/">An Algorithm for Finding Anagrams</a></p><p>An anagram is a word or sentence that can be transformed into another word or sentence. Elvis has all the same letters as Lives, so Elvis is an anagram of Lives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FaL2zhdZfrJaNVrYgJ73Kw.png" /></figure><p>The way most people would immediately solve this problem would be to take a word, go through every word in the dictionary and see if the combinations of letters match exactly.</p><p>The way to do this will use a <em>multiset</em>. <em>Sets </em>are like arrays where the order doesn’t matter and repetitions aren’t allowed. With an array, [a, b] is not the same as [b, a]. But with a set, (a, b) is the same as (b, a).</p><p>Set’s don’t allow repetitions. So (a, a, a, a, a, b) is the same as (b, a) — because the first set would be turned into (a, b).</p><p>A <em>multiset </em>is a set which allows repetitions but the order doesn’t matter. For this example, let’s start small.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f50a47b44224e6e11f9fd9cef2d6a0a8/href">https://medium.com/media/f50a47b44224e6e11f9fd9cef2d6a0a8/href</a></iframe><p>With our example, we have a list called a dictionary where each item in that dictionary is a word. We want to find out which of these words are anagrams of “Elvis”, so what we do is for loop through the dictionary like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a383d46e193c701987083d25b79a33b/href">https://medium.com/media/0a383d46e193c701987083d25b79a33b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*xMJODfbkdrWKBAbqcEt4ig.png" /><figcaption>You, probably.</figcaption></figure><p>You’re right. This is really slow. It would work, but we have 2 problems. The first problem is that capitalisation won’t make the multisets equal. The second problem is that more spaces can appear in the outputted sentence than in the original word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MFUmDL3ubvof-B31sRYMHA.png" /></figure><p>As an example, “roast beef” is an anagram of “eat for BSE”.</p><p>Given 2 sentences such as “roast beef” and “eat for BSE”, if we turned these into multisets they wouldn’t be equal due to the differing amount of spaces. There’s another way we can calculate if 2 sentences are anagrams of each other. The fundamental theorem of arithmetic states:</p><blockquote>Every integer either is a prime number itself or can be represented as the product of prime numbers and that, moreover, this representation is unique, the order of the factors.</blockquote><p><a href="https://www.wikiwand.com/en/Prime_number">Prime numbers</a> are numbers which only have 2 factors — the number itself and 1.</p><p>If we assign each letter in the alphabet to a prime number, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*TU4d_rOQyEN0-OS907FBlA.png" /></figure><p>And so on, then compute the product of these numbers this number is unique — because of the fundamental theorem of arithmetic.</p><p>That means that for a multiset of letters, the product of prime numbers for each letter in that multiset is unique. If two words or sentences have the same number, these two words or sentences are anagrams of each other. Let’s see a quick example, is “BAC” an anagram of “A Bc”?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LlzBw_tdfQOrzAaFUQKg-w.png" /></figure><p>Determining which words are anagrams of other words would be as simple as creating a dictionary of {Word: Prime factorisation} and then grouping all the prime factorisation up.</p><p>Now, given 2 sentences we can easily tell if they are anagrams of each other.</p><h4>Did you like this article? Connect with me on Social Media to discuss all things computer science related 😁</h4><p><a href="https://twitter.com/brandon_skerrit">Twitter</a>| <a href="http://instagram.com/brandon.codes">Instagram</a>| <a href="https://www.linkedin.com/in/brandonls/">LinkedIn</a></p><p>Don’t forget to click that 👏clap👏 button to show your appreciation!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F885736-2%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F885736-2%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/e77f714c4eed7299da2734e0c415149d/href">https://medium.com/media/e77f714c4eed7299da2734e0c415149d/href</a></iframe><p><strong>I didn’t get paid for writing this article. If you want to support me or enjoyed this article, feel free to buy me a cup of tea or something below 😍✨</strong></p><ul><li><a href="https://www.paypal.me/brandonskerritt">Pay Brandon Skerritt using PayPal.Me</a></li><li><a href="https://monzo.me/brandonskerritt">Pay Brandon instantly through Monzo.me</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fe7655de85b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/an-algorithm-for-finding-anagrams-2fe7655de85b">An Algorithm for Finding Anagrams</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Second Class Test for Databases]]></title>
            <link>https://medium.com/brandons-computer-science-notes/second-class-test-for-databases-b1800ddaca3e?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1800ddaca3e</guid>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 00:36:14 GMT</pubDate>
            <atom:updated>2018-12-05T23:04:04.197Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey! This blog post features all content from the lecture slides, things Rasmus has said, vital discussions, material from the book of the course &amp; things from Google. As well as all the tutorials that are required for this class test.</p><p>I’m going to somehow embed my tutorial answers / write-ups here, once I figure out what software Medium supports for embedding PDFs 😁✨</p><p>Most of the test is focussed on chapter 3 (I asked Rasmus), so if you’re strapped for time only focus on chapter 3 😁🔥</p><p>Note: If you fancy supporting the work I do, my PayPal is <a href="https://www.paypal.me/brandonskerritt">https://www.paypal.me/brandonskerritt</a> 😉😜 Or if you have Monzo, you can support me here: <a href="https://monzo.me/brandonskerritt">https://monzo.me/brandonskerritt</a></p><p>Flashcard deck for this module can be found <a href="https://quizlet.com/335892086/databases-flash-cards/">here</a>.</p><ul><li><a href="https://drive.google.com/file/d/1CF2nltnQylaz90eXcMGwyCrbXrp_NGwa/view?usp=sharing">Tutorial-3-Solutions.pdf</a></li><li><a href="https://drive.google.com/file/d/1g-8e1jrTI06Va0hTuObwsCOrl158iqAi/view?usp=sharing">Tutorial-4-Solutions.pdf</a></li><li><a href="https://drive.google.com/file/d/1z4ucvTvK7PU8aEi8ctEzzrB0U9_fAQuR/view?usp=sharing">Tutorial-5-Solutions.pdf</a></li></ul><h3>Aborts</h3><h4>Why might a transaction abort?</h4><ul><li>Deadlock</li><li>Errors while executing transactions</li><li>Explicit request to abort in the code</li><li>Media failures (hard drive dying)</li><li>Fires, floods etc</li><li>System failures</li><li>Logging</li></ul><h4>Deadlock</h4><p>Deadlock occurs when each transaction in a set of two or more transactions is waiting for some item that is locked by some other transaction in the same set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3CU6qOkNiTI3SRSh-4L1Fw.png" /></figure><p>Without looking at the graph, you can clearly see that both transactions are trying to write an item that the other transaction holds a lock on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BLBuTgh7JgobSQ4p2rq9kw.png" /></figure><p>As you can see, it’s rather easy for a transaction to enter deadlock. We’ll talk more about deadlock later.</p><h3>Logging</h3><p>The idea of logging is to write important transactions to a log so that if those transactions fail, we can try again in the future and restore the database to the correct state. Logging should work even in the case of system failures.</p><p>There are 3 main types of logging:</p><ul><li>Undo logging (atomicity)</li><li>Redo logging (durability)</li><li>Combinations of the two</li></ul><h4>Undo Logging</h4><p>We log with the intention to restore the database back to a previous state (undoing the work transactions have done).</p><p>The syntax for this is:</p><ul><li>&lt;start T&gt; — transaction T has started</li><li>&lt;commit T&gt; — Transaction T has been committed</li><li>&lt;abort T&gt; — transaction T has been aborted</li><li>&lt;T, x, v&gt; — transaction T has updated the value to x, and the old value was v.</li></ul><p>If transaction T updates database item X and the old value was v, then &lt;T, X, v&gt; must be written to the log on disk <strong>before</strong> X is written to disk.</p><p>If transaction T commits, then &lt;COMMIT T&gt; must be written to disk as soon as all database elements changed by T have been written to disk.</p><p>What we want to do is before doing anything, we log it. Unless we commit, then the second after we commit we log the commit. No other transactions should occur between the commit and the log.</p><p>Undo essentially ensures Atomicity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*376Fs11g_kgO-M2RVUL5bg.png" /></figure><h4>Recovery with Undo Logs</h4><p>If an error occurs, the recovery manager restores the last consistent database state. It does this by traversing the undo log backwards.</p><h4>Redo Logs</h4><p>Logs activities with the goal of restoring committed transactions (ignores incomplete transactions).</p><p>The syntax is the same as before, but a new meaning to &lt;T, x, v&gt;.</p><blockquote>“Transaction T has updated the value of database item X &amp; the new value of X is v”</blockquote><p>To do this, we need to change the procedure for logging.</p><ol><li>T first writes all log records for all updates to disk</li><li>T writes &lt;COMMIT T&gt; to the log on disk</li><li>T writes all updates to disk</li></ol><p>Redo essentially ensures Durability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pkuzVcp9yzbchKnDiq-bmw.png" /></figure><h4>Recovery with Redo Logs</h4><p>This is essentially the reverse of undo logs.</p><ol><li>Identify all the transactions with a COMMIT log record</li><li>Traverse the log from first to the last item.</li><li>If we see &lt;T, X, v&gt;and T has a COMMIT log record, then change the value of X on disk to v.</li><li>For each incomplete transaction T, write &lt;ABORT T&gt; into the log on disk.</li></ol><h4>What if a transaction aborts?</h4><p>Use the undo log to undo all changes made by the transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6wQcXvDxthM8M-nCKNtFA.png" /></figure><h3>Undo Logging Example</h3><p>Rasmus said that this will be in the exam.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5o-UqDB5GPi5laeWepLluw.png" /></figure><p>The first thing we do is start transaction 1. We write this into the log.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*IU7JRWPUYAKoBd8KMTftlA.png" /></figure><p>When we get to line 3, we log &lt;T1, X, 1&gt; . As in, T1 has changed X from 1. We write what it was before. Before, X = 1.</p><p>We now start transaction 2. We write some write logs.</p><p>The next thing we do is flush the log into the hard disk. Everything written in Log(buffer) we put onto the log(disk).</p><p>Afterwards we write out the values of X and Y to the hard disk. Doesn’t change anything in the log. T1 has finished, so we commit it and T2 has finished so we commit it.</p><p>We write the logs (commit T1, commit T2) to the hard disk (flush_log).</p><h3>Redo Logging Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*yRUfelaBpCjlleU33SLgFQ.png" /></figure><p>Very similar to before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*go1WnfTpHDtagNR1lQS67w.png" /></figure><p>Which transaction here can cause us to want to use undo / redo logging?</p><p>The hint is that you can delete one of these lines and still get the same outcome if you’re using undo / redo logging. Deleting line 13 is a good idea. Line 13 is about outputting X and there’s already another transaction (t2) playing around with X.</p><p>As we know the transaction will delete output x later on, we don’t need to output X here.</p><h3>Undo Without Redo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*kqauUHpp86LSYam38yumZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*E1zdamuIESM6bfmS4ArNKg.png" /></figure><h3>Ensurcing atomicity and durabilit without logging at all</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*jzsNsnyQSSAlDbyzDBBONQ.png" /></figure><p>Stealing means that the working memory is full (think of registers in assembly, very limited working memory) so our transaction needs to clear some data from working memory in order to carry out what it wants to do. Let’s say you have 2 transactions, t1 and t2. T2 writes 10 to x, t1 wants to write 5 to x, so it force-commits x to the database and writes 5 to it. T2 then goes to reuse x as it hasn’t finished, but something else has stolen x from it and changed the value. Forcing means that Everytime a transaction commits, all the effected variables will be pushed to the data base, this is inefficient as multiple transactions can write the same x to the database.</p><p>By using steal / no force we speed it up a lot because we ignore all of these rules. By using logging if we have any issues with stolen memory we can just redo/ undo to fix it.</p><h4>Checkpoints</h4><p>The idea is to checkpoint the log periodically. After t minutes, after m transactions etc we create a checkpoint. It is annoying to go through the entire log file when we want to redo operations, so we place checkpoints in the log file to better find good places to recover to. It flows as follows:</p><ol><li>Stop accepting new transactions</li><li>Wait until all active transactions finish and have written COMMIT or ABORT record to the log.</li><li>Flush the log to disk.</li><li>Write a log record &lt;CHECKPOINT&gt;.</li><li>Flush the log to disk again.</li><li>Resume accepting transactions.</li></ol><h3>Cascading rollbacks</h3><p>If you abort a transaction, you need to find all transactions that depend on this transaction.</p><p>If a transaction, T, aborts then:</p><ul><li>Find all transactions that have read items written by T.</li><li>Recursively abort all transaction that has read items written by an aborted transaction</li></ul><p>If we don’t abort all of the transactions, then we break isolation. If we do abort all of them. we <em>may </em>break durability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LrrQxw-ZMyO17IN3nDvrsw.png" /></figure><p>We want to find a method where neither of these break.</p><p>The problem for durability in regards to cascading rollbacks occurs because a transaction T_1 reads data from some transaction T_2, then T_1 commits and afterwards T_2 aborts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UMywe6BUbZHPmwgCpLZpxA.png" /></figure><h4>Recoverable Schedules</h4><p>A schedule s is recoverable if the following is true:</p><ul><li>if a transaction t_1 commits and has read an item x that was written before by a different transaction t_2.</li><li>then t_2 must commit before t_1 commits</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DNwG7HuEJj9z6-JjUoI4Kg.png" /></figure><p>This schedule is recoverable as it ensures we don’t get problems with durability (and isolation).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DIhZem6w2gQ5KzoHI_f2hQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jBoKiIOrMPgR4ThgIa_myA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5yIRu6C8lW4SoORZ_VJjhQ.png" /></figure><p>If you write something to the log in a certain order, it appears in that disk in that order.</p><p>Recoverable schedules lead us to cascading rollbacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wh7G6m-8z5dR5SNC0bw5FA.png" /></figure><p>Both are active, none have committed, so no durability problems here.</p><h4>Cascadeless Schedules</h4><p>Cascading rollbacks are kinda slow to handle, so it’s better to avoid them entirely.</p><p>A schedule is cascadeless if each transaction in it reads only values that were written by transactions that have already committed. This avoids dirty reads and cascading rollbacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BjL3FdBQA4Uc9QzBFeSvOw.png" /></figure><p>This isn’t allowed This is a recoverable schedule. We read X before T2 commits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*jz8nA_JiA71n33lSCVE2RQ.png" /></figure><p>But this is allowed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*uLIl_YMPMp0Qbi7RS44G8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YtB6BnF6U8vX-OcF-WCjrg.png" /><figcaption>Schedules taken from previous slides. None of them are cascadless.</figcaption></figure><p>All of them read data written by something that isn’t commited yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5mTCHujDyCjubjE9mUxNGA.png" /></figure><p>Cascadeless schedules are recoverable. In general, they are not serializable. Rasmus gives a proof for why they’re recoverable. Tbh I don’t care that much about proofs and I’m sure you don’t either, so I’m not going to include that here.</p><h4>Strict Schedules</h4><p>Strict schedules have no cascading aborts &amp; serializability.</p><p>A schedule is strict if each transaction in it reads and writes only values that were written by transactions that have already committed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OhcerT4dJKg0BJy1kfS0yQ.png" /></figure><p>So this is not possible. But this is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uMrFsAL26voIbEG8bn5wEg.png" /></figure><h4>Strict Two-Phase locking</h4><p>Ensures it’s both conflict-serializable and it is a strict schedule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3VeY9RfaXD5moSXiHPITAQ.png" /></figure><p>You can only unlock things at the very very end of the schedule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xwop2C7akj1la3rlZf8zcw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*DIo5o8W6GVia6ipa2dltUg.png" /></figure><p>Left is 2PL as we have all unlocks following all locks, but it’s not strict yet.</p><p>If a schedule consisting only of strict 2PL transactions then:</p><ul><li>The schedule is conflict-serializable</li><li>The schedule is strict</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*967p9KXYeJiZlLEZCpkAVQ.png" /></figure><p>This is an example of something that is serializable, not conflict serializable and not recoverable (because its reading something written before but not committed).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x_RsPxf5TXTOeoZOLeynew.png" /></figure><p>In total, we have all of these types of reads:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LbNhg8qpNkA4TD3o96smUw.png" /></figure><p>The problem with these is that deadlock may happen.</p><p><strong>1. RECOVERABLE SCHEDULE</strong></p><p>A recoverable schedule is one where, for each pair of Transaction Ti and Tj such that if Tj reads data item previously written by Ti , then the commit operation of Ti appears before the commit operation Tj.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*_czh-7fEBawq_iCE" /></figure><p>Suppose after T2 Read(x) operation, it commits. And then somehow T1 fails. So the transaction T2 must be aborted so as to ensure atomicity. However, since T2 is committed, and can’t be aborted . Hence a situation arrives where it is impossible to recover.</p><p>And hence its necessary that Ti commits before Tj.</p><p><strong>2. CASCADELESS SCHEDULE</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*d8s6-kz-ko3oV31f" /></figure><p>Transaction T1 writes x that is read by Transaction T2. Transaction T2 writes x that is read by Transaction T3. Suppose at this point T1 fails. T1 must be rolled back, since T2 is dependent on T1, T2 must be rolled back,and since T3 is dependent on T2, T3 must be rolled back.</p><p>This phenomenon, in which a single transaction failure leads to a series of transaction rollbacks is called <em>Cascading rollback.</em></p><ul><li>Cascading rollback is undesirable, since it leads to the undoing of a significant amount of work.</li><li>It is desirable to restrict the schedules to those where cascading rollbacks cannot occur, Such schedules are called Cascadeless Schedules.</li><li>Formally, a cascadeless schedule is one where for each pair of transaction Ti and Tj such that Tj reads data item, previously written by Ti the commit operation of Ti appears before the read operation of Tj .</li></ul><p><strong><em>Every Cascadeless schedule is also recoverable schedule.</em></strong></p><p>Cascadeless Schedule Example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/0*OckImq5rM_GxHEr7" /></figure><p><strong>3. STRICT SCHEDULE</strong></p><p>Suppose lets take a scenario of a cascadeless schedule,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/0*DeLb3_Dn1cLJRanD" /></figure><p>In this, the Write(x) of the transaction T2 overwrites the previous value written by T1 , and hence overwrite conflicts arise . This problem is taken care in Strict Schedule.</p><p>Strict Schedule is a schedule in which a transaction can neither Read(x) nor Write(x) until the last transaction that wrote x has committed or aborted.</p><p>The hierarchy is:</p><p>Strict</p><p>Cascadless</p><p>Recoverable</p><p>So if you’re asked “What is the strictest recoverability condition that each schedule satisfies”, see if it’s strict, if not, see if it’s cascadless etc. Go down the pyramid of weird schedule rules.</p><p>Remember that really complicated Venn diagram with like 50 different rings? This is the TL;DR of that.</p><h3>Deadlock Detection</h3><h4>Timeouts</h4><p>We assign to each transaction some sort of time limit, if it takes more than X then it is more than likely to be in deadlock.</p><h4>Wait-for graphs</h4><p>One node is created in the wait-for graph for each transaction that is currently executing. Whenever a transaction is waiting to lock an item that is currently locked by another transaction, a directed edge is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*awQUv9oL8OPKCPAaJjOzTQ.png" /></figure><p>If there is a cycle in this graph we have deadlock. Remember COMP124? This is the same principle as taught there.</p><h4>Timestamp</h4><p>Each transaction is given a unique timestamp upon the arrival. Timestamps do not change even after a restart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uVaWXPYN788wQutzP7CHSQ.png" /></figure><p>Younger transactions can wait for the older transaction but not the other way around.</p><h4>Wait-Die Scheme</h4><p>Older transactions always wait for unlocks.</p><p>In wait-die, older transactions are allowed to wait for a younger transaction, whereas a younger transaction requesting an item held by an older transaction is aborted and restarted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PwpYbixojsj2UyX_rr8YA.png" /></figure><h4>Wound-Wait Scheme</h4><p>In wound-wait, a younger transaction is allowed to wait for an older one, whereas an older transaction requesting an item held by a younger transaction preempts the younger transaction by aborting it.</p><p>Both wait-die and wound-wait end up aborting the younger of the two transactions that may be involved in a deadlock, assuming that this will waste less processing. It can be shown that these two techniques are deadlock-free.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OG3KtBldPz83PgPnOIwCpg.png" /></figure><p>Eventually, any finite number of transactions finishes under wound-wait.</p><p>Wait-Die is similar, but we look at the oldest transaction of the transaction it (recursively) waits for.</p><h3>Timestamp-based alternative to strict two-phase locking</h3><p>The idea is to schedule transactions so that the effect is the same as executing each transaction instantaneously when it is started.</p><p>Equivalent to serial schedule that has all transactions in the order of their start time.</p><h4>Timestamp-based schedulers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EDhESJ1xSupMNnxWp3W_A.png" /></figure><p>Nothing new here.</p><h4>Timestamps in the scheduler</h4><p>Each transaction T is assigned a unique timestamp integer TS(T) when it starts (the timestamp of T). This is different from earlier when it <strong>arrived</strong>. This is <strong>starts. </strong>Restarts get a new time stamp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xqXPIkyyXUDk4t5lYvCLAw.png" /></figure><p>We use these timestamps to define what will happen with a read/write request.</p><p>Before timestamps were arrives, but this time its starts. So if you restart you get a new times stamp. T1 stands and we give it a time stamp of 1, t2 starts and it gets 2, t3 starts and it gets 3. t4 starts and it gets t4. At this point, t2 gets aborted and when it starts it gets 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eE2MRC4DsdbRCYSEhVrA0A.png" /></figure><p>You can not read something that happens in the future, only read in the past.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBc9O36mwDxAN99hmAATxA.png" /></figure><p><strong>Example</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*liwy6H07bDqDWM8fng-fLg.png" /></figure><p>We write Y later on but try to read it earlier, this can’t happen in T_1 so we roll it back. We also need to rollback T_2 as we read an item before writing to it.</p><p>Rasmus adds “additional bookkeeping” below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gNC4jBtayecFWGZAEg5fFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVE48pGBOwhBm0FT-0NhLw.png" /></figure><p>We do everything for t1 as time 1. Later on we write this item at time stamp t2. If t1 was really happening at time stamp 1, it cannot read from the future so we have to restart it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h24ylgnNrPtylP30Qpaxfg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDWlkjeWIerwxvOMSGZOYA.png" /></figure><p>We’re going to see the requests as they’re coming in and then deciding what we should do about it.</p><p>At time 0, all read &amp; write times is time 0. We have 2 transactions, t1 &amp; t2 and each one has a time stamp. t1 has 1, t2 has 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MFuctGEbz9hCuIRIBrcUlQ.png" /></figure><p>T1 reads X, X has been read at time 1 now so we write 1 in read for X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u5Mf33M4t9j25OgqqE147w.png" /></figure><p>We add 100 to X, nothing changes as we haven’t written or read anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dj4dXgCZCJPu8jHiQ2utUA.png" /></figure><p>At this timestamp, T2 decides to do something. So we give read time 2 to transaction 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3_hnm_GjcBxMUTqrVaLB1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NnjiA43HZugCpXnm1YRLOw.png" /></figure><p>At wite_item(Y) we update the write time. Whenever we read / write, we update those times. The read / write time remains the max of whatever process has written to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHJBWtMY3oE4w5Uci0kIMQ.png" /></figure><p>If transaction t1 reads Y, it cannot read Y as it’s been written into the future (timestamp 2) so we have to abort here &amp; restart T1, so it can read transaction 2’s Y in the past.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pz8t4QfBEzJcawqCgu_0fw.png" /></figure><p>Now it’s timestamp 3, it can read timestamp 2 stuff (read item Y).</p><p>We haven’t done anything with X with the next transaction so it goes back to 0, 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gr070zwiQYtUCSaF2GS11g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0TNjjZ6ghW4JwMuqTo0AUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3mVR3X812fqgkiyc8DrnQ.png" /></figure><p>So we redo transaction 1, but this time when we run read_item(Y) it actually works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O3mYr9ZrXpgBfQwR32lJGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ldtgik8Ry4lS2KdKuCWGfw.png" /></figure><h4>Ensuring Strictness</h4><p>To make a timestamp-based schedule strict, we need to enforce this rule:</p><blockquote>“Delay read or write requests until the youngest transaction who wrote X before has committed or aborted”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L2Y1Ivzxan7_6CbWTeczFg.png" /></figure><p>So in this example we have transactions that write to X, we delay the read and write requests of transaction 1 until transaction 3 either commits the transaction to the database or aborts.</p><h3>Deadlock Prevention</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SzUgRHr6KM7W09xZv0wAbw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9a5csRnMY0aN67GfFhKy5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lmsr-BdPyOA1kZLnw4szQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iwnia8qfvGHT1En0lrKMOA.png" /></figure><p>The above stuff is just stuff we’ve seen, this below is slightly different and important (but we’ve still seen most of it, he’s repeating stuff in the slides).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z2yjcb59qBdzjqQM4E037Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFZtre97f6kGFYzzyJE0Rg.png" /></figure><p>This is basically what we’ve seen earlier. He likes to repeat slides a lot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xl21qMCfYDlcK2HRExwPdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L6RVf08H5BH_UQ9O61Tx9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_g95Za_cGDmI8DTBdyRvA.png" /></figure><p>we can either start reading down t1, or start reading down t2. Let’s read down t2.</p><p>We have an item y written to at time 2, we try to read it at time 1. this cannot happen therefore we’re going to roll t1 back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-YT5DPn9kMVQxTS4o7ps3A.png" /><figcaption>Lectue 11 timestamp: 18:30ish</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KEoG5BFNBR3AMXbAeDQelA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bobf1ckFDDkHBCNLN5vJvQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZD9Y4JrhaXcRCnlC7Pw3bw.png" /></figure><p>Yeah uhm, this looks like it’s exactly the same as we’ve done earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zmq8Y0AFryCEvMsu1LFpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwfqslHJwGMnZvwSoYMmww.png" /></figure><h3>Chapter 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FDVeXuwW9wxoLvnbeYeQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_uWhyYMoHFRigF6zZ5xT7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JDb1UbP-bvXXLJo495nEzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*02CGJK4kN1mGsk2rgxdagw.png" /></figure><p>Basically search but with filters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XM2jIJZ0I98_LVV19ab0rw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xz7MsHoi0uQG5mdKeuQA-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGf-zfLs1_L1RWo2x91X1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3WRLZxqMtS8Nk4iEkghaoQ.png" /></figure><p>(SELECT(CONDITION(FROM)))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JdGuP4iyaYc6TP27UMqZjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1HE2-73DzMUdLDO9LKDrTg.png" /></figure><p>Join is about pairing things up with their attributes.</p><p>I made a YouTube video here about natural joins:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7l2f67sJ_kQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7l2f67sJ_kQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7l2f67sJ_kQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7940408fc998d49aea74de10f42b9de0/href">https://medium.com/media/7940408fc998d49aea74de10f42b9de0/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*lYAEhbvva3BNDqWTPKlW2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eVBgVt2rlaJtOJkf3eqUDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-eIGOJZW1HOZDf5qRy2Eiw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8DRPBv4O6lfFLSK4iLHXtA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EslrB4i5PspQMB7U6Rk3Iw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XQ1buoj0AXBZjCSD4NAVbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UF3bsOVr8ToboRRslEfE9A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OFEF1MzH4SbDB52kgdCHog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5pGkk2FqsyavoKjW6n9loA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pEnvxqVrvAu00VPURLenCg.png" /></figure><p>Unlike normal trees, we proceed from the bottom to the top of the plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LdtxahWxKHrO_Np3oHOqtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DDbaBCtiw3PNa_U6UZRjIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Nj3KOYUnvHy0G7Wi3Hldg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37GhqoH8GTHIVaA4X6azvg.png" /></figure><p>He goes over the entire for loop. This is the important part:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6uxaSgQXVFVshnIVJC5cg.png" /></figure><p>We can go faster</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FyXVO50FJIJMSQ%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fsonic-the-hedgehog-sanic-yXVO50FJIJMSQ&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FyXVO50FJIJMSQ%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="342" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea1d5e9d5d8ea72e1800b8fdb06ea6e2/href">https://medium.com/media/ea1d5e9d5d8ea72e1800b8fdb06ea6e2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ghhSLiN6ccHaxSCZmXA5Mw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OIGj1u-Ti3ME3ko_EO7mJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6y5Nr_HZZvQ16ffLe573kA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pshyOt45CbJ-ZTQb62JU_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tphhO0VM_wFGjwmDpw7EXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1CZIQpyjpKcEsGzvxMCCbw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aaYGxollZoO7nU6hWTOVYg.png" /></figure><p>tbh there’s so many slides of just this, i’ll share the important ones. chapter 3 lecture 2 around slide 23 if you want to see all of this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*enOKBO5pVHYfUo7-Vy0ovQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dMEZRsEpEBjCubGXkBJTjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqcIvaw5evqj-dDHDCDszg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vr2QdE948t9fkV6T-CJhQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wFhSCqUMBUXpk8bK7fm8Q.png" /></figure><p>Loads of these slides too… Let’s skip to the end…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MShiDjzA2__T79tavcJ9xA.png" /></figure><p>I don’t think he’s going to ask us about the speed of algorithms… But just in case here they are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LTJpfROuXdlKEfJvX9qJOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zdgoknGlQ7DSTGEXL-SZOw.png" /></figure><p>Summary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSqvFtvo8AVhDXxO-tapfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*B89PMz_j9RtJ7NwnVeNqbQ.png" /></figure><p>Yeah, I’m going to skip ahead like… so many slides just to find the stuff that is in the exam. Chapter 3 lecture 3 if you care about this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uUrYiN7R1jxIFUFQLLPujw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jFSedrNrpkMrN4HIwBEeHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wVqtKYLhVp8yxE5VLi8tLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjCK-4ELpwyHlq3hBLOSOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvgfVNZfB50UXvhD-hX2FA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykTgfjyE5CmecpIfp5mNJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gBfuAMbBCSopEecuDNWJ-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Cm_LxQ1gDtV0e98zTsxXA.png" /></figure><p>It says (idea) because this is what they’re supposed to do, not what they actually do. It’s probably important to learn these in case he asks “in an ideal world, how does this work blah blah blah” meaning that in the world where the idea worked. Probably not that important, but file this among “not important, but just important enough to actually matter”</p><p>It might be a good idea to watch these lectures (last 2–3 lectures of chapter 3) because he’s going over an example and it’s hard to portray the example here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ChwV46mOl2-yx1RQgqrujQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jucvXcAsJ7b9CmU3Y86dGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9W8gm-Ix7mSVaJgLXYg3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bjkH3DIL27JZQpf92bKpw.png" /></figure><p>The pointers are the arrows literally pointing to things I believe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WsQxzVpGtECUZB0yThp1Tw.png" /></figure><p>Smaller is left, larger is right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ofs3_CGtaeaHiMwuv5gfw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_r3b8FFI0OtT7u97iORWw.png" /></figure><p>To get to pointers with ≥ 11, find the first number that is 11 or higher and we just go right along the bottom, printing out 11, 13, 17, 19, 23 etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9KaCbA7JqGY3CiCrvQsXNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rkyvh30CQw_8fWUjlamuaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kj0hv5XodcvMeiOwi4VXVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CQsrSYJAuHBaadYiTIQf5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxglUit2ql9oh17SxvU_0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9H_UZlecmi6bVsdAyd8UBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3k2YdOZE0LxDJw8s6ozwg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXFTr0tLTfDa1iRrPHcXvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4eU9Q5rfqjPAmjHROD9_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWafYQJwdU7yzBtoyYKiOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zvTZpFHLZyUAD7dJBkk1UQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mrIna777t3j2CFRZzBkPtg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wudk5tnBFTyZn2qyrpkoWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmtT6bzznetz1m6dI1dwgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NQaKojVlhmJzBf4zijUKxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wOR_-fkFUx7U0A9sTX_vOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZR1_wkpxmA5W7UlzE3XVqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mAccHaXB3FezJeXw5HJqvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*meAeTeiRk5qRJBPGDuF7eg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cBovmySMFTxnZI8fgVSuvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwb6iA0hBNTuSeYOPJutHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RH2cnHSKSc4yM4g3maeKAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xF-010bUpV1iGgYZEcYx-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QFR6BOad04oeGXotfhzt3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TD3i19Qyz6b2-7Fkq-NJwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HaV2drsvJWJpHk3kgbkmkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2QceEVjaBHVeT_ZL1SFAYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ME2DcJ7kUFPJYG-oVpLyYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8om5sBva0NjD3DC29cVRPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtVP4PBkFhoEPkTxYLC4wg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*19H7vhELK08yfJOcLhoUjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxK8QlgxN5bsL-TyQvSzJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mrUA72w3jmyRzSNewzM7yQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CWdZ6wFeBD29gPSrC5dLdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w4JMMQOz78q3oHC2Qw648Q.png" /></figure><p>These heuristrics are just general tips on what we want to achieve to optimise it, not strict rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rRPa8KDdhqZcGI4SA0vBpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P_-8mIjP7klRfln9X1Kohg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w8krtcgCtScn5UgBu5cAKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBvtnzpXWXP0_99mKUhguQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DXJ9yUq5rMu2hreBjBxJBg.png" /></figure><p>He has a lot of stuff on estimating size / speed, might be in the exam? I’ll ask and found out and then update this text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CoVGxZcNDO7IxeiKpvF4OA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GANzD9OsfVv0jDDMlt413w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o8yBPejYXFAAAXXkRL1tZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3WPGrcdL8pMH1mUohc_wbQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pi2ItT51UFEzgYa123I63Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0VkRG4Lsi7dCJA6XPJgDcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jlVLK4IO29mBox88O2wdzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NnxG1JvCP-kkzXRhtcDT0A.png" /></figure><p>And we’re done. That’s everything. Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1800ddaca3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/brandons-computer-science-notes/second-class-test-for-databases-b1800ddaca3e">Second Class Test for Databases</a> was originally published in <a href="https://medium.com/brandons-computer-science-notes">Notes on Computer Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everything you need to know for this stupid databases exam]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/brandons-computer-science-notes/everything-you-need-to-know-for-this-stupid-databases-exam-9fa12040a74f?source=rss-2480a7e35749------2"><img src="https://cdn-images-1.medium.com/max/1200/0*a4sgSe377Z9zgktX" width="1200"></a></p><p class="medium-feed-snippet">Hi! If you&#x2019;re not a University of Liverpool student, you may find this article pointless. Please do not waste your time unless you really&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/brandons-computer-science-notes/everything-you-need-to-know-for-this-stupid-databases-exam-9fa12040a74f?source=rss-2480a7e35749------2">Continue reading on Notes on Computer Science »</a></p></div>]]></description>
            <link>https://medium.com/brandons-computer-science-notes/everything-you-need-to-know-for-this-stupid-databases-exam-9fa12040a74f?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fa12040a74f</guid>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Mon, 29 Oct 2018 12:04:06 GMT</pubDate>
            <atom:updated>2018-11-01T13:40:39.924Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[What is a Decision Tree in Machine Learning?]]></title>
            <link>https://medium.com/hackernoon/what-is-a-decision-tree-in-machine-learning-15ce51dc445d?source=rss-2480a7e35749------2</link>
            <guid isPermaLink="false">https://medium.com/p/15ce51dc445d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[whats-a-decision-tree]]></category>
            <category><![CDATA[decision-tree-ml]]></category>
            <category><![CDATA[decision-trees-in-ml]]></category>
            <category><![CDATA[decision-tree]]></category>
            <dc:creator><![CDATA[Brandon Skerritt]]></dc:creator>
            <pubDate>Mon, 22 Oct 2018 10:13:36 GMT</pubDate>
            <atom:updated>2019-01-26T14:25:55.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofMfrqFMfpaTH_RMvI_RQA.jpeg" /></figure><p>Decision trees, one of the simplest and yet most useful Machine Learning structures. Decision trees, as the name implies, are <a href="https://medium.com/brandons-computer-science-notes/trees-the-data-structure-e3cb5aabfee9">trees </a>of decisions.</p><p><strong>An updated version of this article can be found here:</strong></p><p><a href="https://skerritt.blog/what-is-a-decision-tree-in-machine-learning/">What is a Decision Tree in Machine Learning?</a></p><figure><img alt="Image result for decision tree" src="https://cdn-images-1.medium.com/proxy/0*Yclq0kqMAwCQcIV_.jpg" /><figcaption>Taken from <a href="https://becominghuman.ai/understanding-decision-trees-43032111380f">here</a></figcaption></figure><p>You have a question, usually a yes or no (binary; 2 options) question with two branches (yes and no) leading out of the tree. You can get more options than 2, but for this article, we’re only using 2 options.</p><p>Trees are weird in computer science. Instead of growing from a root upwards, they grow downwards. Think of it as an upside down tree.</p><p>The top-most item, in this example, “Am I hungry?” is called the <strong><em>root</em></strong>. It’s where everything starts from. <strong><em>Branches </em></strong>are what we call each line. A <strong><em>leaf </em></strong>is everything that isn’t the root or a branch.</p><p>Trees are important in machine learning as not only do they let us visualise an algorithm, but they are a type of machine learning. Take this algorithm as an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*LFepwBvXOWkxezDX" /><figcaption>Taken from <a href="https://www.wikiwand.com/en/Decision_tree_learning">here</a></figcaption></figure><p>This algorithm predicts the probability that a passenger will survive on the Titanic.</p><p>“<em>sibsp</em>” is the number of spouses or siblings aboard the ship. The figures under each leaf show the probability of survival.</p><p>With machine learning trees, the bold text is a condition. It’s not data, it’s a question. The branches are still called branches. The leaves are “<strong><em>decisions</em></strong>”. The tree has decided whether someone would have survived or died.</p><p>This type of tree is a <strong>classification </strong>tree. I talk more about classification <a href="https://hackernoon.com/absolute-fundamentals-of-machine-learning-dca5deee78df">here</a>. In short; we want to classify each person on the ship as more likely to die or to have survived.</p><p>In real life, decision trees aren’t always as easy. Take a look at this photo, and brace yourself. I’ll try to describe as much of it as I can.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_2uJcDN5hKQM9V2InylVA.png" /><figcaption>😴 — Me when I have to look at this image</figcaption></figure><p>This is a decision tree. It wants to answer the question “can I eat this mushroom?”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*eYlru012PubUH5qD.JPG" /><figcaption>Taken from <a href="https://www.wikiwand.com/en/Mushroom">here</a></figcaption></figure><p>Given an image of a mushroom (like on the left) we want to find out if it’s edible.</p><p>You see those things at the top which look like variable assignments? Those are if statements. Let’s take a look at one of those.</p><p><em>“odor = a: e (400.0)”</em></p><p>If the smell (<em>odor</em>) of the mushroom is “<em>a</em>” for almond, then it is edible (<em>e</em>) and we are <em>400.0</em> points confident that it is edible. Each of these statements is a <strong>feature</strong>.</p><p>Features are just attributes of an object. The features of a bike are: it has wheels, it has handlebars etc.</p><p>We do this on and on until we reach a point where the odor is neutral (<em>n</em>) at which point we start to check more <strong>features </strong>of the mushroom.</p><h3>Making decision trees using a formal language</h3><p>Okay, We can draw them but how do we write decision trees? There’s a nice notation for that.</p><p>Let’s jump right into an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*eyHyrMqFuaJCEbFiuzGIdg.png" /><figcaption>Sorry for the blurry formula. It’s a problem with screen shotting LaTeX 😢</figcaption></figure><p>The fancy little “<strong><em>^</em></strong>” means “<em>and</em>”. It’s some fancy mathematical notation. For more notation like this, check out this <a href="https://medium.com/brandons-computer-science-notes/mathematical-logic-f53f9c60d8d9">other article</a> I wrote. In this notation, when we don’t see anything connecting 2 items (like <em>x2</em> and <em>x5</em>) we assume it is “<em>and</em>”. We want a decision tree that returns <strong>True </strong>when both <em>x2 </em>and <em>x5</em> are true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*TMJZmOcSn53PReeaxfeBGw.png" /></figure><p>Okay, let’s see another one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*LtuzvXS1JjJ0Ab8e5KT7GQ.png" /></figure><p>This one features a lot more logic symbols. You might want to check out this <a href="https://medium.com/brandons-computer-science-notes/mathematical-logic-f53f9c60d8d9">other article</a> I wrote. Okay, the “∨” symbol means “<em>or</em>” and the “¬” means “<em>not</em>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*DS4VcU4U3SDkUomS5jknmA.png" /><figcaption>Notice how the X1 decision becomes True if X1 is <strong>not </strong>true. This is because of the “not” symbol before it in the formal notation.</figcaption></figure><h3>Splitting candidates in the tree</h3><p>Decision trees are made by taking data from the root node and splitting the data into parts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*LFepwBvXOWkxezDX" /><figcaption>Taken from <a href="https://www.wikiwand.com/en/Decision_tree_learning">here</a></figcaption></figure><p>Taking the Titanic example from earlier, we split the data so that it makes the most sense and is in alignment with the data we have.</p><p>One of the problems with decision trees is the question “<em>what is the best way to split the data?</em>” Sometimes you’ll instinctively know, other times you’ll need an algorithm</p><p>We want to design a function which when given a dataset will split the data accordingly.</p><p>If we have numerical features we can split it based on the data we see. There are many different ways of splitting. We can sort all the values in the dataset and decide the split thresholds between instances of different classes. We can also cut them straight down the middle. There are too many splitting algorithms to discuss here. So instead we’ll go through a simple algorithm.</p><pre>(1, a), (2, b), (1, c), (0, b), (3, b)</pre><p>So we have 3 classes (a, b, c). The first thing we do is put them into different categories.</p><pre>{(0, b)}, {(1, a), (1, c)}, {(2, b)}, {(3, b)}</pre><p>Now we have 4 different <em>sets</em>. For more on set theory, <a href="https://medium.com/brandons-computer-science-notes/a-primer-on-set-theory-746cd0b13d13">click here</a>.</p><p>Let’s just pick some arbitrary numbers here. We’ll split them like so:</p><pre>Split 1 &lt;= 0.5<br>Split 2 &lt;= 1.5 but &gt; 0.5<br>Split 3 &gt; 1.5</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*6imRsG1-PADkjrYaYtzBgg.png" /></figure><p>We now have a decision tree split up. If we didn’t split the data up, the tree wouldn’t look much like a tree. Imagine what the tree might look like if our split was “<em>all data less than 3</em>”. Everything would be there! It wouldn’t be very tree-like.</p><h3>Occam&#39;s razor</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*hmAFTUepd_9u3P4x.jpeg" /><figcaption>Image of William of Ockham, from <a href="https://www.wikiwand.com/en/William_of_Ockham">here</a>.</figcaption></figure><p>Occam&#39;s razor is a philosophy attributed to William of Ockham in the 14th century. In short, the quote is:</p><blockquote>“When you have two competing theories that make exactly the same predictions, the simpler one is the better one.”</blockquote><p>We can use this principle in machine learning, especially when deciding when to split up decision trees.</p><blockquote>“The simplest tree that classifies the training instances accurcately will work well on previously unseen instances.”</blockquote><p>The simplest tree will often be the best tree, so long as all other possible trees make the same results.</p><h3>Finding the best splits</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FE0Z06zqqlm7jSG6hV2%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Frupaulsdragrace-episode-10-rupauls-drag-race-E0Z06zqqlm7jSG6hV2&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FE0Z06zqqlm7jSG6hV2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/c64b915b31c5127612c47df30f48761b/href">https://medium.com/media/c64b915b31c5127612c47df30f48761b/href</a></iframe><p>Trying to find and return the smallest possible decision tree that accurately classifies the training set is very very hard. In fact, it’s an <a href="https://www.wikiwand.com/en/NP-hardness">NP-hard</a> problem.</p><p>Instead, we’ll try to approximate the best result instead of getting the best result. We’re going to talk a lot about probability and statistics, if you want to know more about probability and statistics <a href="https://medium.com/brandons-computer-science-notes/an-introduction-to-probability-statistics-3f5630824411">click here</a>.</p><p>What we want is information that explicitly splits the data into two. We don’t want something that can include both male and females, we want purity. One singular class for each split.</p><p>This measure of purity is called information. It represents the expected amount of information that would be needed to specify whether a new instance should be classified as the left or right split.</p><p>To find the best splits, we must first learn a few interesting things.</p><h3>Expected Value</h3><p>This part talks about random variables. For more on random variables, check out <a href="https://medium.com/brandons-computer-science-notes/an-introduction-to-probability-statistics-3f5630824411">this article</a> on statistics &amp; probability I wrote.</p><p>The expected value is exactly what it sounds like, what do you expect the value to be? You can use this to work out the average score of a dice roll over 6 rolls, or anything relating to probability where it has a value property.</p><p>Suppose we’re counting types of bikes, and we have 4 bikes. We assign a code to each bike like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*abbFixm6lr_ENDq5OuVFsw.png" /></figure><p>For every bike, we give it a number. For every coding, we can see we use 2 bits. Either 0 or 1. For the expected value, not only do we need the value for the variable but the probability. Each bike has equal probability. So each bike has a 25% chance of appearing.</p><p>Calculating the expected value we multiply the probability by 2 bits, which gets us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*COX5CcPoUAawmFXqd_27WQ.png" /></figure><p>What if the probability wasn’t equal?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*2BN_KfFV2guDUfs89gBSLA.png" /></figure><p>What we need to do is to multiply the number of bits by the probability</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wHvOPbsGOQYbRuMh-A_Ybg.png" /></figure><h3>Entropy</h3><p>This measure of <em>purity</em> is called the <a href="https://en.wikipedia.org/wiki/Information_theory"><strong>information</strong></a>. It represents the <a href="https://en.wikipedia.org/wiki/Expected_value">expected</a> amount of <a href="https://en.wikipedia.org/wiki/Self-information">information</a> that would be needed to specify whether a new instance (first-name) should be classified as male or female, given the example that reached the node. We calculate it based on the number of male and female classes at the node.</p><p>Remember earlier when we talked about purity? Entropy is a measure of impurity. It’s how uncertain something is. The formula for entropy is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*c_3RiTHigg36ry1XOTiQwg.png" /></figure><p>Entropy is trying to give a number to how uncertain something is.</p><p>You can also have conditional entropy, which looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*GJo4JB5Jv8i5OWKct9OJZA.png" /></figure><h4>Information Gain Example</h4><p>Let’s show this using an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*uMkQDAal44EIn2257ypZUw.png" /></figure><p>What’s the information gain of splitting on Humidity?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*kppGR115DWCB7CGCNG2k0A.png" /><figcaption>An example of splitting on humidity</figcaption></figure><p>We have 9+ and 5-. What does that mean? That means in the table we have 9 features where data is positive and 5 where it’s no. So go down the PlayTennis table and count 9 times for positive (Yes) and 5 times for negative (No).</p><p>Now we want to find out the information gain of humidity. If humidity is high, we look at the data and count how many yes’s for humidity high. So when humidity is high, we have 3+ and 4-. 3 positives and 4 negatives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*FP039Ozp4LvQISAfgF1Rmw.png" /><figcaption>D indicates the specific sample, D.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*uMkQDAal44EIn2257ypZUw.png" /></figure><p>The information gain is the gap between uncertainty. We have 14 sets of data in total, The denominator is always 14. Now we just calculate them using the formula. The information gain of playing tennis (yes) when the humidity is high is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*7exXE5m7ACI5wWMGv4OKug.png" /><figcaption>3 yes’s and 4 no’s</figcaption></figure><p>And the information gain of playing tennis when the humidity is normal is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*0SACBDQmRdlC64HO8wYjAg.png" /><figcaption>6 yes’s and 1 no.</figcaption></figure><p>This isn’t how likely something is to happen, it’s just how much information we gain from this. We use information gain when we want to split something. In the below example we want to find out whether it is better to split on humidity or wind.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*j3b8QX69jtM7fTfsniP1ow.png" /></figure><p>Now we know what the information gain on each split is using entropy, we apply the information gain formula.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*f6WKkGsiJVULpmGWmRTTmQ.png" /></figure><p>The information gain on splitting by humidity amongst our sample, D, is 0.151.</p><p>If we use the same formula for entropy in the wind part, we get these results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*rNuDYRWkgn5QbKD27rDDLQ.png" /></figure><p>And if we put them into the information gain formula we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*fs8BNCd10a-3d90E8AiYuQ.png" /></figure><p>It is better to split on humidity rather than wind as humidity has a higher information gain.</p><h3>Definition of accuracy</h3><p>What we want to do is to check how accurate a machine learning model is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*nQGqgAMF-PfSxHchOoTIWQ.png" /></figure><p>M(x) means given a sample, X, we give the predicted classification. The label. lx is actually the true label. So this sample has already been labeled so we know the true label. This set of samples shows that these are correctly labeled.</p><p>What we do is feed the algorithm a sample set where we already know the classification of every single item in that sample set. We then measure how many times the machine learning algorithm was right.</p><h3>Overfitting with noisy data</h3><p>Look at the below example. We have this formula and noisy data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*YfenrQToBs03KizsRUDm4A.png" /></figure><p>Noisy data means that the data isn’t correct. Our formula is X1 and X2 = True. Our noisy data is True and False = True, which is wrong.</p><p>The x3, x4, x5 are all additional features. We don’t care about them, but this is just an example to show that sometimes we have many additional features in a machine learning model which we don’t care about.</p><p>We build a decision tree that can match the training data perfectly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*X7wC32mD2NEODDl0ME2jzw.png" /></figure><p>The accuracy is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*BIzo-gvZI24GTCCCj0sT1w.png" /></figure><p>The problem is that it matches the training data perfectly, 100% but because of the noisy data it doesn’t perform very well on the true data. That one small error makes a larger decision tree and causes it to not perform as well in the real world.</p><p>If we build a decision tree that works well with the true data, we’ll get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QrPJtfJ1LIJttuCa42itWg.png" /></figure><p>Even though it performs worse in the training set, due to not worrying about noisy data it performs perfectly with real-world data.</p><p>Let’s see another example of overfitting.</p><h3>Overfitting with noise-free data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*_CtD1GdnMkecKDPLe6_LEQ.png" /></figure><p>Here are the probabilities for each one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*n-B1Cz6fO01G7zbVg2X9vw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*1AylUEp77wSf-Y_ohZqskw.png" /></figure><p>There’s a 50% chance that the resultant,<em> x3</em>, is True. There’s a 0.66% chance that the resultant, <em>Y</em>, is True.</p><p>For our first model let’s have a quick look.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*Vs0Dbag9ScC1uYApUqdFBw.png" /></figure><p>The accuracy is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*c4hLm7KbonQorvCDSweTUg.png" /></figure><p>It’s good on training data, but on real world data (D_true) it doesn’t perform as well. From this, we can tell that overfitting has occurred.</p><h3>Preventing overfitting</h3><p>The reason for overfitting is because the training model is trying to fit as well as possible over the training data, even if there is noise within the data. The first suggestion is to try and reduce noise in your data.</p><p>Another possibility is that there is no noise, but the training data is small resulting in a difference from the true sample. More data would work.</p><p>It’s hard to give an exact idea of how to prevent overfitting as it differs from model to model.</p><h4>Did you like this article? Connect with me on Social Media to discuss all things computer science related 😁</h4><p><a href="https://twitter.com/brandon_skerrit">Twitter</a>| <a href="http://instagram.com/brandon.codes">Instagram</a>| <a href="https://www.linkedin.com/in/brandonls/">LinkedIn</a></p><p>Don’t forget to click that 👏clap👏 button to show your appreciation!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F885736-2%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F885736-2%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/e77f714c4eed7299da2734e0c415149d/href">https://medium.com/media/e77f714c4eed7299da2734e0c415149d/href</a></iframe><p><strong>I didn’t get paid for writing this article. If you want to support me or enjoyed this article, feel free to buy me a cup of tea or something below 😍✨</strong></p><ul><li><a href="https://www.paypal.me/brandonskerritt">Pay Brandon Skerritt using PayPal.Me</a></li><li><a href="https://monzo.me/brandonskerritt">Pay Brandon instantly through Monzo.me</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15ce51dc445d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/what-is-a-decision-tree-in-machine-learning-15ce51dc445d">What is a Decision Tree in Machine Learning?</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>