clean up repo.

add more notes
This commit is contained in:
2024-02-06 21:53:17 +00:00
parent d552050f7e
commit 3fe14b8ac0
13 changed files with 52 additions and 60 deletions

View File

@@ -2,4 +2,4 @@
- Dijkstra's algorithm works when all weights are non-negative
- If there are negative weights use Bellman-Ford.
- Priority queue + min heap is optimal when compared to a function that operates on a list.
- The book demonstrates a function that operates on a list. Priority queue + min heap added for completeness.

View File

@@ -1,10 +0,0 @@
import heapq
customers = []
heapq.heappush(customers, (2, "Harry"))
heapq.heappush(customers, (3, "Charles"))
heapq.heappush(customers, (1, "Riya"))
heapq.heappush(customers, (4, "Stacy"))
while customers:
print(heapq.heappop(customers))

View File

@@ -1,14 +0,0 @@
customers = []
customers.append((2, "Harry")) # no sort needed here because 1 item.
customers.append((3, "Charles"))
customers.sort(reverse=True)
# Need to sort to maintain order
customers.append((1, "Riya"))
customers.sort(reverse=True)
# Need to sort to maintain order
customers.append((4, "Stacy"))
customers.sort(reverse=True)
while customers:
print(customers.pop(0))
# Will print names in the order: Stacy, Charles, Harry, Riya.

View File

@@ -1,12 +0,0 @@
from queue import PriorityQueue
customers = (
PriorityQueue()
) # we initialise the PQ class instead of using a function to operate upon a list.
customers.put((2, "Harry"))
customers.put((3, "Charles"))
customers.put((1, "Riya"))
customers.put((4, "Stacy"))
while customers:
print(customers.get())