0
0
Data Structures Theoryknowledge~10 mins

Weighted graphs in Data Structures Theory - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to represent a weighted edge between two nodes.

Data Structures Theory
edge = ([1], 5)
Drag options to blanks, or click blank then click option'
A"node"
B"A-B"
C"weight"
D"A"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the weight value instead of the node name.
Putting the entire edge as a string instead of a tuple.
2fill in blank
medium

Complete the code to add a weighted edge from node 'A' to node 'B' with weight 7 in an adjacency list.

Data Structures Theory
graph["A"] = [("B", [1])]
Drag options to blanks, or click blank then click option'
A5
B7
C10
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong weight value.
Confusing node names with weights.
3fill in blank
hard

Fix the error in the weighted graph representation by completing the missing weight value.

Data Structures Theory
edges = {"A-B": [1]
Drag options to blanks, or click blank then click option'
A3
B"weight"
C"3"
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for weight.
Leaving the weight as None.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps nodes to their weighted edges with weights greater than 4.

Data Structures Theory
{node: edges for node, edges in graph.items() if edges[0][[1]] [2] 4}
Drag options to blanks, or click blank then click option'
A1
B>
C<
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong index for weight.
Using less than instead of greater than.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each node to the weight of its first edge if the weight is less than 10.

Data Structures Theory
{node: edges[[1]][[2]] for node, edges in graph.items() if edges[0][[3]] < 10}
Drag options to blanks, or click blank then click option'
A0
B1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up indices for nodes and weights.
Using the wrong index in the condition.