├── .gitignore ├── 00-about ├── about.md └── norms.md ├── 00-intro └── intro.md ├── 00-study-plan ├── study-plan.checkpoint.md └── study-plan.md ├── 01-algorithms ├── 01-algorithms.md ├── 02-algorithm-analysis.md ├── 03-recursion.md ├── 04-algorithms-divide-conquer.md ├── 05-sliding-window.md ├── 06-algorithms-dynamic-programming.md ├── 07-algorithms-supplemental-resources.md ├── 08-algorithms-activity.md ├── 09-algorithms-class-discussion.md ├── archive │ └── zero-sum-subarray.md └── images │ ├── MergeSort.png │ ├── algorithmic-strategies_divide-and-conquer_binary-search.png │ ├── algorithmic-strategies_divide-and-conquer_merge-sort.png │ ├── algorithmic-strategies_divide-and-conquer_min-max.png │ ├── algorithmic-strategies_divide-and-conquer_quick-sort.png │ ├── algorithmic-strategies_dynamic-programming_fibonacci-inefficient.png │ ├── algorithmic-strategies_dynamic-programming_lcs.png │ ├── binary-search-ex.gif │ ├── bst-divide-and-conquer.png │ ├── call-stack-non-recursive.gif │ ├── call-stack-sum-zero-to-n.gif │ ├── coin-change-example-1.png │ ├── coin-change-example-2.png │ ├── contiguous-v-noncontiguous.png │ ├── dijkstras-2.png │ ├── dijkstras-3.png │ ├── dijkstras-example.gif │ ├── dynamic-sliding-window.png │ ├── example-zero-sum-subarrays.png │ ├── fibonacci.png │ ├── greedy-choice-property-dijkstra.png │ ├── greedy-mouse-maze-unsuccessful.png │ ├── greedy-mouse-maze.png │ ├── kadane-Algorithm.png │ ├── longest-route.png │ ├── min-sum-subarray.gif │ ├── optimal-path.png │ ├── overlapping-subproblem.png │ ├── problem-solving-looped-based-vs-arithmetic-timing.svg │ ├── problem-solving__big-o-cheat-sheet.png │ ├── problem-solving__call-stack.svg │ ├── problem-solving__log-example.png │ ├── problem-solving__sliding-window copy.gif │ ├── problem-solving__sliding-window.gif │ ├── sliding-integer-adjacent-pair-sum.gif │ ├── sliding-integer-nonadjacent-pair-sum.gif │ ├── sliding-window-array.png │ ├── sliding-window-integer-array.png │ ├── sliding-window.png │ └── zero-sum-subarray.gif ├── 02-linked-lists ├── 01-linked-lists.md ├── 02-linked-lists-oop.md ├── 03-linked-lists-implementation.md ├── 04-linked-lists-stacks-queues.md ├── 05-linked-lists-supplemental-concepts.md ├── 06-linked-list-activity.md ├── 07-linked-lists-class-discussions.md ├── autoconfig.yaml ├── class-lesson.instructor.md ├── images │ ├── add-first-step-0.png │ ├── add-first-step-1.png │ ├── add-first-step-2.png │ ├── add-first-step-3.png │ ├── archive │ │ ├── add-first-1.png │ │ ├── add-first-2.png │ │ ├── add-first-3.png │ │ ├── add-first-4.png │ │ ├── array.png │ │ ├── nodeLinkedList.png │ │ └── singly-linked-list.png │ ├── array.png │ ├── call-stack.png │ ├── dot-notation-ex.png │ ├── doubly-linked-list.png │ ├── head-unconnected-node.png │ ├── linked-list-remove-node.png │ ├── linked-list-search.gif │ ├── linkedlist.svg │ ├── memory-layout.png │ ├── node-linked-list.png │ ├── queue.png │ ├── remove-node-1.png │ ├── remove-node-2.png │ ├── remove-node-3.png │ ├── remove-node-4.png │ ├── remove.gif │ ├── singly-linked-list.png │ ├── singly-linked-list2.png │ ├── stack.png │ ├── stackADT.png │ ├── two-nodes-singly-linked-list-updated-value.png │ ├── two-nodes-singly-linked-list.png │ └── vars-replace-dot-notation.png └── linked-lists.instructor.md ├── 03-Binary-Search-Trees ├── 01-Binary-Search-Trees.md ├── 02-Binary-Search-Trees-Big-O.md ├── 03-Binary-Search-Trees-Traversal.md ├── 04-Binary-Search-Trees-Resources.md ├── 05-Binary-Search-Trees-Activity.md ├── 06-Binary-Search-Trees-Class-Discussions.md ├── autoconfig.yaml ├── bst.instructor.md ├── class-lesson.instructor.md ├── image-archive │ ├── TreeVocabulary.png │ └── linked-list-vocab.png └── images │ ├── Binary-Search-Trees__find-value.gif │ ├── Binary-search-trees__insert-into-tree.gif │ ├── TreeVocabulary.png │ ├── adding-sorted-array-element.png │ ├── balanced-bst.png │ ├── bfs-example-tree.png │ ├── binary-expression-tree.png │ ├── bst-bfs.gif │ ├── bst-find.gif │ ├── bst2.png │ ├── bst3.png │ ├── deleting-array-element.png │ ├── inorder.gif │ ├── linked-list-vocab.png │ ├── postorder.gif │ ├── preorder.gif │ ├── tree-vocabulary.png │ ├── tree-vs-linked-list.png │ └── unbalanced-bst.png ├── 04-graphs ├── 01-graphs.md ├── 02-representing-graphs.md ├── 03-bfs.md ├── 04-dfs.md ├── 05-application.md ├── 06-graphs-resources.md ├── 07-graphs-activity.md ├── 08-graphs-class-discussions.md ├── XX-coloring-outline.md └── images │ ├── adj_matrix_1.png │ ├── adj_matrix_2.png │ ├── adj_matrix_3.png │ ├── australia-graph.png │ ├── bfs.gif │ ├── dfs-graph-example.png │ ├── dfs.gif │ ├── directed-graph-example.png │ ├── directed-graph-flights.png │ ├── directed-graph.png │ ├── disconnected-graph-example.png │ ├── graph-adjacency-list.png │ ├── graph-adjacency-matrix.png │ ├── graph-cycle-example.png │ ├── graph-edge-list.png │ ├── graph_1.png │ ├── graph_2.png │ ├── graph_a.png │ ├── graph_b.png │ ├── graph_c.png │ ├── graph_neighbors_adj_list.png │ ├── graph_neighbors_adj_matrix.png │ ├── graph_neighbors_list_of_edges.png │ ├── graphs-adjacency-list-cities.png │ ├── graphs-adjacency-list.png │ ├── graphs1.png │ ├── graphs2.png │ ├── graphs_application_maze_backtrack.png │ ├── graphs_application_maze_backtrack.webp │ ├── graphs_application_maze_backtrack.xcf │ ├── graphs_application_maze_backtrack_merged.xcf │ ├── graphs_application_maze_backtrack_parts.png │ ├── graphs_application_maze_corner_edge.fig │ ├── graphs_application_maze_corner_edge.png │ ├── graphs_application_maze_to_graph.fig │ ├── graphs_application_maze_to_graph.png │ ├── graphs_application_mazes.fig │ ├── graphs_application_mazes.png │ ├── representing-weighted-directed-graph-challenge.png │ ├── undirected-graph.png │ ├── unweighted-graph-flights.png │ ├── weighted-graph-flights.png │ └── weighted-graph.png ├── 05-dijkstras ├── 01-graph-representations-review.md ├── 02-traversal-review.md ├── 03-dijkstra.md ├── 04-dijkstras-activity.md ├── 05-dijkstras-class-discussions.md ├── 06-dijkstras-vs-negative-graphs.md ├── autoconfig.yaml └── images │ ├── bfs-shortest-distance.gif │ ├── bfs-undirected-graph.gif │ ├── dfs-shortest-path.png │ ├── dfs-undirected-graph.gif │ ├── dijkstra-challenge-example.png │ ├── dijkstra-q1-graph.png │ ├── dijkstra-subpath.png │ ├── dijkstras-0.png │ ├── dijkstras-1.png │ ├── dijkstras-2.png │ ├── dijkstras-3.png │ ├── dijkstras-4.png │ ├── dijkstras-5.png │ ├── dijkstras-6.png │ ├── dijkstras-7.png │ ├── disconnected-graph.png │ ├── find-shortest-path.gif │ ├── fruit-graph.png │ ├── negative-1.png │ ├── negative-2.png │ ├── negative-3.png │ ├── negative-4.png │ ├── negative-5.png │ ├── negative-6.png │ ├── weighted-adj-matrix.png │ ├── weighted-graph.png │ └── weighted-v-unweighted.png ├── README.md ├── config.yaml ├── course.yaml └── old-lessons ├── 01-Problem-Solving-And-Big-O ├── 01-problem-solving.md ├── 02-big-o.md ├── 03-problem-solving-checkpoint.md ├── 04-in-class-problemset.md ├── class-lesson.instructor.md └── images │ ├── problem-solving__Sliding-Window.svg │ └── problem-solving__sliding-window.gif ├── 04-Stacks-And-Queues ├── 01-stacks-and-queues.md ├── 02-stacks-and-queues-checkpoint.md └── images │ ├── call-stack.png │ ├── circular-array.png │ ├── circular-buffer.png │ ├── memory-layout.png │ ├── queue.png │ ├── stack.png │ └── stackADT.png ├── 05-hash-tables ├── 01-hash-tables.md ├── 02-hash-table-checkpoint.md └── images │ ├── Example-hash.png │ ├── big-o-cheatsheet.png │ ├── cash-register.jpg │ ├── hash-table.png │ ├── linear-probing-clustering.png │ ├── linear-probing-clustering2.png │ └── linear-probing.png ├── 06-heaps ├── 01-heaps.md ├── 02-heaps-exercise-checkpoint.md └── images │ ├── add-element-finished.png │ ├── heap-as-array.png │ ├── heap-delete.png │ ├── heap-down-array-1.png │ ├── heap-down-array-2.png │ ├── heap-down-array-3.png │ ├── heap-remove-1.png │ ├── heap-remove-2.png │ ├── heap-remove-3.png │ ├── heap-remove-4.png │ ├── heap-up-array.png │ ├── heap-up.png │ ├── heap.png │ ├── invalid-max-heap.png │ └── invalid-max-heap2.png ├── 10-negotiations-and-resumes ├── 01-negotiation-fundamentals.md └── resumes.md └── 11-crash-courses ├── 01-oop.md └── 02-recursion.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | -------------------------------------------------------------------------------- /00-about/about.md: -------------------------------------------------------------------------------- 1 | ## CS Fundamentals 2 | 3 | In Computer Science Fundamentals students learn the following concepts and data structures: 4 | 5 | 6 | - [Algorithmic Approaches](../01-algorithms/01-algorithms.md) 7 | - [Linked Lists](../02-linked-lists/01-linked-lists.md) 8 | - [Binary Search Trees](../03-Binary-Search-Trees/01-Binary-Search-Trees.md) 9 | - [Graphs: BFS & DFS](../04-graphs/01-graphs.md) 10 | - [Graphs: Dijkstra's Algorithm](../05-dijkstras/01-graph-representations-review.md) 11 | 12 | ### Reverse Classroom 13 | 14 | CS Fundamentals is taught in a [flipped-classroom](https://omerad.msu.edu/index.php?option=com_content&view=article&id=162:what-why-and-how-to-implement-a-flipped-classroom-model&catid=27:teaching) style. Students are provided with a Learn topic to review two weeks prior to a live review session. In class students are expected to ask questions, review concepts, and work on exercises in groups. 15 | 16 | ### CS Fun Recorded Sessions 17 | 18 | All the CS Fundamentals and Career Services online sessions are recorded in Panopto. 19 | 20 | - [CS Fundamentals Class Lesson Recordings](https://adaacademy.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx?folderID=85008c14-9981-42fe-8950-afc0016af8e9) 21 | - [Career Services Class Lesson Recordings](https://adaacademy.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx?folderID=2887f2f4-b902-4379-8a39-adf101338f83) 22 | 23 | 24 | ### Unit Quick Links 25 | 26 | #### General Resources 27 | - [Internship Guide](https://drive.google.com/file/d/1mAkodI0l6nZBFwpX3tRQG1bNEb7C3tS2/view?usp=share_link) 28 | - [Unit Guide](https://drive.google.com/file/d/1GCwVbRDpdeAagMan-XIPRScxgHr4b7tR/view?usp=sharing) 29 | - [Unit Section Assignments](https://drive.google.com/file/d/1VC7A6J3MV3tbBJUdmW_KwngVfNrM9r_z/view?usp=share_link) 30 | - [Ada Intern Resource Library](https://drive.google.com/drive/folders/1PgOMAmsgIkNEumuJvJmGQJ_uH5rIhCh6?usp=sharing) 31 | - [CS Fundamentals Office Hours Guide](https://docs.google.com/document/d/12gi9oNXoXWvpJPANPbKE_KAvCJ9dwVNSkXmht5H0M84/edit?usp=sharing) 32 | - [CSM Internship Office Hours | Visitor Expectations](https://drive.google.com/file/d/1Hvyi-KmveH81CH3EoJNnhJYuzOimn4dQ/view?usp=share_link) 33 | - [Career Development Post Session Document](https://docs.google.com/document/d/1pILXmhfj0Dt8qdvEZbjc1seDbly01c2QeO9oPBWYvM0/edit) 34 | - [Your Study Plan Template](https://docs.google.com/document/d/1uCUKu9sZLUSbxsUVobnf8d2EaudXIQxqFpSRhhYE2jU/edit?usp=sharing) 35 | - [Submit an Alteration to Your Study Plan](https://docs.google.com/forms/d/e/1FAIpQLSeBxKIJUhkQ9li3ZOmsSnqlQ38xnBhLEYO8Bnh2CkJkf8i3Ww/viewform?usp=sf_link) 36 | - [Mock Interview Question Bank](https://docs.google.com/document/d/1SmKIpGL_z_IXhgLiaGAf3kPc_bApgH1LtIGcXVoKUHE/edit#) 37 | 38 | #### Ligers 39 | - [Ligers Unit Overview Calendar](https://calendar.google.com/calendar/u/0?cid=Y18wZmVlNmQxZWFhNzM4YWVlNzM5YTRkZjZmNmRjN2YzNzFmNmExMDkxYWFjMzlkODBhM2YzMjkyNDBlN2I4ZDBlQGdyb3VwLmNhbGVuZGFyLmdvb2dsZS5jb20) 40 | - [Ligers CS Fundamentals Detailed Class Schedule](https://docs.google.com/document/d/14UwD9Er-pqmEgcEh1efBihnR-dgeSWhPE0K0N8KU1Wo/edit?usp=share_link) 41 | - [Ligers Personal Study Plan Guide](https://docs.google.com/document/d/19RsoW-SDkUapg0CQuTbCLKaUHuPGDFs6jh85QsjSTJs/edit?usp=sharing) 42 | 43 | #### Tigons 44 | - [Tigons Unit Overview Calendar](https://calendar.google.com/calendar/u/0?cid=Y19jYmZjN2VkMGRkMjkxY2M3MGNjMGM1NzljYzkxNzY4MzZhMTQ0MWJlYTk1MWRlMTc4ODc3NGE5ZDA0OTI0MTBmQGdyb3VwLmNhbGVuZGFyLmdvb2dsZS5jb20) 45 | - [ Tigons CS Fundamentals Detailed Class Schedule](https://docs.google.com/document/d/1qQ9FzZ-w0Tep3KENv3knBzXXKmIhCX2il8362ixGWvk/edit?usp=share_link) 46 | - [Tigons Personal Study Plan Guide](https://docs.google.com/document/d/1pwa85WrRYpqs6rVNPSqOB6QZo-BH4tQcItQ_k99gSkc/edit?usp=sharing) 47 | 48 | 49 | #### Office Hours 50 | - [Office Hours Calendar](https://calendar.google.com/calendar/u/0?cid=Y183NGY4Zjk4NDM1MWQ1NzEyZDIxOWVlMGFkOTBmN2EyMjBkYjcxN2RlOTkzODZlZGZlNTZkNDgwNWYxODUxYmVjQGdyb3VwLmNhbGVuZGFyLmdvb2dsZS5jb20) 51 | 52 | #### Classroom Links 53 | - Career Development Sessions and Mock Interviews are hosted in the [Career Services Zoom Room](http://careerservices.adadev.org) 54 | - CS Fundamentals sessions will be held in the [CS Fundamentals Zoom Room](http://cs-fun.adadev.org) 55 | 56 | 57 | #### Study Hall Zoom 58 | - The [http://accel-study-hall.adadev.org/](http://accel-study-hall.adadev.org/) is available for intern use as a study hall and community space. 59 | - Host Key: 283986 60 | -------------------------------------------------------------------------------- /00-about/norms.md: -------------------------------------------------------------------------------- 1 | # Unit Norms 2 | 3 | * **In-person attendance of sessions is optional for graduation** from the program. 4 | * We expect interns to choose to engage with whichever live unit content they find most helpful for their learning needs. 5 | * CS Fundamentals assignments are a required part of your continuing education and graduation requirements. 6 | * **You need to complete 80% (4/5) of problem sets for CS Fundamentals**. 7 | * **You need to complete 100% (5/5) of Problem Solving Exercises for CS Fundamentals**. 8 | * **You need to complete 5 peer-to-peer mock interviews for CS Fundamentals**. 9 | * New topics and problem sets are released at least two weeks before the live session date 10 | * New projects are released at least four weeks before the Plan A proposed completion date 11 | * Please contact your instructors and make use of the TAs for support. 12 | * Contact the Career Services Managers for Internship support 13 | * Career Development facilitators and speakers are volunteers who are excited to share their expertise with you. 14 | * Please keep your video on when possible during in-person sessions, with the understanding that sometimes video on will not feel comfortable, and that is okay. 15 | * Please stay as engaged as possible (answering questions, responding in the chat, participating in interactive breakout sessions or sharing out your thoughts if you are comfortable). 16 | -------------------------------------------------------------------------------- /00-intro/intro.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | CS Fundamentals is a continuation of the data structure and algorithms-focused CS Fundamentals topics encountered during the classroom phase. Studying data structures and algorithms accomplishes several goals: 4 | 5 | 1. It helps us apply our programming skills to new and challenging classes of problems. 6 | 2. It helps us develop our algorithmic thinking. 7 | 3. It helps us build a shared language and understanding with other programming professionals. 8 | 4. It helps us prepare for technical interviews. 9 | 10 | For more information about the structure and expectations of the post-classroom CS Fundamentals material, please visit the Post-Classroom CS Fundamentals Site. 11 | 12 | ### Resources 13 | 14 | - [Post-Classroom CS Fundamentals Site](https://sites.google.com/adadevelopersacademy.org/adacorehub/homework-projects/cs-fundamentals) 15 | - This site has access to resources such as: 16 | - Classroom & Live Session Recordings 17 | - Classroom, Office Hours, & Events calendars 18 | - Graduation Goals & a Study Plan template 19 | - CS Fun Team & Contact Information 20 | - [PSE Feedback Request Form](https://form.asana.com/?k=s_JorjEM5mBvzcDtfw8yJg&d=181459410160484) 21 | - Please be aware grading is subject to the availability of instructor capacity. We will make every effort to evaluate your PSE within one week of receiving your completed form. 22 | - Given limited instructor capacity, we ask that you first attend review sessions which will include a debrief of the topic's PSE *before* requesting feedback. As always, if you are unable to attend the review session live, you are welcome to review the session recording. 23 | - Please submit one form per assignment. 24 | -------------------------------------------------------------------------------- /00-study-plan/study-plan.checkpoint.md: -------------------------------------------------------------------------------- 1 | # Study Plan Submission 2 | 3 | 4 | 5 | 6 | ### !challenge 7 | 8 | * type: multiple-choice 9 | * id: 4676f40f-b9b2-4704-a623-b7b2144282eb 10 | * title: Choose Your Path 11 | * points: 1 12 | 13 | 14 | ##### !question 15 | 16 | Which of the study plan paths are you opting into? 17 | 18 | ##### !end-question 19 | 20 | ##### !options 21 | 22 | a| Path A 23 | b| Path B 24 | c| Path C 25 | 26 | ##### !end-options 27 | 28 | ##### !answer 29 | 30 | a| 31 | b| 32 | c| 33 | 34 | ##### !end-answer 35 | 36 | 37 | 38 | 39 | 40 | 41 | ### !end-challenge 42 | 43 | 44 | 45 | ### !challenge 46 | 47 | * type: short-answer 48 | * id: 133e45ba-8173-44d4-94f5-6cc7e80d8641 49 | * title: Study Plan 50 | * points: 0 51 | 52 | 53 | ##### !question 54 | 55 | If you chose Path C, please submit your study plan. If you chose Option A or B, you do not need to submit your study plan unless you modified the milestone deadlines. You can optionally copy and paste that option into your copy of the personal study plan document to modify as needed. 56 | 57 | ##### !end-question 58 | 59 | ##### !placeholder 60 | 61 | Your Study Plan Document Link 62 | 63 | ##### !end-placeholder 64 | 65 | ##### !answer 66 | 67 | /.+/ 68 | 69 | ##### !end-answer 70 | 71 | 72 | 73 | 74 | 75 | 76 | ### !end-challenge 77 | 78 | -------------------------------------------------------------------------------- /00-study-plan/study-plan.md: -------------------------------------------------------------------------------- 1 | # Study Plan 2 | 3 | Unit deadlines are flexible. We recognize that each intern will have a different internship experience where some may experience greater intensity at the beginning of internship, others may experience a heavier workload at the end of internship, and others may experience something in between. 4 | 5 | To ensure that you recognize the scope of work we are asking you to complete and have a plan in place to complete the unit coursework, we ask that you submit a study plan with proposed completion dates for each of the required elements. 6 | 7 | See more details about each plan in your section specific study guide: 8 | - [Ligers Study Plan Guide](https://docs.google.com/document/d/19RsoW-SDkUapg0CQuTbCLKaUHuPGDFs6jh85QsjSTJs/edit?usp=sharing) 9 | - [Tigons Study Plan Guide](https://docs.google.com/document/d/1pwa85WrRYpqs6rVNPSqOB6QZo-BH4tQcItQ_k99gSkc/edit?usp=sharing) 10 | 11 | ## Completion Options 12 | There are three basic paths to complete the unit requirements. 13 | 14 | ### Path A 15 | Path A keeps pace with CS Fundamentals live sessions and will ensure you have covered all topics by the end of the third month of internship which is when many folks choose to actively begin their job search. Path A follows the pattern of learning a new CS Fundamentals topic and completing a problem solving exercise every two weeks. 16 | 17 | Path A also includes ample time to review topics during the last two months of internship and practice applying them. Following Path A, we hope students will feel very solid on all unit topics by graduation and will be able to independently apply them. 18 | 19 | Accelerate students: we recommend that you choose Path A or a modified version of it as your internship is shorter. Keep in mind that you have covered Linked Lists, Binary Search Trees, and Graphs already. 20 | 21 | ### Path B 22 | Path B will allow you to dedicate most of your first two months solely to internship. We do recommend keeping up with career development sessions as they occur since preparation for career development sessions is optional and you do have facilitated time for unit coursework set aside. We also recommend you complete one mock interview on a topic from the classroom phase early on to familiarize yourself with the format. 23 | 24 | Path B will introduce all topics to you by the end of internship and allow you to complete all CS Fundamentals Graduation requirements with a week long buffer by the deadline. You will review each new topic and accompanying problem set by the review session. By graduation, you may feel that you need additional review of the CS Fun topics but should have a solid foundation to conduct your review independently. 25 | 26 | If you are able to read through the new topic material (without completing the problem set questions) during your first two months of internship, we would highly recommend you do so, that way that the topics are not completely unfamiliar when you start intensive work on CS Fundamentals material. 27 | 28 | ### Path C 29 | Choose your own completion dates by filling out and submitting [your personal study plan](https://docs.google.com/document/d/1uCUKu9sZLUSbxsUVobnf8d2EaudXIQxqFpSRhhYE2jU/edit?usp=sharing) 30 | 31 | ## Need to Change your Study Plan? 32 | We expect that most interns will need to adjust their initial study plan. If you are altering any milestones we ask that you update your study plan and fill out the milestone extension form, to give the instructional team awareness of your progress: 33 | [Milestone Extension Form](https://docs.google.com/forms/d/e/1FAIpQLSeBxKIJUhkQ9li3ZOmsSnqlQ38xnBhLEYO8Bnh2CkJkf8i3Ww/viewform?usp=sf_link) 34 | 35 | ## Final Deadline 36 | 37 | All unit work must be submitted to Learn by Friday, July 21st at 11:59 PM. -------------------------------------------------------------------------------- /01-algorithms/07-algorithms-supplemental-resources.md: -------------------------------------------------------------------------------- 1 | # Vocab and Resources 2 | 3 | ## Terms & Definitions 4 | 5 | | Term | Definition | 6 | |--- |--- | 7 | | Dynamic Programming | A dynamic programming algorithm is an algorithmic strategy which solves and stores subproblems which repeatably occur within a larger problem with the goal of using these saved results to optimize a solution to the larger problem. | 8 | | Divide and Conquer | A divide and conquer algorithm tries to solve a large problem by repeatably dividing it into smaller subproblems until the problems become small enough to be solved directly and then combining the results to solve the larger problem. | 9 | | Memoization | In computer science memoization is an optimization technique used to speed up computer programs by storing the results of expensive function calls and saving the results to use when those method calls occur again. | 10 | | Asymptotic Analysis | A mathematical method of examining programs which describes how the program performs as the input size grows. | 11 | | Profiling | In engineering, profiling is a form of analysis which measures the space and time complexities of a program. This tends to be more a practical and statistical analysis as compared to asymptotic analysis. | 12 | 13 | ## Resources 14 | ### Past Video Lessons 15 | The following video lessons are from past cohorts and cover some of the same materials covered in this lesson. Keep in mind some of the material has diverged. 16 | - [Problem Solving Playlist](https://adaacademy.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=0471a830-aa32-4937-bb42-ae4c0144813e) 17 | - [Algorithms (Divide & Conquer, Greedy, & Dynamic Programming)](https://adaacademy.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=2619c3c1-e6d5-48a1-a199-aad7014dcc4e) 18 | 19 | ### Past Slide Decks 20 | - [C16 Algorithms Slides](https://docs.google.com/presentation/d/1V4ycrfl3dbL0IbRHqK3ytU45VyMJQNHhyxpc3Ti2e28/edit?usp=sharing) 21 | 22 | ### External Resources 23 | - [BaseCS: Less Repetition, More Dynamic Programming](https://medium.com/basecs/less-repetition-more-dynamic-programming-43d29830a630) 24 | 25 | -------------------------------------------------------------------------------- /01-algorithms/08-algorithms-activity.md: -------------------------------------------------------------------------------- 1 | # Activity 2 | 3 | ## Newman-Conway Sequence 4 | 5 | We will go over the recursive solution with and without Dynamic Programming in class. 6 | 7 | Afterwards, you will work in groups to complete an iterative solution using Dynamic Programming. 8 | 9 | ### Class Livecode 10 | 11 | Follow along in the following repository as we livecode a recursive solution with and without Dynamic Programming: [Newman-Conway Recursively](https://github.com/Ada-Activities/newman-conway-recursive/) 12 | * Check out the `solution` branch in the repo to see a version of the Livecode implementation 13 | 14 | ### Small Group Work 15 | 16 | - Spend twenty minutes with your breakout room implementing an iterative solution using dynamic programming to the chosen problem using pseudocode or Python. 17 | - One person in the group should fork the repo and share a link with the rest of the group. 18 | - If your entire group is feeling stuck, start by brainstorming what kind of loop you may want to use in your solution. Consider the base cases, how you can add the base cases to the memo (for the memoization) and the end condition for your loop. 19 | - If your entire group is still feeling lost, discuss what is making you feel stuck and ask an instructor to come to your room for help! 20 | - After small group work, we will come back together as a class to work through a solution together. Groups may ask questions, share where they got stuck, and/or share out their solutions. 21 | 22 | Fork the following repo to work on in small groups: [Newman-Conway Iteratively with DP](https://github.com/Ada-Activities/newman-conway-iterative) 23 | * Check out the `solution` branch in the repo to see one version of a working implementation 24 | -------------------------------------------------------------------------------- /01-algorithms/09-algorithms-class-discussion.md: -------------------------------------------------------------------------------- 1 | # Class Discussions 2 | 3 | ## C18 Recordings 4 | The following videos are the live session recordings of C18’s Tigons and Ligers classrooms. Though the same material was taught to the two classes, there may be different questions asked by students in each class. 5 | 6 | ### Ligers 7 | #### Topic Introduction 8 | 9 | 10 | #### Topic Review Session 11 | 12 | 13 | ### Tigons 14 | #### Topic Introduction 15 | 16 | 17 | 18 | 19 | 20 | 21 | #### Topic Review 22 | -------------------------------------------------------------------------------- /01-algorithms/images/MergeSort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/MergeSort.png -------------------------------------------------------------------------------- /01-algorithms/images/algorithmic-strategies_divide-and-conquer_binary-search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/algorithmic-strategies_divide-and-conquer_binary-search.png -------------------------------------------------------------------------------- /01-algorithms/images/algorithmic-strategies_divide-and-conquer_merge-sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/algorithmic-strategies_divide-and-conquer_merge-sort.png -------------------------------------------------------------------------------- /01-algorithms/images/algorithmic-strategies_divide-and-conquer_min-max.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/algorithmic-strategies_divide-and-conquer_min-max.png -------------------------------------------------------------------------------- /01-algorithms/images/algorithmic-strategies_divide-and-conquer_quick-sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/algorithmic-strategies_divide-and-conquer_quick-sort.png -------------------------------------------------------------------------------- /01-algorithms/images/algorithmic-strategies_dynamic-programming_fibonacci-inefficient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/algorithmic-strategies_dynamic-programming_fibonacci-inefficient.png -------------------------------------------------------------------------------- /01-algorithms/images/algorithmic-strategies_dynamic-programming_lcs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/algorithmic-strategies_dynamic-programming_lcs.png -------------------------------------------------------------------------------- /01-algorithms/images/binary-search-ex.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/binary-search-ex.gif -------------------------------------------------------------------------------- /01-algorithms/images/bst-divide-and-conquer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/bst-divide-and-conquer.png -------------------------------------------------------------------------------- /01-algorithms/images/call-stack-non-recursive.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/call-stack-non-recursive.gif -------------------------------------------------------------------------------- /01-algorithms/images/call-stack-sum-zero-to-n.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/call-stack-sum-zero-to-n.gif -------------------------------------------------------------------------------- /01-algorithms/images/coin-change-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/coin-change-example-1.png -------------------------------------------------------------------------------- /01-algorithms/images/coin-change-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/coin-change-example-2.png -------------------------------------------------------------------------------- /01-algorithms/images/contiguous-v-noncontiguous.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/contiguous-v-noncontiguous.png -------------------------------------------------------------------------------- /01-algorithms/images/dijkstras-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/dijkstras-2.png -------------------------------------------------------------------------------- /01-algorithms/images/dijkstras-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/dijkstras-3.png -------------------------------------------------------------------------------- /01-algorithms/images/dijkstras-example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/dijkstras-example.gif -------------------------------------------------------------------------------- /01-algorithms/images/dynamic-sliding-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/dynamic-sliding-window.png -------------------------------------------------------------------------------- /01-algorithms/images/example-zero-sum-subarrays.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/example-zero-sum-subarrays.png -------------------------------------------------------------------------------- /01-algorithms/images/fibonacci.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/fibonacci.png -------------------------------------------------------------------------------- /01-algorithms/images/greedy-choice-property-dijkstra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/greedy-choice-property-dijkstra.png -------------------------------------------------------------------------------- /01-algorithms/images/greedy-mouse-maze-unsuccessful.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/greedy-mouse-maze-unsuccessful.png -------------------------------------------------------------------------------- /01-algorithms/images/greedy-mouse-maze.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/greedy-mouse-maze.png -------------------------------------------------------------------------------- /01-algorithms/images/kadane-Algorithm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/kadane-Algorithm.png -------------------------------------------------------------------------------- /01-algorithms/images/longest-route.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/longest-route.png -------------------------------------------------------------------------------- /01-algorithms/images/min-sum-subarray.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/min-sum-subarray.gif -------------------------------------------------------------------------------- /01-algorithms/images/optimal-path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/optimal-path.png -------------------------------------------------------------------------------- /01-algorithms/images/overlapping-subproblem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/overlapping-subproblem.png -------------------------------------------------------------------------------- /01-algorithms/images/problem-solving__big-o-cheat-sheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/problem-solving__big-o-cheat-sheet.png -------------------------------------------------------------------------------- /01-algorithms/images/problem-solving__call-stack.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
count_up(n)
count_up(n)
count_up(n - 1)
count_up(n - 1)
count_up(n - 2)
count_up(n - 2)
...
...
count_up(1)
count_up(1)
count_up(0)
count_up(0)
Text is not SVG - cannot display
-------------------------------------------------------------------------------- /01-algorithms/images/problem-solving__log-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/problem-solving__log-example.png -------------------------------------------------------------------------------- /01-algorithms/images/problem-solving__sliding-window copy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/problem-solving__sliding-window copy.gif -------------------------------------------------------------------------------- /01-algorithms/images/problem-solving__sliding-window.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/problem-solving__sliding-window.gif -------------------------------------------------------------------------------- /01-algorithms/images/sliding-integer-adjacent-pair-sum.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/sliding-integer-adjacent-pair-sum.gif -------------------------------------------------------------------------------- /01-algorithms/images/sliding-integer-nonadjacent-pair-sum.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/sliding-integer-nonadjacent-pair-sum.gif -------------------------------------------------------------------------------- /01-algorithms/images/sliding-window-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/sliding-window-array.png -------------------------------------------------------------------------------- /01-algorithms/images/sliding-window-integer-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/sliding-window-integer-array.png -------------------------------------------------------------------------------- /01-algorithms/images/sliding-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/sliding-window.png -------------------------------------------------------------------------------- /01-algorithms/images/zero-sum-subarray.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/01-algorithms/images/zero-sum-subarray.gif -------------------------------------------------------------------------------- /02-linked-lists/04-linked-lists-stacks-queues.md: -------------------------------------------------------------------------------- 1 | # Applications of Linked Lists 2 | 3 | 4 | 5 | ## Overview 6 | 7 | Linked lists have a variety of practical applications. Imagine a playlist in your favorite music application. Each song in the playlist is represented by a node in a doubly linked list. We can add new songs onto the end of our playlist in O(1) time. As we listen to our playlist, it is very easy to replay or skip a song using our previous and next pointers. 8 | 9 | We might also imagine the undo and redo functions of a word processor or other software. Each change to our word document is stored in a node in a doubly linked list. We can undo and redo our changes by traversing our list backwards and forwards. 10 | 11 | Linked lists are also prove useful when implementing many other data types that fall into a category called _abstract data types_. 12 | 13 | ## Abstract Data Types 14 | 15 | An _Abstract Data Type_ (ADT), is a type of object which is described by the methods it has and how they perform. Implementation details are not included. You could for example create a `List` class. You can provide methods to add elements and retrieve elements at a given index. The user of your class never needs to know if you used an array or linked list to store the information internally. The class is called _abstract_ because the data structure's description is independent from it's implementation. 16 | 17 | Linked lists are not considered abstract data types, because a key feature of a linked list is that is implemented by linking nodes together in a chain. However, as mentioned previously, linked lists are often used to implement abstract data types. 18 | 19 | Two abstract data types often implemented with linked lists are stacks and queues. Stacks and queues are, like linked lists, ordered linear collections of data. Unlike linked lists, they are described by what they do, rather than how they are implemented. This means that while we might choose to implement stacks and queues with a linked list, we could also choose to implement them with an array. 20 | 21 | ## Stacks 22 | 23 | A stack is a data structure which stores a list of data and only provides access in a Last-In-First-Out (LIFO) order. You've seen stacks before at Ada. When we discussed recursion we noted that function calls are saved on the system stack. This is so the most recent function called is the first function returned to when the current function ends. 24 | 25 | A stack provides the following methods: 26 | 27 | - **push(item)** - This method adds an item to the top of the stack. 28 | - **pop** - This method removes and returns the item on the top of the stack. 29 | - **is_empty** - This method returns true if the stack is empty and false otherwise. 30 | 31 | A stack might also implement a `peek` method which returns, but does not remove the item on top of the stack, and a `size` method which returns the number of items currently on the stack. 32 | 33 | While arrays and linked lists are usually visualized horizontally, stacks tend to be visualized as vertical data structures. We can picture a stack like a stack of plates where new plates can be added and removed from the top, but cannot be removed from the middle or bottom of the structure. 34 | 35 | ![Stack Diagram](images/stack.png) 36 | 37 | ### Implementation of a Stack 38 | 39 | We can use any linear data structure to implement a stack. For example, using a linked list, we could implement a `Stack` class like this: 40 | 41 | ```python 42 | class Stack: 43 | 44 | def __init__(self): 45 | self.store = LinkedList() 46 | 47 | def push(self, item): 48 | self.store.add_first(item) 49 | 50 | def pop(self): 51 | return self.store.remove_first() 52 | 53 | def is_empty(self): 54 | return self.store.length() == 0 55 | ``` 56 | 57 | In the above example `add_first`, `remove_first`, and `length` are all methods belonging to the `LinkedList` class. Linked lists are a popular choice for stack implementations because insertion and deletion, or `push` and `pop` in the case of our stack, are O(1) operations with linked lists. However, because a stack is an ADT, our `Stack` class doesn't _have_ to be implemented with a linked list. We could later change the implementation to use an array, and the users of the class would not need to change any of their code. This is because the implementation is _hidden_ behind a public interface. The top of the stack would reference the last element in the array. 58 | 59 | **Stack ADT** 60 | ![Stack ADT](images/stackADT.png) 61 | 62 | The implementation code in the diagram above could make use of any data structure - a linked list, array, or something else - so long as it implements each stack method to its specification. 63 | 64 | 65 | ## Queues 66 | 67 | A queue unlike a stack operates in a First-In-First-Out (FIFO) order. Like a line of people at a concert, the first element to enter the queue is the first element removed. 68 | 69 | ![Queue Diagram](images/queue.png) 70 | 71 | As shown above elements are added to the back of the queue in an operation called _enqueue_ and removed with an operation called _dequeue_. 72 | 73 | Queues are great for any operation that needs to work with data in a first-in-first-out order. For example some systems have worker processes which can be assigned tasks to work on and these worker processes take on jobs assigned to them in the order they appeared, completing one before taking on the next. 74 | 75 | A Queue provides the following methods: 76 | 77 | - **enqueue(item)** - This method puts an item into the back of the queue. 78 | - **dequeue** - This method removes and returns the item at the front of the queue. 79 | - **is_empty** - This method returns true if the queue is empty and false otherwise. 80 | 81 | ### Queue Implementation Considerations 82 | 83 | Like a stack, a queue can be implemented several ways and the implementation should be hidden from the user. One way would be to implement a queue with a linked list like this: 84 | 85 | ```python 86 | class Queue: 87 | def __init__(self): 88 | self.store = LinkedList() 89 | 90 | def enqueue(self, item): 91 | self.store.add_last(item) 92 | 93 | def dequeue(self): 94 | if self.is_empty(): 95 | return None 96 | 97 | self.store.remove_first() 98 | 99 | def is_empty(self): 100 | return self.store.length() == 0 101 | ``` 102 | 103 | 104 | 105 | 106 | ### !challenge 107 | 108 | * type: multiple-choice 109 | * id: bade61da-8d68-401f-abd1-345fbd38bc4b 110 | * title: Enqueue & Dequeue 111 | * points: 1 112 | * topics: queues, linked lists 113 | 114 | ##### !question 115 | 116 | What would be the Big-O of enqueue and dequeue for the above queue implementation? 117 | 118 | ##### !end-question 119 | 120 | ##### !options 121 | 122 | * O(1) 123 | * O(log n) 124 | * O(n log n) 125 | * O(n^2) 126 | * It depends 127 | 128 | ##### !end-options 129 | 130 | ##### !answer 131 | 132 | * It depends 133 | 134 | ##### !end-answer 135 | 136 | 137 | ##### !hint 138 | 139 | Do all LinkedList implementation have the same time complexity for add_last and remove_first? Do we know the internal implementation of the LinkedList class? 140 | 141 | ##### !end-hint 142 | 143 | ##### !explanation 144 | 145 | If the Linked List has a tail reference and is a doubly linked list, then both enqueue and dequeue can be done in O(1) time. If there is no tail reference then enqueue should perform in O(n) time. 146 | 147 | ##### !end-explanation 148 | 149 | ### !end-challenge 150 | 151 | 152 | 153 | 154 | ### !challenge 155 | 156 | * type: paragraph 157 | * id: 44b75a3a-ebb1-4b05-ba0e-39ecf8675e7e 158 | * title: Why might we prefer to implement a queue with a linked list instead of an array? 159 | * points: 1 160 | 161 | ##### !question 162 | 163 | Why might we prefer to implement a queue with a linked list instead of an array? 164 | 165 | ##### !end-question 166 | 167 | ##### !placeholder 168 | 169 | 170 | 171 | ##### !end-placeholder 172 | 173 | 174 | 175 | ##### !explanation 176 | With a doubly linked list that maintains a tail pointer, we can enqueue and dequeue elements from the queue in O(1) time. With an array, recall that inserting or removing an element of an array can be expensive as all items after the item inserted or removed need to be shifted over by 1. 177 | 178 | ##### !end-explanation 179 | 180 | ### !end-challenge 181 | 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /02-linked-lists/05-linked-lists-supplemental-concepts.md: -------------------------------------------------------------------------------- 1 | # Supplemental Concepts & Resources 2 | 3 | 4 | 5 | ## Pointers & References 6 | 7 | You will often hear the terms _pointer_ and _reference_ in relation to dynamic data structures like linked lists. Both terms refer to a variable which **points** to data in memory, or holds the address of another variable in memory. The concept is similar to a home. The home is an object in memory, while the home's address is a _reference_ which indicates where to find the home. 8 | 9 | In some languages like C/C++ you can manipulate memory addresses and memory directly. In other languages, like Python, you have references which refer to objects in memory, but you cannot directly work with the memory addresses. 10 | 11 | An example in C++: 12 | 13 | ```c++ 14 | int x = 5; // declare an integer variable x which is assigned value 5 15 | int* ptr_x; // declare a variable ptr_x which will be assigned 16 | // the memory address of an integer variable 17 | ptr_x = &x; // Assign ptr_x the value of the memory address of x. 18 | ``` 19 | 20 | We use references in Python whenever we use a linked list since each node _refers_ to the next node in the chain and `head` refers to the first node in the chain. 21 | 22 | ![Singly Linked List](images/singly-linked-list2.png) 23 | 24 | ## Memory Leaks 25 | 26 | A **memory leak** is a bug resulting from how a program manages memory. A _memory leak_ occurs when memory that is no longer needed by the program is not released back to the operating system. Over time, if memory is used and not returned to the system, less and less memory is available to other programs to use. Eventually, there will not be enough available memory for applications to use. When a program ends, modern operating systems will return all memory allocated to that program back to the operating system itself. For this reason, most memory leaks today occur in long-running processes like [daemons](https://www.techtarget.com/whatis/definition/daemon). 27 | 28 | In Python, the Python interpreter manages memory for developers. Python uses a [garbage collection](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)) system which identifies memory no longer used by the application and returns it. 29 | 30 | Consider when a node is removed from a Linked List: 31 | 32 | ![Removing a node](images/linked-list-remove-node.png) 33 | 34 | 35 | When there is no longer a variable to reference a given node, for example `node.next` no longer references the node with value 98320 in the image above, the Python garbage collector eventually returns the memory used to store node 98320 to the operating system. 36 | 37 | 38 | ```python 39 | def remove_first(self): 40 | if not self.head: 41 | return False 42 | 43 | value = self.head.value 44 | self.head = self.head.next 45 | 46 | return value 47 | ``` 48 | 49 | Other languages place memory management on the developer. C is one such language. These lower-level languages give a developer more flexibility and control over low-level operations at the cost of more responsibility and a greater likelihood of errors. 50 | 51 | Removing a Node from a Linked List in C 52 | 53 | ```c 54 | void removeFirst(struct node **headRef) { 55 | if (*head != NULL) { 56 | struct node* temp = *head; 57 | int value = (*temp)->value; 58 | head = (*head)->next; 59 | free(temp); // <-- Give back memory to the OS 60 | return value; 61 | } 62 | } 63 | ``` 64 | 65 | ## Resources 66 | - [Past Linked List Video Lessons](https://adaacademy.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=b1664c7e-f95e-40f5-971f-ad9000fe85d8) 67 | - [Past Stacks & Queues Video Lessons (in depth)](https://adaacademy.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=b987fd8f-b63c-479a-a679-ad93018aecaa) 68 | - [Past Slide Deck Used](https://docs.google.com/presentation/d/1lJ8WJnA6qRlHAIaRAjim3kiL4nRBWT5qvFGQQIB4EL4/edit?usp=sharing) 69 | - [Linked Lists from Geeks for Geeks](https://www.geeksforgeeks.org/data-structures/linked-list/) - Lots of articles & practice problems 70 | - [Stanford Linked List Basics](http://cslibrary.stanford.edu/103/LinkedListBasics.pdf) 71 | -------------------------------------------------------------------------------- /02-linked-lists/06-linked-list-activity.md: -------------------------------------------------------------------------------- 1 | # Activity 2 | 3 | ## Rotate a Linked List 4 | 5 | We will go over the driving function in class. 6 | 7 | Afterwards, you will work in groups to fill out the helper functions used in the driving function. Tests are added to the repo to help you test if your helper functions work correctly. 8 | 9 | ### Class Livecode 10 | 11 | Follow along in the following repo as we livecode the driving function in class: 12 | * [Rotate Linked List Livecode Start](https://github.com/Ada-Activities/rotate_linked_lists) 13 | * Check out the `solution` branch in the repo to see a completed implementation of both the livecode and activity 14 | 15 | 16 | ### Small Group Work 17 | 18 | - Spend twenty minutes with your breakout room implementing a solution to the two helper functions using pseudocode or Python. 19 | - One person in the group should fork the repo and share a link with the rest of the group. 20 | - If your entire group is feeling stuck, start by discussing how you would solve the helper functions using pen and paper. 21 | - If your entire group is still feeling lost, discuss what is making you feel stuck and ask an instructor to come to your room for help! 22 | - After small group work, we will come back together as a class to work through a solution together, as time allows. Groups may ask questions, share where they got stuck, and/or share out their solutions. 23 | 24 | Fork the following repo to work on in small groups: [Rotate Linked List w/ Helpers](https://github.com/Ada-Activities/rotate_linked_lists) 25 | * Check out the `solution` branch in the repo to see a completed implementation of both the livecode and activity 26 | -------------------------------------------------------------------------------- /02-linked-lists/07-linked-lists-class-discussions.md: -------------------------------------------------------------------------------- 1 | # Class Discussions 2 | 3 | ## C18 Recordings 4 | The following videos are the live session recordings of C18’s Tigons and Ligers classrooms. Though the same material was taught to the two classes, there may be different questions asked by students in each class. 5 | 6 | ### Ligers 7 | #### Topic Introduction 8 | 9 | 10 | 11 | 12 | 13 | 14 | #### Topic Review Session 15 | 16 | 17 | ### Tigons 18 | #### Topic Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | #### Topic Review 26 | -------------------------------------------------------------------------------- /02-linked-lists/autoconfig.yaml: -------------------------------------------------------------------------------- 1 | # This file is auto-generated and orders your content based on the file structure of your repo. 2 | # Do not edit this file; it will be replaced the next time you run the preview command. 3 | 4 | # To manually order the contents of this curriculum rather than using the auto-generated file, 5 | # include a config.yaml in your repo following the same conventions as this auto-generated file. 6 | # A user-created config.yaml will have priority over the auto-generated one. 7 | 8 | -------------------------------------------------------------------------------- /02-linked-lists/class-lesson.instructor.md: -------------------------------------------------------------------------------- 1 | # Instructor Notes 2 | 3 | Linked Lists are a core learning concept in computer science and a common interview question. 4 | 5 | ## Lesson Goals 6 | 7 | We want students to: 8 | 9 | - Get comfortable using ListNodes 10 | - Using them to traverse a list 11 | - Manipulating them to add and remove nodes 12 | - Identify the time complexity of methods involving linked lists 13 | 14 | ## Lesson Introduction - 30 minutes 15 | 16 | Start off the lesson by welcoming students to the class and note attendance. You can use the Google Form The [C17 Attendance Tracking](https://forms.gle/UcN9UnhMjeKve6SB6) is linked. 17 | 18 | Given that this is the first CS Fundamentals session, spend some time motivating CS Fundamentals content (how does it assist their job search and complement internship learning?) and going over logistics - attendance, feedback, learning plans, etc. 19 | 20 | ## Problem Set Review - 45 mintues 21 | 22 | 23 | Conduct a problem set review. Students can ask general questions about lesson content as well as request review of specific problems in the problem set. 24 | 25 | Then follow the 1st part of the [activity](./06-linked-list-activity.md) reviewing where linked lists are useful (when you need to add/remove to the front/rear of a list). 26 | 27 | ## Livecode - 20 minutes 28 | 29 | In the livecode walk through: 30 | 31 | 1. Merge Sorted Lists from the text lesson 32 | 1. Setup the project and write 2 methods 33 | 34 | Remember to: 35 | 36 | - Try to get students to navigate as you type. 37 | - Cause a bug, and try to promote student ideas to fix it. 38 | - Model how to use the tests and print statements. 39 | 40 | ## Coding Activity - 40 minutes 41 | 42 | Break students into breakout rooms to practice the replit. Optionally you can complete one exercise as a class before breaking the remainder into groups. 43 | 44 | Iterate through the breakout rooms answering questions as you go. 45 | 46 | ## Solution Examples 47 | 48 | You can find a solution in [Chris' Replit](https://replit.com/@ChrisMcAnally/List-Practice-Solution#). 49 | 50 | *Code Snippet: is_palindrome* 51 | ```py 52 | from typing import Optional 53 | 54 | class ListNode: 55 | def __init__(self, value, next = None): 56 | self.value = value 57 | self.next = next 58 | def __repr__(self): 59 | return f"ListNode({self.value})" 60 | 61 | def transform_to_doubly_linked_list(head: ListNode): 62 | previous = None 63 | current = head 64 | while current is not None: 65 | current.previous = previous 66 | previous = current 67 | current = current.next 68 | 69 | return previous 70 | 71 | def is_palindrome(head: Optional[ListNode]) -> bool: 72 | if head is None: 73 | return True 74 | 75 | tail = transform_to_doubly_linked_list(head) 76 | 77 | while (head != tail): 78 | if head.value != tail.value: 79 | return False 80 | head = head.next 81 | tail = tail.previous 82 | 83 | return True 84 | ``` 85 | 86 | *Code Snippet: Rotate Linked List* 87 | 88 | ```py 89 | 90 | class ListNode: 91 | def __init__(self, value, next = None): 92 | self.value = value 93 | self.next = next 94 | 95 | def add_first(head: ListNode, node: ListNode): 96 | node.next = head 97 | return node 98 | 99 | def find_last_and_second_to_last(head: ListNode) -> ListNode: 100 | previous = None 101 | current = head 102 | 103 | while current.next is not None: 104 | previous = current 105 | current = current.next 106 | 107 | return (previous, current) 108 | 109 | def rotate_list(head: ListNode, k: int) -> ListNode: 110 | 111 | if head is None: 112 | return None 113 | if k < 0: 114 | raise ValueError("k must be positive") 115 | elif k == 0 or head.next is None: 116 | return head 117 | 118 | for i in range(k): 119 | (new_tail, tail) = find_last_and_second_to_last(head) 120 | 121 | new_tail.next = None 122 | head = add_first(head, tail) 123 | 124 | return head 125 | ``` 126 | ### !callout-secondary 127 | 128 | ## This isn't efficient 129 | 130 | This is **not** an efficient solution. To do this more efficiently (not O(nk) time), we would potentially need to transform this into a doubly linked list or copy it into an array, or calculate the length of the list and a way to rotate in reverse to get a similar outcome. 131 | 132 | ### !end-callout 133 | 134 | 135 | *Code Snippet: Has Cycle* 136 | ```py 137 | def has_cycle(head: Optional[ListNode]) -> bool: 138 | if not head: 139 | return False 140 | 141 | current = head 142 | trailing = head 143 | 144 | while current: 145 | current = current.next 146 | if current: 147 | current = current.next 148 | trailing = trailing.next 149 | 150 | if current and current == trailing: 151 | return True 152 | return False 153 | 154 | ``` 155 | 156 | 157 | -------------------------------------------------------------------------------- /02-linked-lists/images/add-first-step-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/add-first-step-0.png -------------------------------------------------------------------------------- /02-linked-lists/images/add-first-step-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/add-first-step-1.png -------------------------------------------------------------------------------- /02-linked-lists/images/add-first-step-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/add-first-step-2.png -------------------------------------------------------------------------------- /02-linked-lists/images/add-first-step-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/add-first-step-3.png -------------------------------------------------------------------------------- /02-linked-lists/images/archive/add-first-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/archive/add-first-1.png -------------------------------------------------------------------------------- /02-linked-lists/images/archive/add-first-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/archive/add-first-2.png -------------------------------------------------------------------------------- /02-linked-lists/images/archive/add-first-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/archive/add-first-3.png -------------------------------------------------------------------------------- /02-linked-lists/images/archive/add-first-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/archive/add-first-4.png -------------------------------------------------------------------------------- /02-linked-lists/images/archive/array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/archive/array.png -------------------------------------------------------------------------------- /02-linked-lists/images/archive/nodeLinkedList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/archive/nodeLinkedList.png -------------------------------------------------------------------------------- /02-linked-lists/images/archive/singly-linked-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/archive/singly-linked-list.png -------------------------------------------------------------------------------- /02-linked-lists/images/array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/array.png -------------------------------------------------------------------------------- /02-linked-lists/images/call-stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/call-stack.png -------------------------------------------------------------------------------- /02-linked-lists/images/dot-notation-ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/dot-notation-ex.png -------------------------------------------------------------------------------- /02-linked-lists/images/doubly-linked-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/doubly-linked-list.png -------------------------------------------------------------------------------- /02-linked-lists/images/head-unconnected-node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/head-unconnected-node.png -------------------------------------------------------------------------------- /02-linked-lists/images/linked-list-remove-node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/linked-list-remove-node.png -------------------------------------------------------------------------------- /02-linked-lists/images/linked-list-search.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/linked-list-search.gif -------------------------------------------------------------------------------- /02-linked-lists/images/linkedlist.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
head
head
tail
tail
Text is not SVG - cannot display
-------------------------------------------------------------------------------- /02-linked-lists/images/memory-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/memory-layout.png -------------------------------------------------------------------------------- /02-linked-lists/images/node-linked-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/node-linked-list.png -------------------------------------------------------------------------------- /02-linked-lists/images/queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/queue.png -------------------------------------------------------------------------------- /02-linked-lists/images/remove-node-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/remove-node-1.png -------------------------------------------------------------------------------- /02-linked-lists/images/remove-node-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/remove-node-2.png -------------------------------------------------------------------------------- /02-linked-lists/images/remove-node-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/remove-node-3.png -------------------------------------------------------------------------------- /02-linked-lists/images/remove-node-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/remove-node-4.png -------------------------------------------------------------------------------- /02-linked-lists/images/remove.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/remove.gif -------------------------------------------------------------------------------- /02-linked-lists/images/singly-linked-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/singly-linked-list.png -------------------------------------------------------------------------------- /02-linked-lists/images/singly-linked-list2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/singly-linked-list2.png -------------------------------------------------------------------------------- /02-linked-lists/images/stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/stack.png -------------------------------------------------------------------------------- /02-linked-lists/images/stackADT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/stackADT.png -------------------------------------------------------------------------------- /02-linked-lists/images/two-nodes-singly-linked-list-updated-value.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/two-nodes-singly-linked-list-updated-value.png -------------------------------------------------------------------------------- /02-linked-lists/images/two-nodes-singly-linked-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/two-nodes-singly-linked-list.png -------------------------------------------------------------------------------- /02-linked-lists/images/vars-replace-dot-notation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/02-linked-lists/images/vars-replace-dot-notation.png -------------------------------------------------------------------------------- /02-linked-lists/linked-lists.instructor.md: -------------------------------------------------------------------------------- 1 | # Instructor: Project Solution 2 | 3 | ## Simon's Final Implementation 4 | 5 | Simon's implementations for the stubbed `LinkedList` class in the lesson. 6 | 7 | ```python 8 | # Defines a node in the singly linked list 9 | class Node: 10 | def __init__(self, value): 11 | self.data = value 12 | self.next = None 13 | ``` 14 | 15 | ```python 16 | # Defines the singly linked list 17 | class LinkedList: 18 | def __init__(self): 19 | self.head = None 20 | 21 | # Method. Adds a new node with the specific data value to the beginning of the linked list. 22 | def add_first(self, value): 23 | new_node = Node(value) 24 | new_node.next = self.head 25 | self.head = new_node 26 | 27 | # Method. Returns the value in the first node in the linked list. 28 | # Returns None if the list is empty. 29 | def get_first(self): 30 | return self.head.data if self.head else None 31 | 32 | # Method. Returns the value of the last node in the linked list. Returns None if the list is empty. 33 | def get_last(self): 34 | # Return None if the list is empty 35 | # Otherwise, traverse the list to the end 36 | # Then return the last node's value 37 | current_node = self.head 38 | while current_node: 39 | if not current_node.next: 40 | return current_node 41 | current_node = current_node.next 42 | 43 | def add_last(self, value): 44 | new_node = Node(value) 45 | last_node = self.get_last() 46 | if not last_node: 47 | self.head = new_node 48 | else: 49 | last_node.next = new_node 50 | 51 | # Method. Returns the value at a given index in the linked list. 52 | # Index count starts at 0. 53 | # Returns None if there are fewer nodes in the linked list than the index value. 54 | def get_at_index(self, index): 55 | # Traverse the list 56 | # times 57 | # or until the end is reached 58 | # Then return the current node's value 59 | current_node = self.head 60 | for i in range(index + 1): 61 | if i == index: 62 | return current_node.data 63 | if current_node.next is None: 64 | return None 65 | current_node = current_node.next 66 | ``` 67 | -------------------------------------------------------------------------------- /03-Binary-Search-Trees/05-Binary-Search-Trees-Activity.md: -------------------------------------------------------------------------------- 1 | # Livecode & Activity 2 | 3 | ## Height of a Binary Search Tree 4 | 5 | We will go over how to implement a recursive height function for Binary Search Trees as a class. 6 | 7 | ### Class Livecode 8 | 9 | Follow along in the following repo as we livecode the function in class: 10 | * [BST Height Livecode Start](https://github.com/Ada-Activities/bst-height-livecode) 11 | * Check out the `solution` branch in the repo to see a version of the Livecode implementation 12 | 13 | 14 | ### Small Group Work: Kth Smallest Element 15 | 16 | For your small group activity, you will work on implementing 'Kth Smallest Element' which returns the Kth smallest element in a BST given the `root` of the tree and `k`. 17 | 18 | - Spend twenty minutes with your breakout room implementing a solution. 19 | - One person in the group should fork the repo and share a link with the rest of the group. 20 | - If your entire group is feeling stuck, start by discussing how you would solve the function using pen and paper. 21 | - If your entire group is still feeling lost, discuss what is making you feel stuck and ask an instructor to come to your room for help! 22 | - After small group work, we will come back together as a class to work through a solution together, as time allows. Groups may ask questions, share where they got stuck, and/or share out their solutions. 23 | 24 | Fork the following repo to work on in small groups: [Kth Smallest Element in BST](https://github.com/Ada-Activities/bst-kth-smallest) 25 | * Check out the `solution` branch in the repo to see one version of a working implementation -------------------------------------------------------------------------------- /03-Binary-Search-Trees/06-Binary-Search-Trees-Class-Discussions.md: -------------------------------------------------------------------------------- 1 | # Class Discussions 2 | 3 | ## C18 Recordings 4 | The following videos are the live session recordings of C18’s Tigons and Ligers classrooms. Though the same material was taught to the two classes, there may be different questions asked by students in each class. 5 | 6 | ### Ligers 7 | #### Topic Introduction 8 | 9 | 10 | 11 | 12 | 13 | 14 | #### Topic Review Session 15 | 16 | 17 | ### Tigons 18 | #### Topic Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | #### Topic Review 26 | -------------------------------------------------------------------------------- /03-Binary-Search-Trees/autoconfig.yaml: -------------------------------------------------------------------------------- 1 | # This file is auto-generated and orders your content based on the file structure of your repo. 2 | # Do not edit this file; it will be replaced the next time you run the preview command. 3 | 4 | # To manually order the contents of this curriculum rather than using the auto-generated file, 5 | # include a config.yaml in your repo following the same conventions as this auto-generated file. 6 | # A user-created config.yaml will have priority over the auto-generated one. 7 | 8 | -------------------------------------------------------------------------------- /03-Binary-Search-Trees/bst.instructor.md: -------------------------------------------------------------------------------- 1 | # Instructor BST Solution 2 | 3 | ```python 4 | class TreeNode: 5 | def __init__(self, key, val = None): 6 | if val == None: 7 | val = key 8 | 9 | self.key = key 10 | self.value = val 11 | self.left = None 12 | self.right = None 13 | 14 | 15 | class Tree: 16 | def __init__(self): 17 | self.root = None 18 | 19 | def add_helper(self, current_node, new_node): 20 | if new_node.key < current_node.key: 21 | if not current_node.left: 22 | current_node.left = new_node 23 | return 24 | self.add_helper(current_node.left, new_node) 25 | else: 26 | if not current_node.right: 27 | current_node.right = new_node 28 | return 29 | self.add_helper(current_node.right, new_node) 30 | 31 | # Time Complexity: O(log n) 32 | # Space Complexity: O(log n) (recursive, the iterative solution is O(1)). 33 | def add(self, key, value = None): 34 | if not self.root: 35 | self.root = TreeNode(key, value) 36 | else: 37 | new_node = TreeNode(key, value) 38 | self.add_helper(self.root, new_node) 39 | 40 | # Time Complexity: O(log n) 41 | # Space Complexity: O(1) 42 | def find(self, key): 43 | current = self.root 44 | 45 | while current: 46 | if current.key == key: 47 | return current.value 48 | elif key < current.key: 49 | current = current.left 50 | else: 51 | current = current.right 52 | 53 | return None 54 | 55 | def inorder_helper(self, current_node, values): 56 | if not current_node: 57 | return values 58 | 59 | self.inorder_helper(current_node.left, values) 60 | values.append({ 61 | "key": current_node.key, 62 | "value": current_node.value 63 | }) 64 | self.inorder_helper(current_node.right, values) 65 | 66 | return values 67 | 68 | # Time Complexity: O(n) 69 | # Space Complexity: O(n) 70 | def inorder(self): 71 | values = [] 72 | return self.inorder_helper(self.root, values) 73 | 74 | def preorder_helper(self, current_node, values): 75 | if not current_node: 76 | return values 77 | 78 | values.append({ 79 | "key": current_node.key, 80 | "value": current_node.value 81 | }) 82 | self.preorder_helper(current_node.left, values) 83 | self.preorder_helper(current_node.right, values) 84 | 85 | return values 86 | 87 | # Time Complexity: O(n) 88 | # Space Complexity: O(n) 89 | def preorder(self): 90 | values = [] 91 | return self.preorder_helper(self.root, values) 92 | 93 | def postorder_helper(self, current_node, values): 94 | if not current_node: 95 | return values 96 | 97 | self.postorder_helper(current_node.left, values) 98 | self.postorder_helper(current_node.right, values) 99 | values.append({ 100 | "key": current_node.key, 101 | "value": current_node.value 102 | }) 103 | 104 | return values 105 | 106 | # Time Complexity: O(n) 107 | # Space Complexity: O(n) 108 | def postorder(self): 109 | values = [] 110 | return self.postorder_helper(self.root, values) 111 | 112 | def height_helper(self, current_node): 113 | if not current_node: 114 | return 0 115 | 116 | return max(self.height_helper(current_node.left), self.height_helper(current_node.right)) + 1 117 | 118 | # Time Complexity: O(h) or O(n) if the tree is unbalanced and O(log n) if balanced 119 | # Space Complexity: O(h) or O(n) if the tree is unbalanced and O(log n) if balanced 120 | def height(self): 121 | return self.height_helper(self.root) 122 | 123 | 124 | # # Optional Method 125 | # # Time Complexity: O(n) 126 | # # Space Complexity: O(n) 127 | def bfs(self): 128 | values = [] 129 | queue = [] 130 | if self.root: 131 | queue.append(self.root) 132 | 133 | 134 | 135 | while len(queue) > 0: 136 | current_node = queue.pop(0) 137 | if current_node.left: 138 | queue.append(current_node.left) 139 | if current_node.right: 140 | queue.append(current_node.right) 141 | 142 | values.append({ 143 | "key": current_node.key, 144 | "value": current_node.value, 145 | }) 146 | 147 | 148 | return values 149 | 150 | 151 | 152 | 153 | # # Useful for printing 154 | def to_s(self): 155 | return f"{self.inorder()}" 156 | ``` -------------------------------------------------------------------------------- /03-Binary-Search-Trees/class-lesson.instructor.md: -------------------------------------------------------------------------------- 1 | # Lesson Plan 2 | 3 | Binary Search Trees and trees in general are a core learning concept in computer science and a common interview question. This unit compromises focusing on BSTs in particular and just introduces trees in general. This is to support interviewing and give students a start with more advanced data structures. 4 | 5 | In prior years more general tree information was presented, but it was knowledge-level material that was not relevant to interviews and was difficult to retain. So this unit focuses on hands-on work with BSTs. 6 | 7 | Also the project does not involve removing an element from a tree. It was removed to improve the submission rate on the project as this is the 1st really hard project. Instead that's the livecode. 8 | 9 | ## Lesson Goals 10 | 11 | We want students to: 12 | 13 | - Get comfortable with TreeNodes 14 | - Write code to add, and find nodes to a tree 15 | - Manipulating them to add and find nodes in a tree 16 | - Conduct traversals on a tree 17 | - Write recursive code 18 | - Identify the time complexity of methods involving BSTs 19 | 20 | ## Review Linked Lists Project - 10 minutes 21 | 22 | Start off the lesson by welcoming students to the class and note attendance. You can use the Airtable to record attendance The [C16 Airtable](https://airtable.com/appkfPQ769uxQLSei/tbl6oiA8ZG1wKUonM/viwgf4wesbLFMlg1L?blocks=hide) is linked. 23 | 24 | Take a moment to review any questions from Linked Lists and allow students to present their solutions. 25 | 26 | ### !callout-info 27 | 28 | ## Students may not want to do this 29 | 30 | Students can be a bit shy, but you can contact specific students ahead of time asking them to be ready to present, "because you find their solution interesting." Being prepared helps with student confidence. 31 | 32 | ### !end-callout 33 | 34 | ## BST Review 35 | 36 | Do a problem set review for any challenge questions posed in [Ordered Collections of Data](./01-Ordered-Collections-Of-Data.md), [BST Implementation](./02-Binary-Search-Trees.md), [Balancing](./03-Binary-Search-Trees-Height-Big-O.md), and [Serialization](./04-Binary-Search-Trees-Traversal.md) 37 | 38 | Focus on space complexity of recursive implementations vs iterative solutions, strategies for implementing recursive solutions and why recursion can still be useful given the bigger space complexity, and DFS/BFS. 39 | 40 | Part of the goal of this lesson is to set them up to understand graphing algorithms, particularly DFS and BFS. 41 | git restore 42 | Specifically reinforce: 43 | 44 | - BSTs are great when order needs to be maintained with good insertion, deletion, and lookup times. 45 | 46 | ## Livecode - 20 minutes 47 | 48 | In the livecode walk through breadth first search. 49 | 50 | Remember to: 51 | 52 | - Try to get students to navigate as you type. 53 | - Cause a bug, and try to promote student ideas to fix it. 54 | - Model how to use the tests and print statements. 55 | 56 | ## Coding Activity - 40 minutes 57 | 58 | Break students into breakout rooms to practice depth first search traversals. Optionally you can talk through some pseudocode before students start working. 59 | 60 | Iterate through the breakout rooms answering questions as you go. 61 | 62 | ## Solution Examples 63 | 64 | Solutions: 65 | - [Solution to DFS activity is in the `solution` branch](https://github.com/Ada-Activities/bst-dfs-practice) -------------------------------------------------------------------------------- /03-Binary-Search-Trees/image-archive/TreeVocabulary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/image-archive/TreeVocabulary.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/image-archive/linked-list-vocab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/image-archive/linked-list-vocab.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/Binary-Search-Trees__find-value.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/Binary-Search-Trees__find-value.gif -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/Binary-search-trees__insert-into-tree.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/Binary-search-trees__insert-into-tree.gif -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/TreeVocabulary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/TreeVocabulary.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/adding-sorted-array-element.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/adding-sorted-array-element.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/balanced-bst.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/balanced-bst.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/bfs-example-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/bfs-example-tree.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/binary-expression-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/binary-expression-tree.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/bst-bfs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/bst-bfs.gif -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/bst-find.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/bst-find.gif -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/bst2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/bst2.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/bst3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/bst3.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/deleting-array-element.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/deleting-array-element.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/inorder.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/inorder.gif -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/linked-list-vocab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/linked-list-vocab.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/postorder.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/postorder.gif -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/preorder.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/preorder.gif -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/tree-vocabulary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/tree-vocabulary.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/tree-vs-linked-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/tree-vs-linked-list.png -------------------------------------------------------------------------------- /03-Binary-Search-Trees/images/unbalanced-bst.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/03-Binary-Search-Trees/images/unbalanced-bst.png -------------------------------------------------------------------------------- /04-graphs/02-representing-graphs.md: -------------------------------------------------------------------------------- 1 | # Representing Graphs Practice 2 | 3 | 4 | 5 | 6 | ## Graphs and Technical Interviews 7 | 8 | Graph questions are very common in technical interviews. One of the first challenges when we encounter a graph problem, is understanding how the problem is choosing to represent graphs. Feeling comfortable navigating each of the graph representations discussed in the previous lesson can help. Answer the following questions to help familiarize yourself with each graph representation. 9 | 10 | 11 | ### !callout-info 12 | 13 | ## Alternative Representations 14 | 15 | Some technical interview questions can be considered graph questions, but do not provide any of the representations (list of edges, adjacency matrix, adjacency list) discussed in this lesson. Handling these cases will be discussed further on in this course. 16 | 17 | ### !end-callout 18 | 19 | 20 | 21 | 22 | ### !challenge 23 | 24 | * type: multiple-choice 25 | * id: 19d55927-ee3a-47af-8888-ac2b7aaf3dd2 26 | * title: Representing a Graph with a List of Edges 27 | * points: 0 28 | 29 | ##### !question 30 | 31 | Which list of edges represents the graph shown in the diagram below? Assume the graph is undirected. 32 | 33 | ![Graph representing list of edges](images/graph_2.png) 34 | 35 | ##### !end-question 36 | 37 | ##### !options 38 | 39 | a| ```py 40 | [ 41 | [0, 2], 42 | [1, 3], 43 | [2, 3] 44 | ] 45 | ``` 46 | b| ```py 47 | [ 48 | [0, 3], 49 | [0, 1], 50 | [1, 4] 51 | ] 52 | ``` 53 | c| ```py 54 | [ 55 | [0, 3], 56 | [0, 1], 57 | [1, 4], 58 | [1, 3] 59 | ] 60 | ``` 61 | d| ```py 62 | [ 63 | [0, 3], 64 | [0, 1], 65 | [1, 2], 66 | [1, 4] 67 | ] 68 | ``` 69 | 70 | ##### !end-options 71 | 72 | ##### !answer 73 | 74 | d| 75 | 76 | ##### !end-answer 77 | 78 | ### !explanation 79 | Answer D is the correct answer because all of the edges in the graph are represented and correspond correctly to the edges in the graph. 80 | 81 | [0, 3] indicates the edge from node 0 to node 3. 82 | [0, 1] indicates the edge from node 0 to node 1. 83 | [1, 2] indicates the edge from node 1 to node 2. 84 | [1, 4] indicates the edge from node 1 to node 4. 85 | 86 | ### !end-explanation 87 | 88 | ### !end-challenge 89 | 90 | 91 | 92 | 93 | 94 | 95 | ### !challenge 96 | 97 | * type: multiple-choice 98 | * id: ccc3faa5-049d-4dd4-b751-95462a565098 99 | * title: Representing a graph with an adjacency matrix 100 | * points: 0 101 | 102 | ##### !question 103 | 104 | Which adjacency matrix represents the graph shown in the diagram below? Assume the graph is undirected. 105 | 106 | ![Graph representing adjacency matrix](images/graph_1.png) 107 | 108 | Assume the letters are mapped to the following indices: 109 | * A -> 0 110 | * B -> 1 111 | * C -> 2 112 | * D -> 3 113 | * F -> 4 114 | * Z -> 5 115 | 116 | #### Option A 117 | ![Adjacency Matrix A](images/adj_matrix_2.png) 118 | 119 | #### Option B 120 | ![Adjacency Matrix B](images/adj_matrix_1.png) 121 | 122 | #### Option C 123 | ![Adjacency Matrix C](images/adj_matrix_3.png) 124 | 125 | ##### !end-question 126 | 127 | ##### !options 128 | 129 | a| Option A 130 | b| Option B 131 | c| Option C 132 | 133 | ##### !end-options 134 | 135 | ##### !answer 136 | 137 | b| 138 | 139 | ##### !end-answer 140 | 141 | ##### !explanation 142 | 143 | Option B is the correct answer because the edges in the graph are all represented in the adjacency matrix. 144 | 145 | For instance: 146 | 147 | Row A, column C (Matrix[A][C]) is true because there exists an edge between node A and node C. Similarly, row C, column A (Matrix[C][A]) is true because of the same edge. 148 | 149 | Each cell containing true denotes an edge between the corresponding nodes. 150 | 151 | Row Z is all false because node Z does not share an edge with any other node. 152 | 153 | ##### !end-explanation 154 | 155 | ### !end-challenge 156 | 157 | 158 | 159 | 160 | 161 | 162 | ### !challenge 163 | 164 | * type: multiple-choice 165 | * id: af6eb70d-b02c-4f2b-ae39-d945d97076e1 166 | * title: Representing a graph with an adjacency dictionary 167 | * points: 0 168 | 169 | ##### !question 170 | 171 | Which graph is represented by the following adjacency dictionary? 172 | 173 | ```py 174 | adjacency_dict = { 175 | "Seattle": ["Portland"], 176 | "Portland": ["Dallas", "Seattle"], 177 | "Detroit": ["Dallas"], 178 | "Dallas": ["Boston", "Detroit", "Portland"], 179 | "Boston": ["Dallas"] 180 | } 181 | ``` 182 | 183 | #### Option A 184 | ![Graph A](images/graph_a.png) 185 | 186 | #### Option B 187 | ![Graph B](images/graph_b.png) 188 | 189 | #### Option C 190 | ![Graph C](images/graph_c.png) 191 | 192 | ##### !end-question 193 | 194 | ##### !options 195 | 196 | a| Option A 197 | b| Option B 198 | c| Option C 199 | 200 | ##### !end-options 201 | 202 | ##### !answer 203 | 204 | a| 205 | 206 | ##### !end-answer 207 | 208 | ##### !explanation 209 | 210 | Option A is correct because the nodes/edges in the adjacency dictionary correspond with the nodes and edges in the graph. 211 | 212 | For instance: 213 | 214 | * Seattle is connected to only one city: Portland 215 | * Portland is connected to Dallas and Seattle 216 | * Dallas is connected to Boston, Detroit, and Portland 217 | * Detroit is connected to Dallas 218 | * Boston is connected to Dallas 219 | 220 | ##### !end-explanation 221 | 222 | ### !end-challenge 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | ### !challenge 232 | 233 | * type: multiple-choice 234 | * id: 596fa6a0-9144-4078-b672-e4e575939743 235 | * title: Representing a weighted, directed graph 236 | * points: 1 237 | 238 | 239 | ##### !question 240 | 241 | Which of the following options represents the following graph? 242 | 243 | ![Weighted Directed Graph](images/representing-weighted-directed-graph-challenge.png) 244 | 245 | ##### !end-question 246 | 247 | ##### !options 248 | 249 | a| 250 | ```python 251 | list_of_edges = [ 252 | [0, 1, 5], 253 | [1, 2, 10], 254 | [0, 2, 2] 255 | ] 256 | ``` 257 | b| 258 | ```python 259 | adj_matrix = [ 260 | [5, 0, 2], 261 | [5, 0, 10], 262 | [2, 10, 0] 263 | ] 264 | ``` 265 | c| 266 | ```python 267 | adj_list = [ 268 | [(1, 5), (2, 2)], 269 | [(0, 5), (2, 10)], 270 | [] 271 | ] 272 | ``` 273 | 274 | ##### !end-options 275 | 276 | ##### !answer 277 | 278 | c| 279 | 280 | ##### !end-answer 281 | 282 | 283 | ##### !hint 284 | Consider drawing out what each of the options looks like! 285 | ##### !end-hint 286 | 287 | ##### !explanation 288 | The answer is Option C 289 | ```python 290 | adj_list = [ 291 | [(1, 5), (2, 2)], 292 | [(0, 5), (2, 10)], 293 | [] 294 | ] 295 | ``` 296 | Node 0 has two edges: 297 | - `(1, 5)` --> an edge from node 0 to node 1 with weight 5 298 | - `(2, 2)` --> an edge from node 0 to node 2 with weight 2 299 | 300 | Node 1 also has two edges: 301 | - `(0, 5)` --> an edge from node 1 to node 0 with weight 5 302 | - `(2, 10)` --> an edge from node 1 to node 2 with weight 10 303 | 304 | Node 2's list of edges is an empty list, because no edges exist in the list where node 2 is the _source_ node. 305 | 306 | Option A, the list of edges, is incorrect because it is missing the edge `[1, 0, 5]`. 307 | 308 | Option B, the adjacency matrix is incorrect because there are multiple incorrect row-column values. For example, `adj_matrix[0][0]` has weight `5` indicating that there is an edge with weight 5 from node 0 to itself. 309 | ##### !end-explanation 310 | 311 | ### !end-challenge 312 | 313 | 314 | 315 | 316 | 317 | 318 | ### !challenge 319 | 320 | * type: multiple-choice 321 | * id: ea022c3a-94c7-478e-8488-b8999491a7e0 322 | * title: Cheapest Flights within K Stops Graph Representation 323 | * points: 1 324 | 325 | 326 | ##### !question 327 | 328 | The Leetcode exercise `Cheapest Flights Within K Stops` is a graph problem and has the following problem statement: 329 | 330 | "There are `n` cities connected by some number of flights. You are given an array flights where `flights[i] = [from_i, to_i, price_i]` indicates that there is a flight from city `from_i` to city `to_i` with cost `price_i`. 331 | 332 | You are also given three integers `src`, `dst`, and `k`, return the cheapest price from `src` to `dst` with at most `k` stops. If there is no such route, return `-1`." 333 | 334 | Which of the following graph representations does this problem provide us with? 335 | 336 | *Note: You are **not** expected to solve this Leetcode problem!* 337 | 338 | ##### !end-question 339 | 340 | ##### !options 341 | 342 | a| List of Edges 343 | b| Adjacency Matrix 344 | c| Adjacency List 345 | d| None of the above 346 | 347 | ##### !end-options 348 | 349 | ##### !answer 350 | 351 | a| 352 | 353 | ##### !end-answer 354 | 355 | 356 | ##### !hint 357 | Check out the problem on Leetcode to see example inputs and outputs! 358 | [Cheapest Flights Within K Stops](https://leetcode.com/problems/cheapest-flights-within-k-stops/) 359 | ##### !end-hint 360 | 361 | ##### !explanation 362 | This problem provides us with a list of edges. 363 | 364 | The sentence "You are given an array flights where `flights[i] = [from_i, to_i, price_i]` indicates that there is a flight from city `from_i` to city `to_i` with cost `price_i`" tells us this. 365 | 366 | The cities are nodes and flights are edges. Each edge is represented by `[from_i, to_i, price_i]` including the edge's source node/city first, the destination node/city second, and the weight or price of the flight third. 367 | 368 | The indices of `flights` aren't used to represent either the source or the destination nodes so we know that the representation given is neither an adjacency list nor an adjacency matrix. 369 | ##### !end-explanation 370 | 371 | ### !end-challenge 372 | 373 | -------------------------------------------------------------------------------- /04-graphs/06-graphs-resources.md: -------------------------------------------------------------------------------- 1 | # Resources 2 | 3 | ## Terms & Definitions 4 | 5 | | Term | Definition | 6 | |--- |--- | 7 | | Graph | A data structure with two parts: A limited set of verticies, called nodes, and a limited set of connections between nodes known as edges. | 8 | | Edge | A connection between two nodes in a graph. | 9 | | Node | The fundamental unit of a graph in computer science. Each element of a graph, connected by edges. | 10 | | Sparse Graph | A graph with few edges when compared to nodes. | 11 | | Dense Graph | A graph with many more edges when compared to nodes. A graph is considered _dense_ when it has close to the maximum number of possible edges. | 12 | | Directed Graph | A graph where the edges connet in one direction. For example an edge may conect nodes A -> B, but will not connect B -> A. | 13 | | Undirected Graph | A Graph in which each edge is bidirectional. So an edge from A → B also connects B → A. | 14 | | Adjacency Matrix | A 2-dimensional array listing the connections between nodes in a graph. | 15 | | Adjacency List | A collection of unordered lists used to represent a graph. Each list describes the neighors of a particular node. 16 | | Node Degree | The number of edges a particular node has. | 17 | 18 | ## Resources 19 | - [C16 Video Lesson](https://adaacademy.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=09cd9474-04a2-4460-8eb8-aad8005b7065) 20 | - [C16 Accompanying Slide Deck](https://docs.google.com/presentation/d/1pIAhpb0QL7Pk93P3E-jIRbboz6UPRZOnJ2eyVU1Ga3Q/edit#slide=id.p7) 21 | - [BaseCS on Graphs](https://medium.com/basecs/from-theory-to-practice-representing-graphs-cfd782c5be38) 22 | - [Geeks for Geeks: Graphs and its representations](https://www.geeksforgeeks.org/graph-and-its-representations/) 23 | - [Coursera: Algorithms on Graphs](https://www.coursera.org/lecture/algorithms-on-graphs/representing-graphs-c4W9f) 24 | - [Geeks for Geeks: BFS Applications](https://www.geeksforgeeks.org/applications-of-breadth-first-traversal/) 25 | - [Geeks for Geeks: DFS Applications](https://www.geeksforgeeks.org/applications-of-depth-first-search/) -------------------------------------------------------------------------------- /04-graphs/07-graphs-activity.md: -------------------------------------------------------------------------------- 1 | # Livecode & Activity 2 | 3 | ## Bipartition Graph 4 | 5 | We will go over how to implement a solution for the Bipartition Graph problem. 6 | 7 | ### Class Livecode 8 | 9 | Follow along in the following repo as we livecode the function in class: 10 | * [Bipartition Graph Livecode Start](https://github.com/Ada-Activities/bipartition_graph_livecode) 11 | * Check out the `solution` branch in the repo to see a version of the Livecode implementation 12 | 13 | 14 | ### Small Group Work: Graph Variations Activities 15 | 16 | For your small group activity, you will work on one of the graph variation activities. 17 | 18 | - Spend twenty minutes with your breakout room implementing a solution. 19 | - One person in the group should fork the repo and share a link with the rest of the group. 20 | - If your entire group is feeling stuck, start by discussing how you would solve the function using pen and paper. 21 | - If your entire group is still feeling lost, discuss what is making you feel stuck and ask an instructor to come to your room for help! 22 | - After small group work, we will come back together as a class to work through a solution together, as time allows. Groups may ask questions, share where they got stuck, and/or share out their solutions. 23 | 24 | Fork one of the following repos to work on in small groups: 25 | * [Convert Graph](https://github.com/Ada-Activities/convert_graph_activity) 26 | * [DFS with Adjacency Matrix](https://github.com/Ada-Activities/dfs-with-adjacency-matrix) 27 | * [Repeat BFS](https://github.com/Ada-Activities/repeat-bfs-activity/) 28 | 29 | Check out the `solution` branch in each repo to see a version of a working implementation 30 | -------------------------------------------------------------------------------- /04-graphs/08-graphs-class-discussions.md: -------------------------------------------------------------------------------- 1 | # Class Discussions 2 | 3 | ## C18 Recordings 4 | The following videos are the live session recordings of C18’s Tigons and Ligers classrooms. Though the same material was taught to the two classes, there may be different questions asked by students in each class. 5 | 6 | ### Ligers 7 | #### Topic Introduction 8 | 9 | 10 | 11 | 12 | 13 | 14 | #### Topic Review Session 15 | 16 | 17 | ### Tigons 18 | #### Topic Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | #### Topic Review 26 | -------------------------------------------------------------------------------- /04-graphs/XX-coloring-outline.md: -------------------------------------------------------------------------------- 1 | # Graph Algorithms - Application 2 | 3 | 4 | 5 | ## Map Coloring 6 | 7 | ### Problem Statement 8 | 9 | ### Representing Maps as Graphs 10 | 11 | ### Coloring Nodes 12 | 13 | ### Backtracking 14 | 15 | ### Limitations 16 | 17 | ### Complexity 18 | 19 | ### Alternative Approaches 20 | 21 | ### Scheduling and Resource Allocation Problems 22 | 23 | -------------------------------------------------------------------------------- /04-graphs/images/adj_matrix_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/adj_matrix_1.png -------------------------------------------------------------------------------- /04-graphs/images/adj_matrix_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/adj_matrix_2.png -------------------------------------------------------------------------------- /04-graphs/images/adj_matrix_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/adj_matrix_3.png -------------------------------------------------------------------------------- /04-graphs/images/australia-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/australia-graph.png -------------------------------------------------------------------------------- /04-graphs/images/bfs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/bfs.gif -------------------------------------------------------------------------------- /04-graphs/images/dfs-graph-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/dfs-graph-example.png -------------------------------------------------------------------------------- /04-graphs/images/dfs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/dfs.gif -------------------------------------------------------------------------------- /04-graphs/images/directed-graph-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/directed-graph-example.png -------------------------------------------------------------------------------- /04-graphs/images/directed-graph-flights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/directed-graph-flights.png -------------------------------------------------------------------------------- /04-graphs/images/directed-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/directed-graph.png -------------------------------------------------------------------------------- /04-graphs/images/disconnected-graph-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/disconnected-graph-example.png -------------------------------------------------------------------------------- /04-graphs/images/graph-adjacency-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph-adjacency-list.png -------------------------------------------------------------------------------- /04-graphs/images/graph-adjacency-matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph-adjacency-matrix.png -------------------------------------------------------------------------------- /04-graphs/images/graph-cycle-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph-cycle-example.png -------------------------------------------------------------------------------- /04-graphs/images/graph-edge-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph-edge-list.png -------------------------------------------------------------------------------- /04-graphs/images/graph_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph_1.png -------------------------------------------------------------------------------- /04-graphs/images/graph_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph_2.png -------------------------------------------------------------------------------- /04-graphs/images/graph_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph_a.png -------------------------------------------------------------------------------- /04-graphs/images/graph_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph_b.png -------------------------------------------------------------------------------- /04-graphs/images/graph_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph_c.png -------------------------------------------------------------------------------- /04-graphs/images/graph_neighbors_adj_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph_neighbors_adj_list.png -------------------------------------------------------------------------------- /04-graphs/images/graph_neighbors_adj_matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph_neighbors_adj_matrix.png -------------------------------------------------------------------------------- /04-graphs/images/graph_neighbors_list_of_edges.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graph_neighbors_list_of_edges.png -------------------------------------------------------------------------------- /04-graphs/images/graphs-adjacency-list-cities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs-adjacency-list-cities.png -------------------------------------------------------------------------------- /04-graphs/images/graphs-adjacency-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs-adjacency-list.png -------------------------------------------------------------------------------- /04-graphs/images/graphs1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs1.png -------------------------------------------------------------------------------- /04-graphs/images/graphs2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs2.png -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_backtrack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_backtrack.png -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_backtrack.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_backtrack.webp -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_backtrack.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_backtrack.xcf -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_backtrack_merged.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_backtrack_merged.xcf -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_backtrack_parts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_backtrack_parts.png -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_corner_edge.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_corner_edge.fig -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_corner_edge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_corner_edge.png -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_to_graph.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_to_graph.fig -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_maze_to_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_maze_to_graph.png -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_mazes.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_mazes.fig -------------------------------------------------------------------------------- /04-graphs/images/graphs_application_mazes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/graphs_application_mazes.png -------------------------------------------------------------------------------- /04-graphs/images/representing-weighted-directed-graph-challenge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/representing-weighted-directed-graph-challenge.png -------------------------------------------------------------------------------- /04-graphs/images/undirected-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/undirected-graph.png -------------------------------------------------------------------------------- /04-graphs/images/unweighted-graph-flights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/unweighted-graph-flights.png -------------------------------------------------------------------------------- /04-graphs/images/weighted-graph-flights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/weighted-graph-flights.png -------------------------------------------------------------------------------- /04-graphs/images/weighted-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/04-graphs/images/weighted-graph.png -------------------------------------------------------------------------------- /05-dijkstras/04-dijkstras-activity.md: -------------------------------------------------------------------------------- 1 | # Activity: Problem Solving 2 | 3 | ## Goal 4 | 5 | Our goal is to practice using Dijkstra's Algorithm to solve shortest/least costly path problems. 6 | 7 | # As a Class - Cheapest Flight Livecode 8 | 9 | As a class we will introduce the interview problem, discuss test cases, why Dijkstra's is a good fit for solving this problem, and possible modifications we may need to make to Dijkstra's to solve this problem. 10 | 11 | Follow along in the following repo as we livecode the function in class: 12 | * [Cheapest Flight Livecode Start](https://github.com/Ada-Activities/cheapest-flight) 13 | * Check out the `solution` branch in the repo to see a version of the Livecode implementation 14 | 15 | ### Breakout Rooms - Minimum Effort Path Pseudocode 16 | 17 | In small groups of 3-4 students, pseudocode a solution to the Minimum Effort Path problem in the repo. Get as far as you can, asking for instructor assistance when needed. You _do not_ need to finish the pseudocode or implement the problem. 18 | 19 | **One student** should *fork* the following repo and invite the rest of the team. [Minimum Effort Path Activity](https://github.com/Ada-Activities/minimum-effort-path) 20 | * Check out the `solution` branch in the repo to see one version of a working implementation 21 | 22 | #### Exercise 23 | 24 | If you finish early, try implementing your pseudocode and getting all of the tests to pass! 25 | 26 | -------------------------------------------------------------------------------- /05-dijkstras/05-dijkstras-class-discussions.md: -------------------------------------------------------------------------------- 1 | # Class Discussions 2 | 3 | ## C18 Recordings 4 | The following videos are the live session recordings of C18’s Tigons and Ligers classrooms. Though the same material was taught to the two classes, there may be different questions asked by students in each class. 5 | 6 | ### Ligers 7 | #### Topic Introduction 8 | 9 | 10 | 11 | 12 | 13 | 14 | #### Topic Review Session 15 | 16 | 17 | ### Tigons 18 | #### Topic Introduction 19 | 20 | 21 | 22 | 23 | #### Topic Review 24 | -------------------------------------------------------------------------------- /05-dijkstras/06-dijkstras-vs-negative-graphs.md: -------------------------------------------------------------------------------- 1 | # Optional: Dijkstra vs. Negative Weighted Graphs 2 | 3 | ### !callout 4 | 5 | ## Optional Lesson 6 | 7 | This lesson is optional because it is not necessary to learn Dijkstra's Algorithm. However, it does lend a hand in understanding the algorithm. 8 | 9 | ### !end-callout 10 | 11 | As stated previously in the lesson, one of the limitations of Dijkstra’s Algorithm is that when implemented on a graph that contains negatively weighted edges it can possibly produce inaccurate results. This is because of the [“greedy”](https://en.wikipedia.org/wiki/Greedy_algorithm) nature of the algorithm, meaning that it works under the assumption that each subpath it chooses is the most optimal path. Therefore when we visit a node, Dijkstra’s algorithm assumes the current least costly path to the node locally will be the least costly path to the node globally. 12 | 13 | Once we’ve visited a node, it is considered closed and there is no way to re-open the path to that node and further relax the cost of the path. Dijkstra is designed to be applied to graphs with no negative costs. Such graphs can be used to solve many useful problems, so this limitation (the same we have with DFS and BFS) doesn't pose a problem when used as designed. If negative weights need to be handled, then the assumptions no longer hold, and some modification needs to be applied. 14 | 15 | Let's walk through an example of Dijkstra’s Algorithm being implemented on a small negatively weighted graph to find the shortest path from Node A to Node D. 16 | 17 | ![Dijkstra vs.Negative Graph-1](images/negative-1.png) 18 | 19 | Step 0. We start with a weighted graph. Notice that the weight on the edge connecting B to C is -100. The graph is directed. However, this is arbitrary. 20 | 21 | ![Dijkstra vs.Negative Graph-2](images/negative-2.png) 22 | 23 | Step 1. We identify our start node, Node A, and set the cost to travel from the start node to all other nodes to infinity. The cost to travel to Node A (the start node itself) is set to 0. Something else that will prove to be useful is a list that keeps track of the nodes we’ve already visited. Finally, we add Node A to the top of our priority queue. 24 | 25 | ```text 26 | priority queue: 27 | - A 28 | 29 | visited: 30 | 31 | costs/distances: 32 | - A: 0 33 | - B: ∞ 34 | - C: ∞ 35 | - D: ∞ 36 | ``` 37 | 38 | ![Dijkstra vs.Negative Graph-3](images/negative-3.png) 39 | 40 | Step 2. Given that Node A is the only node to have a finite distance it moves to the top of our queue and we begin looking at the edges of Node A’s neighboring nodes. Here we check to see if the cost of visiting each unvisited neighbor node from the current node we are visiting is less than the estimated cost we previously noted. Here we can see that 2 and 1, for B and D respectively, are less than infinity. Therefore we will update the distances accordingly. Finally, we add our start node to the list of visited nodes so we don’t visit it again. 41 | 42 | ```text 43 | current: A 44 | 45 | visited nodes: 46 | - A 47 | 48 | priority queue: 49 | - A 50 | - D 51 | - B 52 | 53 | costs/distances: 54 | - A: 0 55 | - B: 2 56 | - C: ∞ 57 | - D: 1 58 | ``` 59 | ![Dijkstra vs.Negative Graph-4](images/negative-4.png) 60 | 61 | Step 3. The next step is to visit the node that is the closest to our start node, which is Node D. Node D has a cost of 1, whereas Node B has a cost of 2. Here we would compute the cost of visiting all of Node D’s unvisited neighboring nodes. However, since Node D’s only neighbor is Node A, a node we’ve already visited, there are no costs to consider. 62 | 63 | Before moving to the next step let’s recall the “greedy” behavior of Dijkstra’s algorithm. Again, Dijkstra’s Algorithm operates under the assumption that the shortest path to a destination node from a start node is an accumulation of the shortest paths connecting intermediate neighboring nodes between the starting node and destination node. Since the cost of visiting Node D was the least costly path so far, Dijkstra's algorithm viewed Node D as the most locally optimal node to visit next. This resulted in Node D being added to the visited list, and the algorithm moved on with the assumption that it found the least costly path to Node D. 64 | 65 | ```text 66 | current: D 67 | 68 | visited nodes: 69 | - A 70 | - D 71 | 72 | priority queue: 73 | - B 74 | 75 | costs/distances: 76 | - A: 0 77 | - B: 2 78 | - C: ∞ 79 | - D: 1 80 | 81 | ``` 82 | 83 | ![Dijkstra vs.Negative Graph-5](images/negative-5.png) 84 | 85 | Step 4. We now look at the next node at the top of our priority queue, Node B (cost of 2). We will estimate the accumulated cost of reaching Node B’s neighboring nodes, based on the cost we calculated for reaching Node B, plus the cost to reach its neighbors. Node B has a single unvisited neighbor, Node C, and the edge to reach it has a cost of -100. The -100 cost of that edge to C, added to the cost it took to reach Node B (2) results in an estimated cost to Node C of -98. We can update our cost for Node C with our newfound estimate, and since we are now done visiting Node B, we can add Node B to our visited nodes. Finally, we add Node C to our priority queue. 86 | 87 | ```text 88 | current: B 89 | 90 | visited nodes: 91 | - A 92 | - D 93 | - B 94 | 95 | priority queue: 96 | - C 97 | 98 | costs/distances: 99 | - A: 0 100 | - B: 2 101 | - C: -98 102 | - D: 1 103 | ``` 104 | 105 | ![Dijkstra vs.Negative Graph-6](images/negative-6.png) 106 | 107 | Step 5. The next node in our priority queue is Node C. Like before, we will take a look at all of Node C’s unvisited neighbors and calculate the actual cost of visiting. As we can notice, Node C does not have any unvisited nodes and therefore leaves us with nothing to update. 108 | 109 | This brings our algorithm to an end and leaves us with the following result. 110 | 111 | ```text 112 | visited nodes: 113 | - A 114 | - D 115 | - B 116 | - C 117 | 118 | costs/distances: 119 | - A: 0 120 | - B: 2 121 | - C: -98 122 | - D: 1 123 | ``` 124 | But wait, we can clearly see that the least costly path from Node A to Node D is through Nodes B and C! That is correct, however since Dijkstra’s Algorithm operates under the assumption that each local choice we make is the most optimal choice, Node D was visited early in the traversal when it appeared to be the next lowest cost node to visit after Node A. The cost we estimated at the time it was visited became its calculated cost. Even though we found a lower cost path later, the negative edge causes the greedy assumption "the path we find first will be the cheapest" to become violated. Because Node D had already been visited, the edge to Node D along this later, cheaper path would not be considered. This is why Dijkstra’s Algorithm can possibly fail when implemented on graphs with negative weights. 125 | 126 | To circumvent the negative weight limitation, we encourage you to follow your own curiosity and research the A* Search and Bellman Ford Algorithms. 127 | -------------------------------------------------------------------------------- /05-dijkstras/autoconfig.yaml: -------------------------------------------------------------------------------- 1 | # This file is auto-generated and orders your content based on the file structure of your repo. 2 | # Do not edit this file; it will be replaced the next time you run the preview command. 3 | 4 | # To manually order the contents of this curriculum rather than using the auto-generated file, 5 | # include a config.yaml in your repo following the same conventions as this auto-generated file. 6 | # A user-created config.yaml will have priority over the auto-generated one. 7 | 8 | -------------------------------------------------------------------------------- /05-dijkstras/images/bfs-shortest-distance.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/bfs-shortest-distance.gif -------------------------------------------------------------------------------- /05-dijkstras/images/bfs-undirected-graph.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/bfs-undirected-graph.gif -------------------------------------------------------------------------------- /05-dijkstras/images/dfs-shortest-path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dfs-shortest-path.png -------------------------------------------------------------------------------- /05-dijkstras/images/dfs-undirected-graph.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dfs-undirected-graph.gif -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstra-challenge-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstra-challenge-example.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstra-q1-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstra-q1-graph.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstra-subpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstra-subpath.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstras-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstras-0.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstras-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstras-1.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstras-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstras-2.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstras-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstras-3.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstras-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstras-4.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstras-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstras-5.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstras-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstras-6.png -------------------------------------------------------------------------------- /05-dijkstras/images/dijkstras-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/dijkstras-7.png -------------------------------------------------------------------------------- /05-dijkstras/images/disconnected-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/disconnected-graph.png -------------------------------------------------------------------------------- /05-dijkstras/images/find-shortest-path.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/find-shortest-path.gif -------------------------------------------------------------------------------- /05-dijkstras/images/fruit-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/fruit-graph.png -------------------------------------------------------------------------------- /05-dijkstras/images/negative-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/negative-1.png -------------------------------------------------------------------------------- /05-dijkstras/images/negative-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/negative-2.png -------------------------------------------------------------------------------- /05-dijkstras/images/negative-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/negative-3.png -------------------------------------------------------------------------------- /05-dijkstras/images/negative-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/negative-4.png -------------------------------------------------------------------------------- /05-dijkstras/images/negative-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/negative-5.png -------------------------------------------------------------------------------- /05-dijkstras/images/negative-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/negative-6.png -------------------------------------------------------------------------------- /05-dijkstras/images/weighted-adj-matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/weighted-adj-matrix.png -------------------------------------------------------------------------------- /05-dijkstras/images/weighted-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/weighted-graph.png -------------------------------------------------------------------------------- /05-dijkstras/images/weighted-v-unweighted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/05-dijkstras/images/weighted-v-unweighted.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ada-16 -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | Standards: 3 | - 4 | Title: Introduction 5 | Description: Introduction 6 | UID: 7c1d840f-06c8-4dc5-a10a-8fdf61f99c8f 7 | SuccessCriteria: 8 | - success criteria 9 | ContentFiles: 10 | - 11 | Type: Lesson 12 | UID: c831a8e5-20d5-42df-883e-bb0f4deb0e1c 13 | Path: /00-intro/intro.md 14 | - 15 | Title: Algorithmic Approaches 16 | Description: Introduction to Algorithms, Analysis of Algorithms, Recursion Review, Divide and Conquer, ... 17 | UID: ccdccab2-b7f3-42d8-977d-955a58ce9d05 18 | SuccessCriteria: 19 | - success criteria 20 | ContentFiles: 21 | - 22 | Type: Lesson 23 | UID: a76dfc02-3b54-459c-bf72-66a072b26119 24 | Path: /01-algorithms/01-algorithms.md 25 | - 26 | Type: Lesson 27 | UID: 7efe05b0-1021-403b-8f13-553beec28cfe 28 | Path: /01-algorithms/02-algorithm-analysis.md 29 | - 30 | Type: Lesson 31 | UID: 70754423-d4bc-4fc2-8bfc-a6673574d8f4 32 | Path: /01-algorithms/03-recursion.md 33 | - 34 | Type: Lesson 35 | UID: 1609881b-773a-41e3-aee7-c23c66e20d29 36 | Path: /01-algorithms/04-algorithms-divide-conquer.md 37 | - 38 | Type: Lesson 39 | UID: d623f94b-71bc-414b-b138-a4b0264aefcf 40 | Path: /01-algorithms/05-sliding-window.md 41 | - 42 | Type: Lesson 43 | UID: 54496b4c-78bc-46ba-92b4-53ccee97e41f 44 | Path: /01-algorithms/06-algorithms-dynamic-programming.md 45 | - 46 | Type: Lesson 47 | UID: e7ac6f0e-1186-4060-8be5-29e46b2fe352 48 | Path: /01-algorithms/07-algorithms-supplemental-resources.md 49 | - 50 | Type: Lesson 51 | UID: 0f52cf8b-80de-4c9f-9b98-53047d37b0a2 52 | Path: /01-algorithms/08-algorithms-activity.md 53 | - 54 | Type: Lesson 55 | UID: 3e63e944-118b-4904-96d7-ce35e0734f98 56 | Path: /01-algorithms/09-algorithms-class-discussion.md 57 | - 58 | 59 | Title: Linked Lists 60 | Description: Linked Lists, Object Oriented Design of a Linked List, Linked List Methods, Applications of Linked Lists, Supplemental Concepts 61 | UID: 8e6f54bf-41e8-41d6-9a03-dca103bf15ed 62 | SuccessCriteria: 63 | - success criteria 64 | ContentFiles: 65 | - 66 | Type: Instructor 67 | UID: c498e182 68 | Path: /02-linked-lists/linked-lists.instructor.md 69 | - 70 | Type: Instructor 71 | UID: ac3b6860-51fd-4d90-8a68-99875639af1d 72 | Path: /02-linked-lists/class-lesson.instructor.md 73 | - 74 | Type: Lesson 75 | UID: 99474aeb-183e-4f01-990b-0a689c022c30 76 | Path: /02-linked-lists/01-linked-lists.md 77 | - 78 | Type: Lesson 79 | UID: 1622f195-c5bf-4c9e-ab13-f245ed963cc4 80 | Path: /02-linked-lists/02-linked-lists-oop.md 81 | - 82 | Type: Lesson 83 | UID: 0c78e210-d831-41dd-956b-973aa151d904 84 | Path: /02-linked-lists/03-linked-lists-implementation.md 85 | - 86 | Type: Lesson 87 | UID: 444cda30-ac77-4abd-858b-9db81b6f601d 88 | Path: /02-linked-lists/04-linked-lists-stacks-queues.md 89 | - 90 | Type: Lesson 91 | UID: 0d3a9473-199c-430d-bc55-43fc09fd50ff 92 | Path: /02-linked-lists/05-linked-lists-supplemental-concepts.md 93 | - 94 | Type: Lesson 95 | UID: 19b1fbf3-60b6-4a60-895c-7de1b9afe923 96 | Path: /02-linked-lists/06-linked-list-activity.md 97 | - 98 | Type: Lesson 99 | UID: 2c227840-f6ff-4022-a16f-25a3eabf1d41 100 | Path: /02-linked-lists/07-linked-lists-class-discussions.md 101 | - 102 | Title: Binary Search Trees 103 | Description: Binary Search Trees, Balancing Trees, Serializing with Tree Traversal, Resources 104 | UID: fc8d8eae-2456-4b22-9213-127d6e83dd5e 105 | SuccessCriteria: 106 | - success criteria 107 | ContentFiles: 108 | - 109 | Type: Instructor 110 | UID: e153ec41-477e-43fb-bf6d-0173e24aec85 111 | Path: /03-Binary-Search-Trees/bst.instructor.md 112 | - 113 | Type: Lesson 114 | UID: 05732e84-1354-4349-8c71-173460093f9b 115 | Path: /03-Binary-Search-Trees/01-Binary-Search-Trees.md 116 | - 117 | Type: Lesson 118 | UID: c7d8f1dc-2d74-4892-a2ab-69fbd3418ee3 119 | Path: /03-Binary-Search-Trees/02-Binary-Search-Trees-Big-O.md 120 | - 121 | Type: Lesson 122 | UID: 80747284-c3bb-4753-8c1b-9eb0bb834687 123 | Path: /03-Binary-Search-Trees/03-Binary-Search-Trees-Traversal.md 124 | - 125 | Type: Lesson 126 | UID: 1f189042-63dd-4075-9de9-4ca60a3fa5aa 127 | Path: /03-Binary-Search-Trees/04-Binary-Search-Trees-Resources.md 128 | - 129 | Type: Lesson 130 | UID: 06dea201-6230-4967-b98f-2403ab11479a 131 | Path: /03-Binary-Search-Trees/05-Binary-Search-Trees-Activity.md 132 | - 133 | Type: Lesson 134 | UID: f5fc7ed6-5231-4667-a64f-aee2ff4d6652 135 | Path: /03-Binary-Search-Trees/06-Binary-Search-Trees-Class-Discussions.md 136 | - 137 | Title: Graphs Pt. 1 138 | Description: Graphs, Representing Graphs, Graphs Algorithms - Breadth First Search, Graph Algorithms - Depth First Search, Resources 139 | UID: b0d74464-2678-44a8-a4ff-dc74350e7114 140 | SuccessCriteria: 141 | - success criteria 142 | ContentFiles: 143 | - 144 | Type: Lesson 145 | UID: 43ec38b5-3ce1-4882-b709-ca99d4b702c1 146 | Path: /04-graphs/01-graphs.md 147 | - 148 | Type: Lesson 149 | UID: 97afeb52-3626-4cec-95ca-e19171f6d3b8 150 | Path: /04-graphs/02-representing-graphs.md 151 | - 152 | Type: Lesson 153 | UID: 2c83a545-e3fb-4f7f-bd88-3493883e9fa0 154 | Path: /04-graphs/03-bfs.md 155 | - 156 | Type: Lesson 157 | UID: e18e38d1-7995-4e57-80e8-ea3f276741d0 158 | Path: /04-graphs/04-dfs.md 159 | - 160 | Type: Lesson 161 | UID: 99cede61-070b-4d37-904c-ea12aba787b5 162 | Path: /04-graphs/05-application.md 163 | - 164 | Type: Lesson 165 | UID: b7554bcb-53aa-4db8-b447-1c2e4145b1e0 166 | Path: /04-graphs/06-graphs-resources.md 167 | - 168 | Type: Lesson 169 | UID: 96fcef62-30b0-4be7-8a63-c4002a53b0e2 170 | Path: /04-graphs/07-graphs-activity.md 171 | - 172 | Type: Lesson 173 | UID: f5a53e36-300b-4568-9301-08963aad977f 174 | Path: /04-graphs/08-graphs-class-discussions.md 175 | - 176 | Title: Graphs Pt. 2 177 | Description: Graph Data Structures & Algorithms - Dijkstra's 178 | UID: 37e5c085-d3c7-4905-867e-90bd70a14ceb 179 | SuccessCriteria: 180 | - success criteria 181 | ContentFiles: 182 | - 183 | Type: Lesson 184 | UID: a1c9e6cf-0bb8-4d02-bd5e-bda148023dd9 185 | Path: /05-dijkstras/01-graph-representations-review.md 186 | - 187 | Type: Lesson 188 | UID: 401e07cc-abf5-46a4-880f-b61ced1dc235 189 | Path: /05-dijkstras/02-traversal-review.md 190 | - 191 | Type: Lesson 192 | UID: a0b4d6af-65fb-4d82-bd37-0f952f9c3b92 193 | Path: /05-dijkstras/03-dijkstra.md 194 | - 195 | Type: Lesson 196 | UID: b11a0602-959e-42a2-9670-e7d126e9d98c 197 | Path: /05-dijkstras/04-dijkstras-activity.md 198 | - 199 | Type: Lesson 200 | UID: 99db9e58-5ab4-489c-a240-9c67195c7f82 201 | Path: /05-dijkstras/05-dijkstras-class-discussions.md 202 | - 203 | Type: Lesson 204 | UID: 720fe4c8-78f4-11ee-b962-0242ac120002 205 | Path: /05-dijkstras/06-dijkstras-vs-negative-graphs.md -------------------------------------------------------------------------------- /course.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | :Course: 3 | - :Section: "CS Fundamentals" 4 | :Repos: 5 | - :Url: https://github.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship 6 | - :Section: "Career Development" 7 | :Repos: 8 | - :Url: https://github.com/Ada-Developers-Academy/career-development 9 | -------------------------------------------------------------------------------- /old-lessons/01-Problem-Solving-And-Big-O/04-in-class-problemset.md: -------------------------------------------------------------------------------- 1 | # Activity: Problem Solving 2 | 3 | ## Goal 4 | 5 | Our goal is to practice taking a problem, analyzing it, and then refactoring it to improve the solution. 6 | 7 | ## Activity Instructions 8 | 9 | - [Activity Replit](https://replit.com/@adadev/two-sum-II#README.md) 10 | 11 | ### Getting Started 12 | 13 | In small groups of 3-4, **one student** will *fork* the given replit and then share a collaboration link with the rest of the team. 14 | 15 | ### Read The Markdown Document 16 | 17 | Read the replit markdown document to understand the problem. The problem **has already been solved.** However the solution is a brute-force apprach. You can improve it. 18 | 19 | ### Read Through the Solution 20 | 21 | Read through the solution and analyze the time/space complexity. Fill in the time complexity below. 22 | 23 | 24 | 25 | ### !challenge 26 | * type: multiple-choice 27 | * id: 7785c9bb-d328-4325-a6d9-70a42e540bec 28 | * title: What is the time complexity of the initial solution? 29 | 30 | 31 | 32 | ##### !question 33 | 34 | Look at the `two_sum/two_sum.py` file. What is the time complexity of the initial solution presented here? 35 | 36 | ##### !end-question 37 | 38 | ##### !options 39 | 40 | * O(1) 41 | * O(log n) 42 | * O(n) 43 | * O(n log n) 44 | * O(n^2) 45 | * O(n^3) 46 | 47 | 48 | ##### !end-options 49 | 50 | ##### !answer 51 | 52 | * O(n^2) 53 | 54 | ##### !end-answer 55 | 56 | ### !end-challenge 57 | 58 | 59 | 60 | 61 | 62 | ### !challenge 63 | * type: multiple-choice 64 | * id: d55b51b1-29dc-47b9-83d7-5a7004bec8db 65 | * title: What is the *space* complexity of the initial solution? 66 | * topics: python, big-o, space-complexity 67 | 68 | ##### !question 69 | 70 | Look at the `two_sum/two_sum.py` file. What is the space complexity of the initial solution presented here? 71 | 72 | ##### !end-question 73 | 74 | ##### !options 75 | 76 | * O(1) 77 | * O(log n) 78 | * O(n) 79 | * O(n log n) 80 | * O(n^2) 81 | * O(n^3) 82 | 83 | ##### !end-options 84 | 85 | ##### !answer 86 | 87 | * O(1) 88 | 89 | ##### !end-answer 90 | 91 | ### !end-challenge 92 | 93 | 94 | 95 | ### Look For Additional Test/Input Cases 96 | 97 | Look at the test file and try to identify at least 1 additional edge-case. Write that as a test-case and verify the solution works. 98 | 99 | ### Refactor the Solution 100 | 101 | Then as a team refactor the solution to improve the time complexity. 102 | 103 | *Notice that the input list is already sorted...* 104 | 105 | ### !callout-danger 106 | 107 | ## Maintain O(1) Space Complexity 108 | 109 | Note, you should maintain O(1) space complexity. 110 | 111 | ### !end-callout 112 | 113 | ### Analyze Your Solution 114 | 115 | 116 | 117 | 118 | ### !challenge 119 | 120 | * type: short-answer 121 | * id: 3929f4c7-d049-47f6-968f-9fb0c2098a51 122 | * title: What is the time complexity of your solution? 123 | * points: 1 124 | * topics: python, big-o, searching 125 | 126 | ##### !question 127 | 128 | What is your solution's time complexity? 129 | 130 | ##### !end-question 131 | 132 | ##### !placeholder 133 | 134 | O( ... ) 135 | 136 | ##### !end-placeholder 137 | 138 | ##### !answer 139 | 140 | /.+/ 141 | 142 | ##### !end-answer 143 | 144 | ### !end-challenge 145 | 146 | 147 | 148 | 149 | 150 | 151 | ### !challenge 152 | 153 | * type: paragraph 154 | * id: b7befc76-ea5d-44ac-bf4c-7e5205567cf0 155 | * title: Summary 156 | * topics: python, big-o, searching 157 | 158 | ##### !question 159 | 160 | Summarize your solution 161 | 162 | ##### !end-question 163 | 164 | ##### !placeholder 165 | 166 | How does your solution work? 167 | 168 | ##### !end-placeholder 169 | 170 | ### !end-challenge 171 | 172 | -------------------------------------------------------------------------------- /old-lessons/01-Problem-Solving-And-Big-O/class-lesson.instructor.md: -------------------------------------------------------------------------------- 1 | # Instructor Notes 2 | 3 | The problem solving class lesson has a few objectives, not all related to the curriculum topic. 4 | 5 | ## Lesson Goals 6 | 7 | - Non-CS Fun Goals 8 | - Establish classroom expectations and norms 9 | - Students must complete 7 of 8 projects 10 | - Attendance requirements 11 | - Let students know about office hours, from instructors and TAs 12 | - Review the Calendar 13 | - CS Fun Goals Make sure students can: 14 | - List the steps in Problem Solving 15 | - Identify Nominal and Edge-cases 16 | - Explain refactoring 17 | - Walk through the types of Big O 18 | - Analyze a code sample and correctly estimate it's time and space complexity. 19 | 20 | ## Lesson Introduction - 20 minutes 21 | 22 | Start the lesson by welcoming students to the class and note attendance (Note for the future, that Zoom can do attendance tracking). I (Chris) take screenshots of the participants and use that for attendance later. You can use the Airtable to record attendance The [C16 Airtable](https://airtable.com/appkfPQ769uxQLSei/tbl6oiA8ZG1wKUonM/viwgf4wesbLFMlg1L?blocks=hide) is linked. 23 | 24 | ### List Classroom Expectations 25 | 26 | - Review the [Ada Norms Doc](../00-about/norms.md). 27 | - Areas of focus: 28 | - Calendar 29 | - Office Hours 30 | - 7/8 Projects required 31 | - Report Absences via [absent_internship@adadevelopersacademy.org](mailto:absent_internship@adadevelopersacademy.org) 32 | 33 | ### Review the Learn Sections 34 | 35 | - CS Fundamentals 36 | - Career Development 37 | - Specify that this is where they can find the Google Docs Career Services will update 38 | 39 | ## Lesson Start: Review Topics - 30 minutes 40 | 41 | In the [problem solving lesson doc](./01-problem-solving.md) review the `minimum_sub_list_length` problem and ask students the steps in the problem solving process. 42 | 43 | - Clarifying Questions 44 | - Example Input and outputs 45 | - Ask about *Nominal* and *Edge-cases* 46 | - Look at the given solution 47 | 48 | Then have students analyze the solution for time/space complexity. 49 | 50 | - Have them spend 5 minutes looking at it, and write down their analysis before hitting submit in chat. 51 | - Then get one or more students to explain. 52 | 53 | Lastly review the refactor and have students write down their analysis of the solution again. Get students to explain the answer. 54 | 55 | - Make sure students can explain the concept of a *sliding window*. 56 | 57 | ## Exercise - 30 minutes 58 | 59 | The problem is taken from [167. Two Sum II - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/). 60 | 61 | As a class have students ask clarifying questions on the problem. 62 | 63 | *Chris Note: Just an issue of scale, I'd prefer them to ask clarifying questions in breakout sessions and ask instructors/TAs* 64 | 65 | Then have students in breakout sections work to solve the problem listing: 66 | 67 | 1. Edge-case inputs (there's a test case skipped for this) 68 | 1. Analyze the solved problem for time/space complexity 69 | 1. Refactor as a team (3-4 students) and explain the improved time/space complexity. 70 | 71 | ## Close the Lesson - 15 minutes 72 | 73 | Review solutions and ask students to explain their analysis. We will not have time for all students to present solutions. Make an effort to get a couple of solutions. 74 | 75 | Then before dismissing students remind them about Linked Lists next week and to preview the lesson ahead of time. 76 | -------------------------------------------------------------------------------- /old-lessons/01-Problem-Solving-And-Big-O/images/problem-solving__Sliding-Window.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
[3, 4, 7, 21, 18]
[3, 4, 7, 21, 18]
Window from index
0 to 2
Window from index...
Viewer does not support full SVG 1.1
-------------------------------------------------------------------------------- /old-lessons/01-Problem-Solving-And-Big-O/images/problem-solving__sliding-window.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/01-Problem-Solving-And-Big-O/images/problem-solving__sliding-window.gif -------------------------------------------------------------------------------- /old-lessons/04-Stacks-And-Queues/02-stacks-and-queues-checkpoint.md: -------------------------------------------------------------------------------- 1 | # Stacks & Queues Project 2 | 3 | | Logistics | Details | 4 | | --------------------- | ---------------------------------------- | 5 | | Project details | https://github.com/Ada-C16/stacks-queues | 6 | | JS Version | https://github.com/Ada-C16/stacks-queues-js | 7 | | Should you fork this? | Yes (Check project details) | 8 | | Submission method | Learn | 9 | 10 | 11 | ### !challenge 12 | 13 | * type: testable-project 14 | * id: 66d53d48-ba26-4056-bd67-83d0b26806b8 15 | * title: Stacks & Queues Project 16 | * upstream: https://github.com/Ada-C16/stacks-queues 17 | * validate_fork: false 18 | * points: 0 19 | * topics: stacks, queues 20 | 21 | ##### !question 22 | 23 | Complete https://github.com/Ada-C16/stacks-queues and submit a link to your repository, **not** a PR. 24 | 25 | ##### !end-question 26 | 27 | ##### !placeholder 28 | 29 | 30 | ##### !end-placeholder 31 | 32 | 33 | 34 | 35 | 36 | 37 | ### !end-challenge 38 | 39 | 40 | 41 | 42 | 43 | 44 | ### !challenge 45 | 46 | * type: short-answer 47 | * id: 6d5a8dd1-d341-4306-b733-a4208bde9cc6 48 | * title: Stacks & Queues PR 49 | * points: 3 50 | * topics: stacks, queues 51 | 52 | ##### !question 53 | 54 | Submit a link to your PR here please. 55 | 56 | ##### !end-question 57 | 58 | ##### !placeholder 59 | 60 | Add your PR here 61 | 62 | ##### !end-placeholder 63 | 64 | ##### !answer 65 | 66 | ^https:\/\/github.com\/.*\/pull.*\d$ 67 | 68 | ##### !end-answer 69 | 70 | 71 | 72 | 73 | 74 | 75 | ### !end-challenge 76 | 77 | 78 | 79 | ## JS Version 80 | 81 | 82 | 83 | 84 | ### !challenge 85 | 86 | * type: testable-project 87 | * id: 432457c4-46dd-4c99-bc43-0b98d4335f0f 88 | * title: JavaScript version of the project 89 | * upstream: https://github.com/Ada-C16/stacks-queues-js 90 | * validate_fork: false 91 | * points: 0 92 | * topics: stacks, queues, circular buffer 93 | 94 | ##### !question 95 | 96 | Optional: Fork the [JavaScript version](https://github.com/Ada-C16/stacks-queues-js) of the project and submit it here. 97 | 98 | ##### !end-question 99 | 100 | ##### !placeholder 101 | 102 | Your JavaScript Repository **NOT PR** 103 | 104 | ##### !end-placeholder 105 | 106 | 107 | 108 | 109 | 110 | 111 | ### !end-challenge 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /old-lessons/04-Stacks-And-Queues/images/call-stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/04-Stacks-And-Queues/images/call-stack.png -------------------------------------------------------------------------------- /old-lessons/04-Stacks-And-Queues/images/circular-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/04-Stacks-And-Queues/images/circular-array.png -------------------------------------------------------------------------------- /old-lessons/04-Stacks-And-Queues/images/circular-buffer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/04-Stacks-And-Queues/images/circular-buffer.png -------------------------------------------------------------------------------- /old-lessons/04-Stacks-And-Queues/images/memory-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/04-Stacks-And-Queues/images/memory-layout.png -------------------------------------------------------------------------------- /old-lessons/04-Stacks-And-Queues/images/queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/04-Stacks-And-Queues/images/queue.png -------------------------------------------------------------------------------- /old-lessons/04-Stacks-And-Queues/images/stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/04-Stacks-And-Queues/images/stack.png -------------------------------------------------------------------------------- /old-lessons/04-Stacks-And-Queues/images/stackADT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/04-Stacks-And-Queues/images/stackADT.png -------------------------------------------------------------------------------- /old-lessons/05-hash-tables/02-hash-table-checkpoint.md: -------------------------------------------------------------------------------- 1 | # Hashtable Exercises 2 | 3 | | Logistics | Details | 4 | | --------------------- | ---------------------------------------- | 5 | | Project details | https://github.com/Ada-C16/hash-practice | 6 | | JS version | https://github.com/Ada-C16/hash-practice-js | 7 | | Should you fork this? | Yes (Check project details) | 8 | | Submission method | Learn | 9 | 10 | 11 | 12 | ## Exercise 13 | 14 | ### !challenge 15 | 16 | * type: testable-project 17 | * id: 5a4a64b1-a7c3-425a-b073-a093a4d47227 18 | * title: Hash Practice 19 | * upstream: https://github.com/Ada-C16/hash-practice 20 | * validate_fork: false 21 | * points: 0 22 | * topics: hash-table 23 | 24 | ##### !question 25 | 26 | Fork the linked repo and submit your completed exercise. **Then** on the next question submit your PR, so I can make PR comments. 27 | 28 | ##### !end-question 29 | 30 | ##### !placeholder 31 | 32 | Link to your repo 33 | 34 | ##### !end-placeholder 35 | 36 | 37 | 38 | 39 | 40 | 41 | ### !end-challenge 42 | 43 | 44 | 45 | 46 | 47 | 48 | ### !challenge 49 | 50 | * type: short-answer 51 | * id: 692c40a5-d9cc-470f-ada4-bf723ca5cf4b 52 | * title: Link to your PR 53 | * points: 2 54 | * topics: hash-table 55 | 56 | ##### !question 57 | 58 | Submit a link of your PR for the project. 59 | 60 | ##### !end-question 61 | 62 | ##### !placeholder 63 | 64 | Your PR link goes here. 65 | 66 | ##### !end-placeholder 67 | 68 | ##### !answer 69 | 70 | /^https:\/\/github.com\/.*\/pull.*\d$/ 71 | 72 | ##### !end-answer 73 | 74 | 75 | 76 | 77 | 78 | 79 | ### !end-challenge 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | ### !challenge 90 | 91 | * type: testable-project 92 | * id: 4d84719d-6907-4d5f-a686-ff363961e0c2 93 | * title: Optional JS version 94 | * upstream: https://github.com/Ada-C16/hash-practice-js 95 | * validate_fork: false 96 | * points: 0 97 | * topics: hashes 98 | 99 | ##### !question 100 | 101 | Optionally you can for the [JavaScript](https://github.com/Ada-C16/hash-practice-js) version and submit that instead. 102 | 103 | ##### !end-question 104 | 105 | ##### !placeholder 106 | 107 | Fork of the JS version 108 | 109 | ##### !end-placeholder 110 | 111 | 112 | 113 | 114 | 115 | 116 | ### !end-challenge 117 | 118 | -------------------------------------------------------------------------------- /old-lessons/05-hash-tables/images/Example-hash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/05-hash-tables/images/Example-hash.png -------------------------------------------------------------------------------- /old-lessons/05-hash-tables/images/big-o-cheatsheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/05-hash-tables/images/big-o-cheatsheet.png -------------------------------------------------------------------------------- /old-lessons/05-hash-tables/images/cash-register.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/05-hash-tables/images/cash-register.jpg -------------------------------------------------------------------------------- /old-lessons/05-hash-tables/images/hash-table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/05-hash-tables/images/hash-table.png -------------------------------------------------------------------------------- /old-lessons/05-hash-tables/images/linear-probing-clustering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/05-hash-tables/images/linear-probing-clustering.png -------------------------------------------------------------------------------- /old-lessons/05-hash-tables/images/linear-probing-clustering2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/05-hash-tables/images/linear-probing-clustering2.png -------------------------------------------------------------------------------- /old-lessons/05-hash-tables/images/linear-probing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/05-hash-tables/images/linear-probing.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/01-heaps.md: -------------------------------------------------------------------------------- 1 | # Heaps 2 | 3 | 4 | 5 | ## Learning Goals 6 | 7 | By the end of this lesson you should be able to: 8 | 9 | - Describe a heap data structure 10 | - Explain how a heap data structure is maintained as elements are added and removed 11 | - Explain several use-cases for a heap 12 | 13 | ## Video Lesson & Slides 14 | 15 | - [Video Lesson](https://adaacademy.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=608a709b-d0c2-4273-815d-ada2004e4e8d) 16 | - [Slide Deck](https://docs.google.com/presentation/d/1UojimxYNCm7r4lxs5owPuST-e26uwN_h5jLjTBdQzgs/edit#slide=id.p7) 17 | - [Heap Exercise](https://github.com/ada-C16/heaps) 18 | 19 | ## Introduction 20 | 21 | In this lesson we will introduce a new data structure, a heap! Heaps are a great way to store information in a semi-order. Essentially if you have a collection of data that you can sort or compare, you can add it to a heap. A heap maintains a [complete binary tree](https://web.cecs.pdx.edu/~sheard/course/Cs163/Doc/FullvsComplete.html). In a complete binary tree each level is full except the last, and the last level is filled from left-to-right. Further, in a heap each parent has a specific order-relationship with it's children. In a Min-Heap every parent node is less than its child nodes. In a Max-Heap, every parent node is greater than its child nodes. 22 | 23 | Below is a drawing of a Max-Heap. 24 | 25 | ![Heap Diagram](images/heap.png) 26 | 27 | 28 | 29 | On the other hand this is **not** a Max-Heap. Notice that 47 on the bottom level is greater than 25, its parent. 30 | 31 | ![Invalid Max-Heap](images/invalid-max-heap.png) 32 | 33 | This is also **not** a Max-Heap. The last level is not full from left-to-right. The 20 should be the left-child of 35. 34 | 35 | ![Another Invalid Max-Heap](images/invalid-max-heap2.png) 36 | 37 | ## Uses for Heaps 38 | 39 | There are times when you remove items from a data structure in a specific order. For example consider an employee has been given a list of tasks to complete. However they should be handled by priority. The most important jobs should be handled first. 40 | 41 | We could use arrays or linked lists to store tasks, but that would entail `O(n)` time complexity for inserting and removing tasks. 42 | 43 | We could use a binary search tree to store the tasks. However, as we discovered, maintaining the balance of the tree is a very expensive and difficult operation. However, properly handled adding or removing tasks would be `O(log n)` time complexity. Unfortunately however writing the tree to a disk or external storage using a traversal would entail `O(n)` time complexity to convert the data structure to a list. 44 | 45 | Heaps provide a method of maintaining a balanced binary tree (but not a binary *search* tree) with O(log n) time complexity for adding and removing items, and maintain all elements in an internal array to allow faster transfer to external devices, like external storage. 46 | 47 | ### Priority Queues 48 | 49 | What we have described is a _Priority Queue_. A priority queue is an abstract data type, like a stack or a regular queue. However, with a queue items are added and removed in a first-in-first-out (FIFO) order. Priority queues remove items with the highest priority first. By using a heap to implement a priority queue you can build a data structure to serve data by priority. 50 | 51 | ### Heapsort 52 | 53 | Since heaps allow you to extract elements in order, you can use them to sort an array. 54 | 55 | With an array of `n` elements, to perform Heapsort you can add the elements to the heap, an O(nlog n) operation. Then you can remove the elements from the heap one-by-one placing them in the proper place in an array, also an O(nlog n) operation. 56 | 57 | It is possible to do this with O(1) space complexity using the original array to store the heap elements and a single temporary variable. 58 | 59 | So how does this compare? Well, adding the elements to a heap and then placing them back in the array in order is O(nlog n + nlog n) = O(nlog n). That's a pretty good sort. On average it is not as fast as [QuickSort](https://www.geeksforgeeks.org/quick-sort/), but it has a **much** better worst-case time complexity, as QuickSort has a worst-case of O(n2). It is also slower than [MergeSort](https://www.geeksforgeeks.org/merge-sort/), but has a better space complexity - O(1) compared to O(n). 60 | 61 | 62 | ### !callout-secondary 63 | 64 | ## Dijkstra’s Algorithm 65 | 66 | We will later look at [Dijkstra’s algorithm](https://brilliant.org/wiki/dijkstras-short-path-finder/) to find the shortest path in a weighted graph from a starting node to all other points in a graph. 67 | 68 | ### !end-callout 69 | 70 | ## Implementation 71 | 72 | While you **can** implement a heap with linked TreeNode objects, it can be **much** easier to implement a heap with an array. 73 | 74 | Consider if the root is at index 0, the left child could be at index 1, and right index 2. The child of index 1 would be at index 3 and 4 while the children of index 2 are at 5 and 6... we could write a formula to find the children of a node at index _i_. 75 | 76 | ```python 77 | left_child = i * 2 + 1 78 | right_child = i * 2 + 2 79 | ``` 80 | 81 | So this heap: 82 | 83 | ![Heap Diagram](images/heap.png) 84 | 85 | In Array format: 86 | 87 | ![Heap as an Array](images/heap-as-array.png) 88 | 89 | ### Adding An Element 90 | 91 | To add an element to a heap, you place it into the end of the array (or the next logical leaf). Then you do a "heap-up" operation comparing the new node to its parent and swapping them if they are out of order. Then, if a swap occurred, repeat the operation using the new node's updated location. 92 | 93 | Below is an example of adding a node to a heap. 94 | 95 | ![heap-up diagram](images/heap-up.png) 96 | 97 | When finished the heap could look like this. 98 | 99 | ![Heap-up finished diagram](images/add-element-finished.png) 100 | 101 | Pictured with an array it would look like this: 102 | 103 | ![heap-up with an array](images/heap-up-array.png) 104 | 105 | The add method would look like this: 106 | 107 | ```python 108 | # This heap is sorted by key-value pairs 109 | def add(self, key, value) 110 | self.store.append(HeapNode.new(key, value)) 111 | 112 | # Compare the new node with it's parent 113 | # If they are out of order swap and heap-up 114 | # using the parent's index number. 115 | # Implementation not shown purposefully. 116 | self.heap_up(self.store.length - 1) 117 | ``` 118 | 119 | **Exercise:** Write pseudocode for the heap-up method using an array implementation for a heap. Then compare your steps with your neighbor. 120 | 121 | #### Add Node Time Complexity 122 | 123 | Adding a value to the end of the array is an O(1) operation (assuming the array is large enough). Performing the heap-up operation will at worst-case perform 1 swap per level of the heap. Since there are `Log n` levels to the heap, then adding a node is a O(log n) operation. 124 | 125 | ### Removing An Element 126 | 127 | Removing an element in some ways works in the opposite manner of adding an element. To remove an element you can swap the last leaf with the root. Then compare the new root with its children and swap to maintain the heap order in an operation called heap-down. The heap down operation is repeated until a leaf node is reached or no swaps are made. 128 | 129 | 1. First, swap the last leaf & the root node 130 | 131 | ![Initial swap for remove](images/heap-remove-1.png) 132 | 133 | 2. Delete the last leaf (last item in the array) 134 | 135 | ![Heap delete node](images/heap-delete.png) 136 | 137 | 3. Then heap-down the new root, to reestablish the heap property 138 | 139 | ![Initial swap for remove](images/heap-remove-2.png) 140 | 141 | 4. Then you should have a new, slightly smaller heap 142 | 143 | ![Initial swap for remove](images/heap-remove-3.png) 144 | 145 | So removing a node could be done with: 146 | 147 | ```python 148 | def remove(self): 149 | if self.store.empty? 150 | return nil 151 | 152 | self.swap(0, self.store.last - 1) 153 | result = self.store.pop() 154 | 155 | # heap_down is specifically not 156 | # implemented here 157 | # start heap_down with the root (index 0) 158 | self.heap_down(0) unless self.store.empty? 159 | return result 160 | 161 | 162 | def swap(self, index_1, index_2) 163 | temp = self.store[index_1] 164 | self.store[index_1] = self.store[index_2] 165 | self.store[index_2] = temp 166 | ``` 167 | 168 | Looking at it as an array: 169 | 170 | ![heap up with an array 1](images/heap-down-array-1.png) 171 | 172 | ![heap up with an array 2](images/heap-down-array-2.png) 173 | 174 | With the result: 175 | 176 | ![heap up with an array 3](images/heap-down-array-3.png) 177 | 178 | 179 | **Exercise:** Write pseudocode to implement the heap_down operation. Note that you will need to verify that you may swap all the way down to a leaf node. 180 | 181 | 182 | ### !callout-info 183 | 184 | ## Sidenote: The System Heap 185 | 186 | When you allocate memory dynamically with `.new` or `malloc` in C, the operating system allocates the memory from something called [Heap Memory](https://www.geeksforgeeks.org/stack-vs-heap-memory-allocation/). This is **not** the same as the heap data structure. Instead it's considered a "heap" of memory, like clothes in the laundry basket is a heap of clothes. 187 | 188 | ### !end-callout 189 | 190 | ## Summary 191 | 192 | Heaps are a data structure to maintain elements in order. They can be diagramed as a complete tree, but are often implemented as an array. Each array element can represent one node in a binary tree. 193 | 194 | Adding a node involves placing a node in the next available leaf node and then conducting a series of swaps with its parent until heap order is achieved. Removing an element involves swapping the last leaf with the root of the heap, removing the last leaf, and then swapping the updated root with its children until a valid heap realtionship is established. 195 | 196 | ## Resources 197 | 198 | - [Basecs on Heaps](https://medium.com/basecs/learning-to-love-heaps-cef2b273a238) 199 | - [Basecs on Heapsort](https://medium.com/basecs/heapify-all-the-things-with-heap-sort-55ee1c93af82) 200 | - [Geeks for Geeks on Heaps](https://www.geeksforgeeks.org/heap-data-structure/) -------------------------------------------------------------------------------- /old-lessons/06-heaps/02-heaps-exercise-checkpoint.md: -------------------------------------------------------------------------------- 1 | # Heaps Exercise 2 | 3 | | Logistics | Details | 4 | | --------------------- | ---------------------------------------- | 5 | | Project details | https://github.com/Ada-C16/heaps | 6 | | JS Version | https://github.com/Ada-C16/heaps-js | 7 | | Should you fork this? | Yes (Check project details) | 8 | | Submission method | Learn | 9 | 10 | ## Exercise 11 | 12 | ### !challenge 13 | 14 | * type: testable-project 15 | * id: 5dd9df36-0742-4209-8031-2bae37597660 16 | * title: Heaps Practice 17 | * upstream: https://github.com/Ada-C16/heaps 18 | * validate_fork: false 19 | * points: 0 20 | * topics: heaps 21 | 22 | ##### !question 23 | 24 | Fork the linked repo and submit your completed exercise. **Then** on the next question submit your PR, so I can make PR comments. 25 | 26 | ##### !end-question 27 | 28 | ##### !placeholder 29 | 30 | Link to your repo 31 | 32 | ##### !end-placeholder 33 | 34 | 35 | 36 | 37 | 38 | 39 | ### !end-challenge 40 | 41 | 42 | 43 | 44 | 45 | 46 | ### !challenge 47 | 48 | * type: short-answer 49 | * id: 7bd86646-4629-45e2-bded-997a77359c99 50 | * title: Link to your PR 51 | * points: 3 52 | * topics: heaps 53 | 54 | ##### !question 55 | 56 | Submit a link of your PR for the project. 57 | 58 | ##### !end-question 59 | 60 | ##### !placeholder 61 | 62 | Your PR link goes here. 63 | 64 | ##### !end-placeholder 65 | 66 | ##### !answer 67 | 68 | /^https:\/\/github.com\/.*\/pull.*\d$/ 69 | 70 | ##### !end-answer 71 | 72 | 73 | 74 | 75 | 76 | 77 | ### !end-challenge 78 | 79 | 80 | 81 | ## Optional JS Version 82 | 83 | 84 | 85 | 86 | ### !challenge 87 | 88 | * type: testable-project 89 | * id: 770e6706-7f39-4b44-99a4-88c563672c1c 90 | * title: Optional JavaScript Version 91 | * upstream: https://github.com/Ada-C16/heaps-js 92 | * validate_fork: false 93 | * points: 0 94 | * topics: heaps 95 | 96 | ##### !question 97 | 98 | Add a link to your fork of the [JavaScript version](https://github.com/Ada-C16/heaps-js) 99 | 100 | ##### !end-question 101 | 102 | ##### !placeholder 103 | 104 | Add a link to your Heaps-js repo. 105 | 106 | ##### !end-placeholder 107 | 108 | 109 | 110 | 111 | 112 | 113 | ### !end-challenge 114 | 115 | -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/add-element-finished.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/add-element-finished.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-as-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-as-array.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-delete.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-down-array-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-down-array-1.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-down-array-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-down-array-2.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-down-array-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-down-array-3.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-remove-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-remove-1.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-remove-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-remove-2.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-remove-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-remove-3.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-remove-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-remove-4.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-up-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-up-array.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap-up.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/heap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/heap.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/invalid-max-heap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/invalid-max-heap.png -------------------------------------------------------------------------------- /old-lessons/06-heaps/images/invalid-max-heap2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ada-Developers-Academy/ada-CS-Fundamentals-Internship/04850f80a2cb10d9729756878837c580eb6b9053/old-lessons/06-heaps/images/invalid-max-heap2.png -------------------------------------------------------------------------------- /old-lessons/10-negotiations-and-resumes/01-negotiation-fundamentals.md: -------------------------------------------------------------------------------- 1 | # Negotiation Fundamentals 2 | 3 | The following are video webinars designed to help reinforce negotiation techniques and strategies. This is to help you all arrive at the best deals possible for entry-level developers. 4 | 5 | The required videos are must-watch prior to the negotiation lesson held in a session later this unit. 6 | 7 | - Required Videos (in order) 8 | - [Why we need negotiations training](https://player.mediaamp.io/p/U8-EDC/7xghIAXCClvt/select/media/ZpcYXJ8n_d53) (5:30) 9 | - [Planning for a negotiation](https://player.mediaamp.io/p/U8-EDC/7xghIAXCClvt/select/media/CAZ9zvkz65Wm) (4:12) 10 | - [Job Negotiation Tips Part 1](https://player.mediaamp.io/p/U8-EDC/7xghIAXCClvt/select/media/CzHmcOmA3Ms_) (4:35) 11 | - [Job Negotiation Tips Part 2](https://player.mediaamp.io/p/U8-EDC/7xghIAXCClvt/select/media/f6Lyun6_WT98) (4:41) 12 | - Optional videos (full webinars) 13 | - [Introduction to Negotiations](https://www.youtube.com/watch?v=ps4OiLP_rzk&feature=emb_title) (1 hour) 14 | - [Single Issue Negotiations](https://www.youtube.com/watch?v=TKqZQmZ3sVI&feature=emb_title) (1 hour) 15 | - Multi-Issue Negotiations TBD 16 | 17 | 18 | ## Questions 19 | 20 | Please submit any questions you have on the above videos through the following form. 21 | 22 | [Salary Negotiation Questions for Professor Umphress](https://docs.google.com/forms/d/e/1FAIpQLSfzK5TY_yvmAxowB2p0rXZ72aT60ZWQOHgOlAMZbO_LgoANSg/viewform) -------------------------------------------------------------------------------- /old-lessons/10-negotiations-and-resumes/resumes.md: -------------------------------------------------------------------------------- 1 | # Resume Submission 2 | 3 | Please submit your resume to Emma via [this google form](https://docs.google.com/forms/d/e/1FAIpQLSc66i0N0eEuxlbdUlOKk8PJZ7F3usgqTDtRDA8XrgUJPhNKcw/viewform?pli=1) by the morning of ADD-DEADLINE-HERE. 4 | 5 | You may need to log into a Google account to submit the form. 6 | -------------------------------------------------------------------------------- /old-lessons/11-crash-courses/01-oop.md: -------------------------------------------------------------------------------- 1 | # Object Oriented Programming: A Crash Course 2 | 3 | 4 | 5 | ## OOP Crash Course Slides 6 | - [Slide Deck used for OOP Crash Course](https://docs.google.com/presentation/d/1HYJDxmwykDBH2sSQMdmGPHp33QfrS1bmAOmTOPMWfsc/edit?usp=sharing) 7 | 8 | ## Python Tutor 9 | - [Linked List Visualization with Python Tutor](https://pythontutor.com/render.html#code=class%20Node%3A%0A%20%20%20%20def%20__init__%28self,%20value%29%3A%0A%20%20%20%20%20%20%20%20self.val%20%3D%20value%0A%20%20%20%20%20%20%20%20self.next%20%3D%20None%0A%0A%20%20%20%20def%20printNode%28self%29%3A%0A%20%20%20%20%20%20%20%20print%28self.val%29%0A%0Aclass%20LinkedList%3A%0A%20%20%20%20def%20__init__%28self,%20head%20%3D%20None%29%3A%0A%20%20%20%20%20%20%20%20self.head%20%3D%20head%0A%0A%20%20%20%20def%20printList%28self%29%3A%0A%20%20%20%20%20%20current%20%3D%20self.head%0A%20%20%20%20%20%20while%20current%20!%3D%20None%3A%0A%20%20%20%20%20%20%20%20current.printNode%28%29%0A%20%20%20%20%20%20%20%20current%20%3D%20current.next%0A%0A%20%20%20%20def%20printSizeOfList%28self%29%3A%0A%20%20%20%20%20%20pass%0A%0Anode_a%20%3D%20Node%28%22A%22%29%0Anode_b%20%3D%20Node%28%22B%22%29%0Anode_c%20%3D%20Node%28%22C%22%29%0A%0Anode_a.next%20%3D%20node_b%0Anode_b.next%20%3D%20node_c%0A%0Alinked_list%20%3D%20LinkedList%28node_a%29%0Alinked_list.printList%28%29&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false) 10 | 11 | One can use Python Tutor to visualize what happens in the memory addresses of the Python program during the creation of the `Node` and `LinkedList` class and the initialization of the objects `node_a`, `node_b`, `node_c`, and `linked_list`. If you are feeling curious, click the link above and walk through the program line by line to see what happens in the program's memory during execution. 12 | -------------------------------------------------------------------------------- /old-lessons/11-crash-courses/02-recursion.md: -------------------------------------------------------------------------------- 1 | # Recursion: A Crash Course 2 | 3 | 4 | 5 | ## Recursion Crash Course Slides 6 | - [Slide Deck used for Recursion Crash Course](https://docs.google.com/presentation/d/1DrEy1sy7qt2vDp6gKSyuXOvni7NouxfHj6hFAKwYI4I/edit?usp=sharing) 7 | 8 | ## Array-to-BST Code Block (used at timestamp 24:00) 9 | If you have the screen space available to do so, you can follow along to the whiteboard walkthrough at timestamp 24:00 using the code block below. 10 | 11 | ```py 12 | class TreeNode: 13 | def __init__(self, value, left = None, right = None): 14 | self.val = value 15 | self.left = left 16 | self.right = right 17 | 18 | 19 | def arr_to_bst(arr): 20 | if not arr: 21 | return None 22 | 23 | mid = (len(arr)) // 2 24 | 25 | root = TreeNode(arr[mid]) 26 | root.left = arr_to_bst(arr[:mid]) 27 | root.right = arr_to_bst(arr[mid + 1:]) 28 | return root 29 | ``` 30 | 31 | ## Python Tutor 32 | - [Sorted Array to BST Recursive Function with Python Tutor](https://pythontutor.com/visualize.html#code=class%20TreeNode%3A%0A%20%20%20%20def%20__init__%28self,%20value,%20left%20%3D%20None,%20right%20%3D%20None%29%3A%0A%20%20%20%20%20%20%20%20self.val%20%3D%20value%0A%20%20%20%20%20%20%20%20self.left%20%3D%20left%0A%20%20%20%20%20%20%20%20self.right%20%3D%20right%0A%0A%0Adef%20arr_to_bst%28arr%29%3A%0A%20%20%20%20if%20not%20arr%3A%0A%20%20%20%20%20%20%20%20return%20None%0A%0A%20%20%20%20mid%20%3D%20%28len%28arr%29%29%20//%202%0A%0A%20%20%20%20root%20%3D%20TreeNode%28arr%5Bmid%5D%29%0A%20%20%20%20root.left%20%3D%20arr_to_bst%28arr%5B%3Amid%5D%29%0A%20%20%20%20root.right%20%3D%20arr_to_bst%28arr%5Bmid%20%2B%201%3A%5D%29%0A%20%20%20%20return%20root%0A%20%20%20%20%0Asorted_array%20%3D%20%5B4,%205,%2010,%2012,%2019,%2048%5D%0Aarr_to_bst%28sorted_array%29&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false 33 | ) 34 | 35 | One can use Python Tutor to visualize what happens in the memory addresses of the Python program for recursive functions. 36 | --------------------------------------------------------------------------------