Menu
Coddy logo textTech

Implementation (Part 1)

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

We start from the neighbor lookup.

challenge icon

Challenge

Easy

As with any traversal, we first need each vertex's neighbors. (If you took the DFS course, this is the same helper.)

Write a function named getNeighbors that takes the flat edges array (undirected pairs) 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 Breadth-First Search - Graph Algorithms