Skip to content

Commit 737db42

Browse files
authored
Add files via upload
1 parent 67217dd commit 737db42

File tree

3 files changed

+2314
-15
lines changed

3 files changed

+2314
-15
lines changed

04_cohort_three/live_code/4_recursive_ds.ipynb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@
585585
},
586586
{
587587
"cell_type": "code",
588-
"execution_count": 3,
588+
"execution_count": 2,
589589
"id": "23428e44",
590590
"metadata": {},
591591
"outputs": [],
@@ -610,7 +610,7 @@
610610
},
611611
{
612612
"cell_type": "code",
613-
"execution_count": 4,
613+
"execution_count": 3,
614614
"id": "32ada213",
615615
"metadata": {},
616616
"outputs": [],
@@ -619,16 +619,16 @@
619619
" visited = set()\n",
620620
" queue = deque([start])\n",
621621
"\n",
622-
" while queue:\n",
623-
" current_vertex = queue.popleft()\n",
622+
" while queue: # While our queue isn't empty, do the following\n",
623+
" current_vertex = queue.popleft() # Look and remove at the first element in our queue\n",
624624
"\n",
625-
" if current_vertex not in visited:\n",
625+
" if current_vertex not in visited: # If it hasn't been visited, then:\n",
626626
" # Process the current vertex\n",
627-
" print(current_vertex, end=' ')\n",
628-
" visited.add(current_vertex)\n",
627+
" print(current_vertex, end=' ') # Print it\n",
628+
" visited.add(current_vertex) # Add it as visited\n",
629629
"\n",
630630
" # Enqueue unvisited neighbors\n",
631-
" for neighbor in graph.graph.get(current_vertex, []):\n",
631+
" for neighbor in graph.graph.get(current_vertex, []): # Add all of the vertex's neighbours to the queue (if not visi))\n",
632632
" if neighbor not in visited:\n",
633633
" queue.append(neighbor)"
634634
]
@@ -643,15 +643,15 @@
643643
},
644644
{
645645
"cell_type": "code",
646-
"execution_count": 5,
646+
"execution_count": 12,
647647
"id": "3b8d278a",
648648
"metadata": {},
649649
"outputs": [
650650
{
651651
"name": "stdout",
652652
"output_type": "stream",
653653
"text": [
654-
"1 3 6 10 7 "
654+
"15 "
655655
]
656656
}
657657
],
@@ -665,7 +665,7 @@
665665
"ex_graph.add_edge(7, [10, 6])\n",
666666
"\n",
667667
"# Perform BFS starting from vertex 1\n",
668-
"bfs(ex_graph, 1)"
668+
"bfs(ex_graph, 15)"
669669
]
670670
},
671671
{
@@ -680,7 +680,7 @@
680680
},
681681
{
682682
"cell_type": "code",
683-
"execution_count": 6,
683+
"execution_count": 9,
684684
"id": "d883118d",
685685
"metadata": {},
686686
"outputs": [],
@@ -709,20 +709,20 @@
709709
},
710710
{
711711
"cell_type": "code",
712-
"execution_count": 7,
712+
"execution_count": 10,
713713
"id": "c4b48ff8",
714714
"metadata": {},
715715
"outputs": [
716716
{
717717
"name": "stdout",
718718
"output_type": "stream",
719719
"text": [
720-
"1 3 6 10 7 "
720+
"1 3 10 7 6 "
721721
]
722722
}
723723
],
724724
"source": [
725-
"bfs(ex_graph, 1)"
725+
"recursive_preorder_traversal(ex_graph, 1)"
726726
]
727727
},
728728
{

0 commit comments

Comments
 (0)