Slide 1

Slide 1 text

Computer Science the Fundamentals (or some of them at least) Justin Yost Senior Software Engineer Wirecutter 1

Slide 2

Slide 2 text

Computer Science • The formal field of study towards approaching computers, sometimes this is using, designing and writing software for those computers. 2

Slide 3

Slide 3 text

What do you need to know? Data Structures, Algorithms, Basic Cryptography, Search Algorithms, Big O Notation, P vs. NP, Statistics, Theory of Automata, Boolean Logic, Language Theory, Programming Paradigms, Hardware Design, Complier Design, Software Engineering and more... 3

Slide 4

Slide 4 text

We can't cover all of that 4

Slide 5

Slide 5 text

Highlights • Data Structures • Algorithms • Big O Notation • P vs. NP • Programming Paradigms • Turing Completeness 5

Slide 6

Slide 6 text

Data Structures • Basic • Advanced 6

Slide 7

Slide 7 text

Boolean • True or False • 0/1 7

Slide 8

Slide 8 text

Character • Single symbol or glyph • Different encodings means this character may be different lengths • C style char is 1 byte (most common systems do this) • Full unicode requires 21 bits to store a single code point (ie a single symbol) 8

Slide 9

Slide 9 text

Floating Point Integers • Finite numbers with a sign • Example: binary32, binary with 8 bits, stores values up to ~3.402823 × 10^38 • Because of math, it has precision issues at certain points • But smaller storage for number values 9

Slide 10

Slide 10 text

Integer • Signed and Unsigned • Always precise • Short version is the 1 to 1, binary representation of a number, no math needed 10

Slide 11

Slide 11 text

Enum • Data type where you predefine a limited set of possible values • Example: Enum for Credit Card Types, MC, Visa, Amex, etc 11

Slide 12

Slide 12 text

Advanced Data Structures • These are built using the others • Typically using software implementations as opposed to hardware implementations • Some are provided by the language, some by a framework, some in other ways • These are useful for particular scenarios and typically aren't general purpose 12

Slide 13

Slide 13 text

Linked List • A series of nodes where each node contains a value field and a link to the next node • Used to represent graphs and trees, think a series of GPS coordinates that show a path walked for a map • Linked Lists can be more complicated, doubly linked lists, circular linked lists • Commonly used to represent other more complex data structures 13

Slide 14

Slide 14 text

14

Slide 15

Slide 15 text

Array • A series of elements defined by an index • Most arrays have fast retrieval by index (1 operation), slow to search (scan whole array) 15

Slide 16

Slide 16 text

Hash Table • Associative array, where elements are indexed by a (sorta) unique key • Value is taken, a hash function is used, then value is stored at the index in the array equal to the hash output • Searching for a value is fast (1 operation), Searching for an index is fast (1 operation), Insert and Delete is generally fast 16

Slide 17

Slide 17 text

Hash Function? • A value is converted to some different representation of that value • This operation is one way • Most hash functions have collisions, ie certain multiple values will produce identical hash outputs • md5, sha, etc are hash functions 17

Slide 18

Slide 18 text

Binary Tree • A tree where every node has at most 2 other nodes 18

Slide 19

Slide 19 text

19

Slide 20

Slide 20 text

Queue • A collection where the order of items in the collection stays the same • Think a line for a grocery store • Common queue types - FIFO, LIFO 20

Slide 21

Slide 21 text

Stack • Custom collection similar to a queue • Only two operations - push and pop (sometimes peek) • Think a Pez dispenser • Basically a LIFO Queue 21

Slide 22

Slide 22 text

Algorithms 22

Slide 23

Slide 23 text

Quicksort • Common fast sorting algorithm • Divides a collection along a pivot • Puts everything higher than the pivot above the pivot, everything lower than the pivot, below • Selects a new pivot and repeat • Developed in 1959, still used today • No knowledge of anything, this is your algorithm 23

Slide 24

Slide 24 text

24

Slide 25

Slide 25 text

Bubble Sort • Start at the beginning • Compare the two values • If not sorted, swap the items • Go to the next position and repeat • Repeat process through the list until items sorted, ie no swaps occur • Super easy to implement 25

Slide 26

Slide 26 text

26

Slide 27

Slide 27 text

Depth First Search • Search a tree by going down the nodes first • Solving a maze (where there is only one path) 27

Slide 28

Slide 28 text

28

Slide 29

Slide 29 text

Breadth First Search • Search a tree by going across the nodes first • Shortest path searches between two nodes 29

Slide 30

Slide 30 text

30

Slide 31

Slide 31 text

A* Search • Path finding algorithm that optimizes for certain solutions (shortest distance, etc) • Used in games to go from x to y, when you can't see the path 31

Slide 32

Slide 32 text

Dijkstra's Algorithm • Path finding algorithm, typically used to produce a shortest path tree • For a given source find the shortest path to every other node • For a given source find the shortest path to a destination node • Used in networking algorithms, variations used in Google Maps, AI research, etc 32

Slide 33

Slide 33 text

Big O Notation • The abstract number of operations required to complete a task • Short version: What's the most complex part of a piece of software and what does that look like when we add more data 33

Slide 34

Slide 34 text

Big O - Informal Definition • If f(x) is a sum of several terms, if there is one with largest growth rate, it can be kept, and all others omitted. • If f(x) is a product of several factors, any constants (terms in the product that do not depend on x) can be omitted. 34

Slide 35

Slide 35 text

Big O of Searches • Quicksort - Average Case - O(n log n) • Bubble sort - Average Case - O(n^2) 35

Slide 36

Slide 36 text

36

Slide 37

Slide 37 text

Quick and Dirty Calculation • Count number of loops performed given an input • How quickly does the number of loops performed increase compared to the input of data increase 37

Slide 38

Slide 38 text

P vs. NP • Big massive unsolved problem in Computer Science • Also means today some problems are just too hard/slow (in general) today 38

Slide 39

Slide 39 text

What is P • P means a problem that is solvable in polynomial time • O(n^k) (where k is constant) • This doesn't mean these are easy or fast to solve 39

Slide 40

Slide 40 text

NP • Non-deterministic Polynomial time to solve • O(n^n) • P time to verify the answer • NP time to calculate the answer 40

Slide 41

Slide 41 text

NP Complete • Knapsack, Traveling Salesman, Graph Coloring • One solution to NP Complete problems works for others • Mostly a mathy subset of NP problems 41

Slide 42

Slide 42 text

P vs. NP • Can we can prove (write an algorithm) that solves NP problems in P time • If so lots of problems become way faster to solve especially for graph theory 42

Slide 43

Slide 43 text

Programming Paradigms • Imperative • Procedural • Declarative • Functional • Object Oriented 43

Slide 44

Slide 44 text

Imperative • Side effects allowed • Describe what the software should do • ie. PHP, single file, no functions 44

Slide 45

Slide 45 text

Procedural • Step up of Imperative • Software is grouped into common blocks that can be called procedurally • ie. PHP with functions 45

Slide 46

Slide 46 text

Declarative • Logic is expressed without describing the control of operations • Software describe what needs to happen not the how it occurs • Side effects do not happen • ie. Haskell, regular expressions 46

Slide 47

Slide 47 text

Functional • Software uses mathematical functions to express the solution • Based upon lambda calculus (basically the math that proves computers work) • ie. Erlang, some parts of PHP has this (array_map) 47

Slide 48

Slide 48 text

Object Oriented • Objects have data and operations to perform on that data • Probably what you do every day • ie. PHP (with classes), Java, C#, Swift, Ruby, etc 48

Slide 49

Slide 49 text

Turing Machine • An abstract machine that manipulates symbols on a strip of tape according to a table of rules. 49

Slide 50

Slide 50 text

Turning Completeness • The rules (software, hardware, etc) is Turing complete if it can be used to stimulate any other single-taped Turing complete machine. 50

Slide 51

Slide 51 text

Citations • Linked List Image - By Lasindi - Own work, Public Domain, https://commons.wikimedia.org/w/index.php? curid=2245162 • Binary Tree Image - By Derrick Coetzee - Own work, Public Domain, https://commons.wikimedia.org/w/index.php? curid=488419 • Quicksort Animation - By en:User:RolandH, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php? curid=1965827 • Bubblesort Animation - By Swfung8 - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php? curid=14953478 • Depth First Search Image - By Alexander Drichel - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/ index.php?curid=3791979 • Breadth First Search - By Alexander Drichel - Own work, CC BY 3.0, https://commons.wikimedia.org/w/index.php? curid=3786735 • Big O Notation Chart - By Cmglee - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php? curid=50321072 51

Slide 52

Slide 52 text

Thanks Questions? • twitter.com/justinyost • github.com/justinyost • justinyost.com • https://www.linkedin.com/learning/instructors/justin-yost 52