From 4ad0a31bd0faa253d5bec9fb4cb53c5b845ccd69 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Fri, 21 Feb 2020 13:08:05 -0800 Subject: [PATCH 01/24] Add trees slides 1-10 --- Leetcode Workshops/Week 2/Act2_Trees/1.md | 3 +++ Leetcode Workshops/Week 2/Act2_Trees/10.md | 12 ++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/2.md | 3 +++ Leetcode Workshops/Week 2/Act2_Trees/3.md | 13 +++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/4.md | 15 +++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/5.md | 5 +++++ Leetcode Workshops/Week 2/Act2_Trees/6.md | 6 ++++++ Leetcode Workshops/Week 2/Act2_Trees/7.md | 17 +++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/8.md | 10 ++++++++++ Leetcode Workshops/Week 2/Act2_Trees/9.md | 9 +++++++++ 10 files changed, 93 insertions(+) create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/1.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/10.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/2.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/3.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/4.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/5.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/6.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/7.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/8.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/9.md diff --git a/Leetcode Workshops/Week 2/Act2_Trees/1.md b/Leetcode Workshops/Week 2/Act2_Trees/1.md new file mode 100755 index 0000000..575a4eb --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/1.md @@ -0,0 +1,3 @@ + + +# Trees diff --git a/Leetcode Workshops/Week 2/Act2_Trees/10.md b/Leetcode Workshops/Week 2/Act2_Trees/10.md new file mode 100755 index 0000000..7d5e9a9 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/10.md @@ -0,0 +1,12 @@ + + + +```Python +class Node: + def __init__(self, key): + self.left = None + self.right = None + self.key = key +``` + +In order to implement a BST in Python, we just need to adjust our previous `Node` class.Since we know that BST nodes only have two children max, we no longer need a list to store the children. We simply store the left child as the **left** element and the right child as the **right** element. In the `Node` class the left and right children are initialized to null. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/2.md b/Leetcode Workshops/Week 2/Act2_Trees/2.md new file mode 100755 index 0000000..fa38dc6 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/2.md @@ -0,0 +1,3 @@ + + +Today we are going to learn about tree data structures. In order to do so, it is important that we understand the essential terminology. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/3.md b/Leetcode Workshops/Week 2/Act2_Trees/3.md new file mode 100755 index 0000000..8603231 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/3.md @@ -0,0 +1,13 @@ + + +## Tree Terminology: + +* **Tree**: Hierarchical structure used to store data elements. Trees have no cycles (connections are one-way and never to previous elements), and are "upside-down" in that the root is at the top and leaves are at the bottom. + +* **Node**: Each individual data element of the tree that is linked to other data elements within the tree. Identified by a key. + +* **Edge**: Link that connects two nodes. + +* **Level**: The number of parent nodes that a given node has. For instance, the root node has 0 parents so it is at Level 0. It's children are at Level 1, grandchildren at Level 2, and so on. + +* **Subtree**: A grouping of connected nodes within the tree. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/4.md b/Leetcode Workshops/Week 2/Act2_Trees/4.md new file mode 100755 index 0000000..5ac1e51 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/4.md @@ -0,0 +1,15 @@ + + +## Nodes + +* **Root Node**: The node with highest hierarchical precedence. Each tree can only have one root node. + +* **Parent Node**: The predecessor of a node is called its parent. The root node does not have a parent. + +* **Child Node**: The descendant of a node is called its child. + +* **Sibling Nodes**: The nodes that have the same parent are called siblings. + +* **Leaf Nodes**: A node that does not have a child is called a leaf. + +* **Internal Nodes**: A node that has at least one child is called an internal node. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/5.md b/Leetcode Workshops/Week 2/Act2_Trees/5.md new file mode 100755 index 0000000..4e15026 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/5.md @@ -0,0 +1,5 @@ + + + + + In the tree above, the circles with numbers in them are the **nodes** of the tree. The arrows connecting each nodes are the **edges**. The **root** of this tree is the node that contains the number 8. The node containing 3 is a **parent** of the node containing 1. The node containing 1 is a **child** of the node containing 3. The nodes with 4 and 7 are **siblings**. The nodes with 1, 4, 7, and 13 are **leaf nodes**. The nodes containing 8, 3, 10, 6, and 14 are all **internal nodes**. Finally, the group of nodes with values 6, 4, and 7 are a **subtree** of the tree. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/6.md b/Leetcode Workshops/Week 2/Act2_Trees/6.md new file mode 100755 index 0000000..6eb8a8e --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/6.md @@ -0,0 +1,6 @@ + +## Real Life Application of Trees: +### Ancestry Trees: + + +You may be wondering why we would want to use trees. A real life example of a tree structure being used is in ancestry trees. Think of each person in the family as a node. Every person in the family tree is related to other people in the family in some way as a sibling, parent, grandparent, etc. Tree data structures behave in a very similar way as they are both hierarchical structures with nodes, or family members, connected together in a certain manner, and the connection between nodes are there for a specific reason. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/7.md b/Leetcode Workshops/Week 2/Act2_Trees/7.md new file mode 100755 index 0000000..189d8e8 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/7.md @@ -0,0 +1,17 @@ + +## Let's Definen the `Node` Class: + + + + +```Python +class Node: + def __init__(self, key): + self.key = key + self.children = [] + + def insert_child(self, newChild): + self.children.append(newChild) +``` + +for this implementation, we will declare a class `Node` in which in each instance of the class represents a node of the tree. The `Node` class contains the data value of a node and a list of its children. This implementation also includes an `insert_child` function that simply appends the node passed as an argument to the current node's list of children. Since each node has its children stored in it, the structure of the tree is maintained, making the `Tree` class unnecessary. You may be asking why we don't keep track of each node's parent. While this may be useful or necessary for some more advanced types of trees, it is not needed to implement a base tree that we're currently investigating. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/8.md b/Leetcode Workshops/Week 2/Act2_Trees/8.md new file mode 100755 index 0000000..f82bf3f --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/8.md @@ -0,0 +1,10 @@ + +## Binary Trees: + +A simple tree structure is fundamental, but let's investigate a specific type of tree that allows for an interesting and structured way to store data. A **Binary Tree** is a tree where every single node can only have zero, one, or two children. The tree structure we will be dealing with, however, is a special kind of Binary Tree, the **Binary Search Tree (BST)**. **BST**s have a few more restrictions: + +* Every element in the left subtree of a node has keys that are lesser in value than the key of that particular node. + +* Every element in the right subtree of a node has keys that are greater in value than the key of that particular node. + + diff --git a/Leetcode Workshops/Week 2/Act2_Trees/9.md b/Leetcode Workshops/Week 2/Act2_Trees/9.md new file mode 100755 index 0000000..99e529e --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/9.md @@ -0,0 +1,9 @@ + + + Let's see an example of a valid vs invalid BST: + + ​ + + + +The **left** tree is an **invalid** BST because the node containing the key `10` is in a right subtree of the node containing the key `30`. You may have noticed that all subtrees of a BST are also BSTs. From 25ffb37e68d825ff44bd9b1211c329ef16e00303 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Fri, 21 Feb 2020 13:45:33 -0800 Subject: [PATCH 02/24] add 4.2.2 trees slides 11-16 --- Leetcode Workshops/Week 2/Act2_Trees/11.md | 18 ++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/12.md | 6 ++++++ Leetcode Workshops/Week 2/Act2_Trees/13.md | 8 ++++++++ Leetcode Workshops/Week 2/Act2_Trees/14.md | 21 +++++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/15.md | 4 ++++ Leetcode Workshops/Week 2/Act2_Trees/16.md | 13 +++++++++++++ 6 files changed, 70 insertions(+) create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/11.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/12.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/13.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/14.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/15.md create mode 100755 Leetcode Workshops/Week 2/Act2_Trees/16.md diff --git a/Leetcode Workshops/Week 2/Act2_Trees/11.md b/Leetcode Workshops/Week 2/Act2_Trees/11.md new file mode 100755 index 0000000..797a1ac --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/11.md @@ -0,0 +1,18 @@ + + + +## BST Search: + + + +```Python +def BSTSearch(curNode, key): + if curNode is None or curNode.key == key: + return curNode + if curNode.key < key: + return BSTSearch(curNode.right, key) #Go right + else: + return search(curNode.left, key) #Go left +``` + +The `BSTSearch` function behaves similarly to how you would if you were looking for a specific key in a BST: go right if you're looking for a larger key or go left if you're looking for a smaller key. It starts at the root and calls the same function again on its right child if the desired key is greater than the current node's key or calls the same function again on its left child if the desired key is less than the current node's key. It eventually returns the current node being inspected if the node's key matches the desired key or returns null if it doesn't find a node with a desired key. Make sure you understand the code above before moving forward. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/12.md b/Leetcode Workshops/Week 2/Act2_Trees/12.md new file mode 100755 index 0000000..772c718 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/12.md @@ -0,0 +1,6 @@ + + + + + +Let's actually see this in action, using use the tree from the previous card as as an example. Let's say we want to find `7` in our tree. Above, you can see the specific path that `BSTSearch` takes to look for the node diff --git a/Leetcode Workshops/Week 2/Act2_Trees/13.md b/Leetcode Workshops/Week 2/Act2_Trees/13.md new file mode 100755 index 0000000..9ab36f9 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/13.md @@ -0,0 +1,8 @@ + +## Time Complexity of `BSTSearch`: + + + +The diagram depicts the worst-case scenario when searching for the node with key 50. As you can see, the time to reach a desired node would be O(height), and in this worst-case scenario, it would be **O(n)**, with **n** being the amount of nodes in the tree, since you have to search through every node in the tree. + +Thus, the time complexity of `BSTSearch` is **= O(n)** diff --git a/Leetcode Workshops/Week 2/Act2_Trees/14.md b/Leetcode Workshops/Week 2/Act2_Trees/14.md new file mode 100755 index 0000000..fe25965 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/14.md @@ -0,0 +1,21 @@ + +## `BSTInsert`: + +```Python +def BSTInsert(curNode, newNode): + if curNode is None: + curNode = newNode + else: + if curNode.key < newNode.val: + if curNode.right is None: + curNode.right = newNode + else: + BSTInsert(curNode.right, newNode) + else: + if curNode.left is None: + curNode.left = newNode + else: + BSTInsert(curNode.left, newNode) +``` + +When adding a new node to a BST, we must make sure to find the correct place to insert that node.`BSTInsert` traverses through the BST in a similar way to `BSTSearch`. However, once it finds that the specific child is null in the place where the new node belongs, it places that node there. Try working and experimenting with the code on your own machine. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/15.md b/Leetcode Workshops/Week 2/Act2_Trees/15.md new file mode 100755 index 0000000..79755c6 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/15.md @@ -0,0 +1,4 @@ + + + +let's use an example to illustrate how this code works, . We will add a node `11` to this tree. You can see the specific path that `BSTInsert` takes to insert the node as well as the actual position that `11` ends up in. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/16.md b/Leetcode Workshops/Week 2/Act2_Trees/16.md new file mode 100755 index 0000000..0cb7232 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/16.md @@ -0,0 +1,13 @@ + + + +## Time Complexity of `BSTInsert` : + +Similarly to `BSTSearch`, the worst-case scenario runtime for `BSTInsert` is also **O(n)**. The worst-case would occur when you have to go through every node in the tree to find the proper place to insert the node. + + + + + + +In order to insert `60` into this tree, we needed to visit every other node first. Hence, this was a worst-case scenario. \ No newline at end of file From 5a6d842c2bf2e9706a288f42e0012a14bafa4d14 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Fri, 21 Feb 2020 21:51:45 -0800 Subject: [PATCH 03/24] update 4.2.2 trees slides 1-16 --- Leetcode Workshops/Week 2/Act2_Trees/1.md | 11 ++++-- Leetcode Workshops/Week 2/Act2_Trees/10.md | 39 +++++++++++++++++----- Leetcode Workshops/Week 2/Act2_Trees/11.md | 22 ++++-------- Leetcode Workshops/Week 2/Act2_Trees/12.md | 20 +++++++++-- Leetcode Workshops/Week 2/Act2_Trees/13.md | 29 ++++++++++++---- Leetcode Workshops/Week 2/Act2_Trees/14.md | 27 +++++---------- Leetcode Workshops/Week 2/Act2_Trees/15.md | 17 ++++++++-- Leetcode Workshops/Week 2/Act2_Trees/16.md | 12 ------- Leetcode Workshops/Week 2/Act2_Trees/2.md | 20 +++++++++-- Leetcode Workshops/Week 2/Act2_Trees/3.md | 18 ++++++---- Leetcode Workshops/Week 2/Act2_Trees/4.md | 30 ++++++++--------- Leetcode Workshops/Week 2/Act2_Trees/5.md | 11 ++++-- Leetcode Workshops/Week 2/Act2_Trees/6.md | 30 ++++++++++++++--- Leetcode Workshops/Week 2/Act2_Trees/7.md | 27 ++++++++------- Leetcode Workshops/Week 2/Act2_Trees/8.md | 15 ++++++--- Leetcode Workshops/Week 2/Act2_Trees/9.md | 19 +++++++---- 16 files changed, 221 insertions(+), 126 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/1.md b/Leetcode Workshops/Week 2/Act2_Trees/1.md index 575a4eb..07173bb 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/1.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/1.md @@ -1,3 +1,10 @@ - - + + + # Trees + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Today we are going to learn about tree data structures. In order to do so, it is important that we understand the essential terminology) + + diff --git a/Leetcode Workshops/Week 2/Act2_Trees/10.md b/Leetcode Workshops/Week 2/Act2_Trees/10.md index 7d5e9a9..7786999 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/10.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/10.md @@ -1,12 +1,35 @@ - - + + + +## BST Search: + ```Python -class Node: - def __init__(self, key): - self.left = None - self.right = None - self.key = key +def BSTSearch(curNode, key): + if curNode is None or curNode.key == key: + return curNode + if curNode.key < key: + return BSTSearch(curNode.right, key) #Go right + else: + return search(curNode.left, key) #Go left ``` -In order to implement a BST in Python, we just need to adjust our previous `Node` class.Since we know that BST nodes only have two children max, we no longer need a list to store the children. We simply store the left child as the **left** element and the right child as the **right** element. In the `Node` class the left and right children are initialized to null. \ No newline at end of file +- Go right if you're looking for a larger key or go left if you're looking for a smaller key. + +- It starts at the root and calls the same function again on right child if the desired key is greater than the current node's key + +- If it's not it calls the same function again on its left child if the desired key + +- It returns the current node if the node's key matches the desired key +- It returns null if it doesn't find a node with a desired key. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Now that we understand the basic structure of a Binary Search Tree, let's start to build up some useful functions that will allow us to access and manipulate our trees.) +[for speaker]: <> (If you know the key to a specific node in a BST and want to access it within your BST, how would you do this? Let's build a function called `BSTSearch` that will allow us to do this.) + +[for speaker]: <> (The `BSTSearch` function behaves similarly to how you would if you were looking for a specific key in a BST: go right if you're looking for a larger key or go left if you're looking for a smaller key.) + +[for speaker]: <> (It starts at the root and calls the same function again on its right child if the desired key is greater than the current node's key or calls the same function again on its left child if the desired key is less than the current node's key.) + +[for speaker]: <> (It eventually returns the current node being inspected if the node's key matches the desired key or returns null if it doesn't find a node with a desired key. Make sure you understand the code above before moving forward.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/11.md b/Leetcode Workshops/Week 2/Act2_Trees/11.md index 797a1ac..c81d324 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/11.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/11.md @@ -1,18 +1,10 @@ - - + + +## Example of `BFSSearch` + -## BST Search: - - +Use `BFSSearch` to search for 7 -```Python -def BSTSearch(curNode, key): - if curNode is None or curNode.key == key: - return curNode - if curNode.key < key: - return BSTSearch(curNode.right, key) #Go right - else: - return search(curNode.left, key) #Go left -``` +----------------------------------------------------------------------------------------------------- -The `BSTSearch` function behaves similarly to how you would if you were looking for a specific key in a BST: go right if you're looking for a larger key or go left if you're looking for a smaller key. It starts at the root and calls the same function again on its right child if the desired key is greater than the current node's key or calls the same function again on its left child if the desired key is less than the current node's key. It eventually returns the current node being inspected if the node's key matches the desired key or returns null if it doesn't find a node with a desired key. Make sure you understand the code above before moving forward. +[for speaker]: <> (Let's actually see this in action, using use the tree from the previous card as as an example. Let's say we want to find `7` in our tree. Above, you can see the specific path that `BSTSearch` takes to look for the node) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/12.md b/Leetcode Workshops/Week 2/Act2_Trees/12.md index 772c718..8c8a8e7 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/12.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/12.md @@ -1,6 +1,20 @@ - + + +## Time Complexity of `BSTSearch`: + - +* Searching for the node with key 50. -Let's actually see this in action, using use the tree from the previous card as as an example. Let's say we want to find `7` in our tree. Above, you can see the specific path that `BSTSearch` takes to look for the node +* The time to reach a desired node would be O(height) + +* In this worst-case scenario, it would be **O(n)**, with **n** being the amount of nodes in the tree. + +* The time complexity of `BSTSearch` is **= O(n)** + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Since we're interested in finding the asymptotic time in the **worst-case**, we must consider what the worst case situation would be when searching for a node.) +[for speaker]: <> (The diagram depicts the worst-case scenario when searching for the node with key 50. As you can see, the time to reach a desired node would be O[height], and in this worst-case scenario, it would be O[n], with n being the amount of nodes in the tree, since you have to search through every node in the tree.) + +[for speaker]: <> (Thus, the time complexity of `BSTSearch` is O[n]) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/13.md b/Leetcode Workshops/Week 2/Act2_Trees/13.md index 9ab36f9..5add3c6 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/13.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/13.md @@ -1,8 +1,25 @@ - -## Time Complexity of `BSTSearch`: - - + + +## `BSTInsert`: -The diagram depicts the worst-case scenario when searching for the node with key 50. As you can see, the time to reach a desired node would be O(height), and in this worst-case scenario, it would be **O(n)**, with **n** being the amount of nodes in the tree, since you have to search through every node in the tree. +```Python +def BSTInsert(curNode, newNode): + if curNode is None: + curNode = newNode + else: + if curNode.key < newNode.val: + if curNode.right is None: + curNode.right = newNode + else: + BSTInsert(curNode.right, newNode) + else: + if curNode.left is None: + curNode.left = newNode + else: + BSTInsert(curNode.left, newNode) +``` +`BSTInsert` traverses through the BST in a similar way to `BSTSearch`. However, once it finds that the specific child is null in the place where the new node belongs, it places that node there. -Thus, the time complexity of `BSTSearch` is **= O(n)** +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (When adding a new node to a BST, we must make sure to find the correct place to insert that node.`BSTInsert` traverses through the BST in a similar way to `BSTSearch`. However, once it finds that the specific child is null in the place where the new node belongs, it places that node there. Try working and experimenting with the code on your own machine.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/14.md b/Leetcode Workshops/Week 2/Act2_Trees/14.md index fe25965..9c7fe40 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/14.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/14.md @@ -1,21 +1,10 @@ - -## `BSTInsert`: + + +## Example of `BSTInsert` + -```Python -def BSTInsert(curNode, newNode): - if curNode is None: - curNode = newNode - else: - if curNode.key < newNode.val: - if curNode.right is None: - curNode.right = newNode - else: - BSTInsert(curNode.right, newNode) - else: - if curNode.left is None: - curNode.left = newNode - else: - BSTInsert(curNode.left, newNode) -``` +Use `BSTInsert` to add a node `11` to this tree. -When adding a new node to a BST, we must make sure to find the correct place to insert that node.`BSTInsert` traverses through the BST in a similar way to `BSTSearch`. However, once it finds that the specific child is null in the place where the new node belongs, it places that node there. Try working and experimenting with the code on your own machine. \ No newline at end of file +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (let's use an example to illustrate how this code works, . We will add a node `11` to this tree. You can see the specific path that `BSTInsert` takes to insert the node as well as the actual position that `11` ends up in.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/15.md b/Leetcode Workshops/Week 2/Act2_Trees/15.md index 79755c6..f4880c8 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/15.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/15.md @@ -1,4 +1,15 @@ - - + + +## Time Complexity of `BSTInsert` : -let's use an example to illustrate how this code works, . We will add a node `11` to this tree. You can see the specific path that `BSTInsert` takes to insert the node as well as the actual position that `11` ends up in. \ No newline at end of file + + +In order to insert `60` into this tree, we needed to visit all the other nodes in the tree first. + +Similarly to `BSTSearch`, the time complexity of `BSTInsert`is also **O(n)**. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Let's use the same example from the previous slide to illustrate this) + +[for speaker]: <> (Similarly to `BSTSearch`, the worst-case scenario runtime for `BSTInsert` is also O[n]. The worst-case would occur when you have to go through every node in the tree to find the proper place to insert the node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/16.md b/Leetcode Workshops/Week 2/Act2_Trees/16.md index 0cb7232..8b13789 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/16.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/16.md @@ -1,13 +1 @@ - - - -## Time Complexity of `BSTInsert` : -Similarly to `BSTSearch`, the worst-case scenario runtime for `BSTInsert` is also **O(n)**. The worst-case would occur when you have to go through every node in the tree to find the proper place to insert the node. - - - - - - -In order to insert `60` into this tree, we needed to visit every other node first. Hence, this was a worst-case scenario. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/2.md b/Leetcode Workshops/Week 2/Act2_Trees/2.md index fa38dc6..b502913 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/2.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/2.md @@ -1,3 +1,17 @@ - - -Today we are going to learn about tree data structures. In order to do so, it is important that we understand the essential terminology. \ No newline at end of file + + + + + +## Tree Terminology: + +* **Tree**: Hierarchical structure used to store data elements. Trees have no cycles (connections are one-way and never to previous elements), and are "upside-down" in that the root is at the top and leaves are at the bottom. + +* **Node**: Each individual data element of the tree that is linked to other data elements within the tree. Identified by a key. + +* **Edge**: Link that connects two nodes. + +* **Level**: The number of parent nodes that a given node has. For instance, the root node has 0 parents so it is at Level 0. It's children are at Level 1, grandchildren at Level 2, and so on. + +* **Subtree**: A grouping of connected nodes within the tree. + diff --git a/Leetcode Workshops/Week 2/Act2_Trees/3.md b/Leetcode Workshops/Week 2/Act2_Trees/3.md index 8603231..e792a0a 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/3.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/3.md @@ -1,13 +1,17 @@ - + + + -## Tree Terminology: +## Nodes + +* **Root Node**: The node with highest hierarchical precedence. Each tree can only have one root node. -* **Tree**: Hierarchical structure used to store data elements. Trees have no cycles (connections are one-way and never to previous elements), and are "upside-down" in that the root is at the top and leaves are at the bottom. +* **Parent Node**: The predecessor of a node is called its parent. The root node does not have a parent. -* **Node**: Each individual data element of the tree that is linked to other data elements within the tree. Identified by a key. +* **Child Node**: The descendant of a node is called its child. -* **Edge**: Link that connects two nodes. +* **Sibling Nodes**: The nodes that have the same parent are called siblings. -* **Level**: The number of parent nodes that a given node has. For instance, the root node has 0 parents so it is at Level 0. It's children are at Level 1, grandchildren at Level 2, and so on. +* **Leaf Nodes**: A node that does not have a child is called a leaf. -* **Subtree**: A grouping of connected nodes within the tree. \ No newline at end of file +* **Internal Nodes**: A node that has at least one child is called an internal node. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/4.md b/Leetcode Workshops/Week 2/Act2_Trees/4.md index 5ac1e51..f713e65 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/4.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/4.md @@ -1,15 +1,15 @@ - - -## Nodes - -* **Root Node**: The node with highest hierarchical precedence. Each tree can only have one root node. - -* **Parent Node**: The predecessor of a node is called its parent. The root node does not have a parent. - -* **Child Node**: The descendant of a node is called its child. - -* **Sibling Nodes**: The nodes that have the same parent are called siblings. - -* **Leaf Nodes**: A node that does not have a child is called a leaf. - -* **Internal Nodes**: A node that has at least one child is called an internal node. \ No newline at end of file + + + +* Each circles with numbers in them are the **nodes** of the tree. +* The arrows connecting each nodes are the **edges**. +* The **root** of this tree is the node that contains the number 8. +* The node containing 3 is a **parent** of the node containing 1. +* The node containing 1 is a **child** of the node containing 3. +* The nodes with 4 and 7 are **siblings**. +* The nodes with 1, 4, 7, and 13 are **leaf nodes**. +* The nodes containing 8, 3, 10, 6, and 14 are all **internal nodes**. +* the group of nodes with values 6, 4, and 7 are a **subtree** of the tree. +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (In the tree above, the circles with numbers in them are the **nodes** of the tree. The arrows connecting each nodes are the **edges**. The **root** of this tree is the node that contains the number 8. The node containing 3 is a **parent** of the node containing 1. The node containing 1 is a **child** of the node containing 3. The nodes with 4 and 7 are **siblings**. The nodes with 1, 4, 7, and 13 are **leaf nodes**. The nodes containing 8, 3, 10, 6, and 14 are all **internal nodes**. Finally, the group of nodes with values 6, 4, and 7 are a **subtree** of the tree.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/5.md b/Leetcode Workshops/Week 2/Act2_Trees/5.md index 4e15026..fb8236c 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/5.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/5.md @@ -1,5 +1,10 @@ - - + +## Real Life Application of Trees: +### Ancestry Trees: + +* Think of each person in the family as a node. - In the tree above, the circles with numbers in them are the **nodes** of the tree. The arrows connecting each nodes are the **edges**. The **root** of this tree is the node that contains the number 8. The node containing 3 is a **parent** of the node containing 1. The node containing 1 is a **child** of the node containing 3. The nodes with 4 and 7 are **siblings**. The nodes with 1, 4, 7, and 13 are **leaf nodes**. The nodes containing 8, 3, 10, 6, and 14 are all **internal nodes**. Finally, the group of nodes with values 6, 4, and 7 are a **subtree** of the tree. \ No newline at end of file +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (You may be wondering why we would want to use trees. A real life example of a tree structure being used is in ancestry trees. Think of each person in the family as a node. Every person in the family tree is related to other people in the family in some way as a sibling, parent, grandparent, etc. Tree data structures behave in a very similar way as they are both hierarchical structures with nodes, or family members, connected together in a certain manner, and the connection between nodes are there for a specific reason.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/6.md b/Leetcode Workshops/Week 2/Act2_Trees/6.md index 6eb8a8e..8bfbd99 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/6.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/6.md @@ -1,6 +1,26 @@ - -## Real Life Application of Trees: -### Ancestry Trees: - + + + +## Let's Define the `Node` Class: +```Python +class Node: + def __init__(self, key): + self.key = key + self.children = [] + + def insert_child(self, newChild): + self.children.append(newChild) +``` + +The `Node` class contains the data value of a node and a list of its children. + +`insert_child` function appends the node passed as an argument to the current node's list of children. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (-Now that we understand the structure of a tree and the common terminology used to describe elements of a tree, let's think of how we would implement the structure in Python.) + +[for speaker]: <> (It may be tempting to declare a class called `Tree` in which we store all the nodes in the class. While this approach makes sense, it can often lead to confusion and does not have built-in functionality for relationships between the nodes in the tree. When you realize that a class for the tree itself is not necessary, you may think of a second approach, which is the standard implementation. Instead,...) + +[for speaker]: <> (for this implementation, we will declare a class `Node` in which in each instance of the class represents a node of the tree. The `Node` class contains the data value of a node and a list of its children. This implementation also includes an `insert_child` function that simply appends the node passed as an argument to the current node's list of children. Since each node has its children stored in it, the structure of the tree is maintained, making the `Tree` class unnecessary. You may be asking why we don't keep track of each node's parent. While this may be useful or necessary for some more advanced types of trees, it is not needed to implement a base tree that we're currently investigating.) -You may be wondering why we would want to use trees. A real life example of a tree structure being used is in ancestry trees. Think of each person in the family as a node. Every person in the family tree is related to other people in the family in some way as a sibling, parent, grandparent, etc. Tree data structures behave in a very similar way as they are both hierarchical structures with nodes, or family members, connected together in a certain manner, and the connection between nodes are there for a specific reason. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/7.md b/Leetcode Workshops/Week 2/Act2_Trees/7.md index 189d8e8..8d2a448 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/7.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/7.md @@ -1,17 +1,16 @@ - -## Let's Definen the `Node` Class: - + + +## Binary Trees: - +A **Binary Tree** is a tree where every single node can only have zero, one, or two children. -```Python -class Node: - def __init__(self, key): - self.key = key - self.children = [] - - def insert_child(self, newChild): - self.children.append(newChild) -``` +The **Binary Search Tree (BST)** is a special kind of Binary Tree. + +* Every element in the left subtree of a node has keys that are lesser in value than the key of that particular node. + +* Every element in the right subtree of a node has keys that are greater in value than the key of that particular node. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (A simple tree structure is fundamental, but let's investigate a specific type of tree that allowsfor an interesting and structured way to store data.The tree structure we will be dealing with, however, is a special kind of Binary Tree, the Binary Search Tree have a few more restrictions) -for this implementation, we will declare a class `Node` in which in each instance of the class represents a node of the tree. The `Node` class contains the data value of a node and a list of its children. This implementation also includes an `insert_child` function that simply appends the node passed as an argument to the current node's list of children. Since each node has its children stored in it, the structure of the tree is maintained, making the `Tree` class unnecessary. You may be asking why we don't keep track of each node's parent. While this may be useful or necessary for some more advanced types of trees, it is not needed to implement a base tree that we're currently investigating. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/8.md b/Leetcode Workshops/Week 2/Act2_Trees/8.md index f82bf3f..6cced7b 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/8.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/8.md @@ -1,10 +1,15 @@ - -## Binary Trees: + + + + ## Let's see an example of a valid vs invalid BST: -A simple tree structure is fundamental, but let's investigate a specific type of tree that allows for an interesting and structured way to store data. A **Binary Tree** is a tree where every single node can only have zero, one, or two children. The tree structure we will be dealing with, however, is a special kind of Binary Tree, the **Binary Search Tree (BST)**. **BST**s have a few more restrictions: + ​ -* Every element in the left subtree of a node has keys that are lesser in value than the key of that particular node. -* Every element in the right subtree of a node has keys that are greater in value than the key of that particular node. +----------------------------------------------------------------------------------------------------- +[for speaker]: <> (Are you able to tell which tree is a valid BST and which is invalid?) + +[for speaker]: <> (The left tree is an invalid BST because the node containing the key `10` is in a right subtree of the node containing the key `30`.) +[for speaker]: <> (You may have noticed that all subtrees of a BST are also BSTs.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/9.md b/Leetcode Workshops/Week 2/Act2_Trees/9.md index 99e529e..3a9bafb 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/9.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/9.md @@ -1,9 +1,16 @@ - - - Let's see an example of a valid vs invalid BST: + + +## Implement BST `Node` class BST +```Python +class Node: + def __init__(self, key): + self.left = None + self.right = None + self.key = key +``` - ​ + We store the left child as the **left** element and the right child as the **right** element. The left and right child are initialized to null. - +----------------------------------------------------------------------------------------------------- -The **left** tree is an **invalid** BST because the node containing the key `10` is in a right subtree of the node containing the key `30`. You may have noticed that all subtrees of a BST are also BSTs. +[for speaker]: <> (In order to implement a BST in Python, we just need to adjust our previous `Node` class.Since we know that BST nodes only have two children max, we no longer need a list to store the children.) \ No newline at end of file From effd49f62d67bb774d27fc301fe35cca1ab91986 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Sat, 22 Feb 2020 01:39:21 -0800 Subject: [PATCH 04/24] Add the content slide 16-39 only the content, no type yet --- Leetcode Workshops/Week 2/Act2_Trees/1.md | 3 +-- Leetcode Workshops/Week 2/Act2_Trees/16.md | 15 +++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/17.md | 11 +++++++++++ Leetcode Workshops/Week 2/Act2_Trees/18.md | 16 ++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/19.md | 21 +++++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/20.md | 18 ++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/21.md | 19 +++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/22.md | 20 ++++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/23.md | 10 ++++++++++ Leetcode Workshops/Week 2/Act2_Trees/24.md | 21 +++++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/25.md | 12 ++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/26,md | 0 Leetcode Workshops/Week 2/Act2_Trees/26.md | 10 ++++++++++ Leetcode Workshops/Week 2/Act2_Trees/27.md | 15 +++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/28.md | 11 +++++++++++ Leetcode Workshops/Week 2/Act2_Trees/29,md | 0 Leetcode Workshops/Week 2/Act2_Trees/29.md | 10 ++++++++++ Leetcode Workshops/Week 2/Act2_Trees/30.md | 6 ++++++ Leetcode Workshops/Week 2/Act2_Trees/31.md | 8 ++++++++ Leetcode Workshops/Week 2/Act2_Trees/32.md | 7 +++++++ Leetcode Workshops/Week 2/Act2_Trees/33.md | 17 +++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/34.md | 18 ++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/35.md | 19 +++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/36.md | 19 +++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/37.md | 13 +++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/38.md | 13 +++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/39.MD | 13 +++++++++++++ 27 files changed, 343 insertions(+), 2 deletions(-) create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/17.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/18.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/19.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/20.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/21.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/22.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/23.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/24.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/25.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/26,md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/26.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/27.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/28.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/29,md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/29.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/30.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/31.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/32.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/33.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/34.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/35.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/36.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/37.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/38.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/39.MD diff --git a/Leetcode Workshops/Week 2/Act2_Trees/1.md b/Leetcode Workshops/Week 2/Act2_Trees/1.md index 07173bb..1ce946c 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/1.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/1.md @@ -3,8 +3,7 @@ # Trees ------------------------------------------------------------------------------------------------------ - +------------------------------------------------- [for speaker]: <> (Today we are going to learn about tree data structures. In order to do so, it is important that we understand the essential terminology) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/16.md b/Leetcode Workshops/Week 2/Act2_Trees/16.md index 8b13789..47de62e 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/16.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/16.md @@ -1 +1,16 @@ + +## Deleting a BST Node: +When deleting a BST node, there are **two main cases**: + +* **Leaf/One Child Case:** The first case is when the node we want to delete is a leaf in the BST or a node with only one child. + + + ​ ![](https://i0.wp.com/www.techiedelight.com/wp-content/uploads/Deletion-in-BST-Case-1.png?zoom=2.625&resize=368%2C142&ssl=1) + + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (The last fundamental function that allows us to interact with BSTs is `BSTDelete`, which will allow us to remove unwanted nodes from our tree. `BSTDelete` is arguably the most complicated of the BST functions we have learned so far because we have to fix the tree once we remove a node.) + +[for speaker]: <> (Since a leaf does not have any children, deleting it from a BST leaves us with a proper BST, meaning we do not have to change the structure of the tree and can simply remove the node. Also, if a node we want to delete only has one child, we can just delete that node and place its child where it used to be. Here is an example of the former:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/17.md b/Leetcode Workshops/Week 2/Act2_Trees/17.md new file mode 100644 index 0000000..912c401 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/17.md @@ -0,0 +1,11 @@ + + +## Deleting a BST Node: +* **Two Children Case**: The case when you want to delete a node with two children. + +* When an internal node is deleted, it must be replaced with the maximum node of the deleted node's left subtree or minimum node of the deleted node's right subtree in order to follow the rules of a BST. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (The more challenging case occurs when you want to delete an internal node in the BST, or a node with two children.If you simply deleted the node, you would lose the children.) +[for speaker]: <> (Therefore, when an internal node is deleted, it must be replaced with the maximum node of the deleted node's left subtree or minimum node of the deleted node's right subtree [your code implementation will determine the preference between these two options] in order to still follow the rules of a BST. Here is an illustration that should help your understanding:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/18.md b/Leetcode Workshops/Week 2/Act2_Trees/18.md new file mode 100644 index 0000000..7138ef9 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/18.md @@ -0,0 +1,16 @@ + + +## Example of `BSTDelete` + ![](https://i2.wp.com/www.techiedelight.com/wp-content/uploads/Deletion-in-BST-Case-2-1.png?zoom=1.5&resize=586%2C352&ssl=1) + + +* Find the *maximum* value of a node's *left* subtree, which is `19`. +* Replace 20 with 19 +* What if we want to delete the root 15? + + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (As you can see, we chose to delete `20` from the tree, and picked its in-order predecessor node as its replacement. The in-order predecessor node is the maximum value of a node's left subtree, in this case, `19`.. Similarly, we could have also used the in-order *successor* node, which is the *minimum* value of a node's *right* sub-tree. If we had gone that direction, we would have chosen `30` as the replacement for `20` in our example instead. ) + +[for speaker]: <> (Note that the process for deleting a child with two nodes is the same for **any** node, even the root! If we had decided to remove `15` from our tree above, and still decided to use the in-order predecessor node as our replacement, we would have picked `12` to be in its place. We would have chosen `16` if we picked the successor node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/19.md b/Leetcode Workshops/Week 2/Act2_Trees/19.md new file mode 100644 index 0000000..a27d482 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/19.md @@ -0,0 +1,21 @@ + +## `BSTDelete()` +```Python +def smallestNode(curNode): + inspectedNode = curNode + while(inspectedNode.left is not None): + inspectedNode = inspectedNode.left #Go left as far as possible + return inspectedNode +``` +### Step1: define helper function +* Define a function which finds the smallest node in a given node's subtree. + +* It traverses down the node's left subtree, always choosing to visit the left child, until we reach a leaf. + +* That leaf node is the smallest node and gets returned. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Due to the various cases when deleting a BST node, the `BSTDelete` function is a little more complex than `BSTSearch` and `BSTInsert`. However, don't be intimidated by the code; make certain you understand the process of deleting a node, because the code simply follows that logic. Let's take a look:) + +[for speaker]: <> (This is a helper function which will allows us to find the smallest node in a given node's subtree. The process is simple. We simply traverse down the node's left subtree, always choosing to visit the left child, until we reach a leaf. That leaf node is the smallest node and gets returned. As you can tell, we are chooisng the in-order predecessor node as our replacement in this code implementation.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/20.md b/Leetcode Workshops/Week 2/Act2_Trees/20.md new file mode 100644 index 0000000..d0c8f45 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/20.md @@ -0,0 +1,18 @@ + +## `BSTDelete()` +```python +def BSTDelete(curNode, key): + if curNode is None: + return curNode + if (key < curNode.key): + curNode.left = BSTDelete(curNode.left, key) + elif (key > curNode.key): + curNode.right = BSTDelete(curNode.right, key) +``` +### Step2: find the node that we want to delete + +We traverse down the left and right subtree of any given node until we reach the node we are looking to delete. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (In order to delete a node, we need to find it first! This process is the exact same as with `BSTSearch` and `BSTInsert`. We traverse down the left and right subtree of any given node until we reach the node we are looking to delete.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/21.md b/Leetcode Workshops/Week 2/Act2_Trees/21.md new file mode 100644 index 0000000..131f77b --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/21.md @@ -0,0 +1,19 @@ + +## `BSTDelete()` +```python +else: #found node to be deleted + if curNode.left is None: #Case 1 + tempNode = curNode.right + curNode = None #Delete node + return tempNode + elif curNode.right is None: #Case 1 + tempNode = curNode.left + curNode = None #Delete node + return tempNode +``` +### Step3: deal with case 1. +We "delete" a node by setting it to `None`. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Here, we found the node and it falls under one of the two situations listed in Case 1: it is either a leaf, or only has one child. We do the appropriate replacement and deletion procedures. Notice that we "delete" a node by setting it to `None`.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/22.md b/Leetcode Workshops/Week 2/Act2_Trees/22.md new file mode 100644 index 0000000..33fbf69 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/22.md @@ -0,0 +1,20 @@ + + +## `BSTDelete()` +```python + #Internal Node Case: + tempNode = smallestNode(curNode.right) #find smallest key node of right subtree + curNode.key = tempNode.key + curNode.right = BSTDelete(curNode.right, tempNode.key) +``` +### Step4: deal with case2 +* Find its in-order predecessor node. +* Replace its value with the predecessor's value. +* Delete the predecessor node from our tree. + + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Finally, this is the case where the node in question has two children. We find its in-order predecessor node, replace its value with the predecessor's value, and delete the predecessor node from our tree.) + +[for speaker]: <> (Although `BSTDelete` seems complicated initially,you will realize that it simply follows the logic of either the **Leaf/1 Child Case** or the **Internal Node Case**. Feel free to ask questions about the two cases if you're having trouble understanding the `BSTDelete` code.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/23.md b/Leetcode Workshops/Week 2/Act2_Trees/23.md new file mode 100644 index 0000000..0870eb5 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/23.md @@ -0,0 +1,10 @@ + + + +# Let's make a family tree in Python using the `Node` class + +------------------------------------------------- + +[for speaker]: <> (Now that we have learned the basic concepts associated with trees, let's do an activity together that walks through a real life application of data trees to cement our understanding.) + +[for speaker]: <> (As I mentioned prior, a place where a data tree occurs in your real life is with the relationships in your family. For the activity, we will make a data tree in Python using the `Node` class that will be a representation of a family.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/24.md b/Leetcode Workshops/Week 2/Act2_Trees/24.md new file mode 100644 index 0000000..2bf7832 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/24.md @@ -0,0 +1,21 @@ +## Family Tree: +```Python +class Node: + def __init__(self, name, age, gender, sport): + self.key = name + self.age = age + self.gender = gender + self.sport = sport + self.children = [] + + def insert_child(self, newChild): + self.children.append(newChild) +``` +For our family tree, we want to hold the **name**, **age**, **gender**, and **favorite sport** for each member of the family. + +* We use key to identify a certain node. +* Assign the name of the family member to be the key + +------------------------------------------------- + +[for speaker]: <> (As you may have noticed, we added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each family member. Notice that we are now assigning the name of the family member to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each family member. It is just what we will use to identify a certain node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/25.md b/Leetcode Workshops/Week 2/Act2_Trees/25.md new file mode 100644 index 0000000..370cdd1 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/25.md @@ -0,0 +1,12 @@ +## Building the Tree: +Step1: Let's initialize root `Node` + + For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. + +```Python +grandma = Node("Susan", 92, "female", "bowling") +``` + +------------------------------------------------- + +[for speaker]: <> (Now that we have our new `Node` class, let's start initializing some family members to start building the ancestry tree. For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. Let's initialize her `Node` object:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26,md b/Leetcode Workshops/Week 2/Act2_Trees/26,md new file mode 100644 index 0000000..e69de29 diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26.md b/Leetcode Workshops/Week 2/Act2_Trees/26.md new file mode 100644 index 0000000..428b99d --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/26.md @@ -0,0 +1,10 @@ +## Let's say grandma Susan has 3 children. Let's create some node objects for her children: + +```Python +mary = Node("Mary", 57, "female", "soccer") +joe = Node("Joe", 61, "male", "football") +don = Node("Don", 63, "male", "tennis") +``` +------------------------------------------------- + +[for speaker]: <> (Now that we have a node for grandma Susan, let's say she has 3 children. Let's create some node objects for her children:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/27.md b/Leetcode Workshops/Week 2/Act2_Trees/27.md new file mode 100644 index 0000000..abf7757 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/27.md @@ -0,0 +1,15 @@ + +### Connect Susan's children with Susan + +```Python +grandma.insert_child(Mary) +grandma.insert_child(Joe) +grandma.insert_child(Don) +``` +`grandma.children` will now be a list that holds the node Mary, Joe, and Don. + +------------------------------------------------- + +[for speaker]: <> (We have declared node objects for all of Susan's children but we have not indicated in our code that they are her children yet. In order to do so, we can use the `insert_child` function in the `Node` class on Susan's object.) + +[for speaker]: <> (After making those 3 calls, grandma.children will now be a list that holds the node instances mary, joe, and don. We have essentially drawn edges between grandma and mary, grandma and joe, and grandma and don.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/28.md b/Leetcode Workshops/Week 2/Act2_Trees/28.md new file mode 100644 index 0000000..54c7410 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/28.md @@ -0,0 +1,11 @@ +## Let's say that Joe got married and had 2 children. Let's create the `Node` instances for Joe's 2 children: + +```Python +ricky = Node("Ricky", 34, "male", "basketball") +kelly = Node("Kelly", 35, "female", "tennis") +``` + + +------------------------------------------------- + +[for speaker]: <> (Let's say that Joe got married and had 2 children. Although we could adjust our tree structure to include Joe's spouse, let's keep our tree simple for now and only show grandma Susan's direct descendants. Let's create the `Node` instances for Joe's 2 children:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29,md b/Leetcode Workshops/Week 2/Act2_Trees/29,md new file mode 100644 index 0000000..e69de29 diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29.md b/Leetcode Workshops/Week 2/Act2_Trees/29.md new file mode 100644 index 0000000..0b223ae --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/29.md @@ -0,0 +1,10 @@ +## Now let's connect them to Joe's node with edges: + +```Python +joe.insert_child(ricky) +joe.insert_child(kelly) +``` + +------------------------------------------------- + +[for speaker]: <> (Now, we have successfully created a simple family tree using data trees in Python.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/30.md b/Leetcode Workshops/Week 2/Act2_Trees/30.md new file mode 100644 index 0000000..1f0e935 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/30.md @@ -0,0 +1,6 @@ +## Draw the family tree +![img](https://i.imgur.com/pshjK2F.png ) + +------------------------------------------------- + +[for speaker]: <> (For practice, try out drawing the family tree we just created on paper. Also, for more practice, try implementing your own family tree in Python by adding and deleting the new object nodes with family member.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/31.md b/Leetcode Workshops/Week 2/Act2_Trees/31.md new file mode 100644 index 0000000..60311bd --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/31.md @@ -0,0 +1,8 @@ + + +## Let's use BST to make a simple database to be able to search members by their ID + +------------------------------------------------- + +[for speaker]: <> (Now to further **enhance your comprehension for Binary Search Tree's**, we will use a Binary Search Tree in an example **real-world application** in order for you to see the purpose behind this algorithm.) + diff --git a/Leetcode Workshops/Week 2/Act2_Trees/32.md b/Leetcode Workshops/Week 2/Act2_Trees/32.md new file mode 100644 index 0000000..eaaeb86 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/32.md @@ -0,0 +1,7 @@ + + +- Consider that we are admins for a corporation that has many employees and we must have some sort of way to keep track of each employee in our database system. + +- We need an efficient way of **searching** for particular employees based on their **employee identification number**. + +- Each employee has a distinct identification number, so we will use a Binary Search Tree as our structure that stores the employees' ID numbers which represent the nodes. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/33.md b/Leetcode Workshops/Week 2/Act2_Trees/33.md new file mode 100644 index 0000000..8f23847 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/33.md @@ -0,0 +1,17 @@ + +```python +class Node: + def __init__(self,key,name): + self.left = None + self.right = None + self.val = key + self.employeeName = name +``` +- We want to hold each employee's ID number(Key) and name. +------------------------------------------------- + +[for speaker]: <> (We added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each employee's ID number[Key] and name.) + +[for speaker]: <> (For our employee information tree, we weant to hold the key, and **name** for each employee of the company.Therefore, we must slightly modify our 'Node' class to allow us to encompass that data.) + +[for speaker]: <> (We are now assigning the name of the employee to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each employee. It is just what we will use to identify a certain node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/34.md b/Leetcode Workshops/Week 2/Act2_Trees/34.md new file mode 100644 index 0000000..93f1430 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/34.md @@ -0,0 +1,18 @@ + +## A utility function to insert a new node with the given key +```python +def insert(root,node): + if root is None: + root = node + else: + if root.val < node.val: + if root.right is None: + root.right = node + else: + insert(root.right, node) + else: + if root.left is None: + root.left = node + else: + insert(root.left, node) +``` diff --git a/Leetcode Workshops/Week 2/Act2_Trees/35.md b/Leetcode Workshops/Week 2/Act2_Trees/35.md new file mode 100644 index 0000000..62b4612 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/35.md @@ -0,0 +1,19 @@ + +## A utility function to do inorder tree traversal +```python +def inorderID(root): + if root: + inorderID(root.left) + print(root.val) + inorderID(root.right) + +def inorderName(root): + if root: + inorderName(root.left) + print(root.employeeName) + inorderName(root.right) +``` + +------------------------------------------------- + +[for speaker]: <> (Now, we make functions to make a tree in order by the Key value[Employee ID] or the name of employee base on the insert function we produced above.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/36.md b/Leetcode Workshops/Week 2/Act2_Trees/36.md new file mode 100644 index 0000000..b89969d --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/36.md @@ -0,0 +1,19 @@ +## A utility function to search a given key in BST + ```python +def search(root,key): + + # Base Cases: root is null or key is present at root + if root is None or root.val == key: + print(root.employeeName) + return root + + # Key is greater than root's key + if root.val < key: + return search(root.right,key) + + # Key is smaller than root's key + return search(root.left,key) +``` +------------------------------------------------- + +[for speaker]: <> (We make a function to search the name of employee base on the Key value[Employee ID].) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/37.md b/Leetcode Workshops/Week 2/Act2_Trees/37.md new file mode 100644 index 0000000..5d96ee1 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/37.md @@ -0,0 +1,13 @@ + +## Insert root node and other employee + ```python +r = Node(50, "Abel") +insert(r,Node(30, "Bob")) +insert(r,Node(20, "Cathy")) +insert(r,Node(40, "Debbie")) +insert(r,Node(70, "Evan")) +insert(r,Node(60, "Fiona")) +insert(r,Node(80, "Gabriel")) +``` +- Now, we declare "Abel" with ID number '50' as a root of the employee tree. +- We insert 6 employees under the root node of 'Abel' by using 'insert' function. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/38.md b/Leetcode Workshops/Week 2/Act2_Trees/38.md new file mode 100644 index 0000000..fc91329 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/38.md @@ -0,0 +1,13 @@ + +## Order the nodes by ID + ```python +inorderID(r) +inorderName(r) +search(r, 20) +``` +- Use inorderID or inorderName function to make the nodes in order by employee ID or employee name. +- We can search the employee name by the key value(employee ID). + +------------------------------------------------- + +[for speaker]: <> (We have inserted all node objects for the root but we have not made them in order by employee ID or employee name. To do so, we use inorderID or inorderName function. Also, we can search the employee name by the key value[employee ID].) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/39.MD b/Leetcode Workshops/Week 2/Act2_Trees/39.MD new file mode 100644 index 0000000..7418c84 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/39.MD @@ -0,0 +1,13 @@ +## The tree we just implemented should look like: +![](https://i.imgur.com/4FJ4zKR.png) + +| Python Code | Print Output | +| :------------: | :----------------------------------------------------------: | +| inorderID(r) | 20
30
40
50
60
70
80 | +| inorderName(r) | Cathy
Bob
Debbie
Abel
Fiona
Evan
Gabriel | +| search(r, 20) | Cathy | +| search(r, 60) | Fiona | + +------------------------------------------------- + +[for speaker]: <> (Figure 1. Binary Search Tree in order with the employee Identification number and employee's name) \ No newline at end of file From a5bc847c17601a34118caaefc30810f47a10cc37 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Sat, 22 Feb 2020 01:40:29 -0800 Subject: [PATCH 05/24] Revert "Add the content slide 16-39" This reverts commit effd49f62d67bb774d27fc301fe35cca1ab91986. --- Leetcode Workshops/Week 2/Act2_Trees/1.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/16.md | 15 --------------- Leetcode Workshops/Week 2/Act2_Trees/17.md | 11 ----------- Leetcode Workshops/Week 2/Act2_Trees/18.md | 16 ---------------- Leetcode Workshops/Week 2/Act2_Trees/19.md | 21 --------------------- Leetcode Workshops/Week 2/Act2_Trees/20.md | 18 ------------------ Leetcode Workshops/Week 2/Act2_Trees/21.md | 19 ------------------- Leetcode Workshops/Week 2/Act2_Trees/22.md | 20 -------------------- Leetcode Workshops/Week 2/Act2_Trees/23.md | 10 ---------- Leetcode Workshops/Week 2/Act2_Trees/24.md | 21 --------------------- Leetcode Workshops/Week 2/Act2_Trees/25.md | 12 ------------ Leetcode Workshops/Week 2/Act2_Trees/26,md | 0 Leetcode Workshops/Week 2/Act2_Trees/26.md | 10 ---------- Leetcode Workshops/Week 2/Act2_Trees/27.md | 15 --------------- Leetcode Workshops/Week 2/Act2_Trees/28.md | 11 ----------- Leetcode Workshops/Week 2/Act2_Trees/29,md | 0 Leetcode Workshops/Week 2/Act2_Trees/29.md | 10 ---------- Leetcode Workshops/Week 2/Act2_Trees/30.md | 6 ------ Leetcode Workshops/Week 2/Act2_Trees/31.md | 8 -------- Leetcode Workshops/Week 2/Act2_Trees/32.md | 7 ------- Leetcode Workshops/Week 2/Act2_Trees/33.md | 17 ----------------- Leetcode Workshops/Week 2/Act2_Trees/34.md | 18 ------------------ Leetcode Workshops/Week 2/Act2_Trees/35.md | 19 ------------------- Leetcode Workshops/Week 2/Act2_Trees/36.md | 19 ------------------- Leetcode Workshops/Week 2/Act2_Trees/37.md | 13 ------------- Leetcode Workshops/Week 2/Act2_Trees/38.md | 13 ------------- Leetcode Workshops/Week 2/Act2_Trees/39.MD | 13 ------------- 27 files changed, 2 insertions(+), 343 deletions(-) delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/17.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/18.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/19.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/20.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/21.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/22.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/23.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/24.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/25.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/26,md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/26.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/27.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/28.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/29,md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/29.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/30.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/31.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/32.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/33.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/34.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/35.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/36.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/37.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/38.md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/39.MD diff --git a/Leetcode Workshops/Week 2/Act2_Trees/1.md b/Leetcode Workshops/Week 2/Act2_Trees/1.md index 1ce946c..07173bb 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/1.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/1.md @@ -3,7 +3,8 @@ # Trees -------------------------------------------------- +----------------------------------------------------------------------------------------------------- + [for speaker]: <> (Today we are going to learn about tree data structures. In order to do so, it is important that we understand the essential terminology) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/16.md b/Leetcode Workshops/Week 2/Act2_Trees/16.md index 47de62e..8b13789 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/16.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/16.md @@ -1,16 +1 @@ - -## Deleting a BST Node: -When deleting a BST node, there are **two main cases**: - -* **Leaf/One Child Case:** The first case is when the node we want to delete is a leaf in the BST or a node with only one child. - - - ​ ![](https://i0.wp.com/www.techiedelight.com/wp-content/uploads/Deletion-in-BST-Case-1.png?zoom=2.625&resize=368%2C142&ssl=1) - - ------------------------------------------------------------------------------------------------------ - -[for speaker]: <> (The last fundamental function that allows us to interact with BSTs is `BSTDelete`, which will allow us to remove unwanted nodes from our tree. `BSTDelete` is arguably the most complicated of the BST functions we have learned so far because we have to fix the tree once we remove a node.) - -[for speaker]: <> (Since a leaf does not have any children, deleting it from a BST leaves us with a proper BST, meaning we do not have to change the structure of the tree and can simply remove the node. Also, if a node we want to delete only has one child, we can just delete that node and place its child where it used to be. Here is an example of the former:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/17.md b/Leetcode Workshops/Week 2/Act2_Trees/17.md deleted file mode 100644 index 912c401..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/17.md +++ /dev/null @@ -1,11 +0,0 @@ - - -## Deleting a BST Node: -* **Two Children Case**: The case when you want to delete a node with two children. - -* When an internal node is deleted, it must be replaced with the maximum node of the deleted node's left subtree or minimum node of the deleted node's right subtree in order to follow the rules of a BST. - ------------------------------------------------------------------------------------------------------ - -[for speaker]: <> (The more challenging case occurs when you want to delete an internal node in the BST, or a node with two children.If you simply deleted the node, you would lose the children.) -[for speaker]: <> (Therefore, when an internal node is deleted, it must be replaced with the maximum node of the deleted node's left subtree or minimum node of the deleted node's right subtree [your code implementation will determine the preference between these two options] in order to still follow the rules of a BST. Here is an illustration that should help your understanding:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/18.md b/Leetcode Workshops/Week 2/Act2_Trees/18.md deleted file mode 100644 index 7138ef9..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/18.md +++ /dev/null @@ -1,16 +0,0 @@ - - -## Example of `BSTDelete` - ![](https://i2.wp.com/www.techiedelight.com/wp-content/uploads/Deletion-in-BST-Case-2-1.png?zoom=1.5&resize=586%2C352&ssl=1) - - -* Find the *maximum* value of a node's *left* subtree, which is `19`. -* Replace 20 with 19 -* What if we want to delete the root 15? - - ------------------------------------------------------------------------------------------------------ - -[for speaker]: <> (As you can see, we chose to delete `20` from the tree, and picked its in-order predecessor node as its replacement. The in-order predecessor node is the maximum value of a node's left subtree, in this case, `19`.. Similarly, we could have also used the in-order *successor* node, which is the *minimum* value of a node's *right* sub-tree. If we had gone that direction, we would have chosen `30` as the replacement for `20` in our example instead. ) - -[for speaker]: <> (Note that the process for deleting a child with two nodes is the same for **any** node, even the root! If we had decided to remove `15` from our tree above, and still decided to use the in-order predecessor node as our replacement, we would have picked `12` to be in its place. We would have chosen `16` if we picked the successor node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/19.md b/Leetcode Workshops/Week 2/Act2_Trees/19.md deleted file mode 100644 index a27d482..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/19.md +++ /dev/null @@ -1,21 +0,0 @@ - -## `BSTDelete()` -```Python -def smallestNode(curNode): - inspectedNode = curNode - while(inspectedNode.left is not None): - inspectedNode = inspectedNode.left #Go left as far as possible - return inspectedNode -``` -### Step1: define helper function -* Define a function which finds the smallest node in a given node's subtree. - -* It traverses down the node's left subtree, always choosing to visit the left child, until we reach a leaf. - -* That leaf node is the smallest node and gets returned. - ------------------------------------------------------------------------------------------------------ - -[for speaker]: <> (Due to the various cases when deleting a BST node, the `BSTDelete` function is a little more complex than `BSTSearch` and `BSTInsert`. However, don't be intimidated by the code; make certain you understand the process of deleting a node, because the code simply follows that logic. Let's take a look:) - -[for speaker]: <> (This is a helper function which will allows us to find the smallest node in a given node's subtree. The process is simple. We simply traverse down the node's left subtree, always choosing to visit the left child, until we reach a leaf. That leaf node is the smallest node and gets returned. As you can tell, we are chooisng the in-order predecessor node as our replacement in this code implementation.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/20.md b/Leetcode Workshops/Week 2/Act2_Trees/20.md deleted file mode 100644 index d0c8f45..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/20.md +++ /dev/null @@ -1,18 +0,0 @@ - -## `BSTDelete()` -```python -def BSTDelete(curNode, key): - if curNode is None: - return curNode - if (key < curNode.key): - curNode.left = BSTDelete(curNode.left, key) - elif (key > curNode.key): - curNode.right = BSTDelete(curNode.right, key) -``` -### Step2: find the node that we want to delete - -We traverse down the left and right subtree of any given node until we reach the node we are looking to delete. - ------------------------------------------------------------------------------------------------------ - -[for speaker]: <> (In order to delete a node, we need to find it first! This process is the exact same as with `BSTSearch` and `BSTInsert`. We traverse down the left and right subtree of any given node until we reach the node we are looking to delete.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/21.md b/Leetcode Workshops/Week 2/Act2_Trees/21.md deleted file mode 100644 index 131f77b..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/21.md +++ /dev/null @@ -1,19 +0,0 @@ - -## `BSTDelete()` -```python -else: #found node to be deleted - if curNode.left is None: #Case 1 - tempNode = curNode.right - curNode = None #Delete node - return tempNode - elif curNode.right is None: #Case 1 - tempNode = curNode.left - curNode = None #Delete node - return tempNode -``` -### Step3: deal with case 1. -We "delete" a node by setting it to `None`. - ------------------------------------------------------------------------------------------------------ - -[for speaker]: <> (Here, we found the node and it falls under one of the two situations listed in Case 1: it is either a leaf, or only has one child. We do the appropriate replacement and deletion procedures. Notice that we "delete" a node by setting it to `None`.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/22.md b/Leetcode Workshops/Week 2/Act2_Trees/22.md deleted file mode 100644 index 33fbf69..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/22.md +++ /dev/null @@ -1,20 +0,0 @@ - - -## `BSTDelete()` -```python - #Internal Node Case: - tempNode = smallestNode(curNode.right) #find smallest key node of right subtree - curNode.key = tempNode.key - curNode.right = BSTDelete(curNode.right, tempNode.key) -``` -### Step4: deal with case2 -* Find its in-order predecessor node. -* Replace its value with the predecessor's value. -* Delete the predecessor node from our tree. - - ------------------------------------------------------------------------------------------------------ - -[for speaker]: <> (Finally, this is the case where the node in question has two children. We find its in-order predecessor node, replace its value with the predecessor's value, and delete the predecessor node from our tree.) - -[for speaker]: <> (Although `BSTDelete` seems complicated initially,you will realize that it simply follows the logic of either the **Leaf/1 Child Case** or the **Internal Node Case**. Feel free to ask questions about the two cases if you're having trouble understanding the `BSTDelete` code.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/23.md b/Leetcode Workshops/Week 2/Act2_Trees/23.md deleted file mode 100644 index 0870eb5..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/23.md +++ /dev/null @@ -1,10 +0,0 @@ - - - -# Let's make a family tree in Python using the `Node` class - -------------------------------------------------- - -[for speaker]: <> (Now that we have learned the basic concepts associated with trees, let's do an activity together that walks through a real life application of data trees to cement our understanding.) - -[for speaker]: <> (As I mentioned prior, a place where a data tree occurs in your real life is with the relationships in your family. For the activity, we will make a data tree in Python using the `Node` class that will be a representation of a family.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/24.md b/Leetcode Workshops/Week 2/Act2_Trees/24.md deleted file mode 100644 index 2bf7832..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/24.md +++ /dev/null @@ -1,21 +0,0 @@ -## Family Tree: -```Python -class Node: - def __init__(self, name, age, gender, sport): - self.key = name - self.age = age - self.gender = gender - self.sport = sport - self.children = [] - - def insert_child(self, newChild): - self.children.append(newChild) -``` -For our family tree, we want to hold the **name**, **age**, **gender**, and **favorite sport** for each member of the family. - -* We use key to identify a certain node. -* Assign the name of the family member to be the key - -------------------------------------------------- - -[for speaker]: <> (As you may have noticed, we added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each family member. Notice that we are now assigning the name of the family member to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each family member. It is just what we will use to identify a certain node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/25.md b/Leetcode Workshops/Week 2/Act2_Trees/25.md deleted file mode 100644 index 370cdd1..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/25.md +++ /dev/null @@ -1,12 +0,0 @@ -## Building the Tree: -Step1: Let's initialize root `Node` - - For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. - -```Python -grandma = Node("Susan", 92, "female", "bowling") -``` - -------------------------------------------------- - -[for speaker]: <> (Now that we have our new `Node` class, let's start initializing some family members to start building the ancestry tree. For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. Let's initialize her `Node` object:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26,md b/Leetcode Workshops/Week 2/Act2_Trees/26,md deleted file mode 100644 index e69de29..0000000 diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26.md b/Leetcode Workshops/Week 2/Act2_Trees/26.md deleted file mode 100644 index 428b99d..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/26.md +++ /dev/null @@ -1,10 +0,0 @@ -## Let's say grandma Susan has 3 children. Let's create some node objects for her children: - -```Python -mary = Node("Mary", 57, "female", "soccer") -joe = Node("Joe", 61, "male", "football") -don = Node("Don", 63, "male", "tennis") -``` -------------------------------------------------- - -[for speaker]: <> (Now that we have a node for grandma Susan, let's say she has 3 children. Let's create some node objects for her children:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/27.md b/Leetcode Workshops/Week 2/Act2_Trees/27.md deleted file mode 100644 index abf7757..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/27.md +++ /dev/null @@ -1,15 +0,0 @@ - -### Connect Susan's children with Susan - -```Python -grandma.insert_child(Mary) -grandma.insert_child(Joe) -grandma.insert_child(Don) -``` -`grandma.children` will now be a list that holds the node Mary, Joe, and Don. - -------------------------------------------------- - -[for speaker]: <> (We have declared node objects for all of Susan's children but we have not indicated in our code that they are her children yet. In order to do so, we can use the `insert_child` function in the `Node` class on Susan's object.) - -[for speaker]: <> (After making those 3 calls, grandma.children will now be a list that holds the node instances mary, joe, and don. We have essentially drawn edges between grandma and mary, grandma and joe, and grandma and don.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/28.md b/Leetcode Workshops/Week 2/Act2_Trees/28.md deleted file mode 100644 index 54c7410..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/28.md +++ /dev/null @@ -1,11 +0,0 @@ -## Let's say that Joe got married and had 2 children. Let's create the `Node` instances for Joe's 2 children: - -```Python -ricky = Node("Ricky", 34, "male", "basketball") -kelly = Node("Kelly", 35, "female", "tennis") -``` - - -------------------------------------------------- - -[for speaker]: <> (Let's say that Joe got married and had 2 children. Although we could adjust our tree structure to include Joe's spouse, let's keep our tree simple for now and only show grandma Susan's direct descendants. Let's create the `Node` instances for Joe's 2 children:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29,md b/Leetcode Workshops/Week 2/Act2_Trees/29,md deleted file mode 100644 index e69de29..0000000 diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29.md b/Leetcode Workshops/Week 2/Act2_Trees/29.md deleted file mode 100644 index 0b223ae..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/29.md +++ /dev/null @@ -1,10 +0,0 @@ -## Now let's connect them to Joe's node with edges: - -```Python -joe.insert_child(ricky) -joe.insert_child(kelly) -``` - -------------------------------------------------- - -[for speaker]: <> (Now, we have successfully created a simple family tree using data trees in Python.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/30.md b/Leetcode Workshops/Week 2/Act2_Trees/30.md deleted file mode 100644 index 1f0e935..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/30.md +++ /dev/null @@ -1,6 +0,0 @@ -## Draw the family tree -![img](https://i.imgur.com/pshjK2F.png ) - -------------------------------------------------- - -[for speaker]: <> (For practice, try out drawing the family tree we just created on paper. Also, for more practice, try implementing your own family tree in Python by adding and deleting the new object nodes with family member.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/31.md b/Leetcode Workshops/Week 2/Act2_Trees/31.md deleted file mode 100644 index 60311bd..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/31.md +++ /dev/null @@ -1,8 +0,0 @@ - - -## Let's use BST to make a simple database to be able to search members by their ID - -------------------------------------------------- - -[for speaker]: <> (Now to further **enhance your comprehension for Binary Search Tree's**, we will use a Binary Search Tree in an example **real-world application** in order for you to see the purpose behind this algorithm.) - diff --git a/Leetcode Workshops/Week 2/Act2_Trees/32.md b/Leetcode Workshops/Week 2/Act2_Trees/32.md deleted file mode 100644 index eaaeb86..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/32.md +++ /dev/null @@ -1,7 +0,0 @@ - - -- Consider that we are admins for a corporation that has many employees and we must have some sort of way to keep track of each employee in our database system. - -- We need an efficient way of **searching** for particular employees based on their **employee identification number**. - -- Each employee has a distinct identification number, so we will use a Binary Search Tree as our structure that stores the employees' ID numbers which represent the nodes. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/33.md b/Leetcode Workshops/Week 2/Act2_Trees/33.md deleted file mode 100644 index 8f23847..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/33.md +++ /dev/null @@ -1,17 +0,0 @@ - -```python -class Node: - def __init__(self,key,name): - self.left = None - self.right = None - self.val = key - self.employeeName = name -``` -- We want to hold each employee's ID number(Key) and name. -------------------------------------------------- - -[for speaker]: <> (We added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each employee's ID number[Key] and name.) - -[for speaker]: <> (For our employee information tree, we weant to hold the key, and **name** for each employee of the company.Therefore, we must slightly modify our 'Node' class to allow us to encompass that data.) - -[for speaker]: <> (We are now assigning the name of the employee to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each employee. It is just what we will use to identify a certain node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/34.md b/Leetcode Workshops/Week 2/Act2_Trees/34.md deleted file mode 100644 index 93f1430..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/34.md +++ /dev/null @@ -1,18 +0,0 @@ - -## A utility function to insert a new node with the given key -```python -def insert(root,node): - if root is None: - root = node - else: - if root.val < node.val: - if root.right is None: - root.right = node - else: - insert(root.right, node) - else: - if root.left is None: - root.left = node - else: - insert(root.left, node) -``` diff --git a/Leetcode Workshops/Week 2/Act2_Trees/35.md b/Leetcode Workshops/Week 2/Act2_Trees/35.md deleted file mode 100644 index 62b4612..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/35.md +++ /dev/null @@ -1,19 +0,0 @@ - -## A utility function to do inorder tree traversal -```python -def inorderID(root): - if root: - inorderID(root.left) - print(root.val) - inorderID(root.right) - -def inorderName(root): - if root: - inorderName(root.left) - print(root.employeeName) - inorderName(root.right) -``` - -------------------------------------------------- - -[for speaker]: <> (Now, we make functions to make a tree in order by the Key value[Employee ID] or the name of employee base on the insert function we produced above.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/36.md b/Leetcode Workshops/Week 2/Act2_Trees/36.md deleted file mode 100644 index b89969d..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/36.md +++ /dev/null @@ -1,19 +0,0 @@ -## A utility function to search a given key in BST - ```python -def search(root,key): - - # Base Cases: root is null or key is present at root - if root is None or root.val == key: - print(root.employeeName) - return root - - # Key is greater than root's key - if root.val < key: - return search(root.right,key) - - # Key is smaller than root's key - return search(root.left,key) -``` -------------------------------------------------- - -[for speaker]: <> (We make a function to search the name of employee base on the Key value[Employee ID].) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/37.md b/Leetcode Workshops/Week 2/Act2_Trees/37.md deleted file mode 100644 index 5d96ee1..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/37.md +++ /dev/null @@ -1,13 +0,0 @@ - -## Insert root node and other employee - ```python -r = Node(50, "Abel") -insert(r,Node(30, "Bob")) -insert(r,Node(20, "Cathy")) -insert(r,Node(40, "Debbie")) -insert(r,Node(70, "Evan")) -insert(r,Node(60, "Fiona")) -insert(r,Node(80, "Gabriel")) -``` -- Now, we declare "Abel" with ID number '50' as a root of the employee tree. -- We insert 6 employees under the root node of 'Abel' by using 'insert' function. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/38.md b/Leetcode Workshops/Week 2/Act2_Trees/38.md deleted file mode 100644 index fc91329..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/38.md +++ /dev/null @@ -1,13 +0,0 @@ - -## Order the nodes by ID - ```python -inorderID(r) -inorderName(r) -search(r, 20) -``` -- Use inorderID or inorderName function to make the nodes in order by employee ID or employee name. -- We can search the employee name by the key value(employee ID). - -------------------------------------------------- - -[for speaker]: <> (We have inserted all node objects for the root but we have not made them in order by employee ID or employee name. To do so, we use inorderID or inorderName function. Also, we can search the employee name by the key value[employee ID].) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/39.MD b/Leetcode Workshops/Week 2/Act2_Trees/39.MD deleted file mode 100644 index 7418c84..0000000 --- a/Leetcode Workshops/Week 2/Act2_Trees/39.MD +++ /dev/null @@ -1,13 +0,0 @@ -## The tree we just implemented should look like: -![](https://i.imgur.com/4FJ4zKR.png) - -| Python Code | Print Output | -| :------------: | :----------------------------------------------------------: | -| inorderID(r) | 20
30
40
50
60
70
80 | -| inorderName(r) | Cathy
Bob
Debbie
Abel
Fiona
Evan
Gabriel | -| search(r, 20) | Cathy | -| search(r, 60) | Fiona | - -------------------------------------------------- - -[for speaker]: <> (Figure 1. Binary Search Tree in order with the employee Identification number and employee's name) \ No newline at end of file From 4ad8ec76455a30f60f58bf7786163f8cd0e0612b Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Sat, 22 Feb 2020 01:41:38 -0800 Subject: [PATCH 06/24] Revert "Revert "Add the content slide 16-39"" This reverts commit a5bc847c17601a34118caaefc30810f47a10cc37. --- Leetcode Workshops/Week 2/Act2_Trees/1.md | 3 +-- Leetcode Workshops/Week 2/Act2_Trees/16.md | 15 +++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/17.md | 11 +++++++++++ Leetcode Workshops/Week 2/Act2_Trees/18.md | 16 ++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/19.md | 21 +++++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/20.md | 18 ++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/21.md | 19 +++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/22.md | 20 ++++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/23.md | 10 ++++++++++ Leetcode Workshops/Week 2/Act2_Trees/24.md | 21 +++++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/25.md | 12 ++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/26,md | 0 Leetcode Workshops/Week 2/Act2_Trees/26.md | 10 ++++++++++ Leetcode Workshops/Week 2/Act2_Trees/27.md | 15 +++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/28.md | 11 +++++++++++ Leetcode Workshops/Week 2/Act2_Trees/29,md | 0 Leetcode Workshops/Week 2/Act2_Trees/29.md | 10 ++++++++++ Leetcode Workshops/Week 2/Act2_Trees/30.md | 6 ++++++ Leetcode Workshops/Week 2/Act2_Trees/31.md | 8 ++++++++ Leetcode Workshops/Week 2/Act2_Trees/32.md | 7 +++++++ Leetcode Workshops/Week 2/Act2_Trees/33.md | 17 +++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/34.md | 18 ++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/35.md | 19 +++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/36.md | 19 +++++++++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/37.md | 13 +++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/38.md | 13 +++++++++++++ Leetcode Workshops/Week 2/Act2_Trees/39.MD | 13 +++++++++++++ 27 files changed, 343 insertions(+), 2 deletions(-) create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/17.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/18.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/19.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/20.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/21.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/22.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/23.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/24.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/25.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/26,md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/26.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/27.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/28.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/29,md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/29.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/30.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/31.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/32.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/33.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/34.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/35.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/36.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/37.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/38.md create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/39.MD diff --git a/Leetcode Workshops/Week 2/Act2_Trees/1.md b/Leetcode Workshops/Week 2/Act2_Trees/1.md index 07173bb..1ce946c 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/1.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/1.md @@ -3,8 +3,7 @@ # Trees ------------------------------------------------------------------------------------------------------ - +------------------------------------------------- [for speaker]: <> (Today we are going to learn about tree data structures. In order to do so, it is important that we understand the essential terminology) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/16.md b/Leetcode Workshops/Week 2/Act2_Trees/16.md index 8b13789..47de62e 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/16.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/16.md @@ -1 +1,16 @@ + +## Deleting a BST Node: +When deleting a BST node, there are **two main cases**: + +* **Leaf/One Child Case:** The first case is when the node we want to delete is a leaf in the BST or a node with only one child. + + + ​ ![](https://i0.wp.com/www.techiedelight.com/wp-content/uploads/Deletion-in-BST-Case-1.png?zoom=2.625&resize=368%2C142&ssl=1) + + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (The last fundamental function that allows us to interact with BSTs is `BSTDelete`, which will allow us to remove unwanted nodes from our tree. `BSTDelete` is arguably the most complicated of the BST functions we have learned so far because we have to fix the tree once we remove a node.) + +[for speaker]: <> (Since a leaf does not have any children, deleting it from a BST leaves us with a proper BST, meaning we do not have to change the structure of the tree and can simply remove the node. Also, if a node we want to delete only has one child, we can just delete that node and place its child where it used to be. Here is an example of the former:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/17.md b/Leetcode Workshops/Week 2/Act2_Trees/17.md new file mode 100644 index 0000000..912c401 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/17.md @@ -0,0 +1,11 @@ + + +## Deleting a BST Node: +* **Two Children Case**: The case when you want to delete a node with two children. + +* When an internal node is deleted, it must be replaced with the maximum node of the deleted node's left subtree or minimum node of the deleted node's right subtree in order to follow the rules of a BST. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (The more challenging case occurs when you want to delete an internal node in the BST, or a node with two children.If you simply deleted the node, you would lose the children.) +[for speaker]: <> (Therefore, when an internal node is deleted, it must be replaced with the maximum node of the deleted node's left subtree or minimum node of the deleted node's right subtree [your code implementation will determine the preference between these two options] in order to still follow the rules of a BST. Here is an illustration that should help your understanding:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/18.md b/Leetcode Workshops/Week 2/Act2_Trees/18.md new file mode 100644 index 0000000..7138ef9 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/18.md @@ -0,0 +1,16 @@ + + +## Example of `BSTDelete` + ![](https://i2.wp.com/www.techiedelight.com/wp-content/uploads/Deletion-in-BST-Case-2-1.png?zoom=1.5&resize=586%2C352&ssl=1) + + +* Find the *maximum* value of a node's *left* subtree, which is `19`. +* Replace 20 with 19 +* What if we want to delete the root 15? + + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (As you can see, we chose to delete `20` from the tree, and picked its in-order predecessor node as its replacement. The in-order predecessor node is the maximum value of a node's left subtree, in this case, `19`.. Similarly, we could have also used the in-order *successor* node, which is the *minimum* value of a node's *right* sub-tree. If we had gone that direction, we would have chosen `30` as the replacement for `20` in our example instead. ) + +[for speaker]: <> (Note that the process for deleting a child with two nodes is the same for **any** node, even the root! If we had decided to remove `15` from our tree above, and still decided to use the in-order predecessor node as our replacement, we would have picked `12` to be in its place. We would have chosen `16` if we picked the successor node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/19.md b/Leetcode Workshops/Week 2/Act2_Trees/19.md new file mode 100644 index 0000000..a27d482 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/19.md @@ -0,0 +1,21 @@ + +## `BSTDelete()` +```Python +def smallestNode(curNode): + inspectedNode = curNode + while(inspectedNode.left is not None): + inspectedNode = inspectedNode.left #Go left as far as possible + return inspectedNode +``` +### Step1: define helper function +* Define a function which finds the smallest node in a given node's subtree. + +* It traverses down the node's left subtree, always choosing to visit the left child, until we reach a leaf. + +* That leaf node is the smallest node and gets returned. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Due to the various cases when deleting a BST node, the `BSTDelete` function is a little more complex than `BSTSearch` and `BSTInsert`. However, don't be intimidated by the code; make certain you understand the process of deleting a node, because the code simply follows that logic. Let's take a look:) + +[for speaker]: <> (This is a helper function which will allows us to find the smallest node in a given node's subtree. The process is simple. We simply traverse down the node's left subtree, always choosing to visit the left child, until we reach a leaf. That leaf node is the smallest node and gets returned. As you can tell, we are chooisng the in-order predecessor node as our replacement in this code implementation.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/20.md b/Leetcode Workshops/Week 2/Act2_Trees/20.md new file mode 100644 index 0000000..d0c8f45 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/20.md @@ -0,0 +1,18 @@ + +## `BSTDelete()` +```python +def BSTDelete(curNode, key): + if curNode is None: + return curNode + if (key < curNode.key): + curNode.left = BSTDelete(curNode.left, key) + elif (key > curNode.key): + curNode.right = BSTDelete(curNode.right, key) +``` +### Step2: find the node that we want to delete + +We traverse down the left and right subtree of any given node until we reach the node we are looking to delete. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (In order to delete a node, we need to find it first! This process is the exact same as with `BSTSearch` and `BSTInsert`. We traverse down the left and right subtree of any given node until we reach the node we are looking to delete.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/21.md b/Leetcode Workshops/Week 2/Act2_Trees/21.md new file mode 100644 index 0000000..131f77b --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/21.md @@ -0,0 +1,19 @@ + +## `BSTDelete()` +```python +else: #found node to be deleted + if curNode.left is None: #Case 1 + tempNode = curNode.right + curNode = None #Delete node + return tempNode + elif curNode.right is None: #Case 1 + tempNode = curNode.left + curNode = None #Delete node + return tempNode +``` +### Step3: deal with case 1. +We "delete" a node by setting it to `None`. + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Here, we found the node and it falls under one of the two situations listed in Case 1: it is either a leaf, or only has one child. We do the appropriate replacement and deletion procedures. Notice that we "delete" a node by setting it to `None`.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/22.md b/Leetcode Workshops/Week 2/Act2_Trees/22.md new file mode 100644 index 0000000..33fbf69 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/22.md @@ -0,0 +1,20 @@ + + +## `BSTDelete()` +```python + #Internal Node Case: + tempNode = smallestNode(curNode.right) #find smallest key node of right subtree + curNode.key = tempNode.key + curNode.right = BSTDelete(curNode.right, tempNode.key) +``` +### Step4: deal with case2 +* Find its in-order predecessor node. +* Replace its value with the predecessor's value. +* Delete the predecessor node from our tree. + + +----------------------------------------------------------------------------------------------------- + +[for speaker]: <> (Finally, this is the case where the node in question has two children. We find its in-order predecessor node, replace its value with the predecessor's value, and delete the predecessor node from our tree.) + +[for speaker]: <> (Although `BSTDelete` seems complicated initially,you will realize that it simply follows the logic of either the **Leaf/1 Child Case** or the **Internal Node Case**. Feel free to ask questions about the two cases if you're having trouble understanding the `BSTDelete` code.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/23.md b/Leetcode Workshops/Week 2/Act2_Trees/23.md new file mode 100644 index 0000000..0870eb5 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/23.md @@ -0,0 +1,10 @@ + + + +# Let's make a family tree in Python using the `Node` class + +------------------------------------------------- + +[for speaker]: <> (Now that we have learned the basic concepts associated with trees, let's do an activity together that walks through a real life application of data trees to cement our understanding.) + +[for speaker]: <> (As I mentioned prior, a place where a data tree occurs in your real life is with the relationships in your family. For the activity, we will make a data tree in Python using the `Node` class that will be a representation of a family.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/24.md b/Leetcode Workshops/Week 2/Act2_Trees/24.md new file mode 100644 index 0000000..2bf7832 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/24.md @@ -0,0 +1,21 @@ +## Family Tree: +```Python +class Node: + def __init__(self, name, age, gender, sport): + self.key = name + self.age = age + self.gender = gender + self.sport = sport + self.children = [] + + def insert_child(self, newChild): + self.children.append(newChild) +``` +For our family tree, we want to hold the **name**, **age**, **gender**, and **favorite sport** for each member of the family. + +* We use key to identify a certain node. +* Assign the name of the family member to be the key + +------------------------------------------------- + +[for speaker]: <> (As you may have noticed, we added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each family member. Notice that we are now assigning the name of the family member to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each family member. It is just what we will use to identify a certain node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/25.md b/Leetcode Workshops/Week 2/Act2_Trees/25.md new file mode 100644 index 0000000..370cdd1 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/25.md @@ -0,0 +1,12 @@ +## Building the Tree: +Step1: Let's initialize root `Node` + + For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. + +```Python +grandma = Node("Susan", 92, "female", "bowling") +``` + +------------------------------------------------- + +[for speaker]: <> (Now that we have our new `Node` class, let's start initializing some family members to start building the ancestry tree. For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. Let's initialize her `Node` object:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26,md b/Leetcode Workshops/Week 2/Act2_Trees/26,md new file mode 100644 index 0000000..e69de29 diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26.md b/Leetcode Workshops/Week 2/Act2_Trees/26.md new file mode 100644 index 0000000..428b99d --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/26.md @@ -0,0 +1,10 @@ +## Let's say grandma Susan has 3 children. Let's create some node objects for her children: + +```Python +mary = Node("Mary", 57, "female", "soccer") +joe = Node("Joe", 61, "male", "football") +don = Node("Don", 63, "male", "tennis") +``` +------------------------------------------------- + +[for speaker]: <> (Now that we have a node for grandma Susan, let's say she has 3 children. Let's create some node objects for her children:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/27.md b/Leetcode Workshops/Week 2/Act2_Trees/27.md new file mode 100644 index 0000000..abf7757 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/27.md @@ -0,0 +1,15 @@ + +### Connect Susan's children with Susan + +```Python +grandma.insert_child(Mary) +grandma.insert_child(Joe) +grandma.insert_child(Don) +``` +`grandma.children` will now be a list that holds the node Mary, Joe, and Don. + +------------------------------------------------- + +[for speaker]: <> (We have declared node objects for all of Susan's children but we have not indicated in our code that they are her children yet. In order to do so, we can use the `insert_child` function in the `Node` class on Susan's object.) + +[for speaker]: <> (After making those 3 calls, grandma.children will now be a list that holds the node instances mary, joe, and don. We have essentially drawn edges between grandma and mary, grandma and joe, and grandma and don.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/28.md b/Leetcode Workshops/Week 2/Act2_Trees/28.md new file mode 100644 index 0000000..54c7410 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/28.md @@ -0,0 +1,11 @@ +## Let's say that Joe got married and had 2 children. Let's create the `Node` instances for Joe's 2 children: + +```Python +ricky = Node("Ricky", 34, "male", "basketball") +kelly = Node("Kelly", 35, "female", "tennis") +``` + + +------------------------------------------------- + +[for speaker]: <> (Let's say that Joe got married and had 2 children. Although we could adjust our tree structure to include Joe's spouse, let's keep our tree simple for now and only show grandma Susan's direct descendants. Let's create the `Node` instances for Joe's 2 children:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29,md b/Leetcode Workshops/Week 2/Act2_Trees/29,md new file mode 100644 index 0000000..e69de29 diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29.md b/Leetcode Workshops/Week 2/Act2_Trees/29.md new file mode 100644 index 0000000..0b223ae --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/29.md @@ -0,0 +1,10 @@ +## Now let's connect them to Joe's node with edges: + +```Python +joe.insert_child(ricky) +joe.insert_child(kelly) +``` + +------------------------------------------------- + +[for speaker]: <> (Now, we have successfully created a simple family tree using data trees in Python.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/30.md b/Leetcode Workshops/Week 2/Act2_Trees/30.md new file mode 100644 index 0000000..1f0e935 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/30.md @@ -0,0 +1,6 @@ +## Draw the family tree +![img](https://i.imgur.com/pshjK2F.png ) + +------------------------------------------------- + +[for speaker]: <> (For practice, try out drawing the family tree we just created on paper. Also, for more practice, try implementing your own family tree in Python by adding and deleting the new object nodes with family member.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/31.md b/Leetcode Workshops/Week 2/Act2_Trees/31.md new file mode 100644 index 0000000..60311bd --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/31.md @@ -0,0 +1,8 @@ + + +## Let's use BST to make a simple database to be able to search members by their ID + +------------------------------------------------- + +[for speaker]: <> (Now to further **enhance your comprehension for Binary Search Tree's**, we will use a Binary Search Tree in an example **real-world application** in order for you to see the purpose behind this algorithm.) + diff --git a/Leetcode Workshops/Week 2/Act2_Trees/32.md b/Leetcode Workshops/Week 2/Act2_Trees/32.md new file mode 100644 index 0000000..eaaeb86 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/32.md @@ -0,0 +1,7 @@ + + +- Consider that we are admins for a corporation that has many employees and we must have some sort of way to keep track of each employee in our database system. + +- We need an efficient way of **searching** for particular employees based on their **employee identification number**. + +- Each employee has a distinct identification number, so we will use a Binary Search Tree as our structure that stores the employees' ID numbers which represent the nodes. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/33.md b/Leetcode Workshops/Week 2/Act2_Trees/33.md new file mode 100644 index 0000000..8f23847 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/33.md @@ -0,0 +1,17 @@ + +```python +class Node: + def __init__(self,key,name): + self.left = None + self.right = None + self.val = key + self.employeeName = name +``` +- We want to hold each employee's ID number(Key) and name. +------------------------------------------------- + +[for speaker]: <> (We added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each employee's ID number[Key] and name.) + +[for speaker]: <> (For our employee information tree, we weant to hold the key, and **name** for each employee of the company.Therefore, we must slightly modify our 'Node' class to allow us to encompass that data.) + +[for speaker]: <> (We are now assigning the name of the employee to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each employee. It is just what we will use to identify a certain node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/34.md b/Leetcode Workshops/Week 2/Act2_Trees/34.md new file mode 100644 index 0000000..93f1430 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/34.md @@ -0,0 +1,18 @@ + +## A utility function to insert a new node with the given key +```python +def insert(root,node): + if root is None: + root = node + else: + if root.val < node.val: + if root.right is None: + root.right = node + else: + insert(root.right, node) + else: + if root.left is None: + root.left = node + else: + insert(root.left, node) +``` diff --git a/Leetcode Workshops/Week 2/Act2_Trees/35.md b/Leetcode Workshops/Week 2/Act2_Trees/35.md new file mode 100644 index 0000000..62b4612 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/35.md @@ -0,0 +1,19 @@ + +## A utility function to do inorder tree traversal +```python +def inorderID(root): + if root: + inorderID(root.left) + print(root.val) + inorderID(root.right) + +def inorderName(root): + if root: + inorderName(root.left) + print(root.employeeName) + inorderName(root.right) +``` + +------------------------------------------------- + +[for speaker]: <> (Now, we make functions to make a tree in order by the Key value[Employee ID] or the name of employee base on the insert function we produced above.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/36.md b/Leetcode Workshops/Week 2/Act2_Trees/36.md new file mode 100644 index 0000000..b89969d --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/36.md @@ -0,0 +1,19 @@ +## A utility function to search a given key in BST + ```python +def search(root,key): + + # Base Cases: root is null or key is present at root + if root is None or root.val == key: + print(root.employeeName) + return root + + # Key is greater than root's key + if root.val < key: + return search(root.right,key) + + # Key is smaller than root's key + return search(root.left,key) +``` +------------------------------------------------- + +[for speaker]: <> (We make a function to search the name of employee base on the Key value[Employee ID].) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/37.md b/Leetcode Workshops/Week 2/Act2_Trees/37.md new file mode 100644 index 0000000..5d96ee1 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/37.md @@ -0,0 +1,13 @@ + +## Insert root node and other employee + ```python +r = Node(50, "Abel") +insert(r,Node(30, "Bob")) +insert(r,Node(20, "Cathy")) +insert(r,Node(40, "Debbie")) +insert(r,Node(70, "Evan")) +insert(r,Node(60, "Fiona")) +insert(r,Node(80, "Gabriel")) +``` +- Now, we declare "Abel" with ID number '50' as a root of the employee tree. +- We insert 6 employees under the root node of 'Abel' by using 'insert' function. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/38.md b/Leetcode Workshops/Week 2/Act2_Trees/38.md new file mode 100644 index 0000000..fc91329 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/38.md @@ -0,0 +1,13 @@ + +## Order the nodes by ID + ```python +inorderID(r) +inorderName(r) +search(r, 20) +``` +- Use inorderID or inorderName function to make the nodes in order by employee ID or employee name. +- We can search the employee name by the key value(employee ID). + +------------------------------------------------- + +[for speaker]: <> (We have inserted all node objects for the root but we have not made them in order by employee ID or employee name. To do so, we use inorderID or inorderName function. Also, we can search the employee name by the key value[employee ID].) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/39.MD b/Leetcode Workshops/Week 2/Act2_Trees/39.MD new file mode 100644 index 0000000..7418c84 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/39.MD @@ -0,0 +1,13 @@ +## The tree we just implemented should look like: +![](https://i.imgur.com/4FJ4zKR.png) + +| Python Code | Print Output | +| :------------: | :----------------------------------------------------------: | +| inorderID(r) | 20
30
40
50
60
70
80 | +| inorderName(r) | Cathy
Bob
Debbie
Abel
Fiona
Evan
Gabriel | +| search(r, 20) | Cathy | +| search(r, 60) | Fiona | + +------------------------------------------------- + +[for speaker]: <> (Figure 1. Binary Search Tree in order with the employee Identification number and employee's name) \ No newline at end of file From ceb1f84a782b4b1f94e0008022fc41592e1aa986 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Sat, 22 Feb 2020 01:43:32 -0800 Subject: [PATCH 07/24] delete empty file --- Leetcode Workshops/Week 2/Act2_Trees/26,md | 0 Leetcode Workshops/Week 2/Act2_Trees/29,md | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/26,md delete mode 100644 Leetcode Workshops/Week 2/Act2_Trees/29,md diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26,md b/Leetcode Workshops/Week 2/Act2_Trees/26,md deleted file mode 100644 index e69de29..0000000 diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29,md b/Leetcode Workshops/Week 2/Act2_Trees/29,md deleted file mode 100644 index e69de29..0000000 From 057fb2f76a8c723e605fb8c60e7a5fb9dd43a6bc Mon Sep 17 00:00:00 2001 From: Ruby <56561364+Dadao-xiaoguaishou@users.noreply.github.com> Date: Sat, 22 Feb 2020 01:48:10 -0800 Subject: [PATCH 08/24] Create READ.md --- Leetcode Workshops/Week 2/Act2_Trees/READ.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Leetcode Workshops/Week 2/Act2_Trees/READ.md diff --git a/Leetcode Workshops/Week 2/Act2_Trees/READ.md b/Leetcode Workshops/Week 2/Act2_Trees/READ.md new file mode 100644 index 0000000..5ebca88 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act2_Trees/READ.md @@ -0,0 +1,14 @@ +Trees +- 1.md -> slides 1-5 +- 2.md -> slides 6-9 +- 3.md -> slides 10-12 +- 4.md -> slides 13-15 +- 5.md -> slides 16-18 +- 6.md -> slides 19-22 +- 7.md -> slides 23-30 +- 8.md -> slides 31-39 + + In 7.md please fix the insert_child (the name are now all lowercase) + +Please fix 8.md + - break up code, add explanation, introduce in order traversal before use it, explain what will print out From f54c1afcaf4c234960324858cbb56afe7b81d85e Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Sat, 22 Feb 2020 02:44:28 -0800 Subject: [PATCH 09/24] add type for each slide and readme --- Leetcode Workshops/Week 2/Act2_Trees/10.md | 5 +---- Leetcode Workshops/Week 2/Act2_Trees/11.md | 7 ++----- Leetcode Workshops/Week 2/Act2_Trees/12.md | 1 - Leetcode Workshops/Week 2/Act2_Trees/13.md | 5 ++--- Leetcode Workshops/Week 2/Act2_Trees/14.md | 8 +++----- Leetcode Workshops/Week 2/Act2_Trees/16.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/17.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/18.md | 2 +- Leetcode Workshops/Week 2/Act2_Trees/19.md | 1 + Leetcode Workshops/Week 2/Act2_Trees/20.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/21.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/22.md | 7 ++----- Leetcode Workshops/Week 2/Act2_Trees/23.md | 3 +-- Leetcode Workshops/Week 2/Act2_Trees/24.md | 4 +++- Leetcode Workshops/Week 2/Act2_Trees/25.md | 6 +++--- Leetcode Workshops/Week 2/Act2_Trees/26.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/27.md | 6 +++--- Leetcode Workshops/Week 2/Act2_Trees/28.md | 5 ++--- Leetcode Workshops/Week 2/Act2_Trees/29.md | 4 ++-- Leetcode Workshops/Week 2/Act2_Trees/30.md | 2 ++ Leetcode Workshops/Week 2/Act2_Trees/31.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/32.md | 1 + Leetcode Workshops/Week 2/Act2_Trees/33.md | 4 +++- Leetcode Workshops/Week 2/Act2_Trees/34.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/35.md | 4 ++-- Leetcode Workshops/Week 2/Act2_Trees/36.md | 7 +++---- Leetcode Workshops/Week 2/Act2_Trees/37.md | 5 +++-- Leetcode Workshops/Week 2/Act2_Trees/38.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/39.MD | 2 ++ Leetcode Workshops/Week 2/Act2_Trees/4.md | 4 +++- Leetcode Workshops/Week 2/Act2_Trees/5.md | 1 + Leetcode Workshops/Week 2/Act2_Trees/6.md | 2 +- Leetcode Workshops/Week 2/Act2_Trees/7.md | 2 +- Leetcode Workshops/Week 2/Act2_Trees/8.md | 2 +- Leetcode Workshops/Week 2/Act2_Trees/9.md | 2 +- .../Week 2/Act2_Trees/{READ.md => README.md} | 0 36 files changed, 66 insertions(+), 60 deletions(-) rename Leetcode Workshops/Week 2/Act2_Trees/{READ.md => README.md} (100%) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/10.md b/Leetcode Workshops/Week 2/Act2_Trees/10.md index 7786999..87f13ae 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/10.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/10.md @@ -1,9 +1,7 @@ - + ## BST Search: - - ```Python def BSTSearch(curNode, key): if curNode is None or curNode.key == key: @@ -13,7 +11,6 @@ def BSTSearch(curNode, key): else: return search(curNode.left, key) #Go left ``` - - Go right if you're looking for a larger key or go left if you're looking for a smaller key. - It starts at the root and calls the same function again on right child if the desired key is greater than the current node's key diff --git a/Leetcode Workshops/Week 2/Act2_Trees/11.md b/Leetcode Workshops/Week 2/Act2_Trees/11.md index c81d324..71f76ca 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/11.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/11.md @@ -1,10 +1,7 @@ - -## Example of `BFSSearch` + +## Use `BFSSearch` to search for 7 - -Use `BFSSearch` to search for 7 - ----------------------------------------------------------------------------------------------------- [for speaker]: <> (Let's actually see this in action, using use the tree from the previous card as as an example. Let's say we want to find `7` in our tree. Above, you can see the specific path that `BSTSearch` takes to look for the node) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/12.md b/Leetcode Workshops/Week 2/Act2_Trees/12.md index 8c8a8e7..9dd03ae 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/12.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/12.md @@ -3,7 +3,6 @@ ## Time Complexity of `BSTSearch`: - * Searching for the node with key 50. * The time to reach a desired node would be O(height) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/13.md b/Leetcode Workshops/Week 2/Act2_Trees/13.md index 5add3c6..18cc0b6 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/13.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/13.md @@ -1,7 +1,6 @@ - - + + ## `BSTInsert`: - ```Python def BSTInsert(curNode, newNode): if curNode is None: diff --git a/Leetcode Workshops/Week 2/Act2_Trees/14.md b/Leetcode Workshops/Week 2/Act2_Trees/14.md index 9c7fe40..b2788a4 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/14.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/14.md @@ -1,10 +1,8 @@ - -## Example of `BSTInsert` + +## Use `BSTInsert` to add a node `11` to this tree. -Use `BSTInsert` to add a node `11` to this tree. - ------------------------------------------------------------------------------------------------------ +------------------------------------------------- [for speaker]: <> (let's use an example to illustrate how this code works, . We will add a node `11` to this tree. You can see the specific path that `BSTInsert` takes to insert the node as well as the actual position that `11` ends up in.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/16.md b/Leetcode Workshops/Week 2/Act2_Trees/16.md index 47de62e..cce3cbb 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/16.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/16.md @@ -1,4 +1,5 @@ - + + ## Deleting a BST Node: When deleting a BST node, there are **two main cases**: diff --git a/Leetcode Workshops/Week 2/Act2_Trees/17.md b/Leetcode Workshops/Week 2/Act2_Trees/17.md index 912c401..065887e 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/17.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/17.md @@ -1,4 +1,5 @@ - + + ## Deleting a BST Node: * **Two Children Case**: The case when you want to delete a node with two children. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/18.md b/Leetcode Workshops/Week 2/Act2_Trees/18.md index 7138ef9..4399fc0 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/18.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/18.md @@ -1,4 +1,4 @@ - + ## Example of `BSTDelete` ![](https://i2.wp.com/www.techiedelight.com/wp-content/uploads/Deletion-in-BST-Case-2-1.png?zoom=1.5&resize=586%2C352&ssl=1) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/19.md b/Leetcode Workshops/Week 2/Act2_Trees/19.md index a27d482..1c6161e 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/19.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/19.md @@ -1,3 +1,4 @@ + ## `BSTDelete()` ```Python diff --git a/Leetcode Workshops/Week 2/Act2_Trees/20.md b/Leetcode Workshops/Week 2/Act2_Trees/20.md index d0c8f45..9631b84 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/20.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/20.md @@ -1,3 +1,4 @@ + ## `BSTDelete()` ```python @@ -13,6 +14,6 @@ def BSTDelete(curNode, key): We traverse down the left and right subtree of any given node until we reach the node we are looking to delete. ------------------------------------------------------------------------------------------------------ +------------------------------------------------- [for speaker]: <> (In order to delete a node, we need to find it first! This process is the exact same as with `BSTSearch` and `BSTInsert`. We traverse down the left and right subtree of any given node until we reach the node we are looking to delete.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/21.md b/Leetcode Workshops/Week 2/Act2_Trees/21.md index 131f77b..2ca961e 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/21.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/21.md @@ -1,3 +1,4 @@ + ## `BSTDelete()` ```python @@ -14,6 +15,6 @@ else: #found node to be deleted ### Step3: deal with case 1. We "delete" a node by setting it to `None`. ------------------------------------------------------------------------------------------------------ +------------------------------------------------- [for speaker]: <> (Here, we found the node and it falls under one of the two situations listed in Case 1: it is either a leaf, or only has one child. We do the appropriate replacement and deletion procedures. Notice that we "delete" a node by setting it to `None`.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/22.md b/Leetcode Workshops/Week 2/Act2_Trees/22.md index 33fbf69..1029754 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/22.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/22.md @@ -1,4 +1,4 @@ - + ## `BSTDelete()` ```python @@ -11,10 +11,7 @@ * Find its in-order predecessor node. * Replace its value with the predecessor's value. * Delete the predecessor node from our tree. - - ------------------------------------------------------------------------------------------------------ - +------------------------------------------------- [for speaker]: <> (Finally, this is the case where the node in question has two children. We find its in-order predecessor node, replace its value with the predecessor's value, and delete the predecessor node from our tree.) [for speaker]: <> (Although `BSTDelete` seems complicated initially,you will realize that it simply follows the logic of either the **Leaf/1 Child Case** or the **Internal Node Case**. Feel free to ask questions about the two cases if you're having trouble understanding the `BSTDelete` code.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/23.md b/Leetcode Workshops/Week 2/Act2_Trees/23.md index 0870eb5..0da1863 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/23.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/23.md @@ -1,6 +1,5 @@ + - - # Let's make a family tree in Python using the `Node` class ------------------------------------------------- diff --git a/Leetcode Workshops/Week 2/Act2_Trees/24.md b/Leetcode Workshops/Week 2/Act2_Trees/24.md index 2bf7832..3e72bf7 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/24.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/24.md @@ -1,4 +1,6 @@ -## Family Tree: + + +## Define the `Node` class of Family Tree: ```Python class Node: def __init__(self, name, age, gender, sport): diff --git a/Leetcode Workshops/Week 2/Act2_Trees/25.md b/Leetcode Workshops/Week 2/Act2_Trees/25.md index 370cdd1..6d137f4 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/25.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/25.md @@ -1,6 +1,6 @@ -## Building the Tree: -Step1: Let's initialize root `Node` - + + +## Initialize `root Node`: For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. ```Python diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26.md b/Leetcode Workshops/Week 2/Act2_Trees/26.md index 428b99d..b6c69d8 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/26.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/26.md @@ -1,5 +1,6 @@ + + ## Let's say grandma Susan has 3 children. Let's create some node objects for her children: - ```Python mary = Node("Mary", 57, "female", "soccer") joe = Node("Joe", 61, "male", "football") diff --git a/Leetcode Workshops/Week 2/Act2_Trees/27.md b/Leetcode Workshops/Week 2/Act2_Trees/27.md index abf7757..200a69a 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/27.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/27.md @@ -1,6 +1,6 @@ - -### Connect Susan's children with Susan - + + +## Connect Susan's children with Susan ```Python grandma.insert_child(Mary) grandma.insert_child(Joe) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/28.md b/Leetcode Workshops/Week 2/Act2_Trees/28.md index 54c7410..e66a70f 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/28.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/28.md @@ -1,11 +1,10 @@ + + ## Let's say that Joe got married and had 2 children. Let's create the `Node` instances for Joe's 2 children: - ```Python ricky = Node("Ricky", 34, "male", "basketball") kelly = Node("Kelly", 35, "female", "tennis") ``` - - ------------------------------------------------- [for speaker]: <> (Let's say that Joe got married and had 2 children. Although we could adjust our tree structure to include Joe's spouse, let's keep our tree simple for now and only show grandma Susan's direct descendants. Let's create the `Node` instances for Joe's 2 children:) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29.md b/Leetcode Workshops/Week 2/Act2_Trees/29.md index 0b223ae..b2c7d31 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/29.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/29.md @@ -1,10 +1,10 @@ + + ## Now let's connect them to Joe's node with edges: - ```Python joe.insert_child(ricky) joe.insert_child(kelly) ``` - ------------------------------------------------- [for speaker]: <> (Now, we have successfully created a simple family tree using data trees in Python.) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/30.md b/Leetcode Workshops/Week 2/Act2_Trees/30.md index 1f0e935..a2fe46b 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/30.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/30.md @@ -1,3 +1,5 @@ + + ## Draw the family tree ![img](https://i.imgur.com/pshjK2F.png ) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/31.md b/Leetcode Workshops/Week 2/Act2_Trees/31.md index 60311bd..6e5ec67 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/31.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/31.md @@ -1,4 +1,5 @@ - + + ## Let's use BST to make a simple database to be able to search members by their ID diff --git a/Leetcode Workshops/Week 2/Act2_Trees/32.md b/Leetcode Workshops/Week 2/Act2_Trees/32.md index eaaeb86..8149e70 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/32.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/32.md @@ -1,3 +1,4 @@ + - Consider that we are admins for a corporation that has many employees and we must have some sort of way to keep track of each employee in our database system. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/33.md b/Leetcode Workshops/Week 2/Act2_Trees/33.md index 8f23847..020685a 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/33.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/33.md @@ -1,4 +1,6 @@ - + + +## Create the `Node` class ```python class Node: def __init__(self,key,name): diff --git a/Leetcode Workshops/Week 2/Act2_Trees/34.md b/Leetcode Workshops/Week 2/Act2_Trees/34.md index 93f1430..21eae3e 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/34.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/34.md @@ -1,4 +1,5 @@ - + + ## A utility function to insert a new node with the given key ```python def insert(root,node): diff --git a/Leetcode Workshops/Week 2/Act2_Trees/35.md b/Leetcode Workshops/Week 2/Act2_Trees/35.md index 62b4612..3018ee0 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/35.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/35.md @@ -1,4 +1,5 @@ - + + ## A utility function to do inorder tree traversal ```python def inorderID(root): @@ -13,7 +14,6 @@ def inorderName(root): print(root.employeeName) inorderName(root.right) ``` - ------------------------------------------------- [for speaker]: <> (Now, we make functions to make a tree in order by the Key value[Employee ID] or the name of employee base on the insert function we produced above.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/36.md b/Leetcode Workshops/Week 2/Act2_Trees/36.md index b89969d..f9d21b0 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/36.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/36.md @@ -1,16 +1,15 @@ + + ## A utility function to search a given key in BST ```python -def search(root,key): - +def search(root,key): # Base Cases: root is null or key is present at root if root is None or root.val == key: print(root.employeeName) return root - # Key is greater than root's key if root.val < key: return search(root.right,key) - # Key is smaller than root's key return search(root.left,key) ``` diff --git a/Leetcode Workshops/Week 2/Act2_Trees/37.md b/Leetcode Workshops/Week 2/Act2_Trees/37.md index 5d96ee1..79c485d 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/37.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/37.md @@ -1,5 +1,6 @@ - -## Insert root node and other employee + + +## Insert root node and other employees ```python r = Node(50, "Abel") insert(r,Node(30, "Bob")) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/38.md b/Leetcode Workshops/Week 2/Act2_Trees/38.md index fc91329..26b6551 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/38.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/38.md @@ -1,4 +1,5 @@ - + + ## Order the nodes by ID ```python inorderID(r) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/39.MD b/Leetcode Workshops/Week 2/Act2_Trees/39.MD index 7418c84..92f08d8 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/39.MD +++ b/Leetcode Workshops/Week 2/Act2_Trees/39.MD @@ -1,3 +1,5 @@ + + ## The tree we just implemented should look like: ![](https://i.imgur.com/4FJ4zKR.png) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/4.md b/Leetcode Workshops/Week 2/Act2_Trees/4.md index f713e65..910a279 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/4.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/4.md @@ -1,4 +1,6 @@ - + + +## Example of Tree Terminology * Each circles with numbers in them are the **nodes** of the tree. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/5.md b/Leetcode Workshops/Week 2/Act2_Trees/5.md index fb8236c..8a534b6 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/5.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/5.md @@ -1,4 +1,5 @@ + ## Real Life Application of Trees: ### Ancestry Trees: diff --git a/Leetcode Workshops/Week 2/Act2_Trees/6.md b/Leetcode Workshops/Week 2/Act2_Trees/6.md index 8bfbd99..6e5b38c 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/6.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/6.md @@ -1,5 +1,5 @@ - + ## Let's Define the `Node` Class: ```Python diff --git a/Leetcode Workshops/Week 2/Act2_Trees/7.md b/Leetcode Workshops/Week 2/Act2_Trees/7.md index 8d2a448..37b834c 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/7.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/7.md @@ -1,4 +1,4 @@ - + ## Binary Trees: diff --git a/Leetcode Workshops/Week 2/Act2_Trees/8.md b/Leetcode Workshops/Week 2/Act2_Trees/8.md index 6cced7b..35c98a3 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/8.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/8.md @@ -1,6 +1,6 @@ - + ## Let's see an example of a valid vs invalid BST: ​ diff --git a/Leetcode Workshops/Week 2/Act2_Trees/9.md b/Leetcode Workshops/Week 2/Act2_Trees/9.md index 3a9bafb..bdc409a 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/9.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/9.md @@ -1,4 +1,4 @@ - + ## Implement BST `Node` class BST ```Python diff --git a/Leetcode Workshops/Week 2/Act2_Trees/READ.md b/Leetcode Workshops/Week 2/Act2_Trees/README.md similarity index 100% rename from Leetcode Workshops/Week 2/Act2_Trees/READ.md rename to Leetcode Workshops/Week 2/Act2_Trees/README.md From 70ef5ede1d1404ab129b554faa7016ffaa8e88b2 Mon Sep 17 00:00:00 2001 From: Ruby <56561364+Dadao-xiaoguaishou@users.noreply.github.com> Date: Sat, 22 Feb 2020 09:06:25 -0800 Subject: [PATCH 10/24] Rename 39.MD to 39.md --- Leetcode Workshops/Week 2/Act2_Trees/{39.MD => 39.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Leetcode Workshops/Week 2/Act2_Trees/{39.MD => 39.md} (93%) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/39.MD b/Leetcode Workshops/Week 2/Act2_Trees/39.md similarity index 93% rename from Leetcode Workshops/Week 2/Act2_Trees/39.MD rename to Leetcode Workshops/Week 2/Act2_Trees/39.md index 92f08d8..981f909 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/39.MD +++ b/Leetcode Workshops/Week 2/Act2_Trees/39.md @@ -12,4 +12,4 @@ ------------------------------------------------- -[for speaker]: <> (Figure 1. Binary Search Tree in order with the employee Identification number and employee's name) \ No newline at end of file +[for speaker]: <> (Figure 1. Binary Search Tree in order with the employee Identification number and employee's name) From e52bae1e1a4d7f0846de4e1f569f371b2bb1c8b1 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Sat, 22 Feb 2020 15:58:30 -0800 Subject: [PATCH 11/24] add linked list content of slide 1-36 will add type later --- .../Week 2/Act1_Linked list/1.md | 1 + .../Week 2/Act1_Linked list/10.md | 9 +++++++ .../Week 2/Act1_Linked list/11.md | 20 ++++++++++++++ .../Week 2/Act1_Linked list/12.md | 18 +++++++++++++ .../Week 2/Act1_Linked list/13.md | 15 +++++++++++ .../Week 2/Act1_Linked list/14.md | 18 +++++++++++++ .../Week 2/Act1_Linked list/15.md | 17 ++++++++++++ .../Week 2/Act1_Linked list/16.md | 20 ++++++++++++++ .../Week 2/Act1_Linked list/17.md | 18 +++++++++++++ .../Week 2/Act1_Linked list/18.md | 26 +++++++++++++++++++ .../Week 2/Act1_Linked list/19.md | 6 +++++ .../Week 2/Act1_Linked list/2.md | 8 ++++++ .../Week 2/Act1_Linked list/20.md | 11 ++++++++ .../Week 2/Act1_Linked list/21.md | 14 ++++++++++ .../Week 2/Act1_Linked list/22.md | 16 ++++++++++++ .../Week 2/Act1_Linked list/23.md | 14 ++++++++++ .../Week 2/Act1_Linked list/24.md | 4 +++ .../Week 2/Act1_Linked list/25.md | 11 ++++++++ .../Week 2/Act1_Linked list/26.md | 5 ++++ .../Week 2/Act1_Linked list/27.md | 7 +++++ .../Week 2/Act1_Linked list/28.md | 8 ++++++ .../Week 2/Act1_Linked list/29.md | 17 ++++++++++++ .../Week 2/Act1_Linked list/3.md | 7 +++++ .../Week 2/Act1_Linked list/30.md | 16 ++++++++++++ .../Week 2/Act1_Linked list/31.md | 8 ++++++ .../Week 2/Act1_Linked list/32.md | 3 +++ .../Week 2/Act1_Linked list/33.md | 13 ++++++++++ .../Week 2/Act1_Linked list/34.md | 17 ++++++++++++ .../Week 2/Act1_Linked list/35.md | 11 ++++++++ .../Week 2/Act1_Linked list/36.md | 9 +++++++ .../Week 2/Act1_Linked list/4.md | 16 ++++++++++++ .../Week 2/Act1_Linked list/5.md | 3 +++ .../Week 2/Act1_Linked list/6.md | 7 +++++ .../Week 2/Act1_Linked list/7.md | 12 +++++++++ .../Week 2/Act1_Linked list/8.MD | 25 ++++++++++++++++++ .../Week 2/Act1_Linked list/9.md | 23 ++++++++++++++++ 36 files changed, 453 insertions(+) create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/1.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/10.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/11.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/12.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/13.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/14.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/15.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/16.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/17.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/18.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/19.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/2.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/20.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/21.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/22.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/23.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/24.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/25.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/26.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/27.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/28.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/29.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/3.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/30.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/31.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/32.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/33.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/34.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/35.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/36.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/4.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/5.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/6.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/7.md create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/8.MD create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/9.md diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/1.md b/Leetcode Workshops/Week 2/Act1_Linked list/1.md new file mode 100644 index 0000000..2567003 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/1.md @@ -0,0 +1 @@ +# Linked Lists \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/10.md b/Leetcode Workshops/Week 2/Act1_Linked list/10.md new file mode 100644 index 0000000..bfc1fcd --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/10.md @@ -0,0 +1,9 @@ +## Now let's create our linked list and a node for it + +```python +film = LinkedList() +film.head = Node(900) +``` +Our linked list will look like : + + \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/11.md b/Leetcode Workshops/Week 2/Act1_Linked list/11.md new file mode 100644 index 0000000..2dd66de --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/11.md @@ -0,0 +1,20 @@ + +## `insert()` +```python +def insert(self, data): + new_node = Node(data) + new_node.set_next(self.head) + self.head = new_node +``` +- Initialize a new `Node` object with the data +- Make the `Node` points to the old head +- Set `Node` to be the new head +- Time complexity : O(1) + +------------------------------------------------- + +[for speaker]: <> (To begin inserting new nodes into the linked list, we'll create an `insert[]` method! We will take data, initialize a new `Node` object with the data, then add it to the list. Although its possible to insert a new Node anywhere in the list, it becomes less expensive to insert it at the beginning.) + +[for speaker]: <> (If we had a string of pearls and wanted to add a new pearl, we would add the pearl at the start of the string, making our new pearl the "head" pearl. In the same sense, when inserting the new Node at the beginning, it becomes the new "head" of the list, and we can just have the next node [for our new "head"] to point to the old "head" Node.) + +[for speaker]: <> (Upon further observation, we can see that the time complexity for this insert method is in fact constant O[1]: it always takes the same amount of time. It can only take one data point, create only one node, and doesn't need to interact with the other nodes in the linked list besides the "head" node.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/12.md b/Leetcode Workshops/Week 2/Act1_Linked list/12.md new file mode 100644 index 0000000..de82a49 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/12.md @@ -0,0 +1,18 @@ + +## Use `insert()` +```python +film.insert(930) +``` + + +- The data point '930' will be assigned to a new node's `self.data` value. + +- `set_next` function points the current node to the old "head" node. + +- `self.head` will take in our current Node as the new "head" node. +------------------------------------------------- + +[for speaker]: <> (When calling the `insert[]` function in the `main[]` code, it will look like this:) + +[for speaker]: <> (The data point '930' will be assigned to a new node's `self.data` value, while the `set_next` function points the current node to the old "head" node. Then, `self.head` will take in our current Node as the new "head" node. Now, the new "head" is the node with data 930 and this node points to the node with data 900.) + diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/13.md b/Leetcode Workshops/Week 2/Act1_Linked list/13.md new file mode 100644 index 0000000..0fb9bf9 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/13.md @@ -0,0 +1,15 @@ + +```python +film.insert(1000) +``` + + + +The node with '1000' will become our new "head" and it will points to the node with '930'. + +------------------------------------------------- + +[for speaker]: <> (The same will happen to the data entry of '1000' if we write the following line.) + + + diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/14.md b/Leetcode Workshops/Week 2/Act1_Linked list/14.md new file mode 100644 index 0000000..f0d3bdc --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/14.md @@ -0,0 +1,18 @@ +## `delete()` + +```python +def delete(self, data): + current = self.head + previous = None + found = False +``` +- Keep track of current node and previous node +- Time complexity: O(n) + +------------------------------------------------- + +[for speaker]: <> (If we want to remove an item from the list, we can then use the `delete[]` function.) + +[for speaker]: <> (The time complexity for `delete[]` is also O[n], because in the worst case it will visit every node, interacting with each node a fixed number of times.) + +[for speaker]: <> (The `delete[]` function for our linked list goes through the list, and keeps track of the current node, `current`, while also remembering the node it last visited, `previous`. ) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/15.md b/Leetcode Workshops/Week 2/Act1_Linked list/15.md new file mode 100644 index 0000000..fbae316 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/15.md @@ -0,0 +1,17 @@ +## `delete()` +```python + while current and found is False: + if current.get_data() == data: + found = True + else: + previous = current + current = current.get_next() +``` + +- Go through the list until it arrives to the node that it wants to delete. + +- When it find the node, it resets previous node's `next_node` to point at the node that the deleted node is pointing at. + +------------------------------------------------- + +[for speaker]: <> (In order to delete an element, the `delete[]` function goes through the list until it arrives to the node that it wants to delete. When it arrives, it takes a look at the previous node it visited and resets that node's `next_node` to point at the node that comes after the one to be deleted.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/16.md b/Leetcode Workshops/Week 2/Act1_Linked list/16.md new file mode 100644 index 0000000..5ca40cf --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/16.md @@ -0,0 +1,20 @@ +## `delete()` +```python + if current is None: + raise ValueError("Data not in list") + if previous is None: + self.head = current.get_next() + else: + previous.set_next(current.get_next()) + +``` +- If the data is not in the list +- If we are at the `head` node +- Delete current node by setting previous node's `next_node` points at current node's `next_node` + + +------------------------------------------------- + +[for speaker]: <> (Afterwards, we add several statements in the case that the data doesn't exist in the list, moving onto the next node if we're at the "head" node, and moving through the list node by node.) + +[for speaker]: <> (When the previous node's `next_node` points at the next node in line, then no nodes will point at the current node, meaning that the current node has now been deleted!) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/17.md b/Leetcode Workshops/Week 2/Act1_Linked list/17.md new file mode 100644 index 0000000..380cabe --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/17.md @@ -0,0 +1,18 @@ +## `delete()` in `main()` +```python +film.delete(930) +``` + + +| | Step 1 | step 2 | +| -------- | --------------------- | :-------------------- | +| current | node with data '1000' | node with data '930' | +| previous | None | node with data '1000' | +| found | False | True | + + +------------------------------------------------- + +[for speaker]: <> (In our `main[]` function later on, deleting a node from a linked list will look like this) + +[for speaker]: <> (We began looking for the node we want to delete from our head [the node with data '1000']. We found that it's not holding the data we were looking for. So, we go to the next node. At the same time we update the current node and previous node. In this example, we find data '930' in our second step. We set our pervious node points to the node that current node is pointing at. Thus, after deletion the node with '1000' now points at the node with '900' instead of the node with '930.') \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/18.md b/Leetcode Workshops/Week 2/Act1_Linked list/18.md new file mode 100644 index 0000000..039ec10 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/18.md @@ -0,0 +1,26 @@ + + +## `size()` + +```python +def size(self): + current = self.head + count = 0 + while current: + count += 1 + current = current.get_next() + return count +``` +- `size()` return the amount of nodes it found. +- Begin with the "head" node +- Go to the next node and increase the count +- Stop when `current` node becomes None +- The time complexity is O(n) + +------------------------------------------------- + +[for speaker]: <> (In order to find the size of a linked list, we can define our `size[]` function as being able to count nodes until it doesn't find any more, and return the amount of nodes it found.) + +[for speaker]: <> (The method begins with the "head" node and travels through the list using the `next_node` pointers to reach the next node until the `current` node becomes None. Once it reaches that point, it will return the number of nodes that it encountered along the way.) + +[for speaker]: <> (The time complexity of size is O[n] because each time the method is called it will always visit every node in the list but only interact with them once, so n * 1 operations.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/19.md b/Leetcode Workshops/Week 2/Act1_Linked list/19.md new file mode 100644 index 0000000..d1d9ba8 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/19.md @@ -0,0 +1,6 @@ + +## Call `size()` + +```python +print(film.size()) +``` \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/2.md b/Leetcode Workshops/Week 2/Act1_Linked list/2.md new file mode 100644 index 0000000..e0d4a27 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/2.md @@ -0,0 +1,8 @@ + +## Node in Linked List +- The "head" node is the very first node in the list. +- Each node contains two things: some data associated with the node, and a reference to the next node in the list. + +------------------------------------------------- + +[for speaker]: <> (To put it in the simplest terms, one can think of a linked list like a string of pearls. Each pearl in the string leads to the next. The first pearl on the string can be called the "head" pearl. In a linked list, the "head" node, as can be assumed, is the very first node in the list. Each node contains two things: some data associated with the node, and a reference to the next node in the list.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/20.md b/Leetcode Workshops/Week 2/Act1_Linked list/20.md new file mode 100644 index 0000000..b0d3a79 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/20.md @@ -0,0 +1,11 @@ + + +## Visual of `size()` + +![
] + +`size()` should return a size of 4 nodes. + +------------------------------------------------- + +[for speaker]: <> (To further implement a linked list, we'll see that the `search[]` function is actually very similar to `size[]`.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/21.md b/Leetcode Workshops/Week 2/Act1_Linked list/21.md new file mode 100644 index 0000000..552b733 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/21.md @@ -0,0 +1,14 @@ + + +## `search()` +```python +def search(self, data): + current = self.head + found = False +``` +- `search()`: find a certain node in our linked list +- Start from the head node +- Initalize found as False +------------------------------------------------- + +[for speaker]: <> (Now, if we want to find a certain node in our linked list, we can use a search method!) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/22.md b/Leetcode Workshops/Week 2/Act1_Linked list/22.md new file mode 100644 index 0000000..43334b3 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/22.md @@ -0,0 +1,16 @@ + +## `search()` +```python + while current and found is False: + if current.get_data() == data: + found = True + else: + current = current.get_next() +``` +- If the data matches the data it's looking for return the node. +- If not, continue to the next node. + +------------------------------------------------- + +[for speaker]: <> (At each node, the `search[]` function will check to see if the data matches the data it's looking for. If so, then it will return the node that holds the requested data. If not, then it will just continue to go to the next node.) + diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/23.md b/Leetcode Workshops/Week 2/Act1_Linked list/23.md new file mode 100644 index 0000000..9a5f93b --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/23.md @@ -0,0 +1,14 @@ +## `search()` +```python + if current is None: + raise ValueError("Data not in list") + return current +``` +- If data is not in the list +- Time complexity is O(N) + +------------------------------------------------- + +[for speaker]: <> (Should the function not find the data at all, it will return an error notifying the user that the data is not in the list. Note: If the function goes through the entire list without finding the data, that is also our worst-case scenario, meaning our worst-case time complexity is O[N].) + +[for speaker]: <> (Now, if we want to find a certain node in our linked list, we can use a search method!) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/24.md b/Leetcode Workshops/Week 2/Act1_Linked list/24.md new file mode 100644 index 0000000..ee9fcd6 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/24.md @@ -0,0 +1,4 @@ +## Call `search()` +```python +print(film.search(1000)) +``` \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/25.md b/Leetcode Workshops/Week 2/Act1_Linked list/25.md new file mode 100644 index 0000000..b4ba288 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/25.md @@ -0,0 +1,11 @@ + +## Visual of search() + +![
] + + +------------------------------------------------- + +[for speaker]: <> (This is a visual representation of searching for an element in a linked list.) + +[for speaker]: <> (Now that we've covered how to implement and create the different functions and attributes of a linked list, we can put everything together!) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/26.md b/Leetcode Workshops/Week 2/Act1_Linked list/26.md new file mode 100644 index 0000000..a24ea27 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/26.md @@ -0,0 +1,5 @@ +## Let's creat a linked list for a film production company + +------------------------------------------------- + +[for speaker]: <> (Now that we have our Linked List implementation, we can put it to work! Assume we work at a film production company and we're holding auditions! The auditions begin at 9:00 in the morning.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/27.md b/Leetcode Workshops/Week 2/Act1_Linked list/27.md new file mode 100644 index 0000000..16f1a1c --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/27.md @@ -0,0 +1,7 @@ +## Step 1 +```python +film = LinkedList() +film.head = Node(900) +``` + +> Remember that the first node of the Linked List when initialized will be the head node. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/28.md b/Leetcode Workshops/Week 2/Act1_Linked list/28.md new file mode 100644 index 0000000..e91d377 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/28.md @@ -0,0 +1,8 @@ +- let's build onto our Linked List for the duration of our film audition appointments. + +- Each succeeding node will represent another scheduled audition, each 30 minutes apart. + + +------------------------------------------------- + +[for speaker]: <> (Now that we have intialized our Linked List with a head node, we will continue to build onto our Linked List for the duration of our film audition appointments.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/29.md b/Leetcode Workshops/Week 2/Act1_Linked list/29.md new file mode 100644 index 0000000..bccf4aa --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/29.md @@ -0,0 +1,17 @@ +## Step2: +### One way: creating a new node and setting it as the next node following the previous node + +```python +node1 = Node(930) +node2 = Node(1000) +film.head.set_next(node1) +node1.set_next(node2) +``` + +> Note: *node1* and *node2* are new nodes that represent two more scheduled auditions for our Linked List *film* that follow the head node. + + +------------------------------------------------- + +[for speaker]: <> (Since the first node in our Linked List is the head, we then call `film.head.set_next[node1]` in order to assign `node1` as the next node following the head. + Now that `node1` is the tail of our Linked List `film`, we next call `node1.set_next[node2]` in order to assign `node2` as the next node following the tail, `node1`.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/3.md b/Leetcode Workshops/Week 2/Act1_Linked list/3.md new file mode 100644 index 0000000..d965fdd --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/3.md @@ -0,0 +1,7 @@ +- Singly linked list: one single reference to the next node +- A doubly linked list: two references, one for the next node, and one for the previous node. +- The last node points to a "null" node + +------------------------------------------------- + +[for speaker]: <> (In a singly linked list, each node [or pearl] has one single reference to the next node [or pearl]s in the list. A doubly linked list instead has two references, one for the next node, and one for the previous node. The last node in all linked lists points to a "null" node, signfying the end of the list.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/30.md b/Leetcode Workshops/Week 2/Act1_Linked list/30.md new file mode 100644 index 0000000..71bf8d9 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/30.md @@ -0,0 +1,16 @@ + +## Step2: +### Another way: add a new node to our *film* Linked List is by using the *insert()* function. + +Assume we got extra appointments for auditions up until lunchtime. + +```python +film.insert(1030) +film.insert(1100) +film.insert(1130) +film.insert(1200) +film.insert(1230) +``` +------------------------------------------------- + +[for speaker]: <> ( Note: the `insert[]` function defined in the *LinkedList* class is capable of creating a new node with the designated data you pass and will assign it as the next node in your Linked List [only will append node to the END, or tail].) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/31.md b/Leetcode Workshops/Week 2/Act1_Linked list/31.md new file mode 100644 index 0000000..6725dc4 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/31.md @@ -0,0 +1,8 @@ + +## Use `size()` to verify the number of nodes +```python +print(film.size()) +``` +------------------------------------------------- + +[for speaker]: <> (Now we should have a Linked List that contains a total of 8 nodes that represent 8 appointments for auditions in succession. We can verify the number of nodes by using the size[] function) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/32.md b/Leetcode Workshops/Week 2/Act1_Linked list/32.md new file mode 100644 index 0000000..e7e6869 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/32.md @@ -0,0 +1,3 @@ + + +### someone canceled their audition for 10:00 AM. Afterwards, a different person cancels their 12:30 PM appointment. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/33.md b/Leetcode Workshops/Week 2/Act1_Linked list/33.md new file mode 100644 index 0000000..35202db --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/33.md @@ -0,0 +1,13 @@ +## Use `delete()` + +```python +film.delete(1000) +film.delete(1230) +``` + +- The *film* Linked List will retain its order of nodes after deletion of the specified nodes. + +------------------------------------------------- + +[for speaker]: <> (To make sure their appointments are no longer in the system, we can use the `delete[]` function defined in the *LinkedList* class:) + diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/34.md b/Leetcode Workshops/Week 2/Act1_Linked list/34.md new file mode 100644 index 0000000..e1b7b79 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/34.md @@ -0,0 +1,17 @@ +## Check whether we removed the cancelled appointments + +```python +print(film.search(1000)) +print(film.search(1230)) +``` +- Use `search()` +- If removed, it will return data not found +- We can also use `size()` to double check +------------------------------------------------- + +[for speaker]: <> (To confirm that we have removed the canceled appointments, we will check that the corresponding nodes were deleted from our Linked List by searching for them) + +[for speaker]: <> (Note: The first `search[]` function looking for the data point of 10:00 should return an error stating the data was not found [since the node has been deleted]. The same should happen for the 12:30 node.) + +[for speaker]: <> (To double check, we can also check again using the *size()* function to identify that `film` now only contains 6 nodes in this order: 9:00, 9:30, 10:30, 11:00, 11:30, 12:00.) + diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/35.md b/Leetcode Workshops/Week 2/Act1_Linked list/35.md new file mode 100644 index 0000000..e1ddea0 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/35.md @@ -0,0 +1,11 @@ +## Search for an existing appointment + + +```python +print(film.search(930)) +``` + +- The output produced will show the address in memory where the node is stored in our Linked List *film*. + +------------------------------------------------- +[for speaker]: <> (If we were to search for an existing appointment, we can do so in similar fashion) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/36.md b/Leetcode Workshops/Week 2/Act1_Linked list/36.md new file mode 100644 index 0000000..e309d8b --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/36.md @@ -0,0 +1,9 @@ + +## Get the data in the node +```python +print(film.search(930).get_data()) +``` +- This outputs the data at the particular node we searched for, not the address of the node + +------------------------------------------------- +[for speaker]: <> (In the case where we want to access the data in the node associated with 9:30 in `film`) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/4.md b/Leetcode Workshops/Week 2/Act1_Linked list/4.md new file mode 100644 index 0000000..99e1a01 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/4.md @@ -0,0 +1,16 @@ + +## Advantages and Disadvantages of Linked list +### Advantages +- dynamic memory allocation +### Disadvantages +- Use more space +- In order to access the item in the middle, you have to start from the head node +- Some insertion cost more space + +------------------------------------------------- + +[for speaker]: <> (Many benefits come with using a linked list instead of any other similar data structure [like a static array]. This includes dynamic memory allocation--if one doesn't know the amount of data they want to store during initialization, a linked list can help with quickly adjusting the size of the list.) + +[for speaker]: <> (However, there are also several disadvantages to using a linked list. More space is used when dyanmically allocating memory [mostly for the reference to the next node], and if you want to access an item in the middle, you have to start at the "head" node and follow the references until reaching the item wanted.) + +[for speaker]: <> (In practice, some insertions cost more. If the list initially allocates enough space for six nodes, inserting a seventh means the list has to double its space [up to 12].) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/5.md b/Leetcode Workshops/Week 2/Act1_Linked list/5.md new file mode 100644 index 0000000..cc85813 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/5.md @@ -0,0 +1,3 @@ +## Linked list visual + +![
] \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/6.md b/Leetcode Workshops/Week 2/Act1_Linked list/6.md new file mode 100644 index 0000000..1840534 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/6.md @@ -0,0 +1,7 @@ +## Implementation of a linked list + +- Node class: implementing the idea of a Node and its attributes +- Insert: inserts a new node into the list +- Size: returns size of list +- Search: searches list for a node containing the requested data and returns that node if found, otherwise raises an error +- Delete: searches list for a node containing the requested data and removes it from list if found, otherwise raises an error \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/7.md b/Leetcode Workshops/Week 2/Act1_Linked list/7.md new file mode 100644 index 0000000..a2682fd --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/7.md @@ -0,0 +1,12 @@ +## class LinkedList +```python +class LinkedList(object): + def __init__(self, head=None): + self.head = head +``` +- The "head" node is set to None + +------------------------------------------------- + +[for speaker]: <> (Now, we can create the start of our linked list! Luckily, the linked list (as a class) itself is actually the "head" node of the list!) +[for speaker]: <> (Note: Upon initialization, a list has no nodes, so the "head" node is set to None. Because a linked list doesn't necessarily need a node to initialized, the "head" node will, by default, set itself to None.) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/8.MD b/Leetcode Workshops/Week 2/Act1_Linked list/8.MD new file mode 100644 index 0000000..2d0ed81 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/8.MD @@ -0,0 +1,25 @@ + +## Implement the `Node` class + +```python +class Node(object): + def __init__(self, data): + self.data = data + self.next_node = None +``` +- Node is where data is stored in the linked list. + +- Each node also holds a **pointer** which is a reference to the next node in the list. + +------------------------------------------------- + +[for speaker]: <> (Now we can implement the most important attribute of a linked list: the node!) + +[for speaker]: <> (It's a simple implementation of a `Node` class [a representation of the `Node` objects in a linked list].) + +[for speaker]: <> (The node is where data is stored in the linked list; if a pearl was hollow and contained a bead inside, the bead would be the data. Along with the data, each node also holds a pointer which is a reference to the next node in the list. Note: if it was a doubly linked list, the reference to the previous node would be a pointer too.) + +[for speaker]: <> (The node's data is initialized with data received at creation, and its pointer is set to None by default since the first node to be inserted into the will wouldn't have any other node to point to.) + +[for speaker]: <> (Each `Node` object contains data that can be retrieved via the `get_data` function and can get or set the next node via the functions `get_next` and `set_next` respectively.) + diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/9.md b/Leetcode Workshops/Week 2/Act1_Linked list/9.md new file mode 100644 index 0000000..d45762d --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/9.md @@ -0,0 +1,23 @@ + + + +## Implement functions +```python + def get_data(self): + return self.data + + def get_next(self): + return self.next_node + + def set_next(self, new_next): + self.next_node = new_next +``` +- The function `get_data` will return whatever data is stored in the current `Node` object. +- The function `get_next` will return the location of the node that comes next. +- The function `set_next` will reset the next node to a new node. + +**Note: `next_node` is a pointer to another `Node` object! It's not its own node!** + +------------------------------------------------- + +[for speaker]: <> (After implementing the class `Node`, then we can begin to implement functions to help with retrieving information about the specified `Node` object.) From a0c6b09f524799bf910367fb415a2659fbe18802 Mon Sep 17 00:00:00 2001 From: Ruby <56561364+Dadao-xiaoguaishou@users.noreply.github.com> Date: Sat, 22 Feb 2020 16:00:30 -0800 Subject: [PATCH 12/24] Rename 8.MD to 8.md --- Leetcode Workshops/Week 2/Act1_Linked list/{8.MD => 8.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Leetcode Workshops/Week 2/Act1_Linked list/{8.MD => 8.md} (100%) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/8.MD b/Leetcode Workshops/Week 2/Act1_Linked list/8.md similarity index 100% rename from Leetcode Workshops/Week 2/Act1_Linked list/8.MD rename to Leetcode Workshops/Week 2/Act1_Linked list/8.md From 3c46e5c478bce73161eeae1c4749ad6aa33ebb0e Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Sat, 22 Feb 2020 16:57:55 -0800 Subject: [PATCH 13/24] add the type and title for Linked list 1-36.md --- Leetcode Workshops/Week 2/Act1_Linked list/1.md | 4 +++- Leetcode Workshops/Week 2/Act1_Linked list/10.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/11.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/12.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/13.md | 4 +++- Leetcode Workshops/Week 2/Act1_Linked list/14.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/15.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/16.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/17.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/18.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/19.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/2.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/20.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/21.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/22.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/23.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/24.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/25.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/26.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/27.md | 4 +++- Leetcode Workshops/Week 2/Act1_Linked list/28.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/29.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/3.md | 3 +++ Leetcode Workshops/Week 2/Act1_Linked list/30.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/31.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/32.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/33.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/34.md | 4 +++- Leetcode Workshops/Week 2/Act1_Linked list/35.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/36.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/4.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/5.md | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/6.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/7.md | 4 +++- Leetcode Workshops/Week 2/Act1_Linked list/8.MD | 3 ++- Leetcode Workshops/Week 2/Act1_Linked list/9.md | 5 ++--- 36 files changed, 80 insertions(+), 26 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/1.md b/Leetcode Workshops/Week 2/Act1_Linked list/1.md index 2567003..753c7a0 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/1.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/1.md @@ -1 +1,3 @@ -# Linked Lists \ No newline at end of file + + +# Linked List \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/10.md b/Leetcode Workshops/Week 2/Act1_Linked list/10.md index bfc1fcd..67acdd6 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/10.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/10.md @@ -1,3 +1,5 @@ + + ## Now let's create our linked list and a node for it ```python diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/11.md b/Leetcode Workshops/Week 2/Act1_Linked list/11.md index 2dd66de..e7d58ca 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/11.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/11.md @@ -1,4 +1,5 @@ - + + ## `insert()` ```python def insert(self, data): diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/12.md b/Leetcode Workshops/Week 2/Act1_Linked list/12.md index de82a49..e69ad33 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/12.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/12.md @@ -1,4 +1,5 @@ - + + ## Use `insert()` ```python film.insert(930) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/13.md b/Leetcode Workshops/Week 2/Act1_Linked list/13.md index 0fb9bf9..d42d54e 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/13.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/13.md @@ -1,4 +1,6 @@ - + + +## `insert()` ```python film.insert(1000) ``` diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/14.md b/Leetcode Workshops/Week 2/Act1_Linked list/14.md index f0d3bdc..c53c46e 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/14.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/14.md @@ -1,3 +1,5 @@ + + ## `delete()` ```python diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/15.md b/Leetcode Workshops/Week 2/Act1_Linked list/15.md index fbae316..05e92f1 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/15.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/15.md @@ -1,3 +1,5 @@ + + ## `delete()` ```python while current and found is False: diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/16.md b/Leetcode Workshops/Week 2/Act1_Linked list/16.md index 5ca40cf..b5d1eee 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/16.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/16.md @@ -1,3 +1,5 @@ + + ## `delete()` ```python if current is None: diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/17.md b/Leetcode Workshops/Week 2/Act1_Linked list/17.md index 380cabe..d50a5d5 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/17.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/17.md @@ -1,3 +1,5 @@ + + ## `delete()` in `main()` ```python film.delete(930) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/18.md b/Leetcode Workshops/Week 2/Act1_Linked list/18.md index 039ec10..c8b42b3 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/18.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/18.md @@ -1,4 +1,5 @@ - + + ## `size()` diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/19.md b/Leetcode Workshops/Week 2/Act1_Linked list/19.md index d1d9ba8..1c8c3df 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/19.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/19.md @@ -1,4 +1,5 @@ - + + ## Call `size()` ```python diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/2.md b/Leetcode Workshops/Week 2/Act1_Linked list/2.md index e0d4a27..ac29d5b 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/2.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/2.md @@ -1,4 +1,5 @@ - + + ## Node in Linked List - The "head" node is the very first node in the list. - Each node contains two things: some data associated with the node, and a reference to the next node in the list. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/20.md b/Leetcode Workshops/Week 2/Act1_Linked list/20.md index b0d3a79..7f6540d 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/20.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/20.md @@ -1,4 +1,5 @@ - + + ## Visual of `size()` diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/21.md b/Leetcode Workshops/Week 2/Act1_Linked list/21.md index 552b733..7160da3 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/21.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/21.md @@ -1,4 +1,5 @@ - + + ## `search()` ```python diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/22.md b/Leetcode Workshops/Week 2/Act1_Linked list/22.md index 43334b3..08bcef4 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/22.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/22.md @@ -1,4 +1,5 @@ - + + ## `search()` ```python while current and found is False: diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/23.md b/Leetcode Workshops/Week 2/Act1_Linked list/23.md index 9a5f93b..cc03127 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/23.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/23.md @@ -1,3 +1,5 @@ + + ## `search()` ```python if current is None: diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/24.md b/Leetcode Workshops/Week 2/Act1_Linked list/24.md index ee9fcd6..7732316 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/24.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/24.md @@ -1,3 +1,5 @@ + + ## Call `search()` ```python print(film.search(1000)) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/25.md b/Leetcode Workshops/Week 2/Act1_Linked list/25.md index b4ba288..b6f4967 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/25.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/25.md @@ -1,4 +1,5 @@ - + + ## Visual of search() ![
] diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/26.md b/Leetcode Workshops/Week 2/Act1_Linked list/26.md index a24ea27..5247aea 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/26.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/26.md @@ -1,3 +1,5 @@ + + ## Let's creat a linked list for a film production company ------------------------------------------------- diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/27.md b/Leetcode Workshops/Week 2/Act1_Linked list/27.md index 16f1a1c..025c2a2 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/27.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/27.md @@ -1,4 +1,6 @@ -## Step 1 + + +## Step 1: Create the class and the first node ```python film = LinkedList() film.head = Node(900) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/28.md b/Leetcode Workshops/Week 2/Act1_Linked list/28.md index e91d377..f391916 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/28.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/28.md @@ -1,3 +1,5 @@ + + - let's build onto our Linked List for the duration of our film audition appointments. - Each succeeding node will represent another scheduled audition, each 30 minutes apart. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/29.md b/Leetcode Workshops/Week 2/Act1_Linked list/29.md index bccf4aa..3c4cfa9 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/29.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/29.md @@ -1,3 +1,5 @@ + + ## Step2: ### One way: creating a new node and setting it as the next node following the previous node diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/3.md b/Leetcode Workshops/Week 2/Act1_Linked list/3.md index d965fdd..5bf5f31 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/3.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/3.md @@ -1,3 +1,6 @@ + + +## Reference - Singly linked list: one single reference to the next node - A doubly linked list: two references, one for the next node, and one for the previous node. - The last node points to a "null" node diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/30.md b/Leetcode Workshops/Week 2/Act1_Linked list/30.md index 71bf8d9..2a2e790 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/30.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/30.md @@ -1,4 +1,5 @@ - + + ## Step2: ### Another way: add a new node to our *film* Linked List is by using the *insert()* function. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/31.md b/Leetcode Workshops/Week 2/Act1_Linked list/31.md index 6725dc4..21e806e 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/31.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/31.md @@ -1,4 +1,5 @@ - + + ## Use `size()` to verify the number of nodes ```python print(film.size()) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/32.md b/Leetcode Workshops/Week 2/Act1_Linked list/32.md index e7e6869..051a6a0 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/32.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/32.md @@ -1,3 +1,4 @@ + + - -### someone canceled their audition for 10:00 AM. Afterwards, a different person cancels their 12:30 PM appointment. \ No newline at end of file +### Someone canceled their audition for 10:00 AM. Afterwards, a different person cancels their 12:30 PM appointment. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/33.md b/Leetcode Workshops/Week 2/Act1_Linked list/33.md index 35202db..c047605 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/33.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/33.md @@ -1,3 +1,5 @@ + + ## Use `delete()` ```python diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/34.md b/Leetcode Workshops/Week 2/Act1_Linked list/34.md index e1b7b79..856f466 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/34.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/34.md @@ -1,3 +1,5 @@ + + ## Check whether we removed the cancelled appointments ```python @@ -13,5 +15,5 @@ print(film.search(1230)) [for speaker]: <> (Note: The first `search[]` function looking for the data point of 10:00 should return an error stating the data was not found [since the node has been deleted]. The same should happen for the 12:30 node.) -[for speaker]: <> (To double check, we can also check again using the *size()* function to identify that `film` now only contains 6 nodes in this order: 9:00, 9:30, 10:30, 11:00, 11:30, 12:00.) +[for speaker]: <> (To double check, we can also check again using the size[] function to identify that `film` now only contains 6 nodes in this order: 9:00, 9:30, 10:30, 11:00, 11:30, 12:00.) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/35.md b/Leetcode Workshops/Week 2/Act1_Linked list/35.md index e1ddea0..8e655dd 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/35.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/35.md @@ -1,3 +1,5 @@ + + ## Search for an existing appointment diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/36.md b/Leetcode Workshops/Week 2/Act1_Linked list/36.md index e309d8b..331343a 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/36.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/36.md @@ -1,4 +1,5 @@ - + + ## Get the data in the node ```python print(film.search(930).get_data()) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/4.md b/Leetcode Workshops/Week 2/Act1_Linked list/4.md index 99e1a01..7c8d078 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/4.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/4.md @@ -1,7 +1,8 @@ - + + ## Advantages and Disadvantages of Linked list ### Advantages -- dynamic memory allocation +- Dynamic memory allocation ### Disadvantages - Use more space - In order to access the item in the middle, you have to start from the head node diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/5.md b/Leetcode Workshops/Week 2/Act1_Linked list/5.md index cc85813..90547db 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/5.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/5.md @@ -1,3 +1,4 @@ + + ## Linked list visual - ![
] \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/6.md b/Leetcode Workshops/Week 2/Act1_Linked list/6.md index 1840534..f941d10 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/6.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/6.md @@ -1,3 +1,5 @@ + + ## Implementation of a linked list - Node class: implementing the idea of a Node and its attributes diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/7.md b/Leetcode Workshops/Week 2/Act1_Linked list/7.md index a2682fd..15605e9 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/7.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/7.md @@ -1,4 +1,6 @@ -## class LinkedList + + +## class `LinkedList` ```python class LinkedList(object): def __init__(self, head=None): diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/8.MD b/Leetcode Workshops/Week 2/Act1_Linked list/8.MD index 2d0ed81..df08007 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/8.MD +++ b/Leetcode Workshops/Week 2/Act1_Linked list/8.MD @@ -1,4 +1,5 @@ - + + ## Implement the `Node` class ```python diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/9.md b/Leetcode Workshops/Week 2/Act1_Linked list/9.md index d45762d..bf443de 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/9.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/9.md @@ -1,6 +1,5 @@ - - - + + ## Implement functions ```python def get_data(self): From 3d540ea75ef28919d7181266a49b7b9dd87b6190 Mon Sep 17 00:00:00 2001 From: Ruby <56561364+Dadao-xiaoguaishou@users.noreply.github.com> Date: Sat, 22 Feb 2020 17:06:50 -0800 Subject: [PATCH 14/24] Create README.md --- Leetcode Workshops/Week 2/Act1_Linked list/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Leetcode Workshops/Week 2/Act1_Linked list/README.md diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/README.md b/Leetcode Workshops/Week 2/Act1_Linked list/README.md new file mode 100644 index 0000000..d63b49c --- /dev/null +++ b/Leetcode Workshops/Week 2/Act1_Linked list/README.md @@ -0,0 +1,12 @@ +Linked list +- 1.md -> slides 1-7 +- 2.md -> slides 8-10 +- 3.md -> slides 11-13 +- 4.md -> slides 14-17 +- 5.md -> slides 18-20 +- 6.md -> slides 21-25 +- 7.md -> slides 26-36 + +In original card: +- 2.md Please fix " Now to create actually create our linked list and a node for it..." +- 6.md Please move "while current and found is False:" to the second block of code From 9483a511ee151b0be23d05a01e9630b93703c3ac Mon Sep 17 00:00:00 2001 From: Ruby <56561364+Dadao-xiaoguaishou@users.noreply.github.com> Date: Sat, 22 Feb 2020 17:07:35 -0800 Subject: [PATCH 15/24] Update README.md --- Leetcode Workshops/Week 2/Act1_Linked list/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/README.md b/Leetcode Workshops/Week 2/Act1_Linked list/README.md index d63b49c..a53881e 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/README.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/README.md @@ -9,4 +9,4 @@ Linked list In original card: - 2.md Please fix " Now to create actually create our linked list and a node for it..." -- 6.md Please move "while current and found is False:" to the second block of code +- 6.md Please move "`while current and found is False:`" to the second block of code From 5799a42375359a2e21df36909cae6f5db062b6bc Mon Sep 17 00:00:00 2001 From: Ruby <56561364+Dadao-xiaoguaishou@users.noreply.github.com> Date: Sun, 23 Feb 2020 08:45:59 -0800 Subject: [PATCH 16/24] Update README.md --- Leetcode Workshops/Week 2/Act2_Trees/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/README.md b/Leetcode Workshops/Week 2/Act2_Trees/README.md index 5ebca88..aa95776 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/README.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/README.md @@ -8,7 +8,11 @@ Trees - 7.md -> slides 23-30 - 8.md -> slides 31-39 - In 7.md please fix the insert_child (the name are now all lowercase) +In 5.md please + - add explanation for BST delete() 2 child case + - explain what's in-order predecessor before using it + +In 7.md please fix the insert_child (the name are now all lowercase) Please fix 8.md - - break up code, add explanation, introduce in order traversal before use it, explain what will print out + - break up code, add explanation, introduce in order traversal before using it, explain what will print out From af7fc7f38e3236efa2f56dd2fba82c4eebd0158a Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Sun, 23 Feb 2020 14:22:51 -0800 Subject: [PATCH 17/24] Add visuals The visuals are from later examples, still need custom visual for linked list 3.md --- Leetcode Workshops/Week 2/Act1_Linked list/2.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/28.md | 2 +- Leetcode Workshops/Week 2/Act1_Linked list/3.md | 2 ++ Leetcode Workshops/Week 2/Act1_Linked list/6.md | 2 ++ Leetcode Workshops/Week 2/Act2_Trees/17.md | 4 +++- Leetcode Workshops/Week 2/Act2_Trees/2.md | 2 +- Leetcode Workshops/Week 2/Act2_Trees/3.md | 3 ++- Leetcode Workshops/Week 2/Act2_Trees/7.md | 4 +++- 8 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/2.md b/Leetcode Workshops/Week 2/Act1_Linked list/2.md index ac29d5b..f058a2a 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/2.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/2.md @@ -1,6 +1,8 @@ ## Node in Linked List + + - The "head" node is the very first node in the list. - Each node contains two things: some data associated with the node, and a reference to the next node in the list. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/28.md b/Leetcode Workshops/Week 2/Act1_Linked list/28.md index f391916..97b1f13 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/28.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/28.md @@ -1,6 +1,6 @@ -- let's build onto our Linked List for the duration of our film audition appointments. +- Let's build onto our Linked List for the duration of our film audition appointments. - Each succeeding node will represent another scheduled audition, each 30 minutes apart. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/3.md b/Leetcode Workshops/Week 2/Act1_Linked list/3.md index 5bf5f31..5bd84e9 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/3.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/3.md @@ -1,6 +1,8 @@ ## Reference + + - Singly linked list: one single reference to the next node - A doubly linked list: two references, one for the next node, and one for the previous node. - The last node points to a "null" node diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/6.md b/Leetcode Workshops/Week 2/Act1_Linked list/6.md index f941d10..17ed25b 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/6.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/6.md @@ -2,6 +2,8 @@ ## Implementation of a linked list + + - Node class: implementing the idea of a Node and its attributes - Insert: inserts a new node into the list - Size: returns size of list diff --git a/Leetcode Workshops/Week 2/Act2_Trees/17.md b/Leetcode Workshops/Week 2/Act2_Trees/17.md index 065887e..cece563 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/17.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/17.md @@ -1,6 +1,8 @@ - + + + ## Deleting a BST Node: * **Two Children Case**: The case when you want to delete a node with two children. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/2.md b/Leetcode Workshops/Week 2/Act2_Trees/2.md index b502913..1eb7cd3 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/2.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/2.md @@ -1,7 +1,7 @@ - + ## Tree Terminology: diff --git a/Leetcode Workshops/Week 2/Act2_Trees/3.md b/Leetcode Workshops/Week 2/Act2_Trees/3.md index e792a0a..2e7ccb2 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/3.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/3.md @@ -1,7 +1,8 @@ - + + ## Nodes * **Root Node**: The node with highest hierarchical precedence. Each tree can only have one root node. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/7.md b/Leetcode Workshops/Week 2/Act2_Trees/7.md index 37b834c..0846bce 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/7.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/7.md @@ -1,5 +1,7 @@ - + + + ## Binary Trees: A **Binary Tree** is a tree where every single node can only have zero, one, or two children. From cd810279ea11c78aef5dc0763b19b687d6523b0f Mon Sep 17 00:00:00 2001 From: Ruby <56561364+Dadao-xiaoguaishou@users.noreply.github.com> Date: Sun, 23 Feb 2020 19:21:28 -0800 Subject: [PATCH 18/24] Update README.md --- Leetcode Workshops/Week 2/Act2_Trees/README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/README.md b/Leetcode Workshops/Week 2/Act2_Trees/README.md index aa95776..c441133 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/README.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/README.md @@ -8,11 +8,3 @@ Trees - 7.md -> slides 23-30 - 8.md -> slides 31-39 -In 5.md please - - add explanation for BST delete() 2 child case - - explain what's in-order predecessor before using it - -In 7.md please fix the insert_child (the name are now all lowercase) - -Please fix 8.md - - break up code, add explanation, introduce in order traversal before using it, explain what will print out From 33469fec3d35b667732d0a8fce7df0cb3865b415 Mon Sep 17 00:00:00 2001 From: Ruby <56561364+Dadao-xiaoguaishou@users.noreply.github.com> Date: Sun, 23 Feb 2020 19:22:02 -0800 Subject: [PATCH 19/24] Update README.md --- Leetcode Workshops/Week 2/Act1_Linked list/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/README.md b/Leetcode Workshops/Week 2/Act1_Linked list/README.md index a53881e..b8bbf4b 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/README.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/README.md @@ -6,7 +6,3 @@ Linked list - 5.md -> slides 18-20 - 6.md -> slides 21-25 - 7.md -> slides 26-36 - -In original card: -- 2.md Please fix " Now to create actually create our linked list and a node for it..." -- 6.md Please move "`while current and found is False:`" to the second block of code From 6047ecea37b3c85d1710f1beffe9bd0c061c700d Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Wed, 26 Feb 2020 10:09:32 -0800 Subject: [PATCH 20/24] 4.2.2 Make comments visible --- Leetcode Workshops/Week 2/Act2_Trees/1.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/10.md | 16 +++++++++------- Leetcode Workshops/Week 2/Act2_Trees/11.md | 8 +++++--- Leetcode Workshops/Week 2/Act2_Trees/12.md | 12 +++++++----- Leetcode Workshops/Week 2/Act2_Trees/13.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/14.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/15.md | 9 +++++---- Leetcode Workshops/Week 2/Act2_Trees/16.md | 9 +++++---- Leetcode Workshops/Week 2/Act2_Trees/17.md | 10 ++++++---- Leetcode Workshops/Week 2/Act2_Trees/18.md | 9 +++++---- Leetcode Workshops/Week 2/Act2_Trees/19.md | 9 +++++---- Leetcode Workshops/Week 2/Act2_Trees/2.md | 5 +++-- Leetcode Workshops/Week 2/Act2_Trees/20.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/21.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/22.md | 9 +++++---- Leetcode Workshops/Week 2/Act2_Trees/23.md | 9 +++++---- Leetcode Workshops/Week 2/Act2_Trees/24.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/25.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/26.md | 9 +++++---- Leetcode Workshops/Week 2/Act2_Trees/27.md | 9 +++++---- Leetcode Workshops/Week 2/Act2_Trees/28.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/29.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/3.md | 5 +++-- Leetcode Workshops/Week 2/Act2_Trees/30.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/31.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/32.md | 5 +++-- Leetcode Workshops/Week 2/Act2_Trees/33.md | 11 ++++++----- Leetcode Workshops/Week 2/Act2_Trees/34.md | 5 +++-- Leetcode Workshops/Week 2/Act2_Trees/35.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/36.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/37.md | 5 +++-- Leetcode Workshops/Week 2/Act2_Trees/38.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/39.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/4.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/5.md | 7 ++++--- Leetcode Workshops/Week 2/Act2_Trees/6.md | 11 ++++++----- Leetcode Workshops/Week 2/Act2_Trees/7.md | 8 +++++--- Leetcode Workshops/Week 2/Act2_Trees/8.md | 14 ++++++++------ Leetcode Workshops/Week 2/Act2_Trees/9.md | 8 +++++--- 39 files changed, 180 insertions(+), 134 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act2_Trees/1.md b/Leetcode Workshops/Week 2/Act2_Trees/1.md index 1ce946c..de6c53e 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/1.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/1.md @@ -1,9 +1,10 @@ - - +_**type:Title slide**_ + +_**title:Trees**_ # Trees ------------------------------------------------- -[for speaker]: <> (Today we are going to learn about tree data structures. In order to do so, it is important that we understand the essential terminology) +[for speaker]: <> Today we are going to learn about tree data structures. In order to do so, it is important that we understand the essential terminology diff --git a/Leetcode Workshops/Week 2/Act2_Trees/10.md b/Leetcode Workshops/Week 2/Act2_Trees/10.md index 87f13ae..db114f9 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/10.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/10.md @@ -1,5 +1,6 @@ - - +_**type:code left**_ + +_**title:BSTSearch**_ ## BST Search: ```Python @@ -22,11 +23,12 @@ def BSTSearch(curNode, key): ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (Now that we understand the basic structure of a Binary Search Tree, let's start to build up some useful functions that will allow us to access and manipulate our trees.) -[for speaker]: <> (If you know the key to a specific node in a BST and want to access it within your BST, how would you do this? Let's build a function called `BSTSearch` that will allow us to do this.) +[for speaker]: <> Now that we understand the basic structure of a Binary Search Tree, let's start to build up some useful functions that will allow us to access and manipulate our trees. + +[for speaker]: <> If you know the key to a specific node in a BST and want to access it within your BST, how would you do this? Let's build a function called `BSTSearch` that will allow us to do this. -[for speaker]: <> (The `BSTSearch` function behaves similarly to how you would if you were looking for a specific key in a BST: go right if you're looking for a larger key or go left if you're looking for a smaller key.) +[for speaker]: <> The `BSTSearch` function behaves similarly to how you would if you were looking for a specific key in a BST: go right if you're looking for a larger key or go left if you're looking for a smaller key. -[for speaker]: <> (It starts at the root and calls the same function again on its right child if the desired key is greater than the current node's key or calls the same function again on its left child if the desired key is less than the current node's key.) +[for speaker]: <> It starts at the root and calls the same function again on its right child if the desired key is greater than the current node's key or calls the same function again on its left child if the desired key is less than the current node's key. -[for speaker]: <> (It eventually returns the current node being inspected if the node's key matches the desired key or returns null if it doesn't find a node with a desired key. Make sure you understand the code above before moving forward.) \ No newline at end of file +[for speaker]: <> It eventually returns the current node being inspected if the node's key matches the desired key or returns null if it doesn't find a node with a desired key. Make sure you understand the code above before moving forward. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/11.md b/Leetcode Workshops/Week 2/Act2_Trees/11.md index 71f76ca..313a72d 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/11.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/11.md @@ -1,7 +1,9 @@ - - +_**type:Cenntered Img Outline**_ + +_**title: Use `BFSSearch` to search for 7**_ + ## Use `BFSSearch` to search for 7 ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (Let's actually see this in action, using use the tree from the previous card as as an example. Let's say we want to find `7` in our tree. Above, you can see the specific path that `BSTSearch` takes to look for the node) \ No newline at end of file +[for speaker]: <> Let's actually see this in action, using use the tree from the previous card as as an example. Let's say we want to find `7` in our tree. Above, you can see the specific path that `BSTSearch` takes to look for the node \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/12.md b/Leetcode Workshops/Week 2/Act2_Trees/12.md index 9dd03ae..b68e5eb 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/12.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/12.md @@ -1,5 +1,7 @@ - - +_**type:left img + text**_ + +_**title:Time Complexity of `BSTSearch`**_ + ## Time Complexity of `BSTSearch`: @@ -13,7 +15,7 @@ ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (Since we're interested in finding the asymptotic time in the **worst-case**, we must consider what the worst case situation would be when searching for a node.) -[for speaker]: <> (The diagram depicts the worst-case scenario when searching for the node with key 50. As you can see, the time to reach a desired node would be O[height], and in this worst-case scenario, it would be O[n], with n being the amount of nodes in the tree, since you have to search through every node in the tree.) +[for speaker]: <> Since we're interested in finding the asymptotic time in the **worst-case**, we must consider what the worst case situation would be when searching for a node. +[for speaker]: <> The diagram depicts the worst-case scenario when searching for the node with key 50. As you can see, the time to reach a desired node would be O[height], and in this worst-case scenario, it would be O[n], with n being the amount of nodes in the tree, since you have to search through every node in the tree. -[for speaker]: <> (Thus, the time complexity of `BSTSearch` is O[n]) +[for speaker]: <> Thus, the time complexity of `BSTSearch` is O[n] diff --git a/Leetcode Workshops/Week 2/Act2_Trees/13.md b/Leetcode Workshops/Week 2/Act2_Trees/13.md index 18cc0b6..27f1676 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/13.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/13.md @@ -1,5 +1,6 @@ - - +_**type:large code**_ + +_**title:`BSTInsert`**_ ## `BSTInsert`: ```Python def BSTInsert(curNode, newNode): @@ -21,4 +22,4 @@ def BSTInsert(curNode, newNode): ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (When adding a new node to a BST, we must make sure to find the correct place to insert that node.`BSTInsert` traverses through the BST in a similar way to `BSTSearch`. However, once it finds that the specific child is null in the place where the new node belongs, it places that node there. Try working and experimenting with the code on your own machine.) \ No newline at end of file +[for speaker]: <> When adding a new node to a BST, we must make sure to find the correct place to insert that node.`BSTInsert` traverses through the BST in a similar way to `BSTSearch`. However, once it finds that the specific child is null in the place where the new node belongs, it places that node there. Try working and experimenting with the code on your own machine. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/14.md b/Leetcode Workshops/Week 2/Act2_Trees/14.md index b2788a4..e0cfa65 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/14.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/14.md @@ -1,8 +1,9 @@ - - +_**type:Cenntered Img Outline**_ + +_**title:Use `BSTInsert` to add a node `11` to this tree.`**_ ## Use `BSTInsert` to add a node `11` to this tree. ------------------------------------------------- -[for speaker]: <> (let's use an example to illustrate how this code works, . We will add a node `11` to this tree. You can see the specific path that `BSTInsert` takes to insert the node as well as the actual position that `11` ends up in.) \ No newline at end of file +[for speaker]: <> let's use an example to illustrate how this code works, . We will add a node `11` to this tree. You can see the specific path that `BSTInsert` takes to insert the node as well as the actual position that `11` ends up in. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/15.md b/Leetcode Workshops/Week 2/Act2_Trees/15.md index f4880c8..63b1809 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/15.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/15.md @@ -1,5 +1,6 @@ - - +_**type:left img + text**_ + +_**title:Time Complexity of `BSTInsert`**_ ## Time Complexity of `BSTInsert` : @@ -10,6 +11,6 @@ Similarly to `BSTSearch`, the time complexity of `BSTInsert`is also **O(n)**. ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (Let's use the same example from the previous slide to illustrate this) +[for speaker]: <> Let's use the same example from the previous slide to illustrate this -[for speaker]: <> (Similarly to `BSTSearch`, the worst-case scenario runtime for `BSTInsert` is also O[n]. The worst-case would occur when you have to go through every node in the tree to find the proper place to insert the node.) \ No newline at end of file +[for speaker]: <> Similarly to `BSTSearch`, the worst-case scenario runtime for `BSTInsert` is also O[n]. The worst-case would occur when you have to go through every node in the tree to find the proper place to insert the node. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/16.md b/Leetcode Workshops/Week 2/Act2_Trees/16.md index cce3cbb..ffeb4ee 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/16.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/16.md @@ -1,5 +1,6 @@ - - +_**type:center img outline**_ + +_**title:Deleting a BST Node:**_ ## Deleting a BST Node: When deleting a BST node, there are **two main cases**: @@ -12,6 +13,6 @@ When deleting a BST node, there are **two main cases**: ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (The last fundamental function that allows us to interact with BSTs is `BSTDelete`, which will allow us to remove unwanted nodes from our tree. `BSTDelete` is arguably the most complicated of the BST functions we have learned so far because we have to fix the tree once we remove a node.) +[for speaker]: <> The last fundamental function that allows us to interact with BSTs is `BSTDelete`, which will allow us to remove unwanted nodes from our tree. `BSTDelete` is arguably the most complicated of the BST functions we have learned so far because we have to fix the tree once we remove a node. -[for speaker]: <> (Since a leaf does not have any children, deleting it from a BST leaves us with a proper BST, meaning we do not have to change the structure of the tree and can simply remove the node. Also, if a node we want to delete only has one child, we can just delete that node and place its child where it used to be. Here is an example of the former:) \ No newline at end of file +[for speaker]: <> Since a leaf does not have any children, deleting it from a BST leaves us with a proper BST, meaning we do not have to change the structure of the tree and can simply remove the node. Also, if a node we want to delete only has one child, we can just delete that node and place its child where it used to be. Here is an example of the former: \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/17.md b/Leetcode Workshops/Week 2/Act2_Trees/17.md index cece563..32cde6b 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/17.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/17.md @@ -1,5 +1,6 @@ - - +_**type:text + img**_ + +_**title:Deleting a BST Node:**_ @@ -10,5 +11,6 @@ ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (The more challenging case occurs when you want to delete an internal node in the BST, or a node with two children.If you simply deleted the node, you would lose the children.) -[for speaker]: <> (Therefore, when an internal node is deleted, it must be replaced with the maximum node of the deleted node's left subtree or minimum node of the deleted node's right subtree [your code implementation will determine the preference between these two options] in order to still follow the rules of a BST. Here is an illustration that should help your understanding:) \ No newline at end of file +[for speaker]: <> The more challenging case occurs when you want to delete an internal node in the BST, or a node with two children.If you simply deleted the node, you would lose the children. + +[for speaker]: <> Therefore, when an internal node is deleted, it must be replaced with the maximum node of the deleted node's left subtree or minimum node of the deleted node's right subtree [your code implementation will determine the preference between these two options] in order to still follow the rules of a BST. Here is an illustration that should help your understanding: \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/18.md b/Leetcode Workshops/Week 2/Act2_Trees/18.md index 4399fc0..3624133 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/18.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/18.md @@ -1,5 +1,6 @@ - - +_**type:left img + text**_ + +_**title:Example of `BSTDelete`**_ ## Example of `BSTDelete` ![](https://i2.wp.com/www.techiedelight.com/wp-content/uploads/Deletion-in-BST-Case-2-1.png?zoom=1.5&resize=586%2C352&ssl=1) @@ -11,6 +12,6 @@ ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (As you can see, we chose to delete `20` from the tree, and picked its in-order predecessor node as its replacement. The in-order predecessor node is the maximum value of a node's left subtree, in this case, `19`.. Similarly, we could have also used the in-order *successor* node, which is the *minimum* value of a node's *right* sub-tree. If we had gone that direction, we would have chosen `30` as the replacement for `20` in our example instead. ) +[for speaker]: <> As you can see, we chose to delete `20` from the tree, and picked its in-order predecessor node as its replacement. The in-order predecessor node is the maximum value of a node's left subtree, in this case, `19`.. Similarly, we could have also used the in-order *successor* node, which is the *minimum* value of a node's *right* sub-tree. If we had gone that direction, we would have chosen `30` as the replacement for `20` in our example instead. -[for speaker]: <> (Note that the process for deleting a child with two nodes is the same for **any** node, even the root! If we had decided to remove `15` from our tree above, and still decided to use the in-order predecessor node as our replacement, we would have picked `12` to be in its place. We would have chosen `16` if we picked the successor node.) \ No newline at end of file +[for speaker]: <> Note that the process for deleting a child with two nodes is the same for **any** node, even the root! If we had decided to remove `15` from our tree above, and still decided to use the in-order predecessor node as our replacement, we would have picked `12` to be in its place. We would have chosen `16` if we picked the successor node. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/19.md b/Leetcode Workshops/Week 2/Act2_Trees/19.md index 1c6161e..d97726d 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/19.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/19.md @@ -1,5 +1,6 @@ - - +_**type:code steps 1**_ + +_**title:`BSTDelete()`**_ ## `BSTDelete()` ```Python def smallestNode(curNode): @@ -17,6 +18,6 @@ def smallestNode(curNode): ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (Due to the various cases when deleting a BST node, the `BSTDelete` function is a little more complex than `BSTSearch` and `BSTInsert`. However, don't be intimidated by the code; make certain you understand the process of deleting a node, because the code simply follows that logic. Let's take a look:) +[for speaker]: <> Due to the various cases when deleting a BST node, the `BSTDelete` function is a little more complex than `BSTSearch` and `BSTInsert`. However, don't be intimidated by the code; make certain you understand the process of deleting a node, because the code simply follows that logic. Let's take a look: -[for speaker]: <> (This is a helper function which will allows us to find the smallest node in a given node's subtree. The process is simple. We simply traverse down the node's left subtree, always choosing to visit the left child, until we reach a leaf. That leaf node is the smallest node and gets returned. As you can tell, we are chooisng the in-order predecessor node as our replacement in this code implementation.) \ No newline at end of file +[for speaker]: <> This is a helper function which will allows us to find the smallest node in a given node's subtree. The process is simple. We simply traverse down the node's left subtree, always choosing to visit the left child, until we reach a leaf. That leaf node is the smallest node and gets returned. As you can tell, we are chooisng the in-order predecessor node as our replacement in this code implementation. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/2.md b/Leetcode Workshops/Week 2/Act2_Trees/2.md index 1eb7cd3..8205293 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/2.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/2.md @@ -1,5 +1,6 @@ - - +_**type:Text+ Img**_ + +_**title:Tree Terminology**_ diff --git a/Leetcode Workshops/Week 2/Act2_Trees/20.md b/Leetcode Workshops/Week 2/Act2_Trees/20.md index 9631b84..62c8b4e 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/20.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/20.md @@ -1,5 +1,6 @@ - - +_**type:code steps 2**_ + +_**title:`BSTDelete()`**_ ## `BSTDelete()` ```python def BSTDelete(curNode, key): @@ -16,4 +17,4 @@ We traverse down the left and right subtree of any given node until we reach the ------------------------------------------------- -[for speaker]: <> (In order to delete a node, we need to find it first! This process is the exact same as with `BSTSearch` and `BSTInsert`. We traverse down the left and right subtree of any given node until we reach the node we are looking to delete.) +[for speaker]: <> In order to delete a node, we need to find it first! This process is the exact same as with `BSTSearch` and `BSTInsert`. We traverse down the left and right subtree of any given node until we reach the node we are looking to delete. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/21.md b/Leetcode Workshops/Week 2/Act2_Trees/21.md index 2ca961e..ff4b97d 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/21.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/21.md @@ -1,5 +1,6 @@ - - +_**type:code steps 3**_ + +_**title:`BSTDelete()`**_ ## `BSTDelete()` ```python else: #found node to be deleted @@ -17,4 +18,4 @@ We "delete" a node by setting it to `None`. ------------------------------------------------- -[for speaker]: <> (Here, we found the node and it falls under one of the two situations listed in Case 1: it is either a leaf, or only has one child. We do the appropriate replacement and deletion procedures. Notice that we "delete" a node by setting it to `None`.) \ No newline at end of file +[for speaker]: <> Here, we found the node and it falls under one of the two situations listed in Case 1: it is either a leaf, or only has one child. We do the appropriate replacement and deletion procedures. Notice that we "delete" a node by setting it to `None`. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/22.md b/Leetcode Workshops/Week 2/Act2_Trees/22.md index 1029754..e311430 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/22.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/22.md @@ -1,5 +1,6 @@ - - +_**type:code steps 4**_ + +_**title:`BSTDelete()`**_ ## `BSTDelete()` ```python #Internal Node Case: @@ -12,6 +13,6 @@ * Replace its value with the predecessor's value. * Delete the predecessor node from our tree. ------------------------------------------------- -[for speaker]: <> (Finally, this is the case where the node in question has two children. We find its in-order predecessor node, replace its value with the predecessor's value, and delete the predecessor node from our tree.) +[for speaker]: <> Finally, this is the case where the node in question has two children. We find its in-order predecessor node, replace its value with the predecessor's value, and delete the predecessor node from our tree. -[for speaker]: <> (Although `BSTDelete` seems complicated initially,you will realize that it simply follows the logic of either the **Leaf/1 Child Case** or the **Internal Node Case**. Feel free to ask questions about the two cases if you're having trouble understanding the `BSTDelete` code.) \ No newline at end of file +[for speaker]: <> Although `BSTDelete` seems complicated initially,you will realize that it simply follows the logic of either the **Leaf/1 Child Case** or the **Internal Node Case**. Feel free to ask questions about the two cases if you're having trouble understanding the `BSTDelete` code. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/23.md b/Leetcode Workshops/Week 2/Act2_Trees/23.md index 0da1863..e8b2317 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/23.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/23.md @@ -1,9 +1,10 @@ - - +_**type:headline only**_ + +_**title:Let's make a family tree in Python using the `Node` class**_ # Let's make a family tree in Python using the `Node` class ------------------------------------------------- -[for speaker]: <> (Now that we have learned the basic concepts associated with trees, let's do an activity together that walks through a real life application of data trees to cement our understanding.) +[for speaker]: <> Now that we have learned the basic concepts associated with trees, let's do an activity together that walks through a real life application of data trees to cement our understanding. -[for speaker]: <> (As I mentioned prior, a place where a data tree occurs in your real life is with the relationships in your family. For the activity, we will make a data tree in Python using the `Node` class that will be a representation of a family.) \ No newline at end of file +[for speaker]: <> As I mentioned prior, a place where a data tree occurs in your real life is with the relationships in your family. For the activity, we will make a data tree in Python using the `Node` class that will be a representation of a family. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/24.md b/Leetcode Workshops/Week 2/Act2_Trees/24.md index 3e72bf7..df4cf4b 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/24.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/24.md @@ -1,5 +1,6 @@ - - +_**type:code steps1**_ + +_**title:Define the `Node` class of Family Tree:**_ ## Define the `Node` class of Family Tree: ```Python class Node: @@ -20,4 +21,4 @@ For our family tree, we want to hold the **name**, **age**, **gender**, and **fa ------------------------------------------------- -[for speaker]: <> (As you may have noticed, we added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each family member. Notice that we are now assigning the name of the family member to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each family member. It is just what we will use to identify a certain node.) \ No newline at end of file +[for speaker]: <> As you may have noticed, we added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each family member. Notice that we are now assigning the name of the family member to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each family member. It is just what we will use to identify a certain node. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/25.md b/Leetcode Workshops/Week 2/Act2_Trees/25.md index 6d137f4..dbecea6 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/25.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/25.md @@ -1,5 +1,6 @@ - - +_**type:code steps2**_ + +_**title:initialize root `Node`:**_ ## Initialize `root Node`: For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. @@ -9,4 +10,4 @@ grandma = Node("Susan", 92, "female", "bowling") ------------------------------------------------- -[for speaker]: <> (Now that we have our new `Node` class, let's start initializing some family members to start building the ancestry tree. For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. Let's initialize her `Node` object:) \ No newline at end of file +[for speaker]: <> Now that we have our new `Node` class, let's start initializing some family members to start building the ancestry tree. For the **root** of the family tree, we want to use the grandmother of the family. Let's say the grandmother of the family's name is **Susan**, she is **92** years old, and her favorite sport is **bowling**. Let's initialize her `Node` object: \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/26.md b/Leetcode Workshops/Week 2/Act2_Trees/26.md index b6c69d8..acd48ec 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/26.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/26.md @@ -1,6 +1,7 @@ - - -## Let's say grandma Susan has 3 children. Let's create some node objects for her children: +_**type:code steps 3**_ + +_**title:Let's create some node objects for her children:**_ +## Let's say grandma Susan has 3 children. ```Python mary = Node("Mary", 57, "female", "soccer") joe = Node("Joe", 61, "male", "football") @@ -8,4 +9,4 @@ don = Node("Don", 63, "male", "tennis") ``` ------------------------------------------------- -[for speaker]: <> (Now that we have a node for grandma Susan, let's say she has 3 children. Let's create some node objects for her children:) \ No newline at end of file +[for speaker]: <> Now that we have a node for grandma Susan, let's say she has 3 children. Let's create some node objects for her children: \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/27.md b/Leetcode Workshops/Week 2/Act2_Trees/27.md index 200a69a..9644ff2 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/27.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/27.md @@ -1,5 +1,6 @@ - - +_**type:code steps 4**_ + +_**title:Connect Susan's children with Susan**_ ## Connect Susan's children with Susan ```Python grandma.insert_child(Mary) @@ -10,6 +11,6 @@ grandma.insert_child(Don) ------------------------------------------------- -[for speaker]: <> (We have declared node objects for all of Susan's children but we have not indicated in our code that they are her children yet. In order to do so, we can use the `insert_child` function in the `Node` class on Susan's object.) +[for speaker]: <> We have declared node objects for all of Susan's children but we have not indicated in our code that they are her children yet. In order to do so, we can use the `insert_child` function in the `Node` class on Susan's object. -[for speaker]: <> (After making those 3 calls, grandma.children will now be a list that holds the node instances mary, joe, and don. We have essentially drawn edges between grandma and mary, grandma and joe, and grandma and don.) +[for speaker]: <> After making those 3 calls, grandma.children will now be a list that holds the node instances mary, joe, and don. We have essentially drawn edges between grandma and mary, grandma and joe, and grandma and don. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/28.md b/Leetcode Workshops/Week 2/Act2_Trees/28.md index e66a70f..a37d908 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/28.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/28.md @@ -1,5 +1,6 @@ - - +_**type:code step 5**_ + +_**title:**_ ## Let's say that Joe got married and had 2 children. Let's create the `Node` instances for Joe's 2 children: ```Python ricky = Node("Ricky", 34, "male", "basketball") @@ -7,4 +8,4 @@ kelly = Node("Kelly", 35, "female", "tennis") ``` ------------------------------------------------- -[for speaker]: <> (Let's say that Joe got married and had 2 children. Although we could adjust our tree structure to include Joe's spouse, let's keep our tree simple for now and only show grandma Susan's direct descendants. Let's create the `Node` instances for Joe's 2 children:) \ No newline at end of file +[for speaker]: <> Let's say that Joe got married and had 2 children. Although we could adjust our tree structure to include Joe's spouse, let's keep our tree simple for now and only show grandma Susan's direct descendants. Let's create the `Node` instances for Joe's 2 children: \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/29.md b/Leetcode Workshops/Week 2/Act2_Trees/29.md index b2c7d31..be6d7a7 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/29.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/29.md @@ -1,5 +1,6 @@ - - +_**type:code step 6**_ + +_**title:Now let's connect them to Joe's node with edges:**_ ## Now let's connect them to Joe's node with edges: ```Python joe.insert_child(ricky) @@ -7,4 +8,4 @@ joe.insert_child(kelly) ``` ------------------------------------------------- -[for speaker]: <> (Now, we have successfully created a simple family tree using data trees in Python.) +[for speaker]: <> Now, we have successfully created a simple family tree using data trees in Python. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/3.md b/Leetcode Workshops/Week 2/Act2_Trees/3.md index 2e7ccb2..0d3d8aa 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/3.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/3.md @@ -1,5 +1,6 @@ - - +_**type:Text+img**_ + +_**title:Nodes}**_ diff --git a/Leetcode Workshops/Week 2/Act2_Trees/30.md b/Leetcode Workshops/Week 2/Act2_Trees/30.md index a2fe46b..eef25d6 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/30.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/30.md @@ -1,8 +1,9 @@ - - +_**type:center img large**_ + +_**title:Draw the family tree**_ ## Draw the family tree ![img](https://i.imgur.com/pshjK2F.png ) ------------------------------------------------- -[for speaker]: <> (For practice, try out drawing the family tree we just created on paper. Also, for more practice, try implementing your own family tree in Python by adding and deleting the new object nodes with family member.) \ No newline at end of file +[for speaker]: <> For practice, try out drawing the family tree we just created on paper. Also, for more practice, try implementing your own family tree in Python by adding and deleting the new object nodes with family member. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/31.md b/Leetcode Workshops/Week 2/Act2_Trees/31.md index 6e5ec67..8869883 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/31.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/31.md @@ -1,9 +1,10 @@ - - +_**type:headline only**_ + +_**title:Let's use BST to make a simple database to be able to search members by their ID**_ ## Let's use BST to make a simple database to be able to search members by their ID ------------------------------------------------- -[for speaker]: <> (Now to further **enhance your comprehension for Binary Search Tree's**, we will use a Binary Search Tree in an example **real-world application** in order for you to see the purpose behind this algorithm.) +[for speaker]: <> Now to further **enhance your comprehension for Binary Search Tree's**, we will use a Binary Search Tree in an example **real-world application** in order for you to see the purpose behind this algorithm. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/32.md b/Leetcode Workshops/Week 2/Act2_Trees/32.md index 8149e70..91b24e0 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/32.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/32.md @@ -1,5 +1,6 @@ - - +_**type:main point**_ + +_**title:Real Life Application of Binary Search Tree**_ - Consider that we are admins for a corporation that has many employees and we must have some sort of way to keep track of each employee in our database system. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/33.md b/Leetcode Workshops/Week 2/Act2_Trees/33.md index 020685a..28c5e52 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/33.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/33.md @@ -1,5 +1,6 @@ - - +_**type:code steps1**_ + +_**title:Create the `Node` class**_ ## Create the `Node` class ```python class Node: @@ -12,8 +13,8 @@ class Node: - We want to hold each employee's ID number(Key) and name. ------------------------------------------------- -[for speaker]: <> (We added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each employee's ID number[Key] and name.) +[for speaker]: <> We added arguments to the `Node` class initializer function that we will use to let us store the important data we want to store about each employee's ID number[Key] and name. -[for speaker]: <> (For our employee information tree, we weant to hold the key, and **name** for each employee of the company.Therefore, we must slightly modify our 'Node' class to allow us to encompass that data.) +[for speaker]: <> For our employee information tree, we weant to hold the key, and **name** for each employee of the company.Therefore, we must slightly modify our 'Node' class to allow us to encompass that data. -[for speaker]: <> (We are now assigning the name of the employee to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each employee. It is just what we will use to identify a certain node.) \ No newline at end of file +[for speaker]: <> We are now assigning the name of the employee to be the key that we identify each node as, which is an implementation choice. You could really use any data aspect as the key for each employee. It is just what we will use to identify a certain node. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/34.md b/Leetcode Workshops/Week 2/Act2_Trees/34.md index 21eae3e..20cc4ad 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/34.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/34.md @@ -1,5 +1,6 @@ - - +_**type:code steps 2**_ + +_**title:A utility function to insert a new node with the given key**_ ## A utility function to insert a new node with the given key ```python def insert(root,node): diff --git a/Leetcode Workshops/Week 2/Act2_Trees/35.md b/Leetcode Workshops/Week 2/Act2_Trees/35.md index 3018ee0..0744a4a 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/35.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/35.md @@ -1,5 +1,6 @@ - - +_**type:code steps large**_ + +_**title:A utility function to do inorder tree traversal**_ ## A utility function to do inorder tree traversal ```python def inorderID(root): @@ -16,4 +17,4 @@ def inorderName(root): ``` ------------------------------------------------- -[for speaker]: <> (Now, we make functions to make a tree in order by the Key value[Employee ID] or the name of employee base on the insert function we produced above.) \ No newline at end of file +[for speaker]: <> Now, we make functions to make a tree in order by the Key value[Employee ID] or the name of employee base on the insert function we produced above. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/36.md b/Leetcode Workshops/Week 2/Act2_Trees/36.md index f9d21b0..0f02c80 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/36.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/36.md @@ -1,5 +1,6 @@ - - +_**type:code steps large**_ + +_**title:A utility function to search a given key in BST**_ ## A utility function to search a given key in BST ```python def search(root,key): @@ -15,4 +16,4 @@ def search(root,key): ``` ------------------------------------------------- -[for speaker]: <> (We make a function to search the name of employee base on the Key value[Employee ID].) \ No newline at end of file +[for speaker]: <> We make a function to search the name of employee base on the Key value[Employee ID]. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/37.md b/Leetcode Workshops/Week 2/Act2_Trees/37.md index 79c485d..04b845a 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/37.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/37.md @@ -1,5 +1,6 @@ - - +_**type:code steps**_ + +_**title:Insert root node and other employees**_ ## Insert root node and other employees ```python r = Node(50, "Abel") diff --git a/Leetcode Workshops/Week 2/Act2_Trees/38.md b/Leetcode Workshops/Week 2/Act2_Trees/38.md index 26b6551..6e69dab 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/38.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/38.md @@ -1,5 +1,6 @@ - - +_**type:code steps**_ + +_**title:Order the nodes by ID**_ ## Order the nodes by ID ```python inorderID(r) @@ -11,4 +12,4 @@ search(r, 20) ------------------------------------------------- -[for speaker]: <> (We have inserted all node objects for the root but we have not made them in order by employee ID or employee name. To do so, we use inorderID or inorderName function. Also, we can search the employee name by the key value[employee ID].) \ No newline at end of file +[for speaker]: <> We have inserted all node objects for the root but we have not made them in order by employee ID or employee name. To do so, we use inorderID or inorderName function. Also, we can search the employee name by the key value[employee ID]. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/39.md b/Leetcode Workshops/Week 2/Act2_Trees/39.md index 981f909..9d232ea 100644 --- a/Leetcode Workshops/Week 2/Act2_Trees/39.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/39.md @@ -1,5 +1,6 @@ - - +_**type:left img + text**_ + +_**title:The tree we just implemented should look like:**_ ## The tree we just implemented should look like: ![](https://i.imgur.com/4FJ4zKR.png) @@ -12,4 +13,4 @@ ------------------------------------------------- -[for speaker]: <> (Figure 1. Binary Search Tree in order with the employee Identification number and employee's name) +[for speaker]: <> Figure 1. Binary Search Tree in order with the employee Identification number and employee's name diff --git a/Leetcode Workshops/Week 2/Act2_Trees/4.md b/Leetcode Workshops/Week 2/Act2_Trees/4.md index 910a279..bc4a625 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/4.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/4.md @@ -1,5 +1,6 @@ - - +_**type:left img + text**_ + +_**title:Example of Tree Terminology**_ ## Example of Tree Terminology @@ -14,4 +15,4 @@ * the group of nodes with values 6, 4, and 7 are a **subtree** of the tree. ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (In the tree above, the circles with numbers in them are the **nodes** of the tree. The arrows connecting each nodes are the **edges**. The **root** of this tree is the node that contains the number 8. The node containing 3 is a **parent** of the node containing 1. The node containing 1 is a **child** of the node containing 3. The nodes with 4 and 7 are **siblings**. The nodes with 1, 4, 7, and 13 are **leaf nodes**. The nodes containing 8, 3, 10, 6, and 14 are all **internal nodes**. Finally, the group of nodes with values 6, 4, and 7 are a **subtree** of the tree.) \ No newline at end of file +[for speaker]: <> In the tree above, the circles with numbers in them are the **nodes** of the tree. The arrows connecting each nodes are the **edges**. The **root** of this tree is the node that contains the number 8. The node containing 3 is a **parent** of the node containing 1. The node containing 1 is a **child** of the node containing 3. The nodes with 4 and 7 are **siblings**. The nodes with 1, 4, 7, and 13 are **leaf nodes**. The nodes containing 8, 3, 10, 6, and 14 are all **internal nodes**. Finally, the group of nodes with values 6, 4, and 7 are a **subtree** of the tree. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/5.md b/Leetcode Workshops/Week 2/Act2_Trees/5.md index 8a534b6..a4d9a39 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/5.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/5.md @@ -1,5 +1,6 @@ - - +_**type:Text+img**_ + +_**title:Real Life Application of Trees**_ ## Real Life Application of Trees: ### Ancestry Trees: @@ -8,4 +9,4 @@ ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (You may be wondering why we would want to use trees. A real life example of a tree structure being used is in ancestry trees. Think of each person in the family as a node. Every person in the family tree is related to other people in the family in some way as a sibling, parent, grandparent, etc. Tree data structures behave in a very similar way as they are both hierarchical structures with nodes, or family members, connected together in a certain manner, and the connection between nodes are there for a specific reason.) \ No newline at end of file +[for speaker]: <> You may be wondering why we would want to use trees. A real life example of a tree structure being used is in ancestry trees. Think of each person in the family as a node. Every person in the family tree is related to other people in the family in some way as a sibling, parent, grandparent, etc. Tree data structures behave in a very similar way as they are both hierarchical structures with nodes, or family members, connected together in a certain manner, and the connection between nodes are there for a specific reason. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act2_Trees/6.md b/Leetcode Workshops/Week 2/Act2_Trees/6.md index 6e5b38c..6fa3834 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/6.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/6.md @@ -1,5 +1,6 @@ - - +_**type:code centered**_ + +_**title:Let's Define the `Node` Class**_ ## Let's Define the `Node` Class: ```Python @@ -18,9 +19,9 @@ The `Node` class contains the data value of a node and a list of its children. ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (-Now that we understand the structure of a tree and the common terminology used to describe elements of a tree, let's think of how we would implement the structure in Python.) +[for speaker]: <> Now that we understand the structure of a tree and the common terminology used to describe elements of a tree, let's think of how we would implement the structure in Python. -[for speaker]: <> (It may be tempting to declare a class called `Tree` in which we store all the nodes in the class. While this approach makes sense, it can often lead to confusion and does not have built-in functionality for relationships between the nodes in the tree. When you realize that a class for the tree itself is not necessary, you may think of a second approach, which is the standard implementation. Instead,...) +[for speaker]: <> It may be tempting to declare a class called `Tree` in which we store all the nodes in the class. While this approach makes sense, it can often lead to confusion and does not have built-in functionality for relationships between the nodes in the tree. When you realize that a class for the tree itself is not necessary, you may think of a second approach, which is the standard implementation. Instead,... -[for speaker]: <> (for this implementation, we will declare a class `Node` in which in each instance of the class represents a node of the tree. The `Node` class contains the data value of a node and a list of its children. This implementation also includes an `insert_child` function that simply appends the node passed as an argument to the current node's list of children. Since each node has its children stored in it, the structure of the tree is maintained, making the `Tree` class unnecessary. You may be asking why we don't keep track of each node's parent. While this may be useful or necessary for some more advanced types of trees, it is not needed to implement a base tree that we're currently investigating.) +[for speaker]: <> for this implementation, we will declare a class `Node` in which in each instance of the class represents a node of the tree. The `Node` class contains the data value of a node and a list of its children. This implementation also includes an `insert_child` function that simply appends the node passed as an argument to the current node's list of children. Since each node has its children stored in it, the structure of the tree is maintained, making the `Tree` class unnecessary. You may be asking why we don't keep track of each node's parent. While this may be useful or necessary for some more advanced types of trees, it is not needed to implement a base tree that we're currently investigating. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/7.md b/Leetcode Workshops/Week 2/Act2_Trees/7.md index 0846bce..de64307 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/7.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/7.md @@ -1,5 +1,7 @@ - - +_**type:left img + text**_ + +_**title:Binary Trees**_ + ## Binary Trees: @@ -14,5 +16,5 @@ The **Binary Search Tree (BST)** is a special kind of Binary Tree. ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (A simple tree structure is fundamental, but let's investigate a specific type of tree that allowsfor an interesting and structured way to store data.The tree structure we will be dealing with, however, is a special kind of Binary Tree, the Binary Search Tree have a few more restrictions) +[for speaker]: <> A simple tree structure is fundamental, but let's investigate a specific type of tree that allowsfor an interesting and structured way to store data.The tree structure we will be dealing with, however, is a special kind of Binary Tree, the Binary Search Tree have a few more restrictions diff --git a/Leetcode Workshops/Week 2/Act2_Trees/8.md b/Leetcode Workshops/Week 2/Act2_Trees/8.md index 35c98a3..c9e7c24 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/8.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/8.md @@ -1,6 +1,8 @@ - - - +_**type:comparison left right**_ + +_the text should be centered in the bottom_ + +_**title:Let's see an example of a valid vs invalid BST:**_ ## Let's see an example of a valid vs invalid BST: ​ @@ -9,7 +11,7 @@ ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (Are you able to tell which tree is a valid BST and which is invalid?) +[for speaker]: <> Are you able to tell which tree is a valid BST and which is invalid? -[for speaker]: <> (The left tree is an invalid BST because the node containing the key `10` is in a right subtree of the node containing the key `30`.) -[for speaker]: <> (You may have noticed that all subtrees of a BST are also BSTs.) +[for speaker]: <> The left tree is an invalid BST because the node containing the key `10` is in a right subtree of the node containing the key `30`. +[for speaker]: <> You may have noticed that all subtrees of a BST are also BSTs. diff --git a/Leetcode Workshops/Week 2/Act2_Trees/9.md b/Leetcode Workshops/Week 2/Act2_Trees/9.md index bdc409a..5b262bc 100755 --- a/Leetcode Workshops/Week 2/Act2_Trees/9.md +++ b/Leetcode Workshops/Week 2/Act2_Trees/9.md @@ -1,5 +1,7 @@ - - +_**type:small code snipet**_ + +_**title:Implement BST `Node` class BST**_ + ## Implement BST `Node` class BST ```Python class Node: @@ -13,4 +15,4 @@ class Node: ----------------------------------------------------------------------------------------------------- -[for speaker]: <> (In order to implement a BST in Python, we just need to adjust our previous `Node` class.Since we know that BST nodes only have two children max, we no longer need a list to store the children.) \ No newline at end of file +[for speaker]: <> In order to implement a BST in Python, we just need to adjust our previous `Node` class.Since we know that BST nodes only have two children max, we no longer need a list to store the children. \ No newline at end of file From 8fdabad14ec08825cebfb207a100f860aef969b9 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Wed, 26 Feb 2020 13:09:00 -0800 Subject: [PATCH 21/24] 4.2.1 make the type and title visible --- Leetcode Workshops/Week 2/Act1_Linked list/1.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/10.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/11.md | 11 ++++++----- Leetcode Workshops/Week 2/Act1_Linked list/12.md | 9 +++++---- Leetcode Workshops/Week 2/Act1_Linked list/13.md | 6 +++--- Leetcode Workshops/Week 2/Act1_Linked list/14.md | 11 ++++++----- Leetcode Workshops/Week 2/Act1_Linked list/15.md | 6 +++--- Leetcode Workshops/Week 2/Act1_Linked list/16.md | 9 +++++---- Leetcode Workshops/Week 2/Act1_Linked list/17.md | 9 +++++---- Leetcode Workshops/Week 2/Act1_Linked list/18.md | 11 ++++++----- Leetcode Workshops/Week 2/Act1_Linked list/19.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/20.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/21.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/22.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/23.md | 9 +++++---- Leetcode Workshops/Week 2/Act1_Linked list/24.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/25.md | 8 ++++---- Leetcode Workshops/Week 2/Act1_Linked list/26.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/27.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/28.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/29.md | 9 +++++---- Leetcode Workshops/Week 2/Act1_Linked list/3.md | 8 +++++--- Leetcode Workshops/Week 2/Act1_Linked list/30.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/31.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/32.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/33.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/34.md | 11 ++++++----- Leetcode Workshops/Week 2/Act1_Linked list/35.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/36.md | 7 ++++--- Leetcode Workshops/Week 2/Act1_Linked list/4.md | 12 +++++++----- Leetcode Workshops/Week 2/Act1_Linked list/5.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/6.md | 5 +++-- Leetcode Workshops/Week 2/Act1_Linked list/7.md | 10 ++++++---- Leetcode Workshops/Week 2/Act1_Linked list/8.md | 15 ++++++++------- Leetcode Workshops/Week 2/Act1_Linked list/9.md | 7 ++++--- 35 files changed, 153 insertions(+), 118 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/1.md b/Leetcode Workshops/Week 2/Act1_Linked list/1.md index 753c7a0..aa6bd6e 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/1.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/1.md @@ -1,3 +1,4 @@ - - +_**type:title slide**_ + +_**title:Linked List**_ # Linked List \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/10.md b/Leetcode Workshops/Week 2/Act1_Linked list/10.md index 67acdd6..e9a36ea 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/10.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/10.md @@ -1,5 +1,6 @@ - - +_**type:code centered**_ + +_**title:Now let's create our linked list and a node for it**_ ## Now let's create our linked list and a node for it ```python diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/11.md b/Leetcode Workshops/Week 2/Act1_Linked list/11.md index e7d58ca..74032c7 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/11.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/11.md @@ -1,5 +1,6 @@ - - +_**type:small code snipet**_ + +_**title:`insert()`**_ ## `insert()` ```python def insert(self, data): @@ -14,8 +15,8 @@ def insert(self, data): ------------------------------------------------- -[for speaker]: <> (To begin inserting new nodes into the linked list, we'll create an `insert[]` method! We will take data, initialize a new `Node` object with the data, then add it to the list. Although its possible to insert a new Node anywhere in the list, it becomes less expensive to insert it at the beginning.) +[for speaker]: <> To begin inserting new nodes into the linked list, we'll create an `insert[]` method! We will take data, initialize a new `Node` object with the data, then add it to the list. Although its possible to insert a new Node anywhere in the list, it becomes less expensive to insert it at the beginning. -[for speaker]: <> (If we had a string of pearls and wanted to add a new pearl, we would add the pearl at the start of the string, making our new pearl the "head" pearl. In the same sense, when inserting the new Node at the beginning, it becomes the new "head" of the list, and we can just have the next node [for our new "head"] to point to the old "head" Node.) +[for speaker]: <> If we had a string of pearls and wanted to add a new pearl, we would add the pearl at the start of the string, making our new pearl the "head" pearl. In the same sense, when inserting the new Node at the beginning, it becomes the new "head" of the list, and we can just have the next node [for our new "head"] to point to the old "head" Node. -[for speaker]: <> (Upon further observation, we can see that the time complexity for this insert method is in fact constant O[1]: it always takes the same amount of time. It can only take one data point, create only one node, and doesn't need to interact with the other nodes in the linked list besides the "head" node.) \ No newline at end of file +[for speaker]: <> Upon further observation, we can see that the time complexity for this insert method is in fact constant O[1]: it always takes the same amount of time. It can only take one data point, create only one node, and doesn't need to interact with the other nodes in the linked list besides the "head" node. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/12.md b/Leetcode Workshops/Week 2/Act1_Linked list/12.md index e69ad33..e2f058f 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/12.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/12.md @@ -1,5 +1,6 @@ - - +_**type:code centered**_ + +_**title:Use `insert()`**_ ## Use `insert()` ```python film.insert(930) @@ -13,7 +14,7 @@ film.insert(930) - `self.head` will take in our current Node as the new "head" node. ------------------------------------------------- -[for speaker]: <> (When calling the `insert[]` function in the `main[]` code, it will look like this:) +[for speaker]: <> When calling the `insert[]` function in the `main[]` code, it will look like this: -[for speaker]: <> (The data point '930' will be assigned to a new node's `self.data` value, while the `set_next` function points the current node to the old "head" node. Then, `self.head` will take in our current Node as the new "head" node. Now, the new "head" is the node with data 930 and this node points to the node with data 900.) +[for speaker]: <> The data point '930' will be assigned to a new node's `self.data` value, while the `set_next` function points the current node to the old "head" node. Then, `self.head` will take in our current Node as the new "head" node. Now, the new "head" is the node with data 930 and this node points to the node with data 900. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/13.md b/Leetcode Workshops/Week 2/Act1_Linked list/13.md index d42d54e..e2d627f 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/13.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/13.md @@ -1,5 +1,5 @@ - - +_**type:code centered**_ +_**title:insert()**_ ## `insert()` ```python film.insert(1000) @@ -11,7 +11,7 @@ The node with '1000' will become our new "head" and it will points to the node ------------------------------------------------- -[for speaker]: <> (The same will happen to the data entry of '1000' if we write the following line.) +[for speaker]: <> The same will happen to the data entry of '1000' if we write the following line. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/14.md b/Leetcode Workshops/Week 2/Act1_Linked list/14.md index c53c46e..6851475 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/14.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/14.md @@ -1,5 +1,6 @@ - - +_**type:code step1**_ + +_**title:delete()**_ ## `delete()` ```python @@ -13,8 +14,8 @@ def delete(self, data): ------------------------------------------------- -[for speaker]: <> (If we want to remove an item from the list, we can then use the `delete[]` function.) +[for speaker]: <> If we want to remove an item from the list, we can then use the `delete[]` function. -[for speaker]: <> (The time complexity for `delete[]` is also O[n], because in the worst case it will visit every node, interacting with each node a fixed number of times.) +[for speaker]: <> The time complexity for `delete[]` is also O[n], because in the worst case it will visit every node, interacting with each node a fixed number of times. -[for speaker]: <> (The `delete[]` function for our linked list goes through the list, and keeps track of the current node, `current`, while also remembering the node it last visited, `previous`. ) \ No newline at end of file +[for speaker]: <> The `delete[]` function for our linked list goes through the list, and keeps track of the current node, `current`, while also remembering the node it last visited, `previous`. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/15.md b/Leetcode Workshops/Week 2/Act1_Linked list/15.md index 05e92f1..b9a4e8e 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/15.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/15.md @@ -1,5 +1,5 @@ - - +_**type:code step2**_ +_**title:delete()**_ ## `delete()` ```python while current and found is False: @@ -16,4 +16,4 @@ ------------------------------------------------- -[for speaker]: <> (In order to delete an element, the `delete[]` function goes through the list until it arrives to the node that it wants to delete. When it arrives, it takes a look at the previous node it visited and resets that node's `next_node` to point at the node that comes after the one to be deleted.) \ No newline at end of file +[for speaker]: <> In order to delete an element, the `delete[]` function goes through the list until it arrives to the node that it wants to delete. When it arrives, it takes a look at the previous node it visited and resets that node's `next_node` to point at the node that comes after the one to be deleted. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/16.md b/Leetcode Workshops/Week 2/Act1_Linked list/16.md index b5d1eee..84798b0 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/16.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/16.md @@ -1,5 +1,6 @@ - - +_**type:code step3**_ + +_**title:delete()**_ ## `delete()` ```python if current is None: @@ -17,6 +18,6 @@ ------------------------------------------------- -[for speaker]: <> (Afterwards, we add several statements in the case that the data doesn't exist in the list, moving onto the next node if we're at the "head" node, and moving through the list node by node.) +[for speaker]: <> Afterwards, we add several statements in the case that the data doesn't exist in the list, moving onto the next node if we're at the "head" node, and moving through the list node by node. -[for speaker]: <> (When the previous node's `next_node` points at the next node in line, then no nodes will point at the current node, meaning that the current node has now been deleted!) \ No newline at end of file +[for speaker]: <> When the previous node's `next_node` points at the next node in line, then no nodes will point at the current node, meaning that the current node has now been deleted! \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/17.md b/Leetcode Workshops/Week 2/Act1_Linked list/17.md index d50a5d5..9097e7b 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/17.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/17.md @@ -1,5 +1,6 @@ - - +_**type:code centered**_ + +_**title:Call delete()**_ ## `delete()` in `main()` ```python film.delete(930) @@ -15,6 +16,6 @@ film.delete(930) ------------------------------------------------- -[for speaker]: <> (In our `main[]` function later on, deleting a node from a linked list will look like this) +[for speaker]: <> In our `main[]` function later on, deleting a node from a linked list will look like this -[for speaker]: <> (We began looking for the node we want to delete from our head [the node with data '1000']. We found that it's not holding the data we were looking for. So, we go to the next node. At the same time we update the current node and previous node. In this example, we find data '930' in our second step. We set our pervious node points to the node that current node is pointing at. Thus, after deletion the node with '1000' now points at the node with '900' instead of the node with '930.') \ No newline at end of file +[for speaker]: <> We began looking for the node we want to delete from our head [the node with data '1000']. We found that it's not holding the data we were looking for. So, we go to the next node. At the same time we update the current node and previous node. In this example, we find data '930' in our second step. We set our pervious node points to the node that current node is pointing at. Thus, after deletion the node with '1000' now points at the node with '900' instead of the node with '930.' \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/18.md b/Leetcode Workshops/Week 2/Act1_Linked list/18.md index c8b42b3..c7c4ab1 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/18.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/18.md @@ -1,5 +1,6 @@ - - +_**type:code left**_ + +_**title:size()**_ ## `size()` @@ -20,8 +21,8 @@ def size(self): ------------------------------------------------- -[for speaker]: <> (In order to find the size of a linked list, we can define our `size[]` function as being able to count nodes until it doesn't find any more, and return the amount of nodes it found.) +[for speaker]: <> In order to find the size of a linked list, we can define our `size[]` function as being able to count nodes until it doesn't find any more, and return the amount of nodes it found. -[for speaker]: <> (The method begins with the "head" node and travels through the list using the `next_node` pointers to reach the next node until the `current` node becomes None. Once it reaches that point, it will return the number of nodes that it encountered along the way.) +[for speaker]: <> The method begins with the "head" node and travels through the list using the `next_node` pointers to reach the next node until the `current` node becomes None. Once it reaches that point, it will return the number of nodes that it encountered along the way. -[for speaker]: <> (The time complexity of size is O[n] because each time the method is called it will always visit every node in the list but only interact with them once, so n * 1 operations.) \ No newline at end of file +[for speaker]: <> The time complexity of size is O[n] because each time the method is called it will always visit every node in the list but only interact with them once, so n * 1 operations. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/19.md b/Leetcode Workshops/Week 2/Act1_Linked list/19.md index 1c8c3df..7f577dd 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/19.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/19.md @@ -1,5 +1,6 @@ - - +_**type:small code snipet**_ + +_**title:call size()**_ ## Call `size()` ```python diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/20.md b/Leetcode Workshops/Week 2/Act1_Linked list/20.md index 7f6540d..f0d6078 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/20.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/20.md @@ -1,5 +1,6 @@ - - +_**type:link**_ + +_**title:Visual of `size()`**_ ## Visual of `size()` @@ -9,4 +10,4 @@ ------------------------------------------------- -[for speaker]: <> (To further implement a linked list, we'll see that the `search[]` function is actually very similar to `size[]`.) \ No newline at end of file +[for speaker]: <> To further implement a linked list, we'll see that the `search[]` function is actually very similar to `size[]`. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/21.md b/Leetcode Workshops/Week 2/Act1_Linked list/21.md index 7160da3..048d28d 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/21.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/21.md @@ -1,5 +1,6 @@ - - +_**type:code step1**_ + +_**title:search()**_ ## `search()` ```python @@ -12,4 +13,4 @@ def search(self, data): - Initalize found as False ------------------------------------------------- -[for speaker]: <> (Now, if we want to find a certain node in our linked list, we can use a search method!) \ No newline at end of file +[for speaker]: <> Now, if we want to find a certain node in our linked list, we can use a search method! \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/22.md b/Leetcode Workshops/Week 2/Act1_Linked list/22.md index 08bcef4..6580ed9 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/22.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/22.md @@ -1,5 +1,6 @@ - - +_**type:code step2**_ + +_**title:search()**_ ## `search()` ```python while current and found is False: @@ -13,5 +14,5 @@ ------------------------------------------------- -[for speaker]: <> (At each node, the `search[]` function will check to see if the data matches the data it's looking for. If so, then it will return the node that holds the requested data. If not, then it will just continue to go to the next node.) +[for speaker]: <> At each node, the `search[]` function will check to see if the data matches the data it's looking for. If so, then it will return the node that holds the requested data. If not, then it will just continue to go to the next node. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/23.md b/Leetcode Workshops/Week 2/Act1_Linked list/23.md index cc03127..d7de770 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/23.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/23.md @@ -1,5 +1,6 @@ - - +_**type:code step3**_ + +_**title:search()**_ ## `search()` ```python if current is None: @@ -11,6 +12,6 @@ ------------------------------------------------- -[for speaker]: <> (Should the function not find the data at all, it will return an error notifying the user that the data is not in the list. Note: If the function goes through the entire list without finding the data, that is also our worst-case scenario, meaning our worst-case time complexity is O[N].) +[for speaker]: <> Should the function not find the data at all, it will return an error notifying the user that the data is not in the list. Note: If the function goes through the entire list without finding the data, that is also our worst-case scenario, meaning our worst-case time complexity is O[N]. -[for speaker]: <> (Now, if we want to find a certain node in our linked list, we can use a search method!) \ No newline at end of file +[for speaker]: <> Now, if we want to find a certain node in our linked list, we can use a search method! \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/24.md b/Leetcode Workshops/Week 2/Act1_Linked list/24.md index 7732316..03feb1c 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/24.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/24.md @@ -1,5 +1,6 @@ - - +_**type:small code snipet1**_ + +_**title:Call search()**_ ## Call `search()` ```python print(film.search(1000)) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/25.md b/Leetcode Workshops/Week 2/Act1_Linked list/25.md index b6f4967..81060d4 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/25.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/25.md @@ -1,5 +1,5 @@ - - +_**type:Link**_ +_**title:Visual of search()**_ ## Visual of search() ![
] @@ -7,6 +7,6 @@ ------------------------------------------------- -[for speaker]: <> (This is a visual representation of searching for an element in a linked list.) +[for speaker]: <> This is a visual representation of searching for an element in a linked list. -[for speaker]: <> (Now that we've covered how to implement and create the different functions and attributes of a linked list, we can put everything together!) \ No newline at end of file +[for speaker]: <> Now that we've covered how to implement and create the different functions and attributes of a linked list, we can put everything together! \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/26.md b/Leetcode Workshops/Week 2/Act1_Linked list/26.md index 5247aea..2233ffe 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/26.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/26.md @@ -1,7 +1,8 @@ - - +_**type:headline**_ + +_**title:Let's creat a linked list for a film production company**_ ## Let's creat a linked list for a film production company ------------------------------------------------- -[for speaker]: <> (Now that we have our Linked List implementation, we can put it to work! Assume we work at a film production company and we're holding auditions! The auditions begin at 9:00 in the morning.) \ No newline at end of file +[for speaker]: <> Now that we have our Linked List implementation, we can put it to work! Assume we work at a film production company and we're holding auditions! The auditions begin at 9:00 in the morning. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/27.md b/Leetcode Workshops/Week 2/Act1_Linked list/27.md index 025c2a2..5182db0 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/27.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/27.md @@ -1,5 +1,6 @@ - - +_**type:code step1**_ + +_**title:Create the class and the first node**_ ## Step 1: Create the class and the first node ```python film = LinkedList() diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/28.md b/Leetcode Workshops/Week 2/Act1_Linked list/28.md index 97b1f13..0ec2072 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/28.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/28.md @@ -1,5 +1,6 @@ - - +_**type:centered text**_ + +_**title:none**_ - Let's build onto our Linked List for the duration of our film audition appointments. - Each succeeding node will represent another scheduled audition, each 30 minutes apart. @@ -7,4 +8,4 @@ ------------------------------------------------- -[for speaker]: <> (Now that we have intialized our Linked List with a head node, we will continue to build onto our Linked List for the duration of our film audition appointments.) \ No newline at end of file +[for speaker]: <> Now that we have intialized our Linked List with a head node, we will continue to build onto our Linked List for the duration of our film audition appointments. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/29.md b/Leetcode Workshops/Week 2/Act1_Linked list/29.md index 3c4cfa9..4155532 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/29.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/29.md @@ -1,5 +1,6 @@ - - +_**type:code step2**_ + +_**title:Step2:**_ ## Step2: ### One way: creating a new node and setting it as the next node following the previous node @@ -15,5 +16,5 @@ node1.set_next(node2) ------------------------------------------------- -[for speaker]: <> (Since the first node in our Linked List is the head, we then call `film.head.set_next[node1]` in order to assign `node1` as the next node following the head. - Now that `node1` is the tail of our Linked List `film`, we next call `node1.set_next[node2]` in order to assign `node2` as the next node following the tail, `node1`.) \ No newline at end of file +[for speaker]: <> Since the first node in our Linked List is the head, we then call `film.head.set_next[node1]` in order to assign `node1` as the next node following the head. + Now that `node1` is the tail of our Linked List `film`, we next call `node1.set_next[node2]` in order to assign `node2` as the next node following the tail, `node1`. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/3.md b/Leetcode Workshops/Week 2/Act1_Linked list/3.md index 5bd84e9..905260b 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/3.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/3.md @@ -1,5 +1,7 @@ - - +_**type:Centered text**_ + +_**title:Reference**_ + ## Reference @@ -9,4 +11,4 @@ ------------------------------------------------- -[for speaker]: <> (In a singly linked list, each node [or pearl] has one single reference to the next node [or pearl]s in the list. A doubly linked list instead has two references, one for the next node, and one for the previous node. The last node in all linked lists points to a "null" node, signfying the end of the list.) \ No newline at end of file +[for speaker]: <> In a singly linked list, each node [or pearl] has one single reference to the next node [or pearl]s in the list. A doubly linked list instead has two references, one for the next node, and one for the previous node. The last node in all linked lists points to a "null" node, signfying the end of the list. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/30.md b/Leetcode Workshops/Week 2/Act1_Linked list/30.md index 2a2e790..45eddec 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/30.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/30.md @@ -1,5 +1,6 @@ - - +_**type:code step2**_ + +_**title:Step2:**_ ## Step2: ### Another way: add a new node to our *film* Linked List is by using the *insert()* function. @@ -14,4 +15,4 @@ film.insert(1230) ``` ------------------------------------------------- -[for speaker]: <> ( Note: the `insert[]` function defined in the *LinkedList* class is capable of creating a new node with the designated data you pass and will assign it as the next node in your Linked List [only will append node to the END, or tail].) +[for speaker]: <> Note: the `insert[]` function defined in the *LinkedList* class is capable of creating a new node with the designated data you pass and will assign it as the next node in your Linked List [only will append node to the END, or tail]. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/31.md b/Leetcode Workshops/Week 2/Act1_Linked list/31.md index 21e806e..b0d1309 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/31.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/31.md @@ -1,9 +1,10 @@ - - +_**type:code step3**_ + +_**title:Use `size()` to verify the number of nodes**_ ## Use `size()` to verify the number of nodes ```python print(film.size()) ``` ------------------------------------------------- -[for speaker]: <> (Now we should have a Linked List that contains a total of 8 nodes that represent 8 appointments for auditions in succession. We can verify the number of nodes by using the size[] function) \ No newline at end of file +[for speaker]: <> Now we should have a Linked List that contains a total of 8 nodes that represent 8 appointments for auditions in succession. We can verify the number of nodes by using the size[] function \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/32.md b/Leetcode Workshops/Week 2/Act1_Linked list/32.md index 051a6a0..8b48882 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/32.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/32.md @@ -1,4 +1,5 @@ - - +_**type:centered text**_ + +_**title: Someone canceled their audition for 10:00 AM. Afterwards, a different person cancels their 12:30 PM appointment.**_ ### Someone canceled their audition for 10:00 AM. Afterwards, a different person cancels their 12:30 PM appointment. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/33.md b/Leetcode Workshops/Week 2/Act1_Linked list/33.md index c047605..8d14511 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/33.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/33.md @@ -1,5 +1,6 @@ - - +_**type:code step4**_ + +_**title:Use `delete()`**_ ## Use `delete()` ```python @@ -11,5 +12,5 @@ film.delete(1230) ------------------------------------------------- -[for speaker]: <> (To make sure their appointments are no longer in the system, we can use the `delete[]` function defined in the *LinkedList* class:) +[for speaker]: <> To make sure their appointments are no longer in the system, we can use the `delete[]` function defined in the *LinkedList* class: diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/34.md b/Leetcode Workshops/Week 2/Act1_Linked list/34.md index 856f466..277bbda 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/34.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/34.md @@ -1,5 +1,6 @@ - - +_**type:code step5**_ + +_**title:Check whether we removed the cancelled appointments**_ ## Check whether we removed the cancelled appointments ```python @@ -11,9 +12,9 @@ print(film.search(1230)) - We can also use `size()` to double check ------------------------------------------------- -[for speaker]: <> (To confirm that we have removed the canceled appointments, we will check that the corresponding nodes were deleted from our Linked List by searching for them) +[for speaker]: <> To confirm that we have removed the canceled appointments, we will check that the corresponding nodes were deleted from our Linked List by searching for them -[for speaker]: <> (Note: The first `search[]` function looking for the data point of 10:00 should return an error stating the data was not found [since the node has been deleted]. The same should happen for the 12:30 node.) +[for speaker]: <> Note: The first `search[]` function looking for the data point of 10:00 should return an error stating the data was not found [since the node has been deleted]. The same should happen for the 12:30 node. -[for speaker]: <> (To double check, we can also check again using the size[] function to identify that `film` now only contains 6 nodes in this order: 9:00, 9:30, 10:30, 11:00, 11:30, 12:00.) +[for speaker]: <> To double check, we can also check again using the size[] function to identify that `film` now only contains 6 nodes in this order: 9:00, 9:30, 10:30, 11:00, 11:30, 12:00. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/35.md b/Leetcode Workshops/Week 2/Act1_Linked list/35.md index 8e655dd..f503d81 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/35.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/35.md @@ -1,5 +1,6 @@ - - +_**type:code step6**_ + +_**title:Search for an existing appointment**_ ## Search for an existing appointment @@ -10,4 +11,4 @@ print(film.search(930)) - The output produced will show the address in memory where the node is stored in our Linked List *film*. ------------------------------------------------- -[for speaker]: <> (If we were to search for an existing appointment, we can do so in similar fashion) \ No newline at end of file +[for speaker]: <> If we were to search for an existing appointment, we can do so in similar fashion \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/36.md b/Leetcode Workshops/Week 2/Act1_Linked list/36.md index 331343a..2c703ee 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/36.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/36.md @@ -1,5 +1,6 @@ - - +_**type:code step7**_ + +_**title:Get the data in the node**_ ## Get the data in the node ```python print(film.search(930).get_data()) @@ -7,4 +8,4 @@ print(film.search(930).get_data()) - This outputs the data at the particular node we searched for, not the address of the node ------------------------------------------------- -[for speaker]: <> (In the case where we want to access the data in the node associated with 9:30 in `film`) \ No newline at end of file +[for speaker]: <> In the case where we want to access the data in the node associated with 9:30 in `film` \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/4.md b/Leetcode Workshops/Week 2/Act1_Linked list/4.md index 7c8d078..8b4a5a9 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/4.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/4.md @@ -1,5 +1,7 @@ - - +_**type:comparison left right**_ + +_**title: Advantages and Disadvantages of Linked list**_ + ## Advantages and Disadvantages of Linked list ### Advantages - Dynamic memory allocation @@ -10,8 +12,8 @@ ------------------------------------------------- -[for speaker]: <> (Many benefits come with using a linked list instead of any other similar data structure [like a static array]. This includes dynamic memory allocation--if one doesn't know the amount of data they want to store during initialization, a linked list can help with quickly adjusting the size of the list.) +[for speaker]: <> Many benefits come with using a linked list instead of any other similar data structure [like a static array]. This includes dynamic memory allocation--if one doesn't know the amount of data they want to store during initialization, a linked list can help with quickly adjusting the size of the list. -[for speaker]: <> (However, there are also several disadvantages to using a linked list. More space is used when dyanmically allocating memory [mostly for the reference to the next node], and if you want to access an item in the middle, you have to start at the "head" node and follow the references until reaching the item wanted.) +[for speaker]: <> However, there are also several disadvantages to using a linked list. More space is used when dyanmically allocating memory [mostly for the reference to the next node], and if you want to access an item in the middle, you have to start at the "head" node and follow the references until reaching the item wanted. -[for speaker]: <> (In practice, some insertions cost more. If the list initially allocates enough space for six nodes, inserting a seventh means the list has to double its space [up to 12].) +[for speaker]: <> In practice, some insertions cost more. If the list initially allocates enough space for six nodes, inserting a seventh means the list has to double its space [up to 12]. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/5.md b/Leetcode Workshops/Week 2/Act1_Linked list/5.md index 90547db..57ab4c4 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/5.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/5.md @@ -1,4 +1,5 @@ - - +_**type:Link**_ + +_**title:Linked list**_ ## Linked list visual ![
] \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/6.md b/Leetcode Workshops/Week 2/Act1_Linked list/6.md index 17ed25b..d9b100c 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/6.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/6.md @@ -1,5 +1,6 @@ - - +_**type:Centered text**_ + +_**title:Implementation of a linked list**_ ## Implementation of a linked list diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/7.md b/Leetcode Workshops/Week 2/Act1_Linked list/7.md index 15605e9..fe3d8e5 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/7.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/7.md @@ -1,5 +1,6 @@ - - +_**type:small code snipet1**_ + +_**title:class LinkedList**_ ## class `LinkedList` ```python class LinkedList(object): @@ -10,5 +11,6 @@ class LinkedList(object): ------------------------------------------------- -[for speaker]: <> (Now, we can create the start of our linked list! Luckily, the linked list (as a class) itself is actually the "head" node of the list!) -[for speaker]: <> (Note: Upon initialization, a list has no nodes, so the "head" node is set to None. Because a linked list doesn't necessarily need a node to initialized, the "head" node will, by default, set itself to None.) \ No newline at end of file +[for speaker]: <> Now, we can create the start of our linked list! Luckily, the linked list (as a class) itself is actually the "head" node of the list! + +[for speaker]: <> Note: Upon initialization, a list has no nodes, so the "head" node is set to None. Because a linked list doesn't necessarily need a node to initialized, the "head" node will, by default, set itself to None. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/8.md b/Leetcode Workshops/Week 2/Act1_Linked list/8.md index df08007..94fdc61 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/8.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/8.md @@ -1,5 +1,6 @@ - - +_**type:code centered**_ + +_**title:Implement the `Node` class**_ ## Implement the `Node` class ```python @@ -14,13 +15,13 @@ class Node(object): ------------------------------------------------- -[for speaker]: <> (Now we can implement the most important attribute of a linked list: the node!) +[for speaker]: <> Now we can implement the most important attribute of a linked list: the node! -[for speaker]: <> (It's a simple implementation of a `Node` class [a representation of the `Node` objects in a linked list].) +[for speaker]: <> It's a simple implementation of a `Node` class [a representation of the `Node` objects in a linked list]. -[for speaker]: <> (The node is where data is stored in the linked list; if a pearl was hollow and contained a bead inside, the bead would be the data. Along with the data, each node also holds a pointer which is a reference to the next node in the list. Note: if it was a doubly linked list, the reference to the previous node would be a pointer too.) +[for speaker]: <> The node is where data is stored in the linked list; if a pearl was hollow and contained a bead inside, the bead would be the data. Along with the data, each node also holds a pointer which is a reference to the next node in the list. Note: if it was a doubly linked list, the reference to the previous node would be a pointer too. -[for speaker]: <> (The node's data is initialized with data received at creation, and its pointer is set to None by default since the first node to be inserted into the will wouldn't have any other node to point to.) +[for speaker]: <> The node's data is initialized with data received at creation, and its pointer is set to None by default since the first node to be inserted into the will wouldn't have any other node to point to. -[for speaker]: <> (Each `Node` object contains data that can be retrieved via the `get_data` function and can get or set the next node via the functions `get_next` and `set_next` respectively.) +[for speaker]: <> Each `Node` object contains data that can be retrieved via the `get_data` function and can get or set the next node via the functions `get_next` and `set_next` respectively. diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/9.md b/Leetcode Workshops/Week 2/Act1_Linked list/9.md index bf443de..eea6791 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/9.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/9.md @@ -1,5 +1,6 @@ - - +_**type:code left**_ + +_**title:Implement functions**_ ## Implement functions ```python def get_data(self): @@ -19,4 +20,4 @@ ------------------------------------------------- -[for speaker]: <> (After implementing the class `Node`, then we can begin to implement functions to help with retrieving information about the specified `Node` object.) +[for speaker]: <> After implementing the class `Node`, then we can begin to implement functions to help with retrieving information about the specified `Node` object. From 28e6287a700d6443c422d675355c9c1d3e557cf5 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Wed, 26 Feb 2020 13:09:14 -0800 Subject: [PATCH 22/24] Update 2.md --- Leetcode Workshops/Week 2/Act1_Linked list/2.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Leetcode Workshops/Week 2/Act1_Linked list/2.md b/Leetcode Workshops/Week 2/Act1_Linked list/2.md index f058a2a..9b8c78f 100644 --- a/Leetcode Workshops/Week 2/Act1_Linked list/2.md +++ b/Leetcode Workshops/Week 2/Act1_Linked list/2.md @@ -1,5 +1,6 @@ - - +_**type:Centered text**_ + +_**title:Node in Linked List**_ ## Node in Linked List @@ -8,4 +9,4 @@ ------------------------------------------------- -[for speaker]: <> (To put it in the simplest terms, one can think of a linked list like a string of pearls. Each pearl in the string leads to the next. The first pearl on the string can be called the "head" pearl. In a linked list, the "head" node, as can be assumed, is the very first node in the list. Each node contains two things: some data associated with the node, and a reference to the next node in the list.) \ No newline at end of file +[for speaker]: <> To put it in the simplest terms, one can think of a linked list like a string of pearls. Each pearl in the string leads to the next. The first pearl on the string can be called the "head" pearl. In a linked list, the "head" node, as can be assumed, is the very first node in the list. Each node contains two things: some data associated with the node, and a reference to the next node in the list. \ No newline at end of file From d93f4906d4ef4c2f6aac3fd32479a1eb4152b522 Mon Sep 17 00:00:00 2001 From: Dadao-xiaoguaishou Date: Fri, 28 Feb 2020 23:30:00 -0800 Subject: [PATCH 23/24] Add 4.3.3 Binary heaps slides 1-29 --- .../Week 2/Act3_Binary Heaps/1.md | 5 +++++ .../Week 2/Act3_Binary Heaps/10.md | 10 +++++++++ .../Week 2/Act3_Binary Heaps/11.md | 17 ++++++++++++++ .../Week 2/Act3_Binary Heaps/12.md | 15 +++++++++++++ .../Week 2/Act3_Binary Heaps/13.md | 9 ++++++++ .../Week 2/Act3_Binary Heaps/14.md | 14 ++++++++++++ .../Week 2/Act3_Binary Heaps/15.md | 14 ++++++++++++ .../Week 2/Act3_Binary Heaps/16.md | 14 ++++++++++++ .../Week 2/Act3_Binary Heaps/17.md | 16 ++++++++++++++ .../Week 2/Act3_Binary Heaps/18.md | 7 ++++++ .../Week 2/Act3_Binary Heaps/19.md | 16 ++++++++++++++ .../Week 2/Act3_Binary Heaps/2.md | 13 +++++++++++ .../Week 2/Act3_Binary Heaps/20.md | 22 +++++++++++++++++++ .../Week 2/Act3_Binary Heaps/21.md | 17 ++++++++++++++ .../Week 2/Act3_Binary Heaps/22.md | 8 +++++++ .../Week 2/Act3_Binary Heaps/23.md | 14 ++++++++++++ .../Week 2/Act3_Binary Heaps/24.md | 8 +++++++ .../Week 2/Act3_Binary Heaps/25.md | 8 +++++++ .../Week 2/Act3_Binary Heaps/26.md | 8 +++++++ .../Week 2/Act3_Binary Heaps/27.md | 8 +++++++ .../Week 2/Act3_Binary Heaps/28.md | 8 +++++++ .../Week 2/Act3_Binary Heaps/29.md | 16 ++++++++++++++ .../Week 2/Act3_Binary Heaps/3.md | 9 ++++++++ .../Week 2/Act3_Binary Heaps/4.md | 10 +++++++++ .../Week 2/Act3_Binary Heaps/5.md | 10 +++++++++ .../Week 2/Act3_Binary Heaps/6.md | 10 +++++++++ .../Week 2/Act3_Binary Heaps/7.md | 15 +++++++++++++ .../Week 2/Act3_Binary Heaps/8.md | 15 +++++++++++++ .../Week 2/Act3_Binary Heaps/9.md | 12 ++++++++++ 29 files changed, 348 insertions(+) create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/1.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/10.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/11.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/12.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/13.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/14.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/15.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/16.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/17.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/18.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/19.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/2.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/20.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/21.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/22.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/23.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/24.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/25.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/26.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/27.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/28.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/29.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/3.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/4.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/5.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/6.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/7.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/8.md create mode 100644 Leetcode Workshops/Week 2/Act3_Binary Heaps/9.md diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/1.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/1.md new file mode 100644 index 0000000..e49f13a --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/1.md @@ -0,0 +1,5 @@ +_type: title slide_ + +_title: Binary Heaps_ + +# Binary Heaps diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/10.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/10.md new file mode 100644 index 0000000..8e7cf10 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/10.md @@ -0,0 +1,10 @@ +_type: Center img large_ + +_title: `insert()`_ +# `insert()` +![](https://runestone.academy/runestone/books/published/pythonds/_images/percUp.png) + +> Figure 2: Percolate the New Node up to Its Proper Position (MinHeap with the percUp method) + +----- +[for speaker]<> Notice that when we percolate an item up, we are restoring the heap property between the newly added item and the parent. We are also preserving the heap property for any siblings. Of course, **if the newly added item is very small, we may still need to swap it up another level**. In fact, **we may need to keep swapping until we get to the top of the tree while new item is smaller than its parent**. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/11.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/11.md new file mode 100644 index 0000000..ee1276f --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/11.md @@ -0,0 +1,17 @@ +_type: code step2_ + +_title:`percUp()`_ +# `percUp()` + +```python +def percUp(self,i): + while i // 2 > 0: + if self.heapList[i] < self.heapList[i // 2]: + tmp = self.heapList[i // 2] + self.heapList[i // 2] = self.heapList[i] + self.heapList[i] = tmp + i = i // 2 +``` +- Percolates a new item as far up in the tree as it needs to go to maintain the heap property. +----- +[for speaker]<> This depicts the `percUp` method, which percolates a new item as far up in the tree as it needs to go to maintain the heap property. Figure 2 represents the MinHeap (the parent node is less than or equal to the children node) with `percUp` method. MaxHeap (the parent node is greater than or equal to the children node) can be used `percUp` method when the inserting number is greater than the parent node. Here is where our wasted element in `heapList` is important. Notice that we can compute the parent of any node by using simple integer division. The parent of the current node can be computed by dividing the index of the current node by 2. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/12.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/12.md new file mode 100644 index 0000000..5a942f9 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/12.md @@ -0,0 +1,15 @@ +_type:code steps3_ + +_title: `insert()`_ +# `insert()` + +```python +def insert(self,k): + self.heapList.append(k) + self.currentSize = self.currentSize + 1 + self.percUp(self.currentSize) +``` +- Once a new item is appended to the tree, `percUp` takes over and positions the new item properly. + +---- +[for speaker]<> We are now ready to write the `insert` method (see below). Most of the work in the `insert` method is really done by `percUp`. Once a new item is appended to the tree, `percUp` takes over and positions the new item properly. diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/13.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/13.md new file mode 100644 index 0000000..cfc1cd5 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/13.md @@ -0,0 +1,9 @@ +_type: Centered text_ + +_title: `delMin()`_ +# `delMin()` + - Maintain the heap structure and heap order properties after the root has been removed + - Taking the last item in the list and moving it to the root position + - Pushing the new root node down the tree to its proper position. +----- +[for speaker]<> With the `insert` method properly defined, we can now look at the `delMin` method. Since the heap property requires that the root of the tree be the smallest item in the tree, finding the minimum item is easy. The hard part of `delMin` is restoring full compliance with the heap structure and heap order properties after the root has been removed. We can restore our heap in two steps. First, we will restore the root item by taking the last item in the list and moving it to the root position. Moving the last item maintains our heap structure property. However, we have probably destroyed the heap order property of our binary heap. Second, we will restore the heap order property by pushing the new root node down the tree to its proper position. diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/14.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/14.md new file mode 100644 index 0000000..d791b18 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/14.md @@ -0,0 +1,14 @@ +_type: Center img large_ + +_title: `delMin()`_ + +# `delMin()` +![](https://runestone.academy/runestone/books/published/pythonds/_images/percDown.png) + +> Figure 3: Percolating the Root Node down the Tree (delMin from MinHeaps) + + +---- +[for speaker]<> This shows the series of swaps needed to move the new root node to its proper position in the heap + +[for speaker]<> In order to maintain the heap order property, all we need to do is swap the root with its smallest child less than the root. After the initial swap, we may repeat the swapping process with a node and its children until the node is swapped into a position on the tree where it is already less than both children. The code for percolating a node down the tree is found in the `percDown` and `minChild` methods. We are going to introduce `percDown` first. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/15.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/15.md new file mode 100644 index 0000000..4da9a7e --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/15.md @@ -0,0 +1,14 @@ +_type: code steps4_ + +_title: `percDown()`_ +# `percDown()` +```python +def percDown(self,i): + while (i * 2) <= self.currentSize: + mc = self.minChild(i) + if self.heapList[i] > self.heapList[mc]: + tmp = self.heapList[i] + self.heapList[i] = self.heapList[mc] + self.heapList[mc] = tmp + i = mc +``` diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/16.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/16.md new file mode 100644 index 0000000..9ce495a --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/16.md @@ -0,0 +1,14 @@ +_type: code step5 _ + +_title: `minChild()`_ +# `minChild()` +```python +def minChild(self,i): + if i * 2 + 1 > self.currentSize: + return i * 2 + else: + if self.heapList[i*2] < self.heapList[i*2+1]: + return i * 2 + else: + return i * 2 + 1 +``` \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/17.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/17.md new file mode 100644 index 0000000..d19414e --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/17.md @@ -0,0 +1,16 @@ +_type: code steps6_ + +_title: `delmin()`_ +# `delmin()` + +```python +def delMin(self): + retval = self.heapList[1] + self.heapList[1] = self.heapList[self.currentSize] + self.currentSize = self.currentSize - 1 + self.heapList.pop() + self.percDown(1) + return retval +``` +---- +[for speaker]<> The code for the `delmin` operation is defined below. Note that once again the hard work is handled by a helper function, in this case `percDown`. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/18.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/18.md new file mode 100644 index 0000000..100da81 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/18.md @@ -0,0 +1,7 @@ +_type: Center img outline_ + +_title: Example of MaxHeap Deletion_ +# Example of MaxHeap Deletion + +![](https://i.imgur.com/652RHQs.png) +> Figure 3: Percolating the Root Node down the Tree (delMax from MaxHeaps) \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/19.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/19.md new file mode 100644 index 0000000..3a51224 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/19.md @@ -0,0 +1,16 @@ +_type:code step7 _ + +_title: `buildHeap()`_ +# `buildHeap()` +```python +def buildHeap(self,alist): + i = len(alist) // 2 + self.currentSize = len(alist) + self.heapList = [0] + alist[:] + while (i > 0): + self.percDown(i) + i = i - 1 +``` +- Build the heap in **𝑂(𝑛)** operations +--- +[for speaker]<> To finish our discussion of binary heaps, we will look at a method to build an entire heap from a list of keys. The first method you might think of may be like the following. Given a list of keys, you could easily build a heap by inserting each key one at a time. Since you are starting with a list of one item, the list is sorted and you could use binary search to find the right position to insert the next key at a cost of approximately **𝑂(log𝑛)** operations. However, remember that inserting an item in the middle of the list may require **𝑂(𝑛)** operations to shift the rest of the list over to make room for the new key. Therefore, to insert 𝑛 keys into the heap would require a total of **𝑂(𝑛log𝑛)** operations. However, if we start with an entire list then we can build the whole heap in **𝑂(𝑛)** operations. Below shows the code to build the entire heap: diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/2.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/2.md new file mode 100644 index 0000000..0a2e48c --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/2.md @@ -0,0 +1,13 @@ +_type: Centered text_ + +_title: Binary Heap properties_ + +# Binary Heap properties + +- Each node must be filled by the number of children, except the last level of the node if there is no children(object) available. +- New children must be added to the left-most available position. +- It is either an instance of a Min Heap or Max Heap. +- Binary heap is a complete binary tree. + +_________ +[for speaker]<> One interesting type of tree data structure is a Binary Heap, which is a type of binary tree. A binary tree can only have 0, 1, or 2 children. Binary Heaps have the following properties: \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/20.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/20.md new file mode 100644 index 0000000..62e3163 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/20.md @@ -0,0 +1,22 @@ +_type: left img + text_ + +_title:_ + + + +![](https://runestone.academy/runestone/books/published/pythonds/_images/buildheap.png) + +Initial Heap: [9, 6, 5, 2, 3] + + i = 2 : [9, 2, 5, 6, 3] + i = 1 : [2, 9, 5, 6, 3] + i = 0 : [2, 3, 5, 6, 9] + +--- +[for speaker]<>To visually interpret how the heap is built, with the above function, the figure will depict how it is built +Figure 4 shows the swaps that the `buildHeap` method makes as it moves the nodes in an initial tree of [9, 6, 5, 2, 3] into their proper positions. + +[for speaker]<> The `percDown` method ensures that the largest child is always moved down the tree and check the next set of children farther down in the tree to ensure that it is pushed as low as it can go. +The `percDown` method ensures that the largest child is always moved down the tree and check the next set of children farther down in the tree to ensure that it is pushed as low as it can go. + +[for speaker]<> In this case, initial list [9, 6, 5, 2, 3] turned to the list [2, 3, 5, 6, 9]. When **len(aList) = 5; i = len(aList) // 2, i = 2**, a number '2' at the lowest level of the tree swapped with the number '6'. When **i = 1**, the number '2' swapped with the number '9', because 2 is less than 9. Now, the number '2' is located in right position of the heap. The number '9' needed to swap to the lowest level of the tree after the comparison with the number '3'. It results in a swap with the number '3'. Now that the number '9' has been moved to the lowest level of the tree, no further swapping can be done. It is useful to compare the list representation of this series of swaps as shown in [Figure 4] \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/21.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/21.md new file mode 100644 index 0000000..44ad2c2 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/21.md @@ -0,0 +1,17 @@ +_type: code step8_ + +_title: Binary Heap implementation_ +# Binary Heap implementation +```python +bh = BinHeap() +bh.buildHeap([9,6,5,2,3]) +``` +--- +[for speaker]<> Now with our complete implementation of our Binary Heap (Min Heap) + +[for speaker]<> We can now test it out by generating a binary heap and then deleting the minimum element to determine if the functionality of our heap operates properly. Below we will define our binary heap `bh` by calling for the class constructor to intialize our structure. Then we will build our heap by passing in a list of elements. + +[for speaker]<> For reference, given the list `[9, 6, 5, 2 ,3]` + + + diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/22.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/22.md new file mode 100644 index 0000000..f5f7e6c --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/22.md @@ -0,0 +1,8 @@ +_type:Center img large_ + +_title: Binary Heap implementation_ +# Binary Heap implementation +![](https://runestone.academy/runestone/books/published/pythonds/_images/buildheap.png) + +--- +[for speaker]<> our implementation should produce the *Initial Heap* that is shown like this: \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/23.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/23.md new file mode 100644 index 0000000..6de7fd5 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/23.md @@ -0,0 +1,14 @@ +_type: code steps9 _ + +_title: Test Binary Heap_ +# Test Binary Heap + +```python +print(bh.delMin()) +print(bh.delMin()) +print(bh.delMin()) +print(bh.delMin()) +print(bh.delMin()) +``` +---- +[for speaker]<> To test if our Binary Heap functions appropriately as a Min Heap, we can call `delMin()` to retrieve the minimum value in our tree on each call. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/24.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/24.md new file mode 100644 index 0000000..f5c905e --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/24.md @@ -0,0 +1,8 @@ +_type:large code_ + - replace the code with img + +_title: First `delMin()`_ +# First `delMin()` +![img](https://i.imgur.com/SgrYZlc.png) + +- Retrieves node 2 diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/25.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/25.md new file mode 100644 index 0000000..c9a1b47 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/25.md @@ -0,0 +1,8 @@ +_type:large code_ + - replace the code with img + +_title: Second `delMin()`_ +# Second `delMin()` +img + + - Retrieves node 3 \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/26.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/26.md new file mode 100644 index 0000000..88a2e29 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/26.md @@ -0,0 +1,8 @@ +_type:large code_ + - replace the code with img + +_title: Third `delMin()`_ +# Third `delMin()` +img + + - Retrieves node 5 \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/27.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/27.md new file mode 100644 index 0000000..61ec88f --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/27.md @@ -0,0 +1,8 @@ +_type:large code_ + - replace the code with img + +_title: Fourth `delMin()`_ +# Fourth `delMin()` +img + +- Retrieves node 6 \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/28.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/28.md new file mode 100644 index 0000000..f90dbe5 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/28.md @@ -0,0 +1,8 @@ +_type:large code_ + - replace the code with img + +_title: Fifth `delMin()`_ +# Fifth `delMin()` +img + +- Retrieves node 9. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/29.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/29.md new file mode 100644 index 0000000..6ac051b --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/29.md @@ -0,0 +1,16 @@ +_type: Centered text_ + +_title: `delMin()`_ +# `delMin()` + + +| delMin() Order | Print output | +| :------------: | :----------: | +| 1st | 2 | +| 2nd | 3 | +| 3rd | 5 | +| 4th | 6 | +| 5th | 9 | + +--- +[for speaker]<> The implementation should produce the *Initial Heap* list [2, 3, 5, 6, 9]. After each calling `delMin()`, the print statements will output our list from least to greatest which indicates our Binary/Min Heap functions as such! \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/3.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/3.md new file mode 100644 index 0000000..3e0da5f --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/3.md @@ -0,0 +1,9 @@ +_type: comparsion left right_ + +_title: Min Heap & Max Heap_ + +# Min Heap & Max Heap +A **Min Heap** is a heap where the root has the smallest key and the keys on the nodes get larger as you go down the tree. + +A **Max Heap** is a heap where the root has the largest key and the keys on the nodes get smaller as you go down the tree. + diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/4.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/4.md new file mode 100644 index 0000000..d02f18c --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/4.md @@ -0,0 +1,10 @@ +_type: center img outline_ + +_title: Min Heap & Max Heap_ + + + + + +---- +[for speaker]<> The image on the left is an example of a **Min Heap**. The image on the right is an example of a **Max Heap**. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/5.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/5.md new file mode 100644 index 0000000..d717c9b --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/5.md @@ -0,0 +1,10 @@ +_type: center img outline_ + +_title: Valid vs. Invalid Max Heaps_ + +# Valid vs. Invalid Max Heaps: + + + +________ +[for speaker]<> The right tree is invalid heap-order, because 5 has a child 6, which is not the correct heap order. Left and right value of the subtrees must be less than or equal to the value at the parental node. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/6.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/6.md new file mode 100644 index 0000000..b197ef0 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/6.md @@ -0,0 +1,10 @@ +_type: centered text_ + +_title: Why we use Binary Heaps_ +# Why we use Binary Heaps + - Find the min/max of the tree in **O(1)** + - The root of a **Min Heap** is the min of the data + - The root of a **Max Heap** is the max of the data + + ______ +[for speaker]<> One useful attribute of **Binary Heaps** is the ability to find the min/max of the tree in **O(1)** time because the root of a **Min Heap** is the min of the data and the root of a **Max Heap** is the max of the data. diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/7.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/7.md new file mode 100644 index 0000000..8fde758 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/7.md @@ -0,0 +1,15 @@ +_type: large code_ + - replace the code with img + +_title: Convert a list into a Binary Heap_ + +# Convert elements into a Binary Heap + +![](https://runestone.academy/runestone/books/published/pythonds/_images/heapOrder.png) + +- Start from index 1 instead of 0 + +------- +[for speaker]<> Given a list of elements, we want to be able to convert it into a Binary Heap. Below is an example of a list of numbers represented by a Min Heap + +[for speaker]<> Above figure represents the binary heap implementation in order of a Min Heap. You can read the figure by top level from left to right. When you represent the number in the list of array, you must put root at index 1 position, because it is easy to find parent and child node. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/8.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/8.md new file mode 100644 index 0000000..0783f17 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/8.md @@ -0,0 +1,15 @@ +_type:code steps1_ + +_title: Binary Heap Implementation_ +# Binary Heap Implementation + + +```python +class BinHeap: + def __init__(self): + self.heapList = [0] + self.currentSize = 0 +``` + +_____ +[for speaker]<> Now to view this programmatically, we will define a Binary Heap implementation representing a Min Heap. We will begin our implementation of a binary heap with the constructor. Since the entire binary heap can be represented by a single list, all the constructor (`__init__`) will do is initialize the list and an attribute `currentSize` to keep track of the current size of the heap. You will notice that an empty binary heap has a single zero as the first element of `heapList` and that this zero is not used, but is there so that simple integer division can be used in later methods. \ No newline at end of file diff --git a/Leetcode Workshops/Week 2/Act3_Binary Heaps/9.md b/Leetcode Workshops/Week 2/Act3_Binary Heaps/9.md new file mode 100644 index 0000000..8a47f74 --- /dev/null +++ b/Leetcode Workshops/Week 2/Act3_Binary Heaps/9.md @@ -0,0 +1,12 @@ +_type: Centered text_ + +_title: `insert()`_ + +# `insert()` +- Maintain the complete tree property +- Maintain the heap structure property + - Compare with its parent + - if less than its parent, then swap + +----- +[for speaker]<> The next method we will implement is `insert`. The easiest, and most efficient, way to add an item to a list is to simply append the item to the end of the list. The good news about appending is that it guarantees that we will maintain the complete tree property. The bad news about appending is that we will very likely violate the heap structure property. However, it is possible to write a method that will allow us to regain the heap structure property by comparing the newly added item with its parent. If the newly added item is less than its parent, then we can swap the item with its parent. The figure below shows the series of swaps needed to percolate the newly added item up to its proper position in the tree \ No newline at end of file From 03377fdd07b451e4f72730f7fb22e2c566aac770 Mon Sep 17 00:00:00 2001 From: JasonL24 <32722492+JasonL24@users.noreply.github.com> Date: Sun, 1 Mar 2020 15:18:16 -0800 Subject: [PATCH 24/24] Styled Components Workshop --- Other/React/Styled Components Workshop/1.md | 6 +++ Other/React/Styled Components Workshop/10.md | 4 ++ Other/React/Styled Components Workshop/11.md | 9 +++++ Other/React/Styled Components Workshop/12.md | 7 ++++ Other/React/Styled Components Workshop/13.md | 17 ++++++++ Other/React/Styled Components Workshop/14.md | 7 ++++ Other/React/Styled Components Workshop/15.md | 19 +++++++++ Other/React/Styled Components Workshop/16.md | 12 ++++++ Other/React/Styled Components Workshop/17.md | 17 ++++++++ Other/React/Styled Components Workshop/18.md | 19 +++++++++ Other/React/Styled Components Workshop/19.md | 37 ++++++++++++++++++ Other/React/Styled Components Workshop/2.md | 5 +++ Other/React/Styled Components Workshop/20.md | 9 +++++ Other/React/Styled Components Workshop/21.md | 27 +++++++++++++ Other/React/Styled Components Workshop/22.md | 8 ++++ Other/React/Styled Components Workshop/23.md | 7 ++++ Other/React/Styled Components Workshop/24.md | 26 ++++++++++++ Other/React/Styled Components Workshop/25.md | 22 +++++++++++ Other/React/Styled Components Workshop/26.md | 6 +++ Other/React/Styled Components Workshop/27.md | 13 ++++++ Other/React/Styled Components Workshop/28.md | 7 ++++ Other/React/Styled Components Workshop/29.md | 16 ++++++++ Other/React/Styled Components Workshop/3.md | 5 +++ Other/React/Styled Components Workshop/30.md | 7 ++++ Other/React/Styled Components Workshop/31.md | 21 ++++++++++ Other/React/Styled Components Workshop/32.md | 7 ++++ Other/React/Styled Components Workshop/33.md | 31 +++++++++++++++ Other/React/Styled Components Workshop/34.md | 7 ++++ Other/React/Styled Components Workshop/35.md | 5 +++ Other/React/Styled Components Workshop/36.md | 4 ++ Other/React/Styled Components Workshop/37.md | 8 ++++ Other/React/Styled Components Workshop/4.md | 8 ++++ Other/React/Styled Components Workshop/5.md | 4 ++ Other/React/Styled Components Workshop/6.md | 11 ++++++ Other/React/Styled Components Workshop/7.md | 13 ++++++ Other/React/Styled Components Workshop/8.md | 15 +++++++ Other/React/Styled Components Workshop/9.md | 9 +++++ .../Styled Components Workshop/darkSky.jfif | Bin 0 -> 4209 bytes .../Styled Components Workshop/react.png | Bin 0 -> 3426 bytes .../Styled Components Workshop/weatherapp.jpg | Bin 0 -> 16979 bytes 40 files changed, 455 insertions(+) create mode 100644 Other/React/Styled Components Workshop/1.md create mode 100644 Other/React/Styled Components Workshop/10.md create mode 100644 Other/React/Styled Components Workshop/11.md create mode 100644 Other/React/Styled Components Workshop/12.md create mode 100644 Other/React/Styled Components Workshop/13.md create mode 100644 Other/React/Styled Components Workshop/14.md create mode 100644 Other/React/Styled Components Workshop/15.md create mode 100644 Other/React/Styled Components Workshop/16.md create mode 100644 Other/React/Styled Components Workshop/17.md create mode 100644 Other/React/Styled Components Workshop/18.md create mode 100644 Other/React/Styled Components Workshop/19.md create mode 100644 Other/React/Styled Components Workshop/2.md create mode 100644 Other/React/Styled Components Workshop/20.md create mode 100644 Other/React/Styled Components Workshop/21.md create mode 100644 Other/React/Styled Components Workshop/22.md create mode 100644 Other/React/Styled Components Workshop/23.md create mode 100644 Other/React/Styled Components Workshop/24.md create mode 100644 Other/React/Styled Components Workshop/25.md create mode 100644 Other/React/Styled Components Workshop/26.md create mode 100644 Other/React/Styled Components Workshop/27.md create mode 100644 Other/React/Styled Components Workshop/28.md create mode 100644 Other/React/Styled Components Workshop/29.md create mode 100644 Other/React/Styled Components Workshop/3.md create mode 100644 Other/React/Styled Components Workshop/30.md create mode 100644 Other/React/Styled Components Workshop/31.md create mode 100644 Other/React/Styled Components Workshop/32.md create mode 100644 Other/React/Styled Components Workshop/33.md create mode 100644 Other/React/Styled Components Workshop/34.md create mode 100644 Other/React/Styled Components Workshop/35.md create mode 100644 Other/React/Styled Components Workshop/36.md create mode 100644 Other/React/Styled Components Workshop/37.md create mode 100644 Other/React/Styled Components Workshop/4.md create mode 100644 Other/React/Styled Components Workshop/5.md create mode 100644 Other/React/Styled Components Workshop/6.md create mode 100644 Other/React/Styled Components Workshop/7.md create mode 100644 Other/React/Styled Components Workshop/8.md create mode 100644 Other/React/Styled Components Workshop/9.md create mode 100644 Other/React/Styled Components Workshop/darkSky.jfif create mode 100644 Other/React/Styled Components Workshop/react.png create mode 100644 Other/React/Styled Components Workshop/weatherapp.jpg diff --git a/Other/React/Styled Components Workshop/1.md b/Other/React/Styled Components Workshop/1.md new file mode 100644 index 0000000..01a4fb4 --- /dev/null +++ b/Other/React/Styled Components Workshop/1.md @@ -0,0 +1,6 @@ +**Type: title Slide** +**Title: React Weather Application** + +# React Weather Application + +Note to Rochelle: Since this workshop didn't have any cards, I just went in a normal numerical order for the slide cards. \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/10.md b/Other/React/Styled Components Workshop/10.md new file mode 100644 index 0000000..631464c --- /dev/null +++ b/Other/React/Styled Components Workshop/10.md @@ -0,0 +1,4 @@ +**Type: Main Point** +**Title: Components** + +# Components \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/11.md b/Other/React/Styled Components Workshop/11.md new file mode 100644 index 0000000..1b88e35 --- /dev/null +++ b/Other/React/Styled Components Workshop/11.md @@ -0,0 +1,9 @@ +**Type: left img + text** +**Title: Components** + +# Componenets +* React apps are built with the idea of **components** +* Pieces of your application that encapsulate all their data, state, styling, subcomponents, etc. +* Components can then be composed together to create complex UIs + +[React](./react.png) \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/12.md b/Other/React/Styled Components Workshop/12.md new file mode 100644 index 0000000..399282c --- /dev/null +++ b/Other/React/Styled Components Workshop/12.md @@ -0,0 +1,7 @@ +**Type: Side Text** +**Title: Component Types** + +### Stateful Components +* Has internal data and updates every time its data changes +### Stateless/Functional Components +* Does not have internal state but renders based on the properties passed to it \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/13.md b/Other/React/Styled Components Workshop/13.md new file mode 100644 index 0000000..975e74c --- /dev/null +++ b/Other/React/Styled Components Workshop/13.md @@ -0,0 +1,17 @@ +**Type: code centered** +**Title: Component Structure** + +# Component Structure + +```js +export class App extends Component { + state = { + } + componentDidMount() { + } + render() { + return ( + ) + } +} +``` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/14.md b/Other/React/Styled Components Workshop/14.md new file mode 100644 index 0000000..547f00e --- /dev/null +++ b/Other/React/Styled Components Workshop/14.md @@ -0,0 +1,7 @@ +**Type: Side Text** +**Title: App Component Purpose** + +# App Component Purpose +* Manage the state of the whole application +* Will contain `isLoading` and `requested` pieces of state +* `componentDidMount` triggers only once, right when the component is mounted \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/15.md b/Other/React/Styled Components Workshop/15.md new file mode 100644 index 0000000..43f976f --- /dev/null +++ b/Other/React/Styled Components Workshop/15.md @@ -0,0 +1,19 @@ +**Type: Small Code Snippet** +**Title: componentDidMount** + +# componentDidMount +```js + componentDidMount() { + getCoords(({ coords }) => { + fetch(`${baseurl}${secretKey}/${coords.latitude},${coords.longitude}`) + .then(res => res.json()) + .then(dat => dat.currently) + .then(requested => { + this.setState({ isLoading: false, requested }) + }) + }) + } + ``` + +* Place our API call in `componentDidMount` +* Only triggered once when component is mounted to DOM \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/16.md b/Other/React/Styled Components Workshop/16.md new file mode 100644 index 0000000..ee0bcd9 --- /dev/null +++ b/Other/React/Styled Components Workshop/16.md @@ -0,0 +1,12 @@ +**Type: Small Code Snippet** +**Title: App Component State** + +```js + state = { + isLoading: true, + requested: null + } +``` + +* `requested` stores the result of our API call +* `isLoading` tells us weather the API request has completed yet \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/17.md b/Other/React/Styled Components Workshop/17.md new file mode 100644 index 0000000..226b117 --- /dev/null +++ b/Other/React/Styled Components Workshop/17.md @@ -0,0 +1,17 @@ +**Type: code left/right** +**Title: Dark Sky Request** + +# Dark Sky Request + +```js +fetch(`${baseurl}${secretKey}/${coords.latitude},$ {coords.longitude}`) + .then(res => res.json()) + .then(dat => dat.currently) + .then(requested => { + this.setState({ isLoading: false, requested }) + }) +``` + +* API exposes the `/forecast` endpoint +* Parse JSON response into component state +* Calling `setState()` re-renders the `App` component \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/18.md b/Other/React/Styled Components Workshop/18.md new file mode 100644 index 0000000..2922215 --- /dev/null +++ b/Other/React/Styled Components Workshop/18.md @@ -0,0 +1,19 @@ +**Type: Small Code Snippet** +**Title: Render** + +# Render + +```js + render() { + return ( + + {this.state.isLoading ? Loading... : null} + {this.state.requested ? : null} + + ) + } +``` + +* Will render the `Loading` component if `App` component's `isLoading` state piece is **true** +* Will render the `Weather` component if `App` component's `requested` state piece is **true** +* Passes `dat` as a **property** \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/19.md b/Other/React/Styled Components Workshop/19.md new file mode 100644 index 0000000..efcc17d --- /dev/null +++ b/Other/React/Styled Components Workshop/19.md @@ -0,0 +1,37 @@ +**Type: Code Centered** +**Title: Full App Component** + +# Full App Component + +```js +import React, { Component } from 'react' +import styled from 'styled-components' +import { secretKey, getCoords, baseurl } from '../index' +import { Loading } from './Loading' +import { Weather } from './Weather' +import { Card } from './Card' +export class App extends Component { + state = { + isLoading: true, + requested: null + } + componentDidMount() { + getCoords(({ coords }) => { + fetch(`${baseurl}${secretKey}/${coords.latitude},${coords.longitude}`) + .then(res => res.json()) + .then(dat => dat.currently) + .then(requested => { + this.setState({ isLoading: false, requested }) + }) + }) + } + render() { + return ( + + {this.state.isLoading ? Loading... : null} + {this.state.requested ? : null} + + ) + } +} +``` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/2.md b/Other/React/Styled Components Workshop/2.md new file mode 100644 index 0000000..170433a --- /dev/null +++ b/Other/React/Styled Components Workshop/2.md @@ -0,0 +1,5 @@ +**type: Link** +**Title: Source Code and Demo** + +Source Code +Demo diff --git a/Other/React/Styled Components Workshop/20.md b/Other/React/Styled Components Workshop/20.md new file mode 100644 index 0000000..6f4b17b --- /dev/null +++ b/Other/React/Styled Components Workshop/20.md @@ -0,0 +1,9 @@ +**Type: Centered Text** +**Title: animation.js** + +# animation.js + +* Not a React component +* Provides smooth transitions to display data +* Use JavaScript source code for this file +* Animations not covered in this workshop \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/21.md b/Other/React/Styled Components Workshop/21.md new file mode 100644 index 0000000..c574f80 --- /dev/null +++ b/Other/React/Styled Components Workshop/21.md @@ -0,0 +1,27 @@ +**Type: ** +**Title: Card.js Component** + +# Card.js Component + +```js +import styled from 'styled-components' +export const Card = styled.div` + width: 100%; + height: 100%; + max-width: 300px; + max-height: 512px; + background: #fff; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: center; + @media (min-width: 500px) { + border-radius: 5px; + box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.24); + } +` +``` + +* The `Card` component serves as a container for our other components +* Doesn't need to read any properties or maintain any state +* `styled.div` function returns a new `React` component with the styles in the template literal \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/22.md b/Other/React/Styled Components Workshop/22.md new file mode 100644 index 0000000..fff28b8 --- /dev/null +++ b/Other/React/Styled Components Workshop/22.md @@ -0,0 +1,8 @@ +**Type: Centered Text** +**Title: Detail.js Component** + +# Detail.js Component +* Stateless component +* Only renders properties passed to it +* Will use two `styled-compoents` with flexbox property +* Uses our `FadeUp` animation \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/23.md b/Other/React/Styled Components Workshop/23.md new file mode 100644 index 0000000..3cb9ad9 --- /dev/null +++ b/Other/React/Styled Components Workshop/23.md @@ -0,0 +1,7 @@ +**Type: Side Text** +**Title: Detail.js Component Purpose** + +# Detail.js Component Purpose +* Displays the information obtained from Dark Sky API +* Extracts properties `wSpeed`, `humid`, `wGust`, `cover` +* Uses CSS to stylize this data \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/24.md b/Other/React/Styled Components Workshop/24.md new file mode 100644 index 0000000..ccc24c4 --- /dev/null +++ b/Other/React/Styled Components Workshop/24.md @@ -0,0 +1,26 @@ +**Type: code left/right** +**Title: Detail.js Styling** + +# Detail.js Styling +```js +const Container = styled.div` + width: 100%; + height: 200px; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: center; + margin-top: auto; + animation: ${FadeUp} 1s ease-out 0s; + font-size: 16px; +` +const Row = styled.div` + width: 100%; + height: 32px; + display: flex; + flex-direction: row; + justify-content: space-evenly; + align-items: center; + text-align: center; +` +``` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/25.md b/Other/React/Styled Components Workshop/25.md new file mode 100644 index 0000000..7392f71 --- /dev/null +++ b/Other/React/Styled Components Workshop/25.md @@ -0,0 +1,22 @@ +**Type: code left/right** +**Title: Details Export** + +# Details Export +```js +export const Details = ({ wSpeed, humid, wGust, cover }) => ( + + + Wind Speed: {wSpeed} + Humidity: {humid} + + + + Wind Gust: {wGust} + Cloud Cover: {cover} + + + +) +``` +* Exports `Details` to other components +* Extracts data and places them in **JSX** \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/26.md b/Other/React/Styled Components Workshop/26.md new file mode 100644 index 0000000..62f2439 --- /dev/null +++ b/Other/React/Styled Components Workshop/26.md @@ -0,0 +1,6 @@ +**Type: Side text** +**Title: Loading.js Component** + +# Loading.js Component +* Provides the styling when the API request is loading +* Is rendered in `App.js` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/27.md b/Other/React/Styled Components Workshop/27.md new file mode 100644 index 0000000..aaa5204 --- /dev/null +++ b/Other/React/Styled Components Workshop/27.md @@ -0,0 +1,13 @@ +**Type: Code left/right** +**Title: Loading.js** + +# Loading.js +```js +import styled from 'styled-components' +export const Loading = styled.p` + margin-top: auto; + margin-bottom: auto; +` +``` +* Sets top and bottom margins to auto +* Exports `Loading` element \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/28.md b/Other/React/Styled Components Workshop/28.md new file mode 100644 index 0000000..31edca9 --- /dev/null +++ b/Other/React/Styled Components Workshop/28.md @@ -0,0 +1,7 @@ +**Type: side text** +**Title: Summary.js Purpose** + +# Summary.js Purpose + +* Used to stylize the weather summary +* Stateless component \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/29.md b/Other/React/Styled Components Workshop/29.md new file mode 100644 index 0000000..3e34dfb --- /dev/null +++ b/Other/React/Styled Components Workshop/29.md @@ -0,0 +1,16 @@ +**Type: Code left/right** +**Title: Summary.js** + +```js +const Large = styled.p` + font-size: 24px; + animation: ${FadeLeft} 0.5s ease-out 0s; + text-align: center; +` + +export const Summary = ({ weather }) => {weather} +``` + +* Creates style element `Large` +* Uses `Large` to stylize the `weather` property in `Summary` +* Exports `Summary` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/3.md b/Other/React/Styled Components Workshop/3.md new file mode 100644 index 0000000..88a8615 --- /dev/null +++ b/Other/React/Styled Components Workshop/3.md @@ -0,0 +1,5 @@ +**Type: side text** +**Title: styled-components** + +**Text:** +[`styled-components`](https://www.styled-components.com/) is a library that creates styled [React](https://reactjs.org/) components in a clean, idiomatic way. We'll use `styled-components` to create a small weather app. \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/30.md b/Other/React/Styled Components Workshop/30.md new file mode 100644 index 0000000..3553ad3 --- /dev/null +++ b/Other/React/Styled Components Workshop/30.md @@ -0,0 +1,7 @@ +**Type: Side text** +*Title: Temperature.js Purpose** + +# Temperature.js Purpose +* Stylizes the display of the temperature from API +* Provides `FadeRight` animation to display data +* Exports a `Temperature` JSX element that displays the stylized `temp` variable \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/31.md b/Other/React/Styled Components Workshop/31.md new file mode 100644 index 0000000..a7a1774 --- /dev/null +++ b/Other/React/Styled Components Workshop/31.md @@ -0,0 +1,21 @@ +**Type: code left/right** +**Title: Temperature.js** + +# Temperature.js +```js +const Large = styled.p` + font-size: 32px; + animation: ${FadeRight} 0.5s ease-out 0s; + text-align: center; +` + +export const Temperature = ({ temp }) => ( + + {temp} + °F + +) +``` +* Exports `Temperature` JSX element +* Extracts `temp` property from API +* Uses `Large` styling in `Temperature` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/32.md b/Other/React/Styled Components Workshop/32.md new file mode 100644 index 0000000..c9dfc21 --- /dev/null +++ b/Other/React/Styled Components Workshop/32.md @@ -0,0 +1,7 @@ +**Type: centered text** +**Title: Weather.js Component** + +# Weather.js Component +* Stateless component +* Renders the app after we receive data from the Dark Sky's API +* Takes data passed to it through properties and routs it to the proper components for rendering \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/33.md b/Other/React/Styled Components Workshop/33.md new file mode 100644 index 0000000..78ce6e8 --- /dev/null +++ b/Other/React/Styled Components Workshop/33.md @@ -0,0 +1,31 @@ +**Type: code left/right** +**Title: Weather.js** + +# Weather.js +```js +const Container = styled.div` + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: center; +` + +export const Weather = ({ dat }) => ( + + + +
+ +) +``` +* Creates a stylized element `Container` +* `Container` wraps the JSX element `Weather` +* `Weather` extracts the API data from `dat` +* Passes the data as properties to the various components diff --git a/Other/React/Styled Components Workshop/34.md b/Other/React/Styled Components Workshop/34.md new file mode 100644 index 0000000..fb777d1 --- /dev/null +++ b/Other/React/Styled Components Workshop/34.md @@ -0,0 +1,7 @@ +**Type: Centered text** +**Title: Run the Application** + +# Run the Application +* Application code is completed +* Import the proper libraries/components in the source code +* Run `npm start` to run your application \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/35.md b/Other/React/Styled Components Workshop/35.md new file mode 100644 index 0000000..f3bd154 --- /dev/null +++ b/Other/React/Styled Components Workshop/35.md @@ -0,0 +1,5 @@ +**Type: Center Img Outline** +**Title: React Weather Application** + +# React Weather Application +[WeatherApp](./weatherapp.jpg) \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/36.md b/Other/React/Styled Components Workshop/36.md new file mode 100644 index 0000000..66fb75d --- /dev/null +++ b/Other/React/Styled Components Workshop/36.md @@ -0,0 +1,4 @@ +**Type: Main Point** +**Title: Any Questions?** + +# Any Questions? \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/37.md b/Other/React/Styled Components Workshop/37.md new file mode 100644 index 0000000..0f9f1d3 --- /dev/null +++ b/Other/React/Styled Components Workshop/37.md @@ -0,0 +1,8 @@ +**Type: Centered text** +**Title: Challenges** + +# Challenges +* Create a production build with `npm run build` +* Add a 'dark mode' option +* Toggle to Celsius on click +* Add a refresh button \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/4.md b/Other/React/Styled Components Workshop/4.md new file mode 100644 index 0000000..255a2d1 --- /dev/null +++ b/Other/React/Styled Components Workshop/4.md @@ -0,0 +1,8 @@ +**Type: left img + text** +**Title: Dark Sky API** + +**Img:** +![DarkSky](./darkSky.jfif) + +Text: +Use the free Dark Sky API to pull weather data for our application. \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/5.md b/Other/React/Styled Components Workshop/5.md new file mode 100644 index 0000000..8d45e06 --- /dev/null +++ b/Other/React/Styled Components Workshop/5.md @@ -0,0 +1,4 @@ +**Type: Main Point** +**Title: Setup** + +# Setup \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/6.md b/Other/React/Styled Components Workshop/6.md new file mode 100644 index 0000000..8b4da03 --- /dev/null +++ b/Other/React/Styled Components Workshop/6.md @@ -0,0 +1,11 @@ +**Type: Centered Text** +**Title: Initializing Workspace** + +# Initializing Workspace +#### Run the following commands: +`mkdir styled-weather` +`cd styled-weather` +`npm init` +#### Install the libraries: +`npm i react react-dom styled-components --save` +`npm i parcel-bundler --save-dev` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/7.md b/Other/React/Styled Components Workshop/7.md new file mode 100644 index 0000000..79173ef --- /dev/null +++ b/Other/React/Styled Components Workshop/7.md @@ -0,0 +1,13 @@ +**Type: Code Centered** +**Title: Scripts** + +# Scripts +Add the following in the `"scripts"` field of `package.json`: + +```json +"scripts": { + "test": "parcel src/index.html", + "start": "parcel src/index.html", + "build": "parcel build src/index.html" +}, +``` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/8.md b/Other/React/Styled Components Workshop/8.md new file mode 100644 index 0000000..9887152 --- /dev/null +++ b/Other/React/Styled Components Workshop/8.md @@ -0,0 +1,15 @@ +**Type: Centered Text** +**Title: Subdirectories** + +# Subdirectories + +Create these subdirectories in `styled-weather`: +* `src` +* `components` +In `src` create the following files: +* `index.html` +* `index.css` +* `index.js` +* `animation.js` + +Copy source code for `index.html`, `index.css`, `index.js` \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/9.md b/Other/React/Styled Components Workshop/9.md new file mode 100644 index 0000000..be0e902 --- /dev/null +++ b/Other/React/Styled Components Workshop/9.md @@ -0,0 +1,9 @@ +**Type: Link** +**Title: Secret Key** + +# Secret Key + +Obtain secret key from: +**Link:** darksky.net/dev + +Replace `` in `index.js` with your secret key from **Dark Sky** \ No newline at end of file diff --git a/Other/React/Styled Components Workshop/darkSky.jfif b/Other/React/Styled Components Workshop/darkSky.jfif new file mode 100644 index 0000000000000000000000000000000000000000..593b568d2b084c471ebc3e8e0b25b14938ab68cf GIT binary patch literal 4209 zcmbtWbyO5g*Wab3my(p0Si%LCPU(_dazP1UX;xB6L8M$tVkM=-1*D`w8U&?_u2M6~i%D;tx5SIuC5C5-K6-odQ7Y7#~9}k}xAOA0-8*5xV5Iz+< z0UJVfb=FD91t!Dpa5t#00BXip#Ko;(iO33k{j5hU|d+Dsm%6t$m85ovn;1= z;G@d%#Nd(NES+6%PtF4BK(@LmwPdLb%p~eO9dQ3A6gX1nnAaxxu00ZhWN;tPfRXHP zQnxt8hZxSEZ{bWgQ_#IEOP4P8bBHq`6#K!l%b82C7>}nO1Oln3D5|L7{WECio$Gra z25K=PSdC;lZ6hLvkerIrMvc74w;ELg$&kcVE15>lc&EkVGglcaPUVNYqRgD?$=qbqi!igt7txdXiV+X#k z6%`s4MfA_m{2uaB6UHrOf-FLa)<3bE+xr}R>9Uj;yRYq@5!t~O8g4G5N9qL8HV|JH?DX$lG3AGJykB&ea)7gys~Bqmuu2o zeZwq%)){}z_i=@s#DO;!qSy68+RXyCr)5%?Mr0K6Qs}mV!xdOnjU@Tw)(2Le43CQx zGtEWT&L^n_t>So>rCPC|c?DYLsmpfrD`+M~c0rx|wmGTx(u#=@(cH4~PwHEI?YY zunnUkR?&g~!n4BiGjHSg6>*N7vB1x7J+dG1YaE-JR1F5VSyT#3y~4F)Ei@48y4Ap- zMk`fA_qjbjbFmZ{T++W>7@0T~t9}r-D6fTUPR+!b!E{_%#vWe_-z8|r9-5Z@INW#0 zg+Q>W#fP;$U80*gy0YV>Ci&3lcH4lE%l!+1RUvXBVZlMSwCeU9D8(mL8FjL**{?*y zF5?5MfdVje4HHQh_q(hVO6gIR#r5ppr#U!cmdaJ=E7(}#xN6@@?R=^K$bbS)p=m`_ z4DX-$5*s^bWVYYxOiDA58*vlL)qV00p#cm1t_#*{s+A>^GqSD|w$w0qs?-Jh zK}1%nW!u(%ZS%VbThmV!hwELNN^85Mt%;WWoA^5#4XeVKbNmu|A9%u-sa#)kPAT*@ zj?(_Po`k6pR1MtyKIKR%d0#4fc^h7hAP?{3yZv}{J7U6;ssyCORg{cum=8^%)$q`! zKYgXTOIZ0pQg^Q(ioD~@R;3FG$UJklUS2u8`+Xly_XY`O3j1P8$kw)w!G5oOJ8E(% zR#qct8Sb;%cLC`<|Fob=L{Y)^~u$qJ8-z!IP$QMv+-l)vm5>Ewc>JMkMuKdTr$+9|Z zy@Xri5UoH)&FIggdP!u#wu9r(V@0*T3FK-^*vab{3NN@!Z3&%01lZVA3{E0lwIR2e}BU2Fs9q;{%PQ(u)jja|-O(ZuAzOTAi3G*3wQ z^TbbEQBi}J8xyM@?TsP3{v_Ngh5KGZ5)Fg$_9-YQ{Dbn6Xr=D2)L2siJzlPWN*l=m zHWqH=5or*1;KQ?76vOM=RNh5JiF@ab{T@GLMqEWw9{ri|&A;AuGQl*V;9pZqf%az( zPJjz0R_+bq2!b4K+?9a5WDAX1bIyS5Zz-K)LT>y$3&H*L&M(=iL!gGr4izJ>f%);_ z>4X`9FxSxl9LrqMYW#abLzItRcQHHObFU@%S1LZS31K9#zTc zbgP2;FMjYtrryBYHF}p6^~Xt+O3dwetd#EZj|4+wDquEOCco#=In|cacj_!oCcviN=(a!+ z1KHF3rWKYQzh>E(n3A4!KW?m!mh9`^Aq@C)e$2K5jDaLoWbL5A*E3Tjuh;-z;6ak| ziDh5@w%lyGtQL8*LBqZ)vbtek+)lBKZPHc0b8%S*SdvK&ZdmnzP|C9eng}kq z@9_gaXVz*}LH%1ani)bq=_MP0Xbk@OSL2!Tysc&c4`fS(2b#TKE}r3SOpDj2Wu?v6 z@R5-fC=X$>+({_4S1PM7+pI)rE>%fQ%O~pr7kV#QKRvBiV~80ZSJy}IE1~9cJD&D; z=4T*tM_iZLuvVD1t%9`!Wg}%GTGR;_?!WHkXY(cjeM~DuSHglZrnkR%@MT z$GW9L-Hr6G)QVSf2mlro;f1~}p%KUd0c%Y_r5^o*{8wUr@ zA3#esAB-J%Y4}+dB%-dV&nfuS6W}?28SAryNh%59Wj*>CayD=c2(xF=&0HW^kYVq_ zs0b#%O8O{?AQyLu3K4((&c?@S+_+ZqA>WxDYKZ5ZN!ZE}amq|1os8qXiztQ_7e;2O zwEzu{YrxG767Ghigq3m9KuM-ePUqDT`E-cLOWG2IkZy2V=OtGi2$^N@7a4i2QigENB zK-wDi{^Zm$ATAY?T#w=bjy6NenblrOO^eA@k%VgEN<>+wj=B9%6@rj6F@vO~EJ5CJ zLz#|V&npNP)XSf}^hnoOEzP&*E<-E!H1RcsXL0)5J*aCf_IOaBTn&1#>u-D@8Fw_H z?UBxJW8O@hW{2uPEJo}s6ZC;&kHvuLrUM+T(LA;tEPf3j ztY3A0EA6vO?XBy5=(avUPNDsUSo*AW1aV$3;6HeHNUUzaSZs#p z^9ps8*iCRZ4RDAV3-wqn*&!m{Dix1dCEA=y2=8qeZ84XZV1}&1(pm**v|rvbn{%?3 zA~%qu4`K#sT}*det(`d~uD!w)4u`{D$UZF=_Psb{_B7E^fW5Pe zxBg}}X?HU(e@ye|OKK9V|8VW(8n8cebC6%Y8IY~*B-dvNcq)r>c*AhuLoS&_qyd6c z*k7$l#NXWy2_zgnw*un0PesvMg+_G}>ed9t%C4F{8A(tH|zK-5F zd{fXM{Y+ImW&u0&*Kp*UL8Lh0My#--|K%-t9xeu+I7yopU#WQR364{?NrXT#->e>0 z_Lxv=$^kL`8yXLR#7zCqgbusFvN-9W$6^a(?aMJreIuXdRm3pZBXOzo6fw_kFsHYX zBe|D$Mj9vD0@pP-;lx^K(tW+SHa&^eIikGqMU^^wm3_SpXCz3B#XXF=O48ojQk52J zsgjk)k=U`2<^6Oi?PtcJr}4)_K2wAymcSr6$t?6Z+^o-KqV@=XFjmA|5rQxixhs z!`xbQa8mO^C#pZj5;550fxx#aUnLH;t3m`GXrYo&->9r;T{tLYznZg?@w94FaBs*w zN#VXA=OvSR>T5)D4A9+S$`QN@wxa1o_};3r5$M<`aCM7QlayC{n8C;0J>~X96GqdJ z7er%BALaYHVgK6(x&UWlUvOZf{MWkxo{plR=l01Sp3I*c(1APo^x1pdX#_=`{)dMc zYxqI$o(rv2DJe6yXx^PTeJEbk1(1s6b=QP^(8O?u% zirt}2QE2Jww5|i1^-o$XnRa+VE7+vf?a~mxs6i{Vgf;5jAGGhsw81~L#}eFL008SJ zGl&5+tY`<3(p;u>l_4&Ml*lZeOr<$r!OFX1MZbAD&lfx!HJ39sSA@NsBQeA#{om=w zXZL$W%o2pz7kW_hnEsh>>j;~~1TmlEz-7M?EoIgX+R)E}`Dd;#iARCi5nBSG<9%$O zZ}qkqaCwV%vw@mm`DK5N8?;4}-TB3e*v6d_x8P~tOsA*BZXk~|AD=nYKM(FdT)ngV zk3{{Qbwe$ii;xJb$EbN}(N=2Bmk(RXCZRiQqslq}K-3hs;Q zC%jF^NG&$}$bRR-kyx7Xc-ak*b_mJwM))HWRVD*>dRsos+YUWZ1Ylw`r&%Ofp8Wl- z2pjrY9O}K}wyG!`=)Cgt-VC_oV%$Sb(kYkCg06MVNRLGFc9%N~HfnE@DC%8G;)C3X z|JM*6V9Zsu1dMrQ&QOYDbJx|~k_LKl-*$hNjEWz&oY908=EXGD6m)=-jHc+y>EErx z(%X@~w*vWU4OOYWe_0*E%ZE63&ew4q55-z$$WBg)>B=Rm@A|UI{IW*=SFTMHo+U=AyVzRC7=^mjy;P>xWg$IfR zOHoHFfjQ}YH$oV~DI{Pl)O_b{Vni@HYnMKfQ^x3IO|s2MyHSAaLn})RzMK6zm9}q3 zupNau251UWv`&|{O+Pbt&U8wboeo%xbS!nP;=b#&;=nyFs38n!lW-S4$<+32J~Vg{ zq2zagD8_+xCzGa4jj7rA%(cX-SuiY@QguX5J#H!dI4srG4&L>~?Nz`V{Y@4IVO9)2 zHA1p8b})`7$_pVAd64O_?8=N=zqz3#*@k4`oG!5z_q|@oJZoh=ALN&f*=om;DqPjW zXXrIOUUJpxoBuPKy6ZjMs{K?1_K!i6)Pr#2NiiF~*(*PyL{GgOqpk4hr-N4nRp!f> zctx$`1C{wHVIR8!O0$cx`Kp_K?q6K(e>OlMVA@Hjwi<+CH+g`0n|j9 z7WDN_A&&WDm@7pTMMyC(h)ObSE22^~X5Woh(u_D$>ACnc`be)v<+G8;b`_J&4!wyT z%^np?>DRUBOV}}2?H2ig@4w!FE&&?y>qhP5LP<-q6OlxY>6#Rx`pvE_;xwUYHuQQi zLym0lF-U0;vUY&38&A)oGhn+m*gm~-x5PQUXI!Ro*6NbKe=r03Ds=nT0f^%#pPbw~ zGUltlhXD^5;qEs?Z7;$r_pqq?+J8h08PXpd1njYfvNM|BdP)%B(Ybs{>unl9Hurei z$z>;JFy6YeK}FN;oP)s9-XV3zHZatF)cZ8~Q}3ewoRgcBOpM&3)nc!Yt~5Qe>592v ze|IU~DhX-SD3p;p{WWUQ#F6 zA|$TKlfC!+-jlU&cx+7@G_z?zZ}kz36C@<VND7Wo71 z2BDTHe1RF|UBThLa`nDgl#AI}zi zC%GOq_t&5VXrIE2Jv6G_G@a^7UT(;X-PYi}U0J>tPm)VWwD18>RLEdZ4f^%Wd`S^8 zzN--)C!T*whuJ?Mi#;@)?9wH;Bxc+M#f)4IeN0cC^0a~*oA{~RoUG{NYcm3;vKot^ zH0KE8!&}1OKHm#ff}`5Y%0&5)4zKz@_8G;M!OwN_4g@Ef9tO4KD}R`a!>ljAhF@b! zKqdV1N%qD30Of)v=y03pBAGZ@l%C$gVzVZepU&^M&@vN8|cFxp4&WAkNesEeD##2JUMW$oXB&WYX1msp(Htp^p6q|GC+fJ@GwuW zU%GH>2ZpRp>y+X?*df!g0bt8Zk_d_YDyF%anM5*7uz95fxIG@S;Nlv<-BXHve%8Uoay`cU>Tv-C)IYz20N~p=W_F$fY zQbz9G+-k#;VVeg?Ku;zE>cO={D|IE0r0fyy!BlIpS8NlPUeR;2E4o#rW z_u3`3IAFH~kRVsW2~%XbFE*?v;9-^Ln&p$7UQNb+}~R8yh>uJIsvLfzIvUlf`_6`V`E2+P8p?T zHQwsN1O#tTdKtXl+T@7%+O%3%@{&b~tXYLRtMz%6_{4b#i%tJEX+>?De&EV)36gz< z>Bntgh`l%Z+V|yDo(sCssp+}Pvt8ZqK0TqFJy`e?uo|(Z3W;IX7j~6>hC@mouvYlt z7>l|*9}RI=;_vm1 z>T&I^MHOM9Y(nXY4o{5`HYOc+c^ri@WJ}~2+JnDvYlaI!J9X0F_4ZN#WsWlf?xA;ysTcI=_M@s{}o zaX)wLu=ZOnf#)ZDhY;bwaqhCP|?M*v1?s}}3Hk=>4-nY>cFjjvF@nqcdJV#|JU4XB9mzKDX zepn@BoT)||h-Zck@5Lu=_{vgl@~f&dM2V$Vm@CaQ-03`dXpcHa+b?$iKj?~PGL1en UxyL#BUo-*Cj4UApLzlS!0g+d`!TcAng}t=HBbfo4NPC_j~jE=XXQ)hn#cPUT3Yf_t|@`?^=iZ zjXMn3cEZ%c6tH2#20$?H55VmQ90&08@qPdDJ_5Y2;3h#q0Rh3yLP8riZP~nKi^ygX z5z(#U+eEjDZ50vOwtbtJgrt;|)E1z$%yvl`aY-r3?@TuE^ZEz~3JVGfONxq!O8&P$ z+;;%6O?-YELijiA1n`M%;1}D#Z3cht_QWPsWWxn}j!u@CYil0r)oX z^YaPtf0vp^jpSVi2#5)a?>Jz*QNre;&`w{;gW(C!H>n&eZIH74LRCF<$?vxC=Izol zvU0n2tL;(OIIN|ub3|9~_)jLLX66>qj&0bBSt@CJ`x3;+eNt;!yl`N+6FHGWwLhA~#6*bS^gN5G!!=)a`BEYzsXyy3(+ zjT=4WEKR4blq{X&0v=kevTvZ-0)*I*sNTm)eO_FE(rYfD3ilzmpcp;U3tE+4J5wI^ zR|%E>3jKa3lT&5E1!SesqUlICjT7ZbH`&T0ZA zZA|`>X4eZH6+?0X&Z=C%XRF|rP@_^VKsjb%ovg;W?S$9ukm? zEl<@vG~_&B!H;N87yM=>yMp-)@5`rGQuF6_UA&QY$trIqFiifL_JsUv^!-h0ek-dZ zxj{K416uZME#{NP{)+rOTuElg1Q$>#JqM(zy;Iuz1tCH0Y~lil#7{4;FO|3PTkYJV zVPqoUwh*9;Nj5mkJc{Ze@lR9`4BWJ{YA%;(x4b;BT&cSBI{B^GfzQHcZ(V;JfVbE4#;1;O~pb;FOhDk}_|{RU#faI3I>?==Q|o0@TtHvY$O?8&f?D6->~VcBX5?YNtJBN(=K%rE%xz_5v6TK&|J!b=tiAL3pQ)$4fK6aLgo7P9){G&QP#1|^M zuXx5^qR(fN9qz@4vxKf}Euy@NsH%D-Z7w{#voIl*6}&uN|Bwp2y}S^fDfDXD$4E7f zWY*pO{)`(U+)^K%b`VH6K{((Ba!YuIH3OW1Nn>SW?Xxtr8AH0<`MP zHb0KA&^H0s&yyzH87diR$$DFh9FlH@z*yym6US)MbD3HlDOkN3U|ySs{ zSZ{UQlvY+&=ODBudj^QQ4=V2DXr_(3pu}T1uHi@Wbi(R+99t&8yHSw3gKOWys0Wi#W9VT*Pmy3etz}2L$+z3*@x-S z{rQIncYP?wb#}ly1dY!1){?AKUoNgJ#Md82eKJy}Ud4=L%JwlxO&qnlxDQ@}u!`V0)mKzmK<^m$MfE#DZCLJ7tIu*Ja@3nkZR#u$$dO@|Gwf4$p zys+p&oE<5Kx7yc$;a%l}r!UDL|9s)P?mN2F7@BGiS=(&{ z-J6N3TOH^Z-9B9pA4BW77tVFF5|+4t+bDI^H;`Dl%nD|!Cuc`bd9_TobN{!-_vU!h zpIj;R-`LUD>-P@^!<*G8Oi!zVm>i}w{eiGVNGQtN=j{6qL>*HNH8jM>kfsKPBV>&}eQbW-KbG)m!K#+zLU0@TGdOpQhclPaZ4EXBWo$0 zkjMD~qgtym)@aAL06cI6HydA$Pl&Oe?bN^E%mqlNRnJVh!nuI0NvWLZr(D2rIu}4& z$45-%@2;C5U=t6&N;b{Ttf>iFFP(Zk-f4Z*Xi# zCC2XITPr%e?2(|kihO@>73dC*Y7GSlm63>Y(8I9mJ z#9wq$tt+%*R+2i`xqv9sTg=^EtC;LXqeupBqyQzyIz*Gc@2+zFnY-$+(x|$!!}tVC zBDKLEVZ+V}z$kcf0aNZ)X4MDZA9{LU27q2jTv?Z39%m_6F{Y?Zr>PP3SavwQ7j|%A zmV^FqD7nA-)>WDni&oJt0-CH`^>sYXw2Gzj`- zj_xJO2UXpM&TXqd6D0WcxzE7XLv5IE(QBFX81`M3JZ-@q8L0oVR+nNX6WV`yYhq~4 z<;%>`Gsl*T3fo|o(3$b}Ztch&m?=14l6mTzd5qA8 z538RJq%k3MaMy|=i0)3csxNr6tF!O?ZOdm3Cm%RqN-?qw2QEOMiJE#>i=hSE9vnS` zKj>7IxJM3H)@*J77fgRme~&5G)ZFp9B9b_y6}joOs&Cf2v;2U~#Ah#UA4$AT!sT%R z<5z4~G)(Q^L^Iop$kq(7G%E=t#07jiVa*0O34d)V5ENlFL?62WKiDxfrY$3O1wRlaK`x<;Ds*3hRCV%t`w#&mWB{8A~}5M@dd1CX%)?zukRJM8E26nUO4g zf0}%IzrOYJ=1*JMSV__ZUqTX z+0D?knHyiadFSSwwOdkx-YpTT1RF|u+NL&U)KzwI0S8xZ7Vbe4DxLsZA@FbL-m>V}a=eX(Zi2ZKp-XKt zQbB!_BizLpfXRyTjbIAseoaSu(7{RS2YV6w%UjPryQdPp2Be3U_ZsQ3PB1)%MO}$* zxeSE?OaJlb#A#W8kl`Y@jQs{BZbils{h$iL_YF*d;aW0o=PRtY>RQa5ck2u5Kczbt zXW|7`-#z$3SGzX5(qSox@L|wAUIz^G6eE1Hn#oU`nixeIQqAavJqQn)gbgEfq;oU6 z5j5g-4)wXR^yBWxGkBDPz$h0G8_eK&zHz~k*5biWo9Gz;PH)fbK2GNqc;2gS*=^c# z7JPTgx9SD$%w{K{6j^%+oV`G)V6`)}`3ht{v7X5Vh#$O%y11(Q;E)ouZYYZ#c5{pi zh*+atr#M|4e>E#^cIxOs|2wBK8q34WtE!}DX;?Dn(xXQnA1qF% zBzZ9CC>4I!V3%67k@B?mje*YG`2#JUpTa-ri*Hf}y$dMmd`FV5SF;)>NqQ=2Gkn;w z#U8$@m1)JUA&&5BNR7j_vOr8ZNeHU4tA&ebrF)2p)M&H(|H zxZyjkzR}CL7<4)QIqeP|MT>k%O=)+C3zZPp8m+{upY#TW#F}#yi#qG9_119}j@TNG ziw`_C2-$H4jd)p?%zNsdS`%Ehw?L&heVGy*@oBj$3(e?=)7O-?*H<|O)MCGidk}&G zP5d8h4Jm1*-(|naV%Q+bJ`zp0lxfoUSY`r2+BdBCL;~V&M5HG?c!<_u(HTj=r~p#< zx>0^k$B31Gvn#^Q{%x-d@sscgR-2M3u%nw;U&zkdS1;zwP!0Z0K-FUhDGInB7} zl@lD-wWUEoFYz#3LaHJy`!jcGWC5Z>PxI5jQY;vWpjAwNgdSO%7GKj`< zj2`LH^==Yk!APG$8JXN)+4KGjqN`^5qua zQgylKh9?SS^S>P3lBoLR#$<`1%+-Vo(OMd%g)gW1!Zc3o;RBU6VBrZ$Lsj1noS=Vh z3!|xQ==Qr4oe~Z3G%YO=I~H#ulgG~3v706?#G!x5{FL)2u+|U0i~0=o2mi#ruIM}u zQ#9mZib-66u@!&>;4 zgd_h(2mlC;{Rdi~{g3tN^9B>i(|<)1H2l#WCRBL+W|0j06Yu!i9|3It8|U~kezQY) z5i5QizN3FOoBt4?`)%m(#~|LnpxI#kyG>%w@yCcV>rb|fza%U6Js$bz!OUl&D&ikz zp`<98<@v3eZo}TL;`L?SuP`_3?CfK#YEvfbCy(EWbjk5=y+yB~!TLoS-UN3KgYIQl zMs?y!#Ym0?Gxa(`afUkf{;6drkP=qwFxb1U^bnF-Xzp}x=KU7dIri&3Mkw=Gu+uyH zG?(J>*aGA;$cn7a0yZRFKNoCf9cL3#=qzJX z;#|4iLgen5#?{u|dautciDH&5`xzpXwl7rv9^!<1c}=NBmVV>;*6l|XL$1Y7xR`~N zTftn}aU4i+zkTKNcJ10WW&EM96)x2(yEG|081Y?oh{K14>%@5t`y$(C zl}R?dQ?Ob#Xc`$rwvLf=&XA_gwMGZj@t+`Q>5B#X_^fOqs%_9Q|DruoC&?GYXS&hf zMLLRwBxAOF=*VT<$4u2!KE2+u`|X<=i%YR#0+Cl#`8Eh;Ix^HbpngU-9#p23RN`@P zXiAejZdr9Xw$WEu-#IQlyv1MINSL<$4%wP0(Ksa1HD7$Q$cY(p=}ou`+84W;4Rr-f zIXRrzigNCqn{P9N@gS6)>P3ZKYt=kV6t0d=r675hqvw@%v5-`zDK%o~J_QMBc6j6H zGUPO{He`HOZL^!Vd)x|v(}k9Q&d%gWdAjZmh0Mv{i*ABnKP8pxCuIqmzio;vB13?! z!yR4}LIao-#R2ph=y<_{R2^f-dWy^xx;K3aO;70TXhF6!t%IYQloT1~gLEDs^nEF? ztyYI`xHvktjDINnxN*gG)Eyde@$iUM-^@os`ygwjY^nOpXs)e}qhCH;zn%8QB}5^= z0TxY?t+l~8T91%6GJ=j%BL*L&`g+!!oyrvO(U4htAi2#Nc47sLe!$sKgEZVh%ew>i z++y2dXLIjqq-gowwfajyg&<5M+TDp6!APbQfg+td}Qog#1_HTQbFJ!NbrpbfX2u5Ms=<*a?~gzaL&YK)6mh^!4V;3Y-EX zsOgr%txv@zQ|s3gc5B0226Apxnwl!4D-gyBbNpl%yC#_It|~@?yXH`=Zw|44Dpm7& zeMw=Pj5yE9uRP+NK02{8n}HctG;4AdW$3G36ODv{J_-Tc<*y3~SjmM>Lu zPO`4kF=R#)^sgf}$Uo=JFUOsNlH=RrL?B@hxc!IY;tjGdP4 zy1OHG^;Q5HztrMYE?+U#Pfbup~9`<4iIpGLbms6zOuE&t7%!(E(jbHdGNjI{=vo#EDv6p`NLnIzi&) z&lQ0MM&C+#nOLvKvnDYe{*!<8pHW1`g#d6d=Bk*K~G|eG`C0pR=dB{^~$NjD$%TOPx@|pIK_{`LJH`p`iwpx(T zy;>JaXA}q+U@c2J{>p0$i5l0LFA^%VTO38dn(4c=ZQD7~qIZ(1Iu*`^tNj&U6N45j z*h*unb;%QX1f+L&|EC#Nd~yA5RL{_!q}D)JAj6LA1(BG6_M!WwV_$x}6nzAEH0R)0 z4b3&5sn7C^8o@TbMWSalbEn1L_Y!)oG6zrHEeg-*6OvlgnbRi^0?Dv=gG0#t8IC5E z3y9%m014LBK0+s@4-A=nHoZJ#@aB}?jlrTx&^I_4RZMLiesy{#Fv(**@o#M-OkvG%2!-a)@)!mic8?)H>&W^8I`JzQ zahKpEtJ)7_AKX)ErEAu%3vITBI)-AUYjC8tPq_B4HC#ZApQRJ@ z10tT)nPnu2aH^vT-C3y%!Uws^cNH%)`!4F}x#lbMwuz5yw9t8NKk?AK#b1Kc4I;u6 z52J;G1Im%^P3w`#hKtjmokN}ke|`46r_$&Bc>Vq)lafE5&GW0rW>H_C$14#gTl8 z!iNXtLlI5T{c{Ojb$1$Z(g?+o-LIog(Do&ThK2w$rJmKz`kiRUo1gYO`X1Bi5=yQn z;4Zm%(&504(88&VJyjVhqu8gCyP_U{FxG@k@wX0 zd@Eod(fqO%CRsHTH#R~mOxjJoC)|G%c`73%yU?PXD+;7rzMT@db^?YxF7C6`otBy+DzEmnnJ8 z@t9aZXnry_ULoV|KBL>!GyZn@ka0)-n}JrWZg|f*V!Y;wQfo3gnTYF9X{zOCUJf3g zX>k=##Sd*N{fv+r5kBd-@41)0A^zO=MxH6zQmH+og64jgW%3en6UW#!EDCLMtbA6$kPFW1ErDxB9|tDL9^25_kqGE~ ziE(4UMD2yKtQgWGA`pRV#NrQAsiX_N_MxzS#{q!%pBMf1qgJP!>}^h$gNT7kv6LiS z$F%#g#lq^|6bIN4!P-Te3pn(Gp~W;0W;!vR`VYhJ)dRbieaBwGG2C0y!Wj-E4) zR%3VGnx-B&Z1VMTSd(mt$}ptiDI|=vbq=xXVnJu2Q^Vmhk(ftk{4V>AUhu_xec6+j zsX5n6iX=Vmud!JE$_p@#{VTlT=j$~118A8c29J^Tkjtx}6kpZc+>$&-9jwjuo_`Wz z@0*boe}bN-e%{5huxIPK)<9%eFIfJZPnJpaCL6a{$qO3cVM4}>1u z#~qh-e!Y%>lFyY~Evv2vUTTvw^%n;{Hur6p_+({9CNcJGjKX*-iCGwkQ8e`}XlMx4#bp=2+FqBL_?zwHXnR|h+>lF$L2MSC!hIS|x0$G{j0 zNIdw^aVqYffr(aZ&KFO)%J}PxCi&)W-f&_LH8d`{h`Dj5Ch8uqhRtv*(+*ejwInBF zLPt93@SAOFHx7QZ7`~JY9Wu3Z0;4oBpZ%RvtOMs5&g)9i3=#a$9s=~5wG8W64-c16 zoKXTWE)Kgd1~LMoT|SOxrY8#|w5m+;!Vs1$`?-M_^~EskUd0@L^Np^X2G6S7t&VgI?yghq!4Ox4OB}8gKeg_G&-i3Mp$ABf)~wEnu0+yC{B>dR=<+B7o7Pc6)h$zLI}5^KFf>*jHhsBq>+(^C&Q zEmh##2JZ{}omvKMLxT{;^?j+!tU#m8?D{?I$2>o8L4iRw+S!I-n866>H}m`Ud5>Vr z&+Ok>V*h^5_(||W(tAuvtvp4x_99tR-@dAAepwfDaY?ChC9rb?w6RG+?n_H9T9v~E zFyJ%B+K{@#SVGKf<17|C}<#GU1g8Dat$6sOKB=mmR+M z^quK&vJJ0vGTmV^u)-r0{oJMhyo(5U?V`HWr@=-Yl?AuDW2*%kUwT)&yGRq&K7KuP z_Wvz1Lh+$DU zJGT}c;!b;te>g*u)anE>lB^SVkn0Ya)redg&VCc~?1d+*c_Kt1^vn{(mkZ$Snp+21 zb)XBry_OX?`GtNTq=Wx5C3+ksJK&j`30xMgD7sg&a$Zx#>weai%YiBd;06{ruQ*@H z;t2iV-D*ni0B;4k-5AYi#oIBk^nCVngaviIwIwa}HcOU#?S+o*wZ%;(^H;BI*@UcIu3?mWa2}e{#~5{m!Q0mxDI2@X;d3u5c1~Xsi>-F4^Ivjk2Z6W%Z*XR` zD}SjHh!^Fs)UWI=y}q|%+~Oh@_u$m?%J*4-O+sU8#B{r)XqX2E?~G+GtV%%#@wTZZ zXjbaeMQm>8XHW25M#M-b!=4Ke3V=$P$KD`bPur)xvbWz9Y6siP0<$w%Ud*3@Pc=~- zVvNASPfzq}UBCts17iY4&$oik^(2^`bUQM-G?e)EX}rnXmHripz}u;z{bOF7Ys|># zwWL;1<=LnvoP_iDlep9Rd$s7jlTS3rdwPT->=dH`ew9|FuUAe zL;^B0mY4?9B0IB6tMEVhy`0b$@I3|2B=^oiaBy7K;7Cq+Aa0<93*euW12<`P61$sF zax}F#?*OpKWl)GlyNKFwLX#Ra6YbU)j`L|OjmdrA`Q5+gZLOFY5h*7nkZfr^aet5&tAk4oPg z6^Y-!sO!Cqsn&2?u(Mn8n#ZoCYPA_zt8(asN!~^-5bE1OJ{>`hE2a zFwww@xhpv89J?@!_Uh0%O!!#M9hUK)bGE7mKj)*U*vp?OusMCFNqj|i#!ZzD>?4SeuVHrG7VY#sh2f#W4)SE z$H!M<+c(kIa_dd|5`AaEvySSmgEp4=5RUmkDrH5{Y|hSh28}nsP>qiCLa%ZG4^Z0~ z&qj(e0W*36M%!r*Js@K}Vi^?aJx!i_lmooo4VU72W;5Tw8)N;4aScdtUrO1gVuS5OZa_vm@BauS1ra{N%7V#Nl#nmz5UWGGB8Uv>TNu%tXpRR2 zm*H0;iib(kUh(93;cN8x!)3-~ z_eaRrRe06dxI>@(=epCF(b2xES3dHpLKQhn+SS>^>;2SkYY;M|0r~*95n)U_d@YG_ zeZ-uw?|OjYf%zvNab7n9g#il6`o{QBLRSW_NcV0MXInpzVS)Nyo2b*r1$5Q7WR|Vf zvImypl0Vy+kTha~-dJ{8&rpx2*6HZS*b^E$ww@0W%=j{*s7=5_hU*}WDQRy= zB7-~Cm?7r)ku&^rjg4T!5=tGZ#>XYXA`?hUZH?ybSZh(WUchgN2@( z7uyR?RT-?^-IAX6iIzE=M7v{7sP)fhKu%LX<&x1d&K8D)z18x_N>Yc+McIk0No3J{ z8rUMV1J>Q+@nZ4wqXD>kJx&XW4A6z#N$^MRwCP+HvMu zc8Q;V(j)9;Qw=d2C*|yDjm<`985pKM!j!szw~W6}+8BU5*zeHewr#q`9$V$uUcpy1 z7Gfx*^g?&;tkDjZ1f!D{Gu)ApOkrjMaWOk-0y<-R^KMpHURIP$RtvPC)K_GugLX#4 zt`vowA4Kh1GP;h!Wuy>B5y>?EVJIFX#5zM0iZK$KR#Hjl*!*%G!b?ca!c4zH3hm9&x-?FRF}M6i!Ew6UO8lj=P0wE zakN-aMg+wNO^(En``gh{O~PNvgyf#*38%p_A0~81M@KLxCV8dG@$)y~eQ=Hx{aL~B zP|CG^sb?zdtK@e&b&&7RA7hglgsL`J~7E@@rd)NC<*Va||s~Y)X=O2l007snUXg#5-(J#<=bvPC6eYGxR41a@y zqjztmT;#*v8#^}J80{7u&LR2u)lAC}Jkze!T7x%T}w zNv(Gc=+BF|{%d8*(Z9h6|J(n62TME)z4~KTws|V+KNIN3wE2G~(C;VUeV{6LcyIw|0_)mu4*1wo$C;rgdGEZ& z=JV2dFxrdX9A*9Iw!a$u7b7qKXyhLbel{}c2P5-5`8$?8t0w!?Sc72IQY#LvYqLSQFGPpY$9 zSOwW(5^dJ=kTJ8wbVSUWjfpaFm+qSM;)|b8^4`%4v52q2B`eup{`o3E?a^aq%$n_* zMbaW<%tZ1X{88or>_fadlt;uXr5aOP<@NpWo#D@Yzu#doiPwYo!nTqv+83>1ki(&H z&e)vf|Cz`v@q2gPn}v&Z--$-^dEI#hIR=lu6J^-?{(KWay{$j*$3JL)X87~1vZIfx zJ^C&+y@A sdvgAnHv50E+KJbB