These are just dome notes that I have been collecting throughout the lessons. These notes about CS50 have come in handy and useful for my individual learning project because I have to create a website and these lesson have been teaching the basics and functions of certain codes. The scratch programs are similar to the ones on Khan academy but I feel that these go in more in depth about the code and is at the beginners level so that it is easy to understand. This course gives simple activities which help the learner understand binary code and significance for each function and number of code.
Week 0
Symbols and Functions
lower level programming language called C
Scratch: # The block is an example of a statement or function. # and are types of loops
# Hexagon blocks are boolean expressions inside conditions
pictoral, puzzle-piece based code
#include int main(void) { printf("hello, world\n"); }
run program: jharvard@ide50:~/workspace $ make hello clang -ggdb3 -O0 -std=c99 -Wall -Werror hello.c -lcs50 -lm -o hello jharvard@ide50:~/workspace $ ./hello hello, world jharvard@ide50:~/workspace $
turn the source code into a piece of software
compiler converts source code to object code ( 0s and 1s)
puzzle pieces we used in Scratch and the C syntax
#include int main(void) { printf("hello, world\n"); }
#Just block represents a function= printf is a function in C that prints text to the screen
#main indicates where the program should start= int and (void)
while (true) { printf("hello, world\n"); }
#ln while (true)= block in Scratch
while loop continues executing as long as its condition evaluates to true
expression true (which will always evaluate to true ), the loop will run forever
This is a screenshot of one of the videos where it is discussing the basics of the coding language and giving an example explain the functions of each line.
Another screenshot of the instructor of the lesson explain the importance of code to the right and how every aspect is important to make the code function the way that he programmer makes it do.
Week 1
CS50 IDE
for (int i = 0; i < 10; i++) { printf("hello, world!\n"); } # When you want to repeat something a finite number of times, for (int i = 0; i < 10; i++) is equivalent to in Scratch
int counter = 0; while (true) { printf("%i\n", counter); counter++; }
variable stores a value in C
C we can say int counter = 0
variable declaration with int to signify that we want to store an integer, or number
%i that we use in our printf statement in line 4 acts as a placeholder to print a decimal number
printf to replace the placeholder with the value of the variable counter
(x < y) ((x < y) && (y < z))
Boolean expressions is involving more parentheses to compiler interprets our expression in the correct order
if (x < y) { printf("x is less than y\n"); } else if (x > y) { printf("x is greater than y\n"); } else { printf("x is equal to y\n"); }
IDE stands for integrated development environment
CS50 IDE lives in the cloud. The cloud simply refers to a bunch of computers elsewhere that store data and run software and the like that we can rent
hello world: #include int main(void) { printf("hello, world"\n); }
Week 2
function
A bug is a mistake in a program that causes it to behave other than expected
Functional decomposition is the breaking of a program into its constituent bits
Abstract is the building of a higher-level functionality on top of a lower-level code
We can declare a variable globally by putting it at the top of the file, outside the curly braces
Typecasting is the ability to convert one datatype to another
An array is a type of data structure
The general format to declare an array a type and size are given
Command-line arguments are generally separated by spaces
A secret-key crypto can only be decoded by someone who knows the secret key that was used to encode the message
Small programs can be written entirely in main , but as the problems we’re solving get larger and more interesting, it’s often
worthwhile to factor out pieces of logic into separate functionstwo functions here: main and PrintName
PrintName implements into a function as an example of functional decomposition breaking a program down into its constituent bits and abstraction and building higher-level functionality on top of lower-level code
Every variable has a scope, or area of the program in which it’s usable, limited to the area it is declared in, whether it’s an entire function or a loop compiler goes top to bottom, so without the prototype
the compiler complains that we’re trying to use a function that hasn’t been declared yet implemented using a while loop, but either way, it avoids having to copy-paste a line of code to make it happen multiple times
In line 10 we use %c\n to print each character on its own line, and to get each character, we use s[i] , as in the "box number" of the strings
Week 3
Sorting Algorithms and algorithmic efficiency
The algorithms used for sorting are fundamentally the same whether we have eight, a thousand, millions, or billions of inputs
Searching and sorting makes it much faster to method to look for something
Because the inputs (the numbers behind the doors) were in a random order, the best we can do is to pick doors randomly (or sequentially) to find the number 50
This algorithm is called bubble sort, in which we sort pairwise until we can make an entire pass through the array without making any swaps
This works by sorting pairwise until we can make an entire pass through the array without making any swaps
Any algorithm with a fixed number of steps regardless of the length is constant time
Any metric besides big-O refers to lower bound on the running time of an algorithm
Our divide-and-conquer method of finding Mike Smith in the phonebook, which we’ll call binary search or logical time
This algorithm is called selection sort, because we repeatedly "select" the smallest element
An assembly code is composed of simple machine instructions that interact with memory directly
Another metric besides big-O that we’ll care about isΩ,or big-omega,which refers to the lower bound on the running time of an algorithm
Week 4
Recursion
Sigma
Volkswagen and Trust in Software
An algorithm is recursive if it calls itself
Sigma is written with an iterative approach where it does the same thing, over and over again.
A temporary value is used to store a code
Local Variables are able to see the values of all our local variables at a particular point in the execution of a program
A stack frame contains to local variables
typedef and struct define a type that is a container for multiple things
can be used for 2 purposes
it declares a pointer
if it's used without a word, it becomes a dereference operator
syntactic sugar is a simpler or clearer syntax abstracted on top of a more complicated syntax
Eventually we’ll reach the base case, where we have just one page left and either "Smith" is there and we call Mike, or he’s not and we give up
An algorithm is recursive if it calls itself
main , where we ask the user for an integer until we get a positive one, using a do-while loop
Variables are generally scoped to the curly braces that encompass them, so we need to put them outside the curly braces of the for loop in order to return it after
passing each smaller value back to sigma , from sigma(n) to sigma(n - 1) to sigma(n - 2) until we get to sigma(0)
Week 5
More On Pointers
CS50 Library
Segmentation fault is when you've touched a segment of memory that isn't yours
Every time we run out of space, we double the size of our buffer to store what the user types
A memory leak is when you are receiving the memory from an operating system but they are not getting it back
Linked lists is another data structure used to store lists of values
A singly linked list only has one pointer between any pair of nodes
A doubly linked list has every node point both to the next node and to the previous node
A stack canonically supports two operations
Push: an element to the top of the stack
Pull: pull an element off the top of the stack
A queue has twp different operations
Enqueue: an element is added to the back of the queue
Dequeue: an element is taken off the front of the queue
Segments of memory are called a stack
Huffman coding uses the frequency of different characters while avoiding the problem of needing lots of extra space to separate characters
Hashing is taking an input and computing a value
lines int* x; and int* y; , in which we declare two variables of type int* , or pointers to int values
address of x with *x = 42; , which dereferences x (goes to the address x ) and sets the value in that chunk of memory we just allocated to be the number 42
segmentation fault - you’ve touched a segment of memory that isn’t yours
declares a variable x and printf s a message asking for a number
buffer is some garbage value, so scanf will put the input at an address that could be anywhere in memory
support longer sentences by implementing a larger buffer, but that’s a waste of space if we don’t actually fill them
Week 6
Transitioning to Web Programming
Data Structures Recap
IP addresses are unique addresses that are used to identify each device on the Internet
Private IP addresses have been set aside to use within a particular network but not on the Internet
When data is requested, sent, or received on the Internet, it is broken up into a bunch of packets
A firewall is a device that all Internet traffic at a particular location has to go through
A VPN (Virtual Private Network) can be used to encrypt a connection between your computer and a server elsewhere
Data that a web browser can understand is HTML (Hypertext Markup Language)
transition from lower-level C programming to higher-level web programming
A hash table (with separate chaining) gives us O(log n) search time, assuming that we use a good hash function that spreads elements out well over the table
hashing that we brought up in the context of hash tables has many more applications
One hash function that’s been used for a while in the real world is SHA1
There’s a special server on most networks called a DHCP server, which stands for Dynamic Host Configuration Protocol, which assigns an address each time a new computer joins the local network
Though 4 billion is a high number, we have lots of servers and devices
Private IP addresses have been one way we’ve dealt with the problem of running out of addresses
Week 7
HTML
It's common in web development to minify a code. It removes any superfluous characters to make the file sizes as small as possible
A web server is just a program whose job it is to serve up web pages
A subdomain is the courses overarching domain
A self-closing tag doesn't have a separate close tag
Relative Path is the path from our content directory to the image
Associative arrays has rather than elements being indexed by some number between 0 and the length of the array
Interpreted language is not compiled into machine code
Interpreter is a program that understands PHP code
In Chrome, you can right-click/Ctrl-click on a webpage and select "inspect element" from the menu that appears to open Chrome’s Inspector, a debugging tool that lets you see under the hood of what’s happening on a webpage
Week 8
PHP
Variable interpolation only works within double-quotes
Controller code is the brains of the site
View code is what the user sees
Model code is the data
SQL (Structured Query Language) is programming language for data bases
Lets us store and query huge amounts of data
Powerful but can be boiled to just 4 main operations
#SELECT lets you receive data from database
#INSERT adds new rows to database
#DELETE deletes rows from database
#UPDATE lets you change rows from database
Index: a way of telling the database in advance how you’re going to query the data
Variables beginning with $ are superglobal variables
Need to be careful with SQL injection attacks
compare C, a low-level language, to PHP (or other higher-level languages)
C is not necessarily the right tool for most applications (we teach it because it’s a great way to explain computer science and programming fundamentals, and its syntax and concepts are extremely transferable to other languages)
a dinky little hello, world program, saved it in a file called hello.php , and ran it using php hello.php
Week 9
Syntax
Document Object Model
JavaScript is an interpreted language
Runs client-side which is not being interpreted by your web server
No main function when starting code
JavaScript lets you manipulate DOM
Anonymous functions is when a property needs to be a function but instead of being named, it is written separately and then called
jQuery is a common JavaScript library
Use JavaScript to perform client-side validation à checks for correct input before the request is sent to the server
Ajax is a technique that uses JavaScript to send additional HTTP requests after the page is loaded à doesn’t reload the whole page
Example: when looking something up on Google, a new request gets sent every time you add another character in your search
JavaScript is also quite syntactically similar to C and PHP
There’s no main function - you just start writing your code
Conditions are syntactically identical to C and PHP
The loops we’ve seen before are structured the exact same way, too, such as the for loop: for (initializations; condition; updates) { // do this again and again }
got an object (which we’ll describe more in a moment), we can iterate over the key-value pairs inside, with JavaScript grabbing a new key from the object each iteration.
Arrays are declared similarly to PHP: var numbers = [4, 8, 15, 16, 23, 42]
More generally, we can declare variables like so: var s = "hello, world"
Objects with keys and values, not unlike PHP’s associative arrays (although with some differences): var quote = {symbol: "FB", price: 101.53
This is an object in JavaScript - there’s one key-value pair, where the key is database , and the value is itself another object (with keys host , name , username , and password )
JSON is a standard format for storing data - a little nitpicky (a JSON file won’t be readable if we omit a comma or quotes, etc), but widely used
Week 10
Security
An attacker can load a huge dictionary into memory & then guess your password
Salting a password at least ensures that the hashes pf similar passwords won’t be too similar
Phishing is trying to get a user to give you their password by pretending tp b a legitimate entity
Password manager is a piece of software tbat generates big passwords that humans couldn’t remember
Two-factor authentication is where you need something you know and something you have in order to log in
Audits are used to know if an account has been compromised
Session hijacking is where an attacker copies your cookies to impersonate you
make better technological decisions, given how widespread misunderstandings of how technology works are, especially among politicians
Bertucci’s WiFi is labeled "Secure Internet Portal", so it must be secure, right?
reserve the right to log or monitor traffic to ensure that these terms are being followed
the URL you’re trying to access (domain name as well as path)
If you read the terms & conditions of some of these smart TVs, there’s specific language indicating that you might not want to have personal conversations in front of your TV
An attacker can load a huge dictionary into memory and then guess and check against the hash. # Salting a password at least ensures that the hashes of similar passwords won’t be too similar
better ways of generating passwords1 , but the best defense for passwords is something much more random.
Week 11
AI Search
Depth first search: where we go all the way down one path & the n go back up to the top and start down another path
Breadth first search: where we look at all the top-level nodes, then all the nodes one level down, then all the nodes two levels down, and so on
Minimax strategy: choosing the move which leaves our opponent with the worst set of possibilities
Nodes controlled by opponent à choose minimum value
Nodes controlled by you à choose maximum value
Reinforcement learning à learning without seeing the rules of the game; only looking at the screen inputs
Depth first search, where we go all the way down one path and then go back up to the top and start down another path
Breadth first search, where we look at all the top-level nodes, then all the nodes one level down, then all the nodes two levels down
These search trees are fundamental to AI, but they don’t always get everything perfectly right
Adversarial Search
Week 0
This is a screenshot of one of the videos where it is discussing the basics of the coding language and giving an example explain the functions of each line.
Another screenshot of the instructor of the lesson explain the importance of code to the right and how every aspect is important to make the code function the way that he programmer makes it do.
Week 1
Week 2
An array is a type of data structure
Week 3
Week 4
Sigma
Volkswagen and Trust in Software
Sigma is written with an iterative approach where it does the same thing, over and over again.
A temporary value is used to store a code
Local Variables are able to see the values of all our local variables at a particular point in the execution of a program
A stack frame contains to local variables
typedef and struct define a type that is a container for multiple things
- can be used for 2 purposes
it declares a pointerif it's used without a word, it becomes a dereference operator
syntactic sugar is a simpler or clearer syntax abstracted on top of a more complicated syntax
Eventually we’ll reach the base case, where we have just one page left and either "Smith" is there and we call Mike, or he’s not and we give up
An algorithm is recursive if it calls itself
main , where we ask the user for an integer until we get a positive one, using a do-while loop
Variables are generally scoped to the curly braces that encompass them, so we need to put them outside the curly braces of the for loop in order to return it after
passing each smaller value back to sigma , from sigma(n) to sigma(n - 1) to sigma(n - 2) until we get to sigma(0)
Week 5
CS50 Library
Every time we run out of space, we double the size of our buffer to store what the user types
A memory leak is when you are receiving the memory from an operating system but they are not getting it back
Linked lists is another data structure used to store lists of values
A singly linked list only has one pointer between any pair of nodes
A doubly linked list has every node point both to the next node and to the previous node
A stack canonically supports two operations
Push: an element to the top of the stack
Pull: pull an element off the top of the stack
A queue has twp different operations
Enqueue: an element is added to the back of the queue
Dequeue: an element is taken off the front of the queue
Segments of memory are called a stack
Huffman coding uses the frequency of different characters while avoiding the problem of needing lots of extra space to separate characters
Hashing is taking an input and computing a value
lines int* x; and int* y; , in which we declare two variables of type int* , or pointers to int values
address of x with *x = 42; , which dereferences x (goes to the address x ) and sets the value in that chunk of memory we just allocated to be the number 42
segmentation fault - you’ve touched a segment of memory that isn’t yours
declares a variable x and printf s a message asking for a number
buffer is some garbage value, so scanf will put the input at an address that could be anywhere in memory
support longer sentences by implementing a larger buffer, but that’s a waste of space if we don’t actually fill them
Week 6
Data Structures Recap
Private IP addresses have been set aside to use within a particular network but not on the Internet
When data is requested, sent, or received on the Internet, it is broken up into a bunch of packets
A firewall is a device that all Internet traffic at a particular location has to go through
A VPN (Virtual Private Network) can be used to encrypt a connection between your computer and a server elsewhere
Data that a web browser can understand is HTML (Hypertext Markup Language)
transition from lower-level C programming to higher-level web programming
A hash table (with separate chaining) gives us O(log n) search time, assuming that we use a good hash function that spreads elements out well over the table
hashing that we brought up in the context of hash tables has many more applications
One hash function that’s been used for a while in the real world is SHA1
There’s a special server on most networks called a DHCP server, which stands for Dynamic Host Configuration Protocol, which assigns an address each time a new computer joins the local network
Though 4 billion is a high number, we have lots of servers and devices
Private IP addresses have been one way we’ve dealt with the problem of running out of addresses
Week 7
A web server is just a program whose job it is to serve up web pages
A subdomain is the courses overarching domain
A self-closing tag doesn't have a separate close tag
Relative Path is the path from our content directory to the image
Associative arrays has rather than elements being indexed by some number between 0 and the length of the array
Interpreted language is not compiled into machine code
Interpreter is a program that understands PHP code
In Chrome, you can right-click/Ctrl-click on a webpage and select "inspect element" from the menu that appears to open Chrome’s Inspector, a debugging tool that lets you see under the hood of what’s happening on a webpage
Week 8
Controller code is the brains of the site
View code is what the user sees
Model code is the data
SQL (Structured Query Language) is programming language for data bases
Lets us store and query huge amounts of data
Powerful but can be boiled to just 4 main operations
#SELECT lets you receive data from database
#INSERT adds new rows to database
#DELETE deletes rows from database
#UPDATE lets you change rows from database
Index: a way of telling the database in advance how you’re going to query the data
Variables beginning with $ are superglobal variables
Need to be careful with SQL injection attacks
compare C, a low-level language, to PHP (or other higher-level languages)
C is not necessarily the right tool for most applications (we teach it because it’s a great way to explain computer science and programming fundamentals, and its syntax and concepts are extremely transferable to other languages)
a dinky little hello, world program, saved it in a file called hello.php , and ran it using php hello.php
Week 9
Document Object Model
Runs client-side which is not being interpreted by your web server
No main function when starting code
JavaScript lets you manipulate DOM
Anonymous functions is when a property needs to be a function but instead of being named, it is written separately and then called
jQuery is a common JavaScript library
Use JavaScript to perform client-side validation à checks for correct input before the request is sent to the server
Ajax is a technique that uses JavaScript to send additional HTTP requests after the page is loaded à doesn’t reload the whole page
Example: when looking something up on Google, a new request gets sent every time you add another character in your search
JavaScript is also quite syntactically similar to C and PHP
There’s no main function - you just start writing your code
Conditions are syntactically identical to C and PHP
The loops we’ve seen before are structured the exact same way, too, such as the for loop: for (initializations; condition; updates) { // do this again and again }
got an object (which we’ll describe more in a moment), we can iterate over the key-value pairs inside, with JavaScript grabbing a new key from the object each iteration.
Arrays are declared similarly to PHP: var numbers = [4, 8, 15, 16, 23, 42]
More generally, we can declare variables like so: var s = "hello, world"
Objects with keys and values, not unlike PHP’s associative arrays (although with some differences): var quote = {symbol: "FB", price: 101.53
This is an object in JavaScript - there’s one key-value pair, where the key is database , and the value is itself another object (with keys host , name , username , and password )
JSON is a standard format for storing data - a little nitpicky (a JSON file won’t be readable if we omit a comma or quotes, etc), but widely used
Week 10
Salting a password at least ensures that the hashes pf similar passwords won’t be too similar
Phishing is trying to get a user to give you their password by pretending tp b a legitimate entity
Password manager is a piece of software tbat generates big passwords that humans couldn’t remember
Two-factor authentication is where you need something you know and something you have in order to log in
Audits are used to know if an account has been compromised
Session hijacking is where an attacker copies your cookies to impersonate you
make better technological decisions, given how widespread misunderstandings of how technology works are, especially among politicians
Bertucci’s WiFi is labeled "Secure Internet Portal", so it must be secure, right?
reserve the right to log or monitor traffic to ensure that these terms are being followed
the URL you’re trying to access (domain name as well as path)
If you read the terms & conditions of some of these smart TVs, there’s specific language indicating that you might not want to have personal conversations in front of your TV
An attacker can load a huge dictionary into memory and then guess and check against the hash. # Salting a password at least ensures that the hashes of similar passwords won’t be too similar
better ways of generating passwords1 , but the best defense for passwords is something much more random.
Week 11
Breadth first search: where we look at all the top-level nodes, then all the nodes one level down, then all the nodes two levels down, and so on
Minimax strategy: choosing the move which leaves our opponent with the worst set of possibilities
Nodes controlled by opponent à choose minimum value
Nodes controlled by you à choose maximum value
Reinforcement learning à learning without seeing the rules of the game; only looking at the screen inputs
Depth first search, where we go all the way down one path and then go back up to the top and start down another path
Breadth first search, where we look at all the top-level nodes, then all the nodes one level down, then all the nodes two levels down
These search trees are fundamental to AI, but they don’t always get everything perfectly right
Adversarial Search