Discrete Math

Siraj Raval · Beginner ·📊 Data Analytics & Business Intelligence ·7y ago

Key Takeaways

The video covers discrete math, a fundamental subject in computer science, including topics such as graph theory, set theory, number theory, combinatorics, and recursion, with applications in algorithms, databases, and security structures. It explains Dijkstra's shortest path algorithm and the Caesar cipher, and discusses the importance of discrete math in computer science.

Full Transcript

discrete math will help us build trauma hello world it's Suraj and if you're interested in coding not just machine learning but any kind of coding you need to understand discrete mathematics it's become a really important subject in the past few years because of how useful it is in computer science in fact pretty much every single computer science degree program contains at least one course on discrete mathematics sometimes to liberal arts majors it's okay breathe I'm here now in this video I'm gonna give you an overview of the foundational topics in discrete math to help you understand how it all works learn about each of them by necessity since we'll play the role of a cybersecurity agent working for mi6 our task is to crack a password-protected database of international criminals that's stored on a USB Drive discrete math isn't actually the name of a traditional branch of mathematics like calculus or linear algebra is its instead a description of a set of branches of math that all have in common one feature they're discrete rather than continuous discrete stands for individually separate and distinct while continuous stands for forming an unbroken whole without interruption discrete math deals in objects in discrete bundles like one or two kendrick lamar albums at least three if you're a real fan especially down in contrast continuous math deals with objects that vary continuously like three point four centimeters from a wall a good analogy would be digital watches versus analog watches the ones where the second hand loops around continuously without stopping basically discrete data is able to take on only integer values but continuous data can take on any value discrete math was created several decades ago as the mathematical language of computer science colleges learned that traditional math subjects did not cover the type of math needed by computer scientists so they put a bunch of math topics together and called it discrete math discrete math helps us design high speed networks and message routing paths perform web searches analyzed algorithms for efficiency and design cryptographic protocols that can do things like automatically block any image of Wilson as a genie beyond cringy before we can start cracking the password to get the data on the USB drive we've got to get to the lab and there are a lot of different paths we can take they drive there but we're on a deadline so we want to get to the lab as fast as possible meaning we want to take the shortest path to compute this we'll need to represent the collection of streets and intersections as a graph so that we can design an algorithm that will calculate the fastest way to get there since each street is two-way this is an undirected graph so there's no distinction between the two vertices associated with each edge this is graph theory the study of graphs and an important part of discrete math graphs are mathematical structures used to model relations between objects in our case intersections in graph theory the problem of finding a path between two vertices such that the sum of the weights of its constituent edges is minimized would be ideal the weights in our case would be the time it takes to drive from one vertex to the other here we can use one of the most famous algorithms in computer science Dijkstra's shortest path algorithm which is a five step procedure luckily we're not in LA even Dijkstra is no match for its traffic we start by marking our initial node which is our current location with the current distance of zero and the rest with infinity then we set the non visited node with the smallest current distance as the current node for each neighbor of our current node we add the current distance of the current node with the weight of the edge connecting it to the neighbor if it's smaller than the current distance of n we set it as a new current distance of n we then mark the current node as visited and if there are any non visited nodes left we repeat the process starting at the second step until we visited all the nodes thanks to a little Python script we can easily find the shortest path to the lab saving us a lot of time now that we've arrived at the lab let's plug this USB into the computer to see what we've got here in order to access the database we need a password and we have the password here but it's encrypted we need to figure out how to decrypt it into the actual password the only thing we know is that the length of the password is 6 characters long and it can contain either numbers alphab characters or both no emojis thankfully our first strategy here will be to see if we can write a script that will brute-force all possible combinations of every character a through Z and 1 through 9 but when we start running the script it starts taking quite a while in the meantime let's try and calculate how many combinations are possible here since there are 26 letters and 10 digits we have a total of 36 characters to choose from for each position if we start from the left we can fill in the first position 36 possible ways for each of the 36 possibilities for the first character there are 36 possibilities for the second character that means our 36 squared waste fill in the first two characters for each of the 36 squared ways to fill in the first two characters there are an additional 36 ways to fill in the third character so there are 36 cubed ways to fill in the first three characters notice the pattern here and know that number 69 is not involved here the total number of possible combinations is 36 to the n where n is the length of the character field which is 6 in our case making it over 2 billion possible combinations way too much to brute-force so we can go ahead and pause our script this is an example of common atour x the study of counting both has a means and an end in obtaining results and it's a part of discrete math we need to think of a smarter way to decode this password what if each of the characters in the string what's equivalent to a number and the actual password was solely numerical what could the mapping from characters and numbers be here maybe if we converted each character to its numerical position in the alphabet it would represent a prime number one that's X counts away from zero but if we try that out it doesn't work never may be the numerical version of it correlate to some sort of sequence here notice how I'm trying to categorize these integers into different numbered types based on their relationships the study of relationships between numbers is called number theory a part of discrete math there are odd numbers and even numbers square numbers Pythagorean triples the Fibonacci sequence number theory involves analyzing the mathematical relationships between numbers right now I'm trying to figure out the theory behind these numbers in particular maybe each letter of this text can actually be replaced by a letter some fixed number of positions down the alphabet the question then becomes how many positions let's write out a function for this one where we can call the function inside of itself for each character in the string we'll apply a shift operation and recursively call our function until we're done shifting the entire phrase recursion a part of discrete math is a way to solve a problem where the solution depends on solutions to smaller instances of the same problem if we google search the word recursion it recursively asks did you mean recursion which is a fun little easter egg from the programmers at Google in fact the internet is riddled with these a popular reddit threads top answer for the question what is recursion is a link to that very same post an example of recursion a recursive function is a function that calls itself until some base condition is true and the execution stops when we write out our recursive function we can try out different lengths of the possible shifts until we get one that works and it turns out that it's three shifts that was the password we just needed to shift the characters it turns out that this password was encrypted using what's called the Caesar cipher one of the simplest methods of encryption each letter of a given text is replaced by a letter some fixed number of positions down the alphabet for example with the shift of one a would be replaced by B B would become C and so on it's named after Julius Caesar who apparently use it to communicate with his officials is this ambition this is Bridgeland we now have the database of known criminals this is a sequel database and we'll want to compile a report for mi6 now that we've cracked it and that lists the top 10 most wealthy criminals by amount of money they donated to underground organizations in order to do that we'll write some sequel queries which will select the top 10 highest spenders from a certain section of the database relational databases like sequel are based almost entirely upon set theory a part of discrete math as is nothing more than an unordered collection of elements with absolutely no duplicates even the most complicated sequel statements are nothing more than operations on sets a sequel inner join is the intersection of two sets for example a Venn diagram is an easy way to explain the concept of sets two different sets have distinct values and where they intersect they have similar values unions disjunctions there are all sorts of terminologies related to sets and this is what set theory is all about we can write down the top ten criminals for our report but we have one more step here we need to create a proof for our report to show mi6 how we crack the code the rules of logic a part of discrete math specify the meaning of mathematical statements they help us understand and reason with statements like there exists an integer that is not the sum of two squares it's the basis of all mathematical reasoning and has practical applications in all of computer science one of the basic building blocks of logic are propositions a declarative sentence that is either true or false but not both like DC is the capital of the USA is true while DC is the capital of Mexico is false negations truth tables combinations conjunctions we can build off of the basic rules of logic to create all sorts of proofs so logically speaking we can define the proof of our algorithm with the following equation where the decrypted version of the text is equal to each character shifting n degrees out of 26 possible characters mi6 is going to be very pleased with this we'll probably get a double ho status now license code so those are some of the major concepts in discrete math I've listed them all in the video description as well as a free open-source textbook I found on the topic of discrete math study it there are three things to remember from this video discrete math is a set of branches of math that all have in common the feature that they are discrete rather than continuous discrete data can only take on integer values whereas continuous data can take on any value and discrete math topics like recursion logic and community oryx help define the basis of compute signs what's your favorite topic and Matt let me know in the comments section and please subscribe for more programming videos for now I've got to check my logic so thanks for watching

Original Description

Discrete Math is a subject everyone interested in Computer Science needs to understand. It consists of math branches like graph theory, set theory, number theory, & combinatorics. It helps create databases, algorithms, & security structures. In this video, I'll explain the most relevant topics in Discrete Math one by one as we try to decrypt the password for a SQL database. Along the way, we'll use discrete math in various ways. I wanted to see if I could summarize an important course I took in college in a single video. Enjoy! Code for this video: https://github.com/llSourcell/DiscreteMath Please Subscribe! And Like. And comment. Thats what keeps me going. Want more education? Connect with me here: Twitter: https://twitter.com/sirajraval instagram: https://www.instagram.com/sirajraval Facebook: https://www.facebook.com/sirajology More learning resources: http://discrete.openmathbooks.org/home.php https://cse.buffalo.edu/~rapaport/191/S09/whatisdiscmath.html https://www.cs.odu.edu/~toida/nerzic/content/intro2discrete/intro2discrete.html https://www.youtube.com/watch?v=YzfdL58virc Join us at the School of AI: https://theschool.ai/ Join us in the Wizards Slack channel: http://wizards.herokuapp.com/ Please support me on Patreon: https://www.patreon.com/user?u=3191693 Signup for my newsletter for exciting updates in the field of AI: https://goo.gl/FZzJ5w Join my AI community: http://chatgptschool.io/ Sign up for my AI Sports betting Bot, WagerGPT! (500 spots available): https://www.wagergpt.xyz
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Siraj Raval · Siraj Raval · 0 of 60

← Previous Next →
1 What is Bitcoin?
What is Bitcoin?
Siraj Raval
2 5 Ways to Use Bitcoin
5 Ways to Use Bitcoin
Siraj Raval
3 BTC Fever - Siraj [Music Video]
BTC Fever - Siraj [Music Video]
Siraj Raval
4 5 Reasons to Build Decentralized Apps
5 Reasons to Build Decentralized Apps
Siraj Raval
5 The Interplanetary File System
The Interplanetary File System
Siraj Raval
6 How to Build a Dapp in 3 min
How to Build a Dapp in 3 min
Siraj Raval
7 Life Before Smartphones
Life Before Smartphones
Siraj Raval
8 4 Ways to Use Smart Contracts
4 Ways to Use Smart Contracts
Siraj Raval
9 3 Dapps You HAVE to See
3 Dapps You HAVE to See
Siraj Raval
10 Char's Life as a BitTorrent Engineer
Char's Life as a BitTorrent Engineer
Siraj Raval
11 4 Reasons AlphaGo is a Huge Deal
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
12 Build a Neural Net in 4 Minutes
Build a Neural Net in 4 Minutes
Siraj Raval
13 Sentiment Analysis in 4 Minutes
Sentiment Analysis in 4 Minutes
Siraj Raval
14 The Hackathon Life
The Hackathon Life
Siraj Raval
15 Your First ML App - Machine Learning for Hackers #1
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
16 Build an AI Composer - Machine Learning for Hackers #2
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
17 Build a Game AI - Machine Learning for Hackers #3
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
18 Build a Movie Recommender - Machine Learning for Hackers #4
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
19 Build an AI Artist - Machine Learning for Hackers #5
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
20 Build a Chatbot - ML for Hackers #6
Build a Chatbot - ML for Hackers #6
Siraj Raval
21 Build an AI Reader - Machine Learning for Hackers #7
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
22 Build an AI Writer - Machine Learning for Hackers #8
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
23 Build a Chatbot w/ an API - ML for Hackers #9
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
24 One-Shot Learning - Fresh Machine Learning #1
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
25 Generative Adversarial Nets - Fresh Machine Learning #2
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
26 Tone Analysis - Fresh Machine Learning #3
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
27 Generate Rap Lyrics - Fresh Machine Learning #4
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
28 Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
29 Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
30 Build an Antivirus in 5 Min - Fresh Machine Learning #7
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
31 TensorFlow in 5 Minutes (tutorial)
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
32 Build a Recurrent Neural Net in 5 Min
Build a Recurrent Neural Net in 5 Min
Siraj Raval
33 Build a Simulation in 5 Min
Build a Simulation in 5 Min
Siraj Raval
34 Build a TensorFlow Image Classifier in 5 Min
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
35 Tensorboard Explained in 5 Min
Tensorboard Explained in 5 Min
Siraj Raval
36 Generate Music in TensorFlow
Generate Music in TensorFlow
Siraj Raval
37 Build a Game Bot (LIVE)
Build a Game Bot (LIVE)
Siraj Raval
38 Deep Learning Frameworks Compared
Deep Learning Frameworks Compared
Siraj Raval
39 Introduction - Learn Python for Data Science #1
Introduction - Learn Python for Data Science #1
Siraj Raval
40 Build a Neural Network (LIVE)
Build a Neural Network (LIVE)
Siraj Raval
41 Twitter Sentiment Analysis - Learn Python for Data Science #2
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
42 Recommendation Systems - Learn Python for Data Science #3
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
43 Predicting Stock Prices - Learn Python for Data Science #4
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
44 Pong Neural Network (LIVE)
Pong Neural Network (LIVE)
Siraj Raval
45 Deep Dream in TensorFlow - Learn Python for Data Science #5
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
46 Visualizing Data with D3.js (LIVE)
Visualizing Data with D3.js (LIVE)
Siraj Raval
47 Genetic Algorithms - Learn Python for Data Science #6
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
48 Enter Siraj [Music Video]
Enter Siraj [Music Video]
Siraj Raval
49 Build a Web Scraper (LIVE)
Build a Web Scraper (LIVE)
Siraj Raval
50 Why is P vs NP Important?
Why is P vs NP Important?
Siraj Raval
51 How to Make a Neural Network (LIVE)
How to Make a Neural Network (LIVE)
Siraj Raval
52 How to Make an Amazing Tensorflow Chatbot Easily
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
53 How to Make an Amazing Video Game Bot Easily
How to Make an Amazing Video Game Bot Easily
Siraj Raval
54 How to Make a Tensorflow Neural Network (LIVE)
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
55 How to Make a Simple Tensorflow Speech Recognizer
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
56 Joel Shor - Really Quick Questions with an Awesome Google Engineer
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
57 How to Make a Path Planning Algorithm Easily (LIVE)
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
58 The Best Way to Prepare a Dataset Easily
The Best Way to Prepare a Dataset Easily
Siraj Raval
59 Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
60 How to Make a Tic Tac Toe Neural Network Easily (LIVE)
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval

This video teaches the fundamentals of discrete math, including graph theory, set theory, number theory, combinatorics, and recursion, and explains how these concepts are applied in computer science. It covers Dijkstra's shortest path algorithm and the Caesar cipher, and discusses the importance of discrete math in computer science. By watching this video, viewers will gain a solid understanding of discrete math and its applications in computer science.

Key Takeaways
  1. Mark the initial node with the current distance of zero and the rest with infinity
  2. Set the non-visited node with the smallest current distance as the current node
  3. For each neighbor of the current node, add the current distance of the current node with the weight of the edge connecting it to the neighbor
  4. If it's smaller than the current distance of n, set it as a new current distance of n
  5. Mark the current node as visited and repeat the process for any non-visited nodes left
  6. Write a script to brute-force all possible combinations of every character a through Z and 1 through 9
  7. Calculate how many combinations are possible for a 6 character password
  8. Notice the pattern of 36^n where n is the length of the character field
💡 Discrete math is a fundamental subject in computer science, and its concepts, such as graph theory, set theory, number theory, combinatorics, and recursion, are crucial for understanding and applying computer science principles.

Related AI Lessons

Web Scraping with Python in 2026: Best Libraries and Anti-Bot Strategies
Learn to scrape websites with Python in 2026 using the best libraries and anti-bot strategies to avoid being blocked
Dev.to · Etrit Neziri
Python for Data Science — Probability Basics for Data Science
Learn probability basics for data science with Python to enhance your statistical analysis skills
Medium · Data Science
Python for Data Science — Probability Basics for Data Science
Learn probability basics for data science in Python to improve statistical analysis and modeling skills
Medium · Python
The Survivorship Bias in Your Funnel Data: Why Drop-Off Analysis Misses the Point
Learn how survivorship bias in funnel data leads to incorrect conclusions about user behavior and investment strategies, and why drop-off analysis is insufficient
Medium · Data Science
Up next
Spreadsheet Guy Meets the CFO: "Define How Much"
Digital Transformation with Eric Kimberling
Watch →