## Intro [00:00]
[00:00] Computers make no sense. Throw some metal in a boxΒ
and boom [monke]. What the heck is going on here? Inside your PC is a Central Processing Unit,Β
or CPU. Itβs basically just a piece of silicon
[00:15] with billions of microscopic switches calledΒ
transistors. Depending on the flow of electricity, they can be on or off, kind of like a lightΒ
bulb, which gives us two states: 1 and 0. The value at one of these switches is called aΒ
βbitβ. One bit by itself doesnβt really do much.
[00:28] But put them together, and magic starts to happen.
A group of 8 bits is called a βbyteβ and can
## Binary [00:30]
[00:32] have 256 different combinations of 0s and 1s.Β
Congratulations! We can now store information by counting in a system called βbinaryβ.
Every bit represents a power of 2, 1 meaning the power is included and 0 meaningΒ
itβs not, so this number has 1 times 64, 1 times 4, and 1 times 1, which adds up to 69.
This is nice, but for humans, hexadecimal is
## Hexadecimal [00:47]
[00:50] even better: Itβs often denoted by this 0x andΒ
is simply a more readable format than binary: [00:54] Four binary bits can take any value fromΒ
0 to 15. Hexadecimal uses 0-9 and a-f to represent those values, so a group of fourΒ
bits can be replaced by one hexadecimal digit. Okay. Now that we can store numbers,Β
we just need computers to actually, you know, do something with them.
Using transistors, you can make logic gates,
## Logic Gates [01:09]
[01:11] which are electronic circuits that encapsulateΒ
logical statements. You can think of it as a lightbulb with two switches, where the lightΒ
only turns on under certain conditions. For example, only if A AND B are on.
By combining logic gates in a clever way,
## Boolean Algebra [01:20]
[01:22] you can build circuits that perform calculationsΒ
according to Boolean algebra, which is a system [01:26] formalizing mathematical operations in binary.
But, even though computers understand 0s and 1s,
## ASCII [01:28]
[01:31] for humans, itβs not really all that useful.Β
So, using a character encoding like ASCII, we can assign a binary number to eachΒ
character. When you type an A on your keyboard, it gets translated into this binary code, and asΒ
soon as the computer sees this, it says: βAh yes, that is a capital A.β, and slaps it on the screen.
How these devices fit together is handled by an
## Operating System Kernel [01:46]
[01:48] operating system kernel, like Windows, Linux orΒ
Mac, which sits between computer hardware and [01:52] applications and manages how they all workΒ
together, for example with device drivers.
## Machine Code [01:56]
[01:56] Input devices allow you to give the computerΒ
instructions with the press of a button, [02:00] but at the lowest level, computers onlyΒ
understand instructions in machine code, [02:03] which is binary code telling the CPUΒ
what to do, and which data to use. When it comes to following these instructions,Β
the CPU is kind of like a genius, just with the memory of a demented goldfish. It can handleΒ
any instructions but it cannot store any data,
## RAM [02:15]
[02:15] so itβs only really useful withΒ
random access memory or RAM. You can imagine it like a grid, whereΒ
every box can hold one byte of information, which can be data or instructions, and has anΒ
address, so the CPU can access it in four steps:
## Fetch-Execute Cycle [02:25]
[02:26] Fetch from memory, decode instructionsΒ
and data and finally, execute and store [02:30] the result. This is one machine cycle.
Since a program is basically just a list of instructions in memory, to run it,Β
the CPU executes them one by one in machine cycles until itβs complete. Oh yeah didΒ
I mention that this happens, like, really fast?
## CPU [02:38]
[02:41] Modern CPUs can do billions of cycles everyΒ
second, which are coordinated and synchronized [02:45] by a clock generator. The speed of this clockΒ
is measured in GHz, and people often overclock their CPUs to improve performance, which isΒ
nice, but might just set your PC on fire. Whatβs ever crazier though, is that a CPU hasΒ
multiple cores, which can all execute different instructions in parallel, so at the same time.Β
Each core can be split into multiple threads, which also allows every single core toΒ
handle multiple instructions concurrently, so switch between them really quickly.
Okay, thatβs cool, but it doesnβt matter
[03:10] how powerful a computer is if you have no wayΒ
to give it instructions in the first place. Typing machine code by hand would probably makeΒ
you go insane, but luckily, you donβt have to:
## Shell [03:18]
[03:18] The kernel is wrapped in a shell, which is justΒ
a program that exposes the kernel to the user, [03:22] allowing for simple instructions in aΒ
command line interface with text inputs.
## Programming Languages [03:25]
[03:26] But the best way to make a computer doΒ
something useful is with a programming language, [03:29] which uses abstraction, so that instead ofΒ
this, you can write code that looks like this, [03:33] which is then converted into machine code for you.
Some languages like Python use an interpreter,
## Source Code to Machine Code [03:35]
[03:37] which directly tries to execute the sourceΒ
code line by line. Other languages like C or GO use a compiler, which convertsΒ
the entire program into machine code, before putting it in a file the CPU can execute.
Now, every programming language has different syntax, but thereβs some basicΒ
tools almost all of them have:
## Variables & Data Types [03:51]
[03:51] The most basic way to use data is withΒ
variables, which assigns a value to a name, [03:55] which can then be reused and modified.
Depending on the value, variables can have different data types. For text, thereβs singleΒ
characters and strings of multiple characters. For numbers, thereβs integers, which can alsoΒ
be signed if theyβre negative, and floating point numbers for decimal values. Theyβre calledΒ
floating point, because the decimal point can
[04:09] float around to trade off precision with range.Β
This is possible because they use scientific notation. Itβs some number times a power tellingΒ
you where to put the decimal point, which is exactly what they look like under the hood.
The actual number is stored with binary fractions. Some fractions like 1/3 can only beΒ
approximated in binary with an infinite sum, but,
[04:26] since memory is not infinite, you have to cut itΒ
off at some point, which leads to rounding errors, [04:30] causing pretty weird calculations, sometimes.
If these are not enough, long and double use twice the amount of memory toΒ
double the range of ints and floats. Some languages like Python automaticallyΒ
figure out which type a variable is, but in a language like C, you have toΒ
explicitly declare the type of a variable.
## Pointers [04:44]
[04:44] The value of a variable is stored at someΒ
address in memory. Pointers are variables whose value is the memory address of another variable,Β
which is denoted by this ampersand. So really, a pointer is just some chunk of memory,Β
pointing to another chunk of memory. Since a memory address is just a number,Β
you can add and subtract from it to navigate through individual bytes of memory.Β
This is called βpointer arithmeticβ.
## Memory Management [05:01]
[05:01] In some low-level languages like C, you have toΒ
manually allocate and free up memory once itβs [05:05] no longer used. This all happens in the heap,Β
which is a part of memory that can dynamically grow and shrink as the program demands,Β
which allows for more control but makes in incredibly easy to completely break your code.
You could touch memory youβre not supposed to, or that simply doesnβt exist, which is known asΒ
a βsegmentation faultβ. But also, if thereβs some chunk of memory thatβs no longer used, and youΒ
forget to free it or you have no way to access it anymore, that memory is no longer usable.
This is called a βmemory leakβ and will make
[05:27] the program slow down and eventually crash.
To avoid this mess, high level languages like Python have built in garbageΒ
collectors that manage memory for you. Different data types take up a different amount ofΒ
memory. Integers are most often 4 bytes of memory.
[05:39] A single character is most often oneΒ
byte of memory, and a string is just [05:42] multiple character bytes, with a βNULβΒ
character to signal the end of the string.
## Arrays [05:45]
[05:45] Storing multiple items in a contiguous chunkΒ
of memory like this is the idea of an array: [05:49] More generally, itβs a list ofΒ
items with the same data type, [05:51] with each item having a numerical index, mostΒ
often starting at 0. Since the items are next to each other in memory, by knowing the addressΒ
of the first item, you can quickly index to any item in the array by using pointer arithmetic.
Arrays are whatβs known as a data structure, which is just a way to organizeΒ
data to make it easier to work with. Retrieving values from an array is blazinglyΒ
fast, but the size of an array is often fixed when creating it, so when itβs full, you canβtΒ
add anything, and if you donβt use all of it, itβs just wasted memory, so a moreΒ
flexible option is a linked list.
## Linked Lists [06:16]
[06:18] It uses nodes containing a valueΒ
and a pointer to the next node, [06:21] which allows them to be spread apart in memory.Β
Also, it can grow and shrink dynamically, as you can add and remove any node, and you canΒ
reorder it, by simply rearranging the pointers. This is great, but they can be impractical, asΒ
you have no way to access the last node except if you traverse every single one before it. ButΒ
still, both arrays and liked lists are useful, as they allow you to create queues and stacks.
A stack follows the last in, first out principle,
## Stacks & Queues [06:38]
[06:41] just like taking a pancake from a stack.Β
Practically, just imagine a pointer that always points to the item that was last addedΒ
to the structure. Then you can pop, so remove the last item which increments the pointer back.
A queue follows the first in first out principle and uses two pointers, one forΒ
the first item that was added, and one for the last. Any new item gets addedΒ
after the last pointer, which is then updated,
[07:00] and dequeuing starts at the first pointer.
Another useful data structure is a hash map,
## Hash Maps [07:02]
[07:04] which is just a collection of key value pairs.
It works kind of like an array but uses a hash function to take a key and assign it toΒ
an index, where its value is then stored. But sometimes, two different keys can map to theΒ
same index, which is called a βcollisionβ. Thereβs different ways to deal with this, but one way isΒ
to create a linked list at that position in the array, which makes it a little slower to look upΒ
that value, but still, hash maps are incredibly useful, because you can define the keys that pointΒ
to every value, and since theyβre based on arrays, retrieving them is blazingly fast.
For many problems, it can be very
## Graphs [07:30]
[07:31] useful to represent the relationship betweenΒ
different datapoints as a data structure. If you take the nodes of a linked list, butΒ
allow any node to point to any other node, you get a graph, where the nodes areΒ
connected by edges that can be directed, undirected and can even carry a weight, which canΒ
stand for any metric, such as distance or cost. Graphs are useful for analyzing groups insideΒ
networks or finding the shortest path between two points, for example in Google Maps. Thereβs twoΒ
main ways to search a graph: Breadth first search, starts at one node and moves out layer byΒ
layer until it finds the target node for the first time. Depth first search explores everyΒ
single path fully until it reaches a dead end,
[08:02] then it backtracks to the last node with aΒ
different path and continues from there in [08:05] the same way until it finds the target node.
A graph where any two nodes are connected by
## Trees [08:07]
[08:10] exactly one path is called a tree, and representsΒ
a hierarchy, for example the file system on your [08:14] computer. A tree starts at the root and branchesΒ
out into subtrees, which end in leaf nodes. Parent nodes can have any number of childΒ
nodes, but oftentimes, binary trees are the most useful. For example, a binary tree whereΒ
all the values left of any node are smaller, and all the values right of it are greater,Β
is called a βbinary search treeβ, which makes finding specific values super fast.
If you want to find a target value, just
[08:33] start at the root. If the target is smaller thanΒ
that node , go left, if itβs greater, go right, and repeat this until you find the target.
What we just used is a very simple algorithm,
## Functions [08:39]
[08:41] which is just a set of instructionsΒ
that solves a problem step by step. The simplest way to write an algorithm isΒ
in the form of a function. It takes inputs, does something with them, and returns an output.
Just like variables, you can then call a function by its name and pass in different arguments.
When calling a function, the function call
[08:55] gets pushed onto the call stack, which isΒ
short-term memory used for executing code, [08:59] and as the name implies, itβs based on the stackΒ
data structure, which means last in first out.
## Booleans, Conditionals, Loops [09:03]
[09:03] To implement algorithms, you often have toΒ
compare two values, which you can do with [09:06] operators like greater than or equality, andΒ
logical expressions such as AND, OR and NOT. Expressions like these are simple:Β
they can be true or false, which are the possible values of the Boolean data typeΒ
and allow you to write conditional statements: If some condition is true, do this, else do that.
Booleans can also be used to loop over certain parts of code. One way is with a while loop: WhileΒ
this condition is true, this code will execute.
[09:28] Another way is a for loop, which can iterateΒ
over every element inside a data structure [09:32] like an array, but can also loop for a specificΒ
number of iterations, by setting a starting value, [09:36] incrementing it after each iteration, andΒ
setting an upper bound with a condition.
## Recursion [09:40]
[09:40] Functions can also call themselves, which is knownΒ
as βrecursionβ. This is useful when a problem can be broken down into smaller identicalΒ
problems, such as calculating 5 factorial, which is just 5 times 4 factorial, whichΒ
is just 4 times 3 factorial and so on. But, by default, a recursive function willΒ
just keep on calling itself forever. This means that it keeps pushing more functionΒ
calls onto the call stack, until the stack memory is exceeded in a βstack overflowβ.
To stop this, you have to add a base condition
[10:03] to a recursive function, which defines whenΒ
to stop. Only then will the function calls be executed without crashing your PC.
Recursion is cool, but it can be pretty
## Memoization [10:09]
[10:11] expensive time and spacewise. So, to minimize theΒ
amount of computations needed, past results can be saved in a cache, so if they come up again,Β
the computer doesnβt have to recompute them from scratch. This is called βmemoizationβ.
Speaking of performance, to judge how good
## Time Complexity & Big O [10:21]
[10:23] an algorithm is, you can look at time andΒ
space complexity, so how much time or space [10:27] is required to run it. This is measured in BigΒ
O notation, which describes the relationship between growth of input size and number ofΒ
operations needed to execute the algorithm. For example, adding 1 to every number inside anΒ
array is O(n), because the number of operations increases in a linear way as the array grows.
Whatβs relevant is not the exact number of operations, but rather the trend as the the inputΒ
size goes to infinity. You see, something like n!
[10:48] grows way faster than any linear function everΒ
could, so as long as the time complexity is some [10:53] kind of linear relation, itβs simplified down toΒ
O(n), and the same thing goes for any other group.
## Algorithms [10:57]
[10:57] When writing algorithms, thereβs some generalΒ
approaches: For example, when searching an item [11:00] in a list, a brute force approach would be toΒ
simply check every item until we find the target, [11:04] but a more sophisticated approach would be divideΒ
and conquer. For example, in binary search, you cut the problem in half each time by checkingΒ
the middle element of a list and seeing on which side the target is until you land on the target.
Now, when solving a problem with code, thereβs
## Programming Paradigms [11:15]
[11:17] always multiple ways to achieve the same result,Β
which are called programming paradigms. Letβs try to find the sum of all elements in this list.
βDeclarative programmingβ, describes what the code does, but not how exactly the computerΒ
should do it, whereas βImperative programmingβ explicitly describes how the computer shouldΒ
achieve a result with detailed instructions.
## Object Oriented Programming OOP [11:30]
[11:30] An extension of imperative programming isΒ
object-oriented programming, where you can [11:33] define classes as blueprints for objects, whichΒ
are single units consisting of data in the form of [11:38] properties and behaviours in the form of methods.
To code a call, you begin by defining the properties as variables, andΒ
the methods as functions. After encapsulating properties and methodsΒ
in a class, you can instantiate an object and use the dot notation to workΒ
with its properties and methods. Classes make it easy to organize and reuse code,Β
because you can define subclasses that inherit properties and behaviours of a superclass,Β
but can also extend and override them.
[12:00] For example, a RubberDuck subclass might implementΒ
quack() with a squeak(), instead. As a result, rubber rucks can be treated as objects of theΒ
Duck class, but behave differently when quack() is called, which is the concept of βpolymorphismβ.
But for some problems, none of these traditional
## Machine Learning [12:12]
[12:13] paradigms will work.
Letβs say you want to make a computer recognize which of these imagesΒ
is a bee. The problem is, you canβt really describe what a bee looks like with code.
This is where machine learning comes in, aka teaching a computer to do a task withoutΒ
explicitly programming it to do that task.
[12:27] First you need a lot of data whichΒ
you split into training and test data. Next you choose an algorithm thatΒ
can change its parameters over time, for example a neural network, where the weightsΒ
can be updated to achieve a different result. By feeding lots and lots of training data intoΒ
this algorithm you can build a model, whose accuracy you can then check with the test data.
If itβs not quite right, the model can improve over time by comparing the output to what itΒ
should have been, capturing the difference in an error function, and tweaking itsΒ
parameters to minimize the difference.
## Internet [12:52]
[12:52] But no matter how futuristic, bleeding-edge,Β
blazingly fast and optimized it is, if you [12:57] want people to actually use the applicationΒ
you wrote, you should probably know about [13:00] the internet. Itβs a network of computers fromΒ
all around the globe connected by wires. Like, literally, the internet is a bunch of thiccΒ
cables that run at the bottom of the ocean along with facilities like Internet ServiceΒ
Providers that connect you to your destination.
## Internet Protocol [13:12]
[13:12] These computers communicate with the InternetΒ
Protocol Suite. Every computer on the network has a unique IP address. Two computers canΒ
then transfer data with the transmission control protocol. It breaks messages into a bunchΒ
of packets, sends them through a network of wires, before the receiving end puts the message backΒ
together. If you have a poor internet connection,
[13:27] you might have experienced βpacket lossβ, which isΒ
just if some these packets get lost along the way.
## World Wide Web [13:31]
[13:31] If the internet is the hardware, then the web isΒ
the software, which you can use with a browser. Every page on the web has a URL. When you type itΒ
into your browser, it looks up the IP address of the server hosting this website with the domainΒ
name system, which is like a dictionary mapping domain names to IP addresses of actual servers.
After connecting to it via TCP, your browser,
## HTTP [13:47]
[13:49] called the client, uses the hypertext transferΒ
protocol to send an http request to the server, [13:53] which then gives a response, ideallyΒ
containing the contents of the webpage.
## HTML, CSS, JavaScript [13:57]
[13:57] The actual website most often consists of threeΒ
parts: An HTML file contains all the content of [14:01] a website and is basically just a collection ofΒ
elements, which can be text, links, buttons and [14:05] so on. A CSS file controls the visuals and makesΒ
a website look nice. But, a website is useless if pressing nice looking buttons does nothing, soΒ
a language like JavaScript adds functionality.
## HTTP Codes [14:15]
[14:15] But sometimes things can go wrong. WithΒ
every http response comes a response code, which carries information about the statusΒ
of the response. For example, 200 means βOKβ, and anything starting with 4 is an error, theΒ
most famous one being β404 β page not foundβ.
## HTTP Methods [14:28]
[14:28] HTTP requests can carry different methods, forΒ
example GET, POST, PUT and DELETE, so retrieve, [14:33] add, update and delete information. These areΒ
often used by Application Programming Interfaces,
## APIs [14:35]
[14:38] which connect two applications and allowΒ
them to interact with each other, for [14:41] example store and retrieve data from a database.
The most common type of database is a relational
## Relational Databases [14:44]
[14:46] database, which uses tables to store data.
Columns of a table contain different attributes, and rows represent individual datapoints.Β
Also, each table has one unique attribute called the primary key. A foreign keyΒ
is the primary key of another table, establishing a relationship between the two. InΒ
this case, each book is connected to an author.
## SQL [15:03]
[15:03] With a language like SQL, you can write statementsΒ
to work with data from these tables. You could look up the titles and authors of all books,Β
whose title starts with βHβ, but for that, we have to join the authors table withΒ
the books table on the matching key to combine two attributes from differentΒ
tables into one, giving us this output. These statements are useful, but youβve gotΒ
to be careful, or you might just delete an entire database with one line of code. But,Β
donβt worry. Thatβs never happened before.
## SQL Injection Attacks [15:27]
[15:27] Behind every login page is a database withΒ
usernames and passwords. When a user tries to log in, an SQL query is often used to check if theΒ
user input matches with an entry in the database. Thatβs good, but, a devious actor could typeΒ
something like this, which changes the query by terminating the string early and commenting outΒ
the rest, which means as long as this username exists in the database, access is granted.
This is called an SQL injection attack and is one of the easiest ways hackersΒ
get places theyβre not supposed to.
## Brilliant [15:51]
[16:03] Hearing about all these concepts isΒ
one thing, but to really learn them, [16:06] you have to see them in action and useΒ
them yourself, which is exactly what you [16:09] can do with Brilliant, which has thousandsΒ
of interactive lessons for everything from [16:12] math and data science to programming and AI.
They make knowledge stick with visual lessons and interactive problems, which is not only funΒ
and builds intuitive problem solving skills, but also proven to be 6x more effectiveΒ
than simply watching hours of lectures. I know that making time to learn new skills can beΒ
difficult, but Brilliant makes it so easy: You can build valuable knowledge from the ground up inΒ
just a couple of minutes a day with bite-sized lessons from any device, anywhere, anytime.
Youβll go from the basics of data science to analysing real datasets fromΒ
Spotify in absolutely no time, which you can supplement with math fundamentalsΒ
and programming courses in Python to build one of the most in demand skillsets of our time.
The best part? You can try everything Brilliant
[16:47] has to offer for free for a full 30 days, byΒ
visiting brilliant.org/WackyScience/. Youβll also get 20% off an annual premium subscription.Β
Thanks to Brilliant for sponsoring this video.