Week 18 Day 2 - Graph Adjacency Lists
We started off today by showing a common problem when debugging code - that the line that the compiler shows the error on is actually one below the actual problem line. In this case, it was extra tricky due to one #include messing up the next #include, making it look like a system header was broken, when all it was was the student's header file missing a close parenthesis.
Our main topic for today was graphs, again. I first showed a general method for traversing a graph, which works as follows (you start with the node you want to begin with on the to_process list). "to_process" is a min heap, sorted by the distance each vertex is from the start. "processed" is a hash table, that keeps track of which vertices we've already seen before (this stops infinite loops).
Step 1) Pop the top vertex off of "to_process", and add it to "processed".
Step 2) Add all of the vertices connected to that vertex to the to_process list, unless they are in "processed" or "to_process" already. (Sometimes I just insert them again into to_process and simply discard any duplicates that come out.)
Repeat until the to_process heap is empty.
Easy peasey. And this same algorithm is used in 1001 different contexts and industries. We'll get practice coding it in CSCI 26, for now just understand it at a conceptual level.
We talked a bit about Big-O in relation to space (which is to say RAM usage). Adjacency matrices are rarely used in real life scenarios since they require RAM proportional to the square of the number of vertices. An "Adjacency List" simply has a linked list (or BST or other data structure) for each vertex, making the RAM usage proportional to the number of edges in the graph. For full graphs (where every vertex is connected to every other one) this will also be O(N^2) RAM usage, but for most real life graphs, they are very sparse, which will take the RAM usage down to O(N*M), where M is the average number of edges per vertex. In the case of something like Facebook, M is going to be way less than a billion. So it will be much more RAM friendly.
We then moved on to talking about the homework assignment, which is to implement a quiz show in Java (or I guess C++ if you really want to) using Sockets and Threads. I'm pushing out demo code to you with a working client and server, so all you need to do is make it do a 10 question quiz show (keeping track of points) for three players at the same time. That's the minimum - if you go above and beyond you will get extra credit, such as by:
1) Adding a GUI
2) Allowing multiple lobbies or sessions to go on at one time
3) Players being able to chat with each other
4) ???
Other Videos By Bill Kerney
2021-07-09 | Week 1 Day 2 - A Little Advanced C++... |
2021-07-09 | Week 1 Lecture 4 - Materials in UE4 |
2021-07-09 | Week 1 Day 3 - Lighting |
2021-07-07 | Week 1 Day 1 - Voroni Diagrams |
2021-07-07 | Week 1 Lecture 2 - Intro to Unreal Engine |
2021-07-07 | Week 1 Day 1 - Welcome to IS50A |
2021-05-15 | Week 18 - Bounding Volume Hierarchies |
2021-05-14 | Week 18 Day 3 - Use Cases |
2021-05-13 | Week 18 Day 2 - Final Presentations |
2021-05-13 | Week 18 Day 2 - Hyperthreading |
2021-05-12 | Week 18 Day 2 - Graph Adjacency Lists |
2021-05-12 | CSCI 41 Study Session: BSTs |
2021-05-12 | Week 17 Day 2 - The Development Process and AI |
2021-05-11 | Week 18 Day 1 - Shaders, Rasterization |
2021-05-11 | Week 18 Day 1 - Sockets Programming |
2021-05-10 | Week 18 Day 1 - EC, BST deletes, Graphs |
2021-05-08 | Week 17 - Making a 2.5D Game (Wolfenstein-style) from Scratch |
2021-05-08 | Week 17 Day 3 - Circular Arrays |
2021-05-07 | Week 17 Day 2 - Being a Sysadmin |
2021-05-05 | Week 17 Day 2 - Threads and Sockets Part II |
2021-05-05 | Week 16 Day 2 - Final Review |