How is a certain graph determined?

I saw an interview question in which the chart structure was defined:

struct Node{
   vector<Node*> neighbors;
}

I thought this was unusual or perhaps a mistake, since there is nothing to really distinguish between nodes. Am I reasoning correctly, or can a graph correctly determine only the vector of neighbors? I thought we would need something like this:

template<typename T>
struct Node{
   T value;
   vector<Node*> neighbors;
}

Which intuitively makes more sense to me.

Is there any β€œtypical” way to define a schedule? For example, with a binary tree, we would have (at least) a value plus left and right pointers. With a linked list, we would have (at least) the value and the next pointer, etc.

+4
source share
5 answers

, - . , , . , , . .

, , , , node. , , . , .

, " , ".

. , , , " ", .

:

+3

node? . node ( edge), , . , " " " " BGL. node , , - . , " ", std::unordered_map<void*, P> . , .

. , , . (.. , , , , ). , , . , . , , N M , N M GCD .

, . node , - , , , . , , , .

+2

Compressed Sparse Row (CSR), . ( , ..) , . CSR , , .

, NVIDIA Parallel Forall. . " ". , HPC .

, :


(: nvidia.com)

( BC[x] = y)

0... 8, 1... 9, CSR :


(: nvidia.com)

R - , C - . - n + 1, , . , u C[R[u]] C[R[u+1]-1] .

, , 4 , 3, , R[3] = 8 R[4] = 12, , , 3, C[8] C[12] {0,2,4,5}, {1,3,5,6}, .

+1

. - , (node) , .

, , , , , node . , . , node , , .

0

, Adjacency. (i, j) , node j.

0

Source: https://habr.com/ru/post/1568564/


All Articles