Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
saliaqat authored Jul 18, 2024
1 parent 67217dd commit 737db42
Show file tree
Hide file tree
Showing 3 changed files with 2,314 additions and 15 deletions.
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

0 comments on commit 737db42

Please sign in to comment.