Menu
Coddy logo textTech

Implementation (Part 1)

Lesson 5 of 9 in Coddy's Depth-First Search - Graph Algorithms course.

We will build DFS starting from the adjacency lookup.

challenge icon

Challenge

Easy

Before traversing a graph, we need to know each vertex's neighbors. Let's build that lookup from the flat edge list.

Write a function named getNeighbors that takes the edges array (flat pairs [u0, v0, u1, v1, ...], undirected) and a vertex node, and returns the sorted list of node's neighbors, with no duplicates.

For example, getNeighbors([0,1, 0,2, 1,2, 3,0], 0) returns [1, 2, 3].

Try it yourself

#include <stdlib.h>

int* getNeighbors(int* edges, int edges_size, int node, int* returnSize) {
    // Write code here
    *returnSize = 0;
    return edges;
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Depth-First Search - Graph Algorithms