Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4ad0a31
Add trees slides 1-10
Dadao-xiaoguaishou Feb 21, 2020
25ffb37
add 4.2.2 trees slides 11-16
Dadao-xiaoguaishou Feb 21, 2020
5a6d842
update 4.2.2 trees slides 1-16
Dadao-xiaoguaishou Feb 22, 2020
effd49f
Add the content slide 16-39
Dadao-xiaoguaishou Feb 22, 2020
a5bc847
Revert "Add the content slide 16-39"
Dadao-xiaoguaishou Feb 22, 2020
4ad8ec7
Revert "Revert "Add the content slide 16-39""
Dadao-xiaoguaishou Feb 22, 2020
ceb1f84
delete empty file
Dadao-xiaoguaishou Feb 22, 2020
057fb2f
Create READ.md
Dadao-xiaoguaishou Feb 22, 2020
f54c1af
add type for each slide and readme
Dadao-xiaoguaishou Feb 22, 2020
70ef5ed
Rename 39.MD to 39.md
Dadao-xiaoguaishou Feb 22, 2020
e52bae1
add linked list content of slide 1-36
Dadao-xiaoguaishou Feb 22, 2020
a0c6b09
Rename 8.MD to 8.md
Dadao-xiaoguaishou Feb 23, 2020
3c46e5c
add the type and title for Linked list 1-36.md
Dadao-xiaoguaishou Feb 23, 2020
61e9709
Merge branch 'Ruby' of https://github.com/bitprj/workshops into Ruby
Dadao-xiaoguaishou Feb 23, 2020
3d540ea
Create README.md
Dadao-xiaoguaishou Feb 23, 2020
9483a51
Update README.md
Dadao-xiaoguaishou Feb 23, 2020
5799a42
Update README.md
Dadao-xiaoguaishou Feb 23, 2020
af7fc7f
Add visuals
Dadao-xiaoguaishou Feb 23, 2020
cd81027
Update README.md
Dadao-xiaoguaishou Feb 24, 2020
33469fe
Update README.md
Dadao-xiaoguaishou Feb 24, 2020
6047ece
4.2.2 Make comments visible
Dadao-xiaoguaishou Feb 26, 2020
8fdabad
4.2.1 make the type and title visible
Dadao-xiaoguaishou Feb 26, 2020
28e6287
Update 2.md
Dadao-xiaoguaishou Feb 26, 2020
d93f490
Add 4.3.3 Binary heaps slides 1-29
Dadao-xiaoguaishou Feb 29, 2020
1751caf
Merge pull request #9 from bitprj/Ruby
JasonL24 Mar 1, 2020
03377fd
Styled Components Workshop
JasonL24 Mar 1, 2020
9f053ae
Merge branch 'Jason' of https://github.com/bitprj/workshops into Jason
JasonL24 Mar 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_**type:title slide**_

_**title:Linked List**_
# Linked List
12 changes: 12 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_**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
film = LinkedList()
film.head = Node(900)
```
Our linked list will look like :

<img src="https://tva1.sinaimg.cn/large/0082zybpgy1gc0lqmxalej317904w0t8.jpg" style="zoom:25%;" />
22 changes: 22 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/11.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
_**type:small code snipet**_

_**title:`insert()`**_
## `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.
20 changes: 20 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
_**type:code centered**_

_**title:Use `insert()`**_
## Use `insert()`
```python
film.insert(930)
```
<img src="https://tva1.sinaimg.cn/large/0082zybpgy1gc0lrqgwglj31tk04wjs9.jpg" style="zoom:25%;" />

- 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.

17 changes: 17 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/13.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
_**type:code centered**_
_**title:insert()**_
## `insert()`
```python
film.insert(1000)
```

<img src="https://tva1.sinaimg.cn/large/0082zybpgy1gc0lsgn5toj32e6054t9z.jpg" style="zoom:25%;" />

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.



21 changes: 21 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
_**type:code step1**_

_**title:delete()**_
## `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`.
19 changes: 19 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/15.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
_**type:code step2**_
_**title:delete()**_
## `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.
23 changes: 23 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/16.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
_**type:code step3**_

_**title:delete()**_
## `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!
21 changes: 21 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/17.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
_**type:code centered**_

_**title:Call delete()**_
## `delete()` in `main()`
```python
film.delete(930)
```
<img src="https://tva1.sinaimg.cn/large/0082zybpgy1gc0ltl0pfzj32e6054dgu.jpg" style="zoom:25%;" />

| | 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.'
28 changes: 28 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/18.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
_**type:code left**_

_**title:size()**_

## `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.
8 changes: 8 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_**type:small code snipet**_

_**title:call size()**_
## Call `size()`

```python
print(film.size())
```
12 changes: 12 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_**type:Centered text**_

_**title:Node in Linked List**_
## Node in Linked List
<img src="https://tva1.sinaimg.cn/large/0082zybpgy1gc0lrqgwglj31tk04wjs9.jpg" style="zoom:25%;" />

- 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.
13 changes: 13 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_**type:link**_

_**title:Visual of `size()`**_

## Visual of `size()`

![<div style="width: 480px; height: 360px; margin: 10px; position: relative;"><iframe allowfullscreen frameborder="0" style="width:480px; height:360px" src="https://www.lucidchart.com/documents/embeddedchart/e89bfe15-787e-4a95-ab8a-331ac9b72d84" id="nHdoMIDHEv0z"></iframe></div>]

`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[]`.
16 changes: 16 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
_**type:code step1**_

_**title:search()**_

## `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!
18 changes: 18 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
_**type:code step2**_

_**title:search()**_
## `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.

17 changes: 17 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
_**type:code step3**_

_**title:search()**_
## `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!
7 changes: 7 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/24.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_**type:small code snipet1**_

_**title:Call search()**_
## Call `search()`
```python
print(film.search(1000))
```
12 changes: 12 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/25.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_**type:Link**_
_**title:Visual of search()**_
## Visual of search()

![<div style="width: 480px; height: 360px; margin: 10px; position: relative;"><iframe allowfullscreen frameborder="0" style="width:480px; height:360px" src="https://www.lucidchart.com/documents/embeddedchart/32d95bb7-cdec-412d-b1c2-56ff92f94ffd" id="eJdoS7QA_DOn"></iframe></div>]


-------------------------------------------------

[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!
8 changes: 8 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/26.md
Original file line number Diff line number Diff line change
@@ -0,0 +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.
10 changes: 10 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/27.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_**type:code step1**_

_**title:Create the class and the first node**_
## Step 1: Create the class and the first node
```python
film = LinkedList()
film.head = Node(900)
```

> Remember that the first node of the Linked List when initialized will be the head node.
11 changes: 11 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/28.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
_**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.


-------------------------------------------------

[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.
20 changes: 20 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/29.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
_**type:code step2**_

_**title:Step2:**_
## 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`.
14 changes: 14 additions & 0 deletions Leetcode Workshops/Week 2/Act1_Linked list/3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
_**type:Centered text**_

_**title:Reference**_

## Reference
<img src="https://tva1.sinaimg.cn/large/0082zybpgy1gc0lrqgwglj31tk04wjs9.jpg" style="zoom:25%;" />

- 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.
Loading