How do I calculate Second Neighborhood?

Hello All,
I was wondering how I can calculate the second neighborhood given an adjacency matrix of size "n".
The second neighborhood has to account for any repeated node counts.

 Accepted Answer

VeeVan
VeeVan on 27 Jul 2018
Solution was found! Thank you all!

More Answers (2)

For each node, I would start with a 1xn column vector initialized with 0s. Then, access row i in the adjacency matrix and find each index j that is valued 1. For each vertex in the first neighborhood, iterate through row j of the adjacency matrix. When you encounter a 1 in row j at index k, change the value at index k of the earlier column vector to a 1. Index k of the column vector should represent whether vertex k is in the second neighborhood, so then just count the number of 1s in the column vector.

1 Comment

This answer wouldn't work due to the marginalized coefficiency adjacency matrix theorem which doesn't function under set conditions.

Sign in to comment.

I'm not familiar with the term "second neighborhood" in the context of graph theory. My guess is that what you're looking for is all nodes that are distance at most two from the node whose neighborhood you're trying to find. If that's the case, build a graph object and call the distances function or the nearest function on it.

Categories

Products

Release

R2018a

Asked:

on 27 Jul 2018

Answered:

on 28 Jul 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!