"## Exercise 2: Return the list of links from a tree\n",
"\n",
"Given the two data structure from the previous exercise (i.e. dict and object), return the list of links of those two trees in the same order and compare them. Return `-1` if the trees have a cycle."
"## Exercise 3: Calculate the total weight of a weighted tree\n",
"\n",
"Update the two previous data structure to store a weight value. The weight is stored in links and is any numerical value. For the dictionnary, adapt the data structured using named values as below. Provide examples of weighted trees similar as the previous questions (you assign random weights, if no weight then assign `0`)."
## Exercise 2: Return the list of links from a tree
Given the two data structure from the previous exercise (i.e. dict and object), return the list of links of those two trees in the same order and compare them. Return `-1` if the trees have a cycle.
## Exercise 3: Calculate the total weight of a weighted tree
Update the two previous data structure to store a weight value. The weight is stored in links and is any numerical value. For the dictionnary, adapt the data structured using named values as below. Provide examples of weighted trees similar as the previous questions (you assign random weights, if no weight then assign `0`).
" for neighbor in reversed(graph[node]['neighbors']):\n",
" if neighbor and not graph[neighbor]['visited']:\n",
" stack.append(neighbor)\n",
" \n",
"dfs2(g2, 'a')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e4fcaef5-cfb0-4d10-a8ca-930696b29c89",
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "a51b3775bbd811fdc5c3405386189c3f",
"grade": false,
"grade_id": "cell-646e92ff31a3a804",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
},
"tags": []
},
"outputs": [],
"source": [
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
]
},
{
"cell_type": "markdown",
"id": "50882bb9-8de8-4e0a-93db-38aedfa77ca0",
"metadata": {},
"source": [
"Write tests."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7fb9a85c-976f-4054-948a-a58d6e4504ea",
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "d4cf1af31642fc40582135f3e0fc1976",
"grade": false,
"grade_id": "cell-585b0274f5419089",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
},
"tags": []
},
"outputs": [],
"source": [
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
]
},
{
"cell_type": "markdown",
"id": "ce9470d2-7b5c-48a9-9ebf-7060a023a379",
"metadata": {},
"source": [
"## Exercise 6: Use a Graph POO data structure\n",
"\n",
"Instead of using a Dict, use a POO class (that may use a dict internally) and associated methods to solve the above problems (as new methods of the class)."
Instead of using a Dict, use a POO class (that may use a dict internally) and associated methods to solve the above problems (as new methods of the class).