diff --git a/Leetcode Workshops/Week 1/Queues(1).md b/Leetcode Workshops/Week 1/Queues(1).md new file mode 100644 index 0000000..d344399 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(1).md @@ -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) + diff --git a/Leetcode Workshops/Week 1/Queues(10).md b/Leetcode Workshops/Week 1/Queues(10).md new file mode 100644 index 0000000..0a85c63 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(10).md @@ -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]) +``` diff --git a/Leetcode Workshops/Week 1/Queues(11).md b/Leetcode Workshops/Week 1/Queues(11).md new file mode 100644 index 0000000..c6a1fc4 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(11).md @@ -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] +``` diff --git a/Leetcode Workshops/Week 1/Queues(12).md b/Leetcode Workshops/Week 1/Queues(12).md new file mode 100644 index 0000000..7e03522 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(12).md @@ -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] +``` diff --git a/Leetcode Workshops/Week 1/Queues(13).md b/Leetcode Workshops/Week 1/Queues(13).md new file mode 100644 index 0000000..df74b4d --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(13).md @@ -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) +``` diff --git a/Leetcode Workshops/Week 1/Queues(14).md b/Leetcode Workshops/Week 1/Queues(14).md new file mode 100644 index 0000000..be82c85 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(14).md @@ -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) diff --git a/Leetcode Workshops/Week 1/Queues(15).md b/Leetcode Workshops/Week 1/Queues(15).md new file mode 100644 index 0000000..32ef08b --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(15).md @@ -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 +``` diff --git a/Leetcode Workshops/Week 1/Queues(16).md b/Leetcode Workshops/Week 1/Queues(16).md new file mode 100644 index 0000000..ff15305 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(16).md @@ -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 +``` diff --git a/Leetcode Workshops/Week 1/Queues(2).md b/Leetcode Workshops/Week 1/Queues(2).md new file mode 100644 index 0000000..5951aca --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(2).md @@ -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) diff --git a/Leetcode Workshops/Week 1/Queues(3).md b/Leetcode Workshops/Week 1/Queues(3).md new file mode 100644 index 0000000..774919f --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(3).md @@ -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=[] +``` diff --git a/Leetcode Workshops/Week 1/Queues(4).md b/Leetcode Workshops/Week 1/Queues(4).md new file mode 100644 index 0000000..0690bff --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(4).md @@ -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 +``` diff --git a/Leetcode Workshops/Week 1/Queues(5).md b/Leetcode Workshops/Week 1/Queues(5).md new file mode 100644 index 0000000..94ff6f8 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(5).md @@ -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() +``` diff --git a/Leetcode Workshops/Week 1/Queues(6).md b/Leetcode Workshops/Week 1/Queues(6).md new file mode 100644 index 0000000..6e49872 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(6).md @@ -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) +``` diff --git a/Leetcode Workshops/Week 1/Queues(7).md b/Leetcode Workshops/Week 1/Queues(7).md new file mode 100644 index 0000000..e4d741d --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(7).md @@ -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 +``` diff --git a/Leetcode Workshops/Week 1/Queues(8).md b/Leetcode Workshops/Week 1/Queues(8).md new file mode 100644 index 0000000..db28398 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(8).md @@ -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. + diff --git a/Leetcode Workshops/Week 1/Queues(9).md b/Leetcode Workshops/Week 1/Queues(9).md new file mode 100644 index 0000000..c9c65e1 --- /dev/null +++ b/Leetcode Workshops/Week 1/Queues(9).md @@ -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 +``` diff --git a/Leetcode Workshops/Week 1/Stacks(1).md b/Leetcode Workshops/Week 1/Stacks(1).md new file mode 100644 index 0000000..97a9b51 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(1).md @@ -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) diff --git a/Leetcode Workshops/Week 1/Stacks(10).md b/Leetcode Workshops/Week 1/Stacks(10).md new file mode 100644 index 0000000..f95da3c --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(10).md @@ -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 +``` diff --git a/Leetcode Workshops/Week 1/Stacks(11).md b/Leetcode Workshops/Week 1/Stacks(11).md new file mode 100644 index 0000000..391fff8 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(11).md @@ -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! +``` diff --git a/Leetcode Workshops/Week 1/Stacks(12).md b/Leetcode Workshops/Week 1/Stacks(12).md new file mode 100644 index 0000000..aef604e --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(12).md @@ -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) diff --git a/Leetcode Workshops/Week 1/Stacks(13).md b/Leetcode Workshops/Week 1/Stacks(13).md new file mode 100644 index 0000000..29b1321 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(13).md @@ -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] +[] +[] +``` + diff --git a/Leetcode Workshops/Week 1/Stacks(14).md b/Leetcode Workshops/Week 1/Stacks(14).md new file mode 100644 index 0000000..2ada63a --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(14).md @@ -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] +``` diff --git a/Leetcode Workshops/Week 1/Stacks(15).md b/Leetcode Workshops/Week 1/Stacks(15).md new file mode 100644 index 0000000..a9781b2 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(15).md @@ -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] +``` diff --git a/Leetcode Workshops/Week 1/Stacks(16).md b/Leetcode Workshops/Week 1/Stacks(16).md new file mode 100644 index 0000000..990e32e --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(16).md @@ -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] +[] +``` diff --git a/Leetcode Workshops/Week 1/Stacks(17).md b/Leetcode Workshops/Week 1/Stacks(17).md new file mode 100644 index 0000000..88fc5ef --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(17).md @@ -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] +``` diff --git a/Leetcode Workshops/Week 1/Stacks(18).md b/Leetcode Workshops/Week 1/Stacks(18).md new file mode 100644 index 0000000..8cf9efd --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(18).md @@ -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] +``` diff --git a/Leetcode Workshops/Week 1/Stacks(19).md b/Leetcode Workshops/Week 1/Stacks(19).md new file mode 100644 index 0000000..5a220d7 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(19).md @@ -0,0 +1,17 @@ +### Type: Code Steps Large ### +7. The 7th step is to place the medium sized disk into our 3rd pole. + +```python +#Moving the medium sized disk into our 3rd pole +disk=auxPole.pop() +destPole.push(disk) + +print(sourcePole.stack) +print(auxPole.stack) +print(destPole.stack) + +#Result of the code +[1] +[] +[3, 2] +``` diff --git a/Leetcode Workshops/Week 1/Stacks(2).md b/Leetcode Workshops/Week 1/Stacks(2).md new file mode 100644 index 0000000..b38d500 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(2).md @@ -0,0 +1,18 @@ +### Type: Text + Image ### + +### A Real-Life Example of a Stack ### + +- An example can be a stack of books. Say that you have a huge stack of books at the library and you want to access your Calculus + textbook that's below your Physics, Circuits, and Chemistry textbooks. + +- This is where you get to see the wonderful implementation of using a stack. + +- You would remove the most recent book that's on top of your stack (this is what we call popping an item into a stack) in order until + you can access your textbook. + +- Congratulations! You can now work on those wonderful triple integrals that you have to do for your homework :`) + +- After finishing your homework, you can put your textbooks back on top of your calculus textbook (this is what we call pushing an + an item into a stack). + + ![](https://ya-webdesign.com/transparent250_/stack-of-clipart-tall-2.png) diff --git a/Leetcode Workshops/Week 1/Stacks(20).md b/Leetcode Workshops/Week 1/Stacks(20).md new file mode 100644 index 0000000..ea1f922 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(20).md @@ -0,0 +1,18 @@ +### Type: Code Steps Large ### + +8. The final step would be to place the smallest disk into the pole and just like that, we solved the Tower of Hanoi :) + +```python +#Moving the smallest disk into our 3rd pole +disk=sourcePole.pop() +destPole.push(disk) + +print(sourcePole.stack) +print(auxPole.stack) +print(destPole.stack) + +#Result of the code +[] +[] +[3, 2, 1] +``` diff --git a/Leetcode Workshops/Week 1/Stacks(3).md b/Leetcode Workshops/Week 1/Stacks(3).md new file mode 100644 index 0000000..75133f7 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(3).md @@ -0,0 +1,13 @@ +### Type: Code steps large ### + +### Title: Implementing a Stack ### + +- Now that you have seen an example of what a stack is, let's put this knowledge into practice. + +- Before we get into the code, we should go over how each function in a stack works. + +- push() adds elements to the front of the stack (stacking items on top) and pop() removes the latest elements that are on top of the + stack. + +- Now that you know these basics, let's make our stack class. + diff --git a/Leetcode Workshops/Week 1/Stacks(4).md b/Leetcode Workshops/Week 1/Stacks(4).md new file mode 100644 index 0000000..98710fd --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(4).md @@ -0,0 +1,11 @@ +### Type: Code steps large ### + + The 1st step is to intialize our stack class with stack() being an empty list. + +```python +class Stack: + + #Constructor creates a list + def __init__(self): + self.stack = list() +``` diff --git a/Leetcode Workshops/Week 1/Stacks(5).md b/Leetcode Workshops/Week 1/Stacks(5).md new file mode 100644 index 0000000..ad7a54d --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(5).md @@ -0,0 +1,10 @@ +### Type: Code steps large ### + +The 2nd step is to create a push() function that adds elements to the stack. + +```python + #Adding elements to stack + def push(self,data): + self.stack.append(data) + return True +``` diff --git a/Leetcode Workshops/Week 1/Stacks(6).md b/Leetcode Workshops/Week 1/Stacks(6).md new file mode 100644 index 0000000..b953400 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(6).md @@ -0,0 +1,11 @@ +### Type: Code steps large ### + +The 3rd step is to create a pop() function that removes elements from the stack. + +```python + #Removing last element from the stack + def pop(self): + if len(self.stack)<=0: + return ("Stack Empty!") + return self.stack.pop() +``` diff --git a/Leetcode Workshops/Week 1/Stacks(7).md b/Leetcode Workshops/Week 1/Stacks(7).md new file mode 100644 index 0000000..b0654ea --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(7).md @@ -0,0 +1,11 @@ +Faux Slide 7: + +### Type: Code steps large ### + +The final step is to create a size() function that returns our current size of the stack. + +```python +#Getting the size of the stack + def size(self): + return len(self.stack) +```` diff --git a/Leetcode Workshops/Week 1/Stacks(8).md b/Leetcode Workshops/Week 1/Stacks(8).md new file mode 100644 index 0000000..c981907 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(8).md @@ -0,0 +1,12 @@ +### Type: Code Steps Large ### + +### Title: Testing out your Stack Class ### + +- If you're curious about testing out your stack class, here's an example of how to do it. + +1. Initialize your stack class to a stack variable that you're creating. + +```python +myStack = Stack() +``` + diff --git a/Leetcode Workshops/Week 1/Stacks(9).md b/Leetcode Workshops/Week 1/Stacks(9).md new file mode 100644 index 0000000..f74e7f3 --- /dev/null +++ b/Leetcode Workshops/Week 1/Stacks(9).md @@ -0,0 +1,30 @@ +### Type: Code Steps Large ### + +2. Add elements to your stack through calling the push() function. + +```python +#The process of implementing push() call for stack +myStack = Stack() +print(myStack.push(5)) #prints whether the operation "push" successes +print(myStack.stack) #print the stack(left is bottom of the stack,right is the top of stack) +print(myStack.push(6)) +print(myStack.stack) +print(myStack.push(9)) +print(myStack.stack) +print(myStack.push(5)) +print(myStack.stack) +print(myStack.push(3)) +print(myStack.stack) + +#The result of the above code +True +[5] +True +[5, 6] +True +[5, 6, 9] +True +[5, 6, 9, 5] +True +[5, 6, 9, 5, 3] +```