Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lecture 5 live code #24

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 15 additions & 15 deletions 04_cohort_three/live_code/4_recursive_ds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "23428e44",
"metadata": {},
"outputs": [],
Expand All @@ -610,7 +610,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "32ada213",
"metadata": {},
"outputs": [],
Expand All @@ -619,16 +619,16 @@
" visited = set()\n",
" queue = deque([start])\n",
"\n",
" while queue:\n",
" current_vertex = queue.popleft()\n",
" while queue: # While our queue isn't empty, do the following\n",
" current_vertex = queue.popleft() # Look and remove at the first element in our queue\n",
"\n",
" if current_vertex not in visited:\n",
" if current_vertex not in visited: # If it hasn't been visited, then:\n",
" # Process the current vertex\n",
" print(current_vertex, end=' ')\n",
" visited.add(current_vertex)\n",
" print(current_vertex, end=' ') # Print it\n",
" visited.add(current_vertex) # Add it as visited\n",
"\n",
" # Enqueue unvisited neighbors\n",
" for neighbor in graph.graph.get(current_vertex, []):\n",
" for neighbor in graph.graph.get(current_vertex, []): # Add all of the vertex's neighbours to the queue (if not visi))\n",
" if neighbor not in visited:\n",
" queue.append(neighbor)"
]
Expand All @@ -643,15 +643,15 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 12,
"id": "3b8d278a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 3 6 10 7 "
"15 "
]
}
],
Expand All @@ -665,7 +665,7 @@
"ex_graph.add_edge(7, [10, 6])\n",
"\n",
"# Perform BFS starting from vertex 1\n",
"bfs(ex_graph, 1)"
"bfs(ex_graph, 15)"
]
},
{
Expand All @@ -680,7 +680,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 9,
"id": "d883118d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -709,20 +709,20 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"id": "c4b48ff8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 3 6 10 7 "
"1 3 10 7 6 "
]
}
],
"source": [
"bfs(ex_graph, 1)"
"recursive_preorder_traversal(ex_graph, 1)"
]
},
{
Expand Down
Loading
Loading