0
0
DSA Cprogramming~10 mins

Graph Terminology Vertices Edges Directed Undirected Weighted in DSA C - Interactive Practice

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

Complete the code to declare a graph vertex structure with an integer id.

DSA C
typedef struct Vertex {
    int [1];
} Vertex;
Drag options to blanks, or click blank then click option'
Avalue
Bweight
Cedge
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'weight' or 'edge' as the vertex identifier field.
Using a generic name like 'value' instead of 'id'.
2fill in blank
medium

Complete the code to declare an edge structure with source and destination vertices.

DSA C
typedef struct Edge {
    int source;
    int [1];
} Edge;
Drag options to blanks, or click blank then click option'
Aweight
Bdestination
Cid
Dvertex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'weight' instead of the destination vertex.
Using 'id' or 'vertex' which are not correct here.
3fill in blank
hard

Fix the error in the code to correctly declare a weighted edge structure.

DSA C
typedef struct WeightedEdge {
    int source;
    int destination;
    float [1];
} WeightedEdge;
Drag options to blanks, or click blank then click option'
Aweight
Bid
Cvalue
Dcost
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' or 'value' which are ambiguous.
Using 'cost' which is less common in this context.
4fill in blank
hard

Fill both blanks to complete the function that checks if a graph is directed or undirected based on edges.

DSA C
int isDirectedGraph(Edge edges[], int n) {
    for (int i = 0; i < n; i++) {
        int src = edges[i].source;
        int dest = edges[i].[1];
        int found = 0;
        for (int j = 0; j < n; j++) {
            if (edges[j].source == dest && edges[j].[2] == src) {
                found = 1;
                break;
            }
        }
        if (!found) return 1; // Directed
    }
    return 0; // Undirected
}
Drag options to blanks, or click blank then click option'
Adestination
Bweight
Csource
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'weight' or 'id' instead of 'destination' causes logic errors.
Mixing source and destination fields incorrectly.
5fill in blank
hard

Fill all three blanks to complete the function that creates a weighted edge and assigns values.

DSA C
WeightedEdge createWeightedEdge(int [1], int [2], float [3]) {
    WeightedEdge e;
    e.source = [1];
    e.destination = [2];
    e.weight = [3];
    return e;
}
Drag options to blanks, or click blank then click option'
Asrc
Bdest
Cw
Dcost
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names that don't match the assignments.
Using 'cost' instead of 'w' for weight parameter.