Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Jeffrey #10

Open
wants to merge 86 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
c756b21
Created 1st Queues Slide
JeffTheAggie Feb 29, 2020
c9f4f3e
Updated Card
JeffTheAggie Feb 29, 2020
07da78c
Created Queues(2).md
JeffTheAggie Feb 29, 2020
6e04383
Updated
JeffTheAggie Feb 29, 2020
68d9f60
Updated
JeffTheAggie Feb 29, 2020
b8a3eea
Updated
JeffTheAggie Feb 29, 2020
e9096e0
Create Queue(3).md
JeffTheAggie Feb 29, 2020
b0d00be
Created Queues(4).md
JeffTheAggie Feb 29, 2020
0cbeefc
Created Stacks(1).md
JeffTheAggie Mar 1, 2020
8fe930b
Spelling Error
JeffTheAggie Mar 1, 2020
5b827b8
Created Stacks(2).md
JeffTheAggie Mar 1, 2020
475dcfc
Created Stacks(3).md
JeffTheAggie Mar 1, 2020
5b07385
Created Stacks(4).md
JeffTheAggie Mar 1, 2020
5f69f62
Created Stacks(5).md
JeffTheAggie Mar 1, 2020
8dadf8d
Made a mistake
JeffTheAggie Mar 1, 2020
c284753
Updated Queues Slide 1
JeffTheAggie Mar 18, 2020
3cf6a5b
Created Faux Queues(2).md
JeffTheAggie Mar 18, 2020
30465b3
Rename
JeffTheAggie Mar 19, 2020
3ce11e4
Create Faux Queues(4).md
JeffTheAggie Mar 19, 2020
a41c35c
Create Faux Queues(5).md
JeffTheAggie Mar 19, 2020
4592b56
Create Faux Queues(6).md
JeffTheAggie Mar 19, 2020
41e2c63
Create Faux Queues(7).md
JeffTheAggie Mar 19, 2020
6599fe7
Update and rename Queues(3).md to Queues(8).md
JeffTheAggie Mar 19, 2020
690901a
Create Faux Queues(9).md
JeffTheAggie Mar 19, 2020
f50fcfa
Create Faux Queues(10).md
JeffTheAggie Mar 19, 2020
075bfe3
Create Faux Queues(11).md
JeffTheAggie Mar 19, 2020
9cf22e8
Create Faux Queues(12).md
JeffTheAggie Mar 19, 2020
bb25d2a
Create Faux Queues(13).md
JeffTheAggie Mar 19, 2020
c7eca87
Update and rename Queues(4).md to Queues(14).md
JeffTheAggie Mar 19, 2020
4150eaa
Create Faux Queues(15).md
JeffTheAggie Mar 19, 2020
bf4ba48
Create Faux Queues(16).md
JeffTheAggie Mar 19, 2020
d0afdd1
Rename Faux Queues(2).md to Queues(2).md
JeffTheAggie Mar 19, 2020
c43076a
Rename Faux Queues(3).md to Queues(3).md
JeffTheAggie Mar 19, 2020
538f8d0
Rename Faux Queues(4).md to Queues(4).md
JeffTheAggie Mar 19, 2020
d6a1186
Rename Faux Queues(5).md to Queues(5).md
JeffTheAggie Mar 19, 2020
140ff51
Rename Faux Queues(6).md to Queues(6).md
JeffTheAggie Mar 19, 2020
2b810e1
Rename Faux Queues(7).md to Queues(7).md
JeffTheAggie Mar 19, 2020
2e546bc
Rename Faux Queues(9).md to Queues(9).md
JeffTheAggie Mar 19, 2020
fde1c65
Rename Faux Queues(10).md to Queues(10).md
JeffTheAggie Mar 19, 2020
a16ea0b
Rename Faux Queues(11).md to Queues(11).md
JeffTheAggie Mar 19, 2020
6195a7d
Rename Faux Queues(12).md to Queues(12).md
JeffTheAggie Mar 19, 2020
e1205c2
Rename Faux Queues(13).md to Queues(13).md
JeffTheAggie Mar 19, 2020
aab5714
Rename Faux Queues(15).md to Queues(15).md
JeffTheAggie Mar 19, 2020
5b21dba
Rename Faux Queues(16).md to Queues(16).md
JeffTheAggie Mar 19, 2020
e2fec04
Update Queues(14).md
JeffTheAggie Mar 19, 2020
2f74098
Update Stacks(1).md
JeffTheAggie Mar 19, 2020
fb242e9
Create Faux Stacks(2).md
JeffTheAggie Mar 19, 2020
8487f05
Update and rename Stacks(2).md to Faux Stacks(3).md
JeffTheAggie Mar 19, 2020
d342f6a
Create Faux Stacks(4).md
JeffTheAggie Mar 19, 2020
f8b34b5
Create Faux Stacks(5).md
JeffTheAggie Mar 19, 2020
a9e8e37
Create Faux Stacks(6).md
JeffTheAggie Mar 19, 2020
89e3795
Create Faux Stacks(7).md
JeffTheAggie Mar 19, 2020
9859127
Update Stacks(3).md
JeffTheAggie Mar 20, 2020
9133072
Rename Stacks(3).md to Faux Stacks(8).md
JeffTheAggie Mar 20, 2020
02c73b6
Update Faux Stacks(8).md
JeffTheAggie Mar 20, 2020
b85b878
Create Faux Stacks(9).md
JeffTheAggie Mar 20, 2020
28f934a
Create Faux Stacks(10).md
JeffTheAggie Mar 20, 2020
4d73ce1
Create Faux Stacks(11).md
JeffTheAggie Mar 20, 2020
c914c45
Update and rename Stacks(5).md to Faux Stacks(13).md
JeffTheAggie Mar 20, 2020
e31e527
Create Faux Stacks(14).md
JeffTheAggie Mar 20, 2020
c791b0f
Create Faux Stacks(15).md
JeffTheAggie Mar 20, 2020
b95d91e
Create Faux Stacks(16).md
JeffTheAggie Mar 20, 2020
83db18b
Create Faux Stacks(17).md
JeffTheAggie Mar 20, 2020
ea44e4a
Create Faux Stacks(18).md
JeffTheAggie Mar 20, 2020
bc5a532
Create Faux Stacks(19).md
JeffTheAggie Mar 20, 2020
aac1f06
Create Faux Stacks(20).md
JeffTheAggie Mar 20, 2020
bea278f
Rename Stacks(4).md to Stacks(13).md
JeffTheAggie Mar 20, 2020
d6747c8
Rename Faux Stacks(2).md to Stacks(2).md
JeffTheAggie Mar 20, 2020
0a4384d
Rename Faux Stacks(3).md to Stacks(3).md
JeffTheAggie Mar 20, 2020
a0f1c4c
Rename Faux Stacks(4).md to Stacks(4).md
JeffTheAggie Mar 20, 2020
ca4e003
Rename Faux Stacks(5).md to Stacks(5).md
JeffTheAggie Mar 20, 2020
c9ec4b3
Rename Faux Stacks(6).md to Stacks(6).md
JeffTheAggie Mar 20, 2020
5ddef4b
Rename Faux Stacks(7).md to Stacks(7).md
JeffTheAggie Mar 20, 2020
9c40f09
Rename Faux Stacks(8).md to Stacks(8).md
JeffTheAggie Mar 20, 2020
8e34a97
Rename Faux Stacks(9).md to Stacks(9).md
JeffTheAggie Mar 20, 2020
4016d0e
Rename Faux Stacks(10).md to Stacks(10).md
JeffTheAggie Mar 20, 2020
cc7a1e5
Rename Faux Stacks(11).md to Stacks(11).md
JeffTheAggie Mar 20, 2020
8717948
Rename Stacks(13).md to Stacks(12).md
JeffTheAggie Mar 20, 2020
5ae24f6
Rename Faux Stacks(13).md to Stacks(13).md
JeffTheAggie Mar 20, 2020
9f38088
Rename Faux Stacks(14).md to Stacks(14).md
JeffTheAggie Mar 20, 2020
70cf333
Rename Faux Stacks(15).md to Stacks(15).md
JeffTheAggie Mar 20, 2020
b88f7a1
Rename Faux Stacks(16).md to Stacks(16).md
JeffTheAggie Mar 20, 2020
31a6504
Rename Faux Stacks(17).md to Stacks(17).md
JeffTheAggie Mar 20, 2020
a1ca485
Rename Faux Stacks(18).md to Stacks(18).md
JeffTheAggie Mar 20, 2020
40a33a0
Rename Faux Stacks(19).md to Stacks(19).md
JeffTheAggie Mar 20, 2020
7a5bbf8
Rename Faux Stacks(20).md to Stacks(20).md
JeffTheAggie Mar 20, 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
12 changes: 12 additions & 0 deletions Leetcode Workshops/Week 1/Queues(1).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Type: Text + Image ###

### Title: What's a Queue? ###

### Content:

- Queues are data structures that remove the first element that was added into a list.

- An example could be you waiting at a long line at In-N-Out and the car that was there the earliest gets served first.

![](https://coyotechronicle.net/wp-content/uploads/2012/04/IMG_0018-150x112.jpg)

8 changes: 8 additions & 0 deletions Leetcode Workshops/Week 1/Queues(10).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Type of Card: Code left/right ###

-The 2nd step would be to create your queue of elements while calling the deque function.

```python
# Creating a Queue
queue = deque([1,5,8,9])
```
9 changes: 9 additions & 0 deletions Leetcode Workshops/Week 1/Queues(11).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Type of Card: Code left/right ###

-The 3rd step would be to append elements towards the rear of the queue.

```python
# Enqueuing elements to the Queue
queue.append(7) #[1,5,8,9,7]
queue.append(0) #[1,5,8,9,7,0]
```
9 changes: 9 additions & 0 deletions Leetcode Workshops/Week 1/Queues(12).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Type of Card: Code left/right ###

-This is where you can implement the deque() properly when you’re dequeuing elements. For deque, you would use the popleft() function to delete elements in the front of the list (the version of deleting elements from the rear is popright()).

```python
# Dequeuing elements from the Queue
queue.popleft() #[5,8,9,7,0]
queue.popleft() #[8,7,9,0]
```
7 changes: 7 additions & 0 deletions Leetcode Workshops/Week 1/Queues(13).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Type of Card: Code left/right ###

-The final step would be to call the print() function to check what elements are still left in the queue.
```python
#Printing the elements of the Queue
print(queue)
```
11 changes: 11 additions & 0 deletions Leetcode Workshops/Week 1/Queues(14).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Type of Card: Text + image ###

### Title: A Real-life Example of a Queue ###

- You're probably thinking, "Learning about queues is cool and all, but when will I ever apply this in my life?"

- Well today's your lucky day!

- Let's say that you're boarding a plane and you're fighting to get the first front seats of the plane.

![](https://thecontextofthings.com/wp-content/uploads/2014/04/tra2687.jpg)
15 changes: 15 additions & 0 deletions Leetcode Workshops/Week 1/Queues(15).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Type of Card: Code left/right ###

-Let's say that the total number of passengers is 50 people. Let's add each passenger in the plane using the enqueue() call
to fill up the number of spots available.

```python
passengers = 50 #Total of the current 50 passengers on the plane
boardingPlane = Queue()
int(passengers) = 50

for x in range(passengers):
boardingPlane.enqueue(x)

print(boardingPlane.size()) #result prints a size of 50
```
15 changes: 15 additions & 0 deletions Leetcode Workshops/Week 1/Queues(16).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Type of Card: Code left/right ###

-Now you're plane arrived at the Sacramento airport and the first 30 passengers hopped off the plane while the last 20 waited
in the back because they're going to catch a different flight right after the plane has landed. We would now remove each of the
30 passengers in order using the dequeue() call.

```python
frontPassengers = 30 #1st 30 passengers that left the plane
int frontPassengers = 30

for x in range(frontPassengers):
boardingPlane.dequeue(x)

print(boardingPlane.size()) #result prints a size of 20
```
11 changes: 11 additions & 0 deletions Leetcode Workshops/Week 1/Queues(2).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Type: Text + Image ###

### Title: What's a Queue? ###

### Content:

- Queues are implemented through adding elements to the rear of the queue and deleting elements at the front of the Queue.

- This technique is known as FIFO (First in First out).

![](https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2014/02/Queue.png)
15 changes: 15 additions & 0 deletions Leetcode Workshops/Week 1/Queues(3).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Type of Card: Code left/right ###

### Title: Implementing a Queue ###

- We're going to make a Queue class to show how the Queue itself works.

- The first step would be to create our queue constructor in which we start our queue off as an empty list for adding items

```python

class Queue:
#Constructor creates a list
def __init__(self):
self.queue=[]
```
13 changes: 13 additions & 0 deletions Leetcode Workshops/Week 1/Queues(4).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Type of Card: Code left/right ###

-We’re now going to create our enqueue() function in the queue class.

- enqueue() adds elements to the rear of the queue.

```python

#Adding elements to queue
def enqueue(self,data):
self.queue.insert(0,data)
return True
```
12 changes: 12 additions & 0 deletions Leetcode Workshops/Week 1/Queues(5).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Type of Card: Code left/right ###

-We’re now going to create our dequeue() function in the queue class.

- dequeue() deletes elements from the front of the queue.

```python

#Removing the last element from the queue
def dequeue(self):
return self.queue.pop()
```
12 changes: 12 additions & 0 deletions Leetcode Workshops/Week 1/Queues(6).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Type of Card: Code left/right ###

-We’re now going to create our size() function in the queue class.

- size() looks at the current size that the Queue has for its total number of elements.

```python

#Getting the size of the queue
def size(self):
return len(self.queue)
```
12 changes: 12 additions & 0 deletions Leetcode Workshops/Week 1/Queues(7).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Type of Card: Code left/right ###

-Finally, we’re going to create our printQueue() function in our queue class.

- printQueue() prints out the current elements that are left inside the queue

```python

#printing the elements of the queue
def printQueue(self):
return self.queue
```
8 changes: 8 additions & 0 deletions Leetcode Workshops/Week 1/Queues(8).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Type of Card: Text ###

### Title: What’s a Deque? ###

- A deque (or a double ended queue) is a data structure that removes and adds elements from either the front or the rear of a queue.

- We're going to show you an example on how to implement a deque.

7 changes: 7 additions & 0 deletions Leetcode Workshops/Week 1/Queues(9).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Type of Card: Code left/right ###

- The 1st step would be to import the deque library from Python’s collection module.

```python
from collections import deque
```
12 changes: 12 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(1).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Type: Text + Image ###

### Title: What's a Stack? ###

- A stack is a data structure that adds elements to the front of the list.

- How this data structure works is that earliest elements that are added into the stack will be on the bottom of the stack
and the most recent element that is on the stack will get removed first.

- This process is called LIFO (Last in, First out).

![](https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2013/03/stack.png)
11 changes: 11 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(10).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Type: Code Steps Large ###

3. Check the current size of the stack by using the size() function.

```python
#The process of implementing the size() function call
print(myStack.size())

#The result of the code
5
```
32 changes: 32 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(11).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### Type: Code Steps Large ###
4. Remove elements from the stack by using the pop() function.

```python
#The process of implementing the pop() function call
print(myStack.pop()) #print the value of removed element
print("Current stack :",myStack.stack) #print the stack now
print(myStack.pop())
print("Current stack :",myStack.stack)
print(myStack.pop())
print("Current stack :",myStack.stack)
print(myStack.pop())
print("Current stack :",myStack.stack)
print(myStack.pop())
print("Current stack :",myStack.stack)
print("the size of the stack now :",myStack.size()) #print the size of stack
print(myStack.pop())

#The result of the code
3
Current stack : [5, 6, 9, 5]
5
Current stack : [5, 6, 9]
9
Current stack : [5, 6]
6
Current stack : [5]
5
Current stack : []
the size of the stack now : 0
Stack Empty!
```
15 changes: 15 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(12).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Type: Text + Image ###

### Title: The Tower of Hanoi ###

- The tower of Hanoi is a puzzle in which you have 3 poles and 3 disks of different sizes. You'll always start with the largest disk
on the bottom of the 1st pole and the smallest disk on the top of the 1st pole

- The goal is to see if we can sort the stack of disks in their original order by the time you stack the disks on the 3rd pole.

- The rule of the puzzle is that you can't place a larger disk on a smaller disk and only one disk can be moved at a time.

- In order to solve this puzzle, we need to use our good old friend, the stack class since the stack algorithm can remove the latest
item that was on top of the list and sort it into another pole into the proper order.

![](https://www.includehelp.com/data-structure-tutorial/images/tower-of-hanoi.jpg)
32 changes: 32 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(13).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### Type: Code steps Large ###

### Title: Implementing the Stack Class for the Tower of Hanoi Puzzle ###

- We're now going to solve the Tower of Hanoi puzzle using the stack class

1. The 1st step is to initialize the necessary values that we will need for this puzzle (the disk sizes and the type of poles).

```python
#Initializing the necessary items
sourcePole = Stack()
auxPole = Stack()
destPole = Stack()

smallDisk = 1
avgDisk = 2
largeDisk = 3

sourcePole.push(largeDisk)
sourcePole.push(avgDisk)
sourcePole.push(smallDisk)

print(sourcePole.stack) # print the Initial state of 3 poles
print(auxPole.stack)
print(destPole.stack)

#Result of the code
[3, 2, 1]
[]
[]
```

18 changes: 18 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(14).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Type: Code Steps Large ###

2. The 2nd step is to place the smallest disk into our 3rd pole (`destPole`).

```python
#Moving the smallest disk to the 3rd pole
disk = sourcePole.pop() #remove the top disk of source pole to destination pole
destPole.push(disk)

print(sourcePole.stack) #print the state now
print(auxPole.stack)
print(destPole.stack)

#Result of the code
[3, 2]
[]
[1]
```
18 changes: 18 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(15).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Type: Code Steps Large ###

3. The 3rd step is to place the medium sized disk into our 2nd pole ('auxPole`).

```python
#Moving the medium sized disk into the 2nd pole
disk = sourcePole.pop() #remove the top disk of source pole now to destination pole
auxPole.push(disk)

print(sourcePole.stack) #print the state now
print(auxPole.stack)
print(destPole.stack)

#Result of the code
[3]
[2]
[1]
```
18 changes: 18 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(16).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Type: Code Steps Large ###

4. The 4th step is to place the smallest disk into our 2nd pole.

```python
#Moving the smallest disk into our 2nd pole
disk=destPole.pop()
auxPole.push(disk)

print(sourcePole.stack)
print(auxPole.stack)
print(destPole.stack)

#Result of the code
[3]
[2, 1]
[]
```
18 changes: 18 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(17).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Type: Code Steps Large ###

5. The 5th step is to place the largest disk into our 3rd pole.

```python
#Moving the largest disk into our 3rd pole
disk=sourcePole.pop()
destPole.push(disk)

print(sourcePole.stack)
print(auxPole.stack)
print(destPole.stack)

#Result of the code
[]
[2, 1]
[3]
```
18 changes: 18 additions & 0 deletions Leetcode Workshops/Week 1/Stacks(18).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Type: Code Steps Large ###

6. The 6th step is to place the smallest disk into our 1st pole(`sourcePole`).

```python
#Moving the smallest disk into our 1st pole
disk=auxPole.pop()
sourcePole.push(disk)

print(sourcePole.stack)
print(auxPole.stack)
print(destPole.stack)

#Result of the code
[1]
[2]
[3]
```
Loading