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
EasyBefore 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;
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Depth-First Search - Graph Algorithms
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)