AI Glossary / Mathematics and optimization / Intermediate

Neighbor

Definition

A neighbor of a node in a simple undirected graph is another node connected to it directly by an edge. The relationship depends on the graph's definition: an edge might represent communication, similarity, a transaction, or another specified connection. Being reachable through a longer path does not by itself make two nodes immediate neighbors.

What it means

A graph describes objects as nodes and relationships as edges. If a graph contains an edge joining A and B, B is a neighbor of A and A is a neighbor of B. The set of all immediate neighbors of A is commonly written N(A).

This entry follows the supplied glossary's graph-adjacency meaning. In other machine-learning contexts, a “nearest neighbor” is a data point selected using a distance or similarity rule. These ideas can be connected by constructing a graph from nearest-neighbor relationships, but a graph edge need not represent physical proximity or numerical closeness.

How it works

Start with the node and edge definitions. For an undirected graph, inspect the edges incident to the node and collect the nodes at their other ends. An adjacency list stores those connections directly; an adjacency matrix marks which node pairs are connected.

Directed graphs require a convention. An outgoing neighbor is reached by an edge leaving the node, while an incoming neighbor has an edge pointing into it. These sets can differ. For example, NetworkX's directed-graph neighbors operation returns successors, meaning outgoing neighbors.

State how self-loops and multiple edges are treated. In a simple graph without loops, a node is not its own neighbor, and its degree equals the number of distinct neighbors. More general graph types can break that equality. An edge weight can describe connection strength without changing whether the edge exists, unless a separate thresholding rule is applied.

Three practical examples

1. Device coordination: a sensor exchanges an update with devices directly connected in a communication graph. A distant device may be reachable only through forwarding.

2. Recommendation: items connected in a co-occurrence graph are neighbors under the chosen edge rule, even if their descriptions are not similar.

3. Graph learning: a model aggregates information from immediate neighbors to form a node representation. Multiple update layers can expand the region from which information is incorporated, subject to the model's design.

Think of it this way

Think of a map of direct train services. Two stations are neighbors in the service graph if a direct connection is represented, even if another station is geographically closer.

The analogy explains direct connection versus physical distance. It does not imply that every direct service has the same travel time, frequency, or reliability. Those properties need weights or additional attributes. A graph can also represent abstract relationships that have no transport interpretation.

Worked example

Consider five nodes A, B, C, D, and E, with undirected edges AB, AC, BD, and CD. Node E is isolated. The neighbor sets are N(A)={B,C}, N(B)={A,D}, N(C)={A,D}, N(D)={B,C}, and N(E)={}.

Node D is two steps from A, through either B or C, but it is not an immediate neighbor of A. The degrees are two, two, two, two, and zero. Their sum is eight, equal to twice the four edges, because each undirected edge contributes once at each endpoint.

Suppose B carries value two and C carries value six. An unweighted average of A's neighbors is (2+6)/2=4. Including A's own value of ten would instead give (10+2+6)/3=6. These are different aggregation rules; neither follows automatically from the word neighbor.

For a separate directed graph with A→B and C→A, A has outgoing neighbor B and incoming neighbor C. Treating both as outgoing contacts would add a direction of connection that the graph does not contain.

Illustrative case study

Fictional case study: a warehouse dashboard shows relationships between processing stations. Analysts call two stations neighbors when packages move directly between them. A planning team mistakenly interprets the graph as a floor map and assumes that neighboring stations are physically adjacent.

The teams clarify the edge definition and store travel distance separately. They also distinguish incoming package flows from outgoing flows. The corrected interpretation does not claim a throughput improvement; it prevents the system from presenting a process relationship as a physical location relationship.

Common misconceptions and mistakes

Do not confuse a neighbor with every node in the same connected component. Connectivity can involve many intermediate nodes.

Do not assume adjacency means similarity, influence, trust, or permission. Those interpretations require evidence from the edge definition.

Do not count repeated edges as additional distinct neighbor identities. In a multigraph, edge counts and neighbor counts can differ. Also check self-loop behavior in the actual implementation rather than assuming every library uses the simple-graph convention of excluding the node itself.

Business use

Neighbor definitions determine what a graph-based system treats as local. This affects recommendations, alerts, communication patterns, and the information supplied to graph-learning models.

Document the edge construction, direction, time window, and treatment of weights. If an edge means two events occurred within a recent period, the neighbor set can change as the window moves. Review isolated nodes and unexpectedly dense neighborhoods: they may be legitimate features of the system or signs of missing records, overly broad matching, or incorrect identifiers.

People also ask

Are neighbors always close in physical space?

No. They are directly connected according to the graph's edge definition, which may describe an abstract relationship.

Is a node two edges away a neighbor?

It is not an immediate neighbor under the simple adjacency definition. It can be described explicitly as a two-hop neighbor.

Does an incoming edge count as a neighbor relationship?

In a directed graph, specify incoming or outgoing neighbors. A software method may expose only one convention by default.

Check your understanding

In the worked undirected graph, why does A have two neighbors even though it can reach D?

Answer: A has direct edges only to B and C. Reaching D requires an intermediate node, so D is reachable but not immediately adjacent to A.

Related terms

  • Node
  • Neighborhood
  • Directed graph
  • Nearest neighbor
  • Graph neural network
  • edge
  • adjacency
  • degree
  • connected component

Learn next

write neighbor lists for a small graph and compare them with its adjacency matrix. Then direct some edges and list incoming and outgoing neighbors separately, checking how each convention changes an aggregation or traversal.

More in Mathematics and optimization

  • Absolute error loss - Absolute error loss measures a numerical prediction's error as the absolute difference between its predicted and reference values: L(y,y-hat)=|y-y-hat|.
  • Active-set method - An active-set method is an optimization approach that works with a changing subset of constraints believed to be tight at the solution.
  • Adjoint state method - The adjoint state method computes how a chosen objective changes when the parameters of a mathematical model change.
  • Σ-algebra
  • Algebraic connectivity - Algebraic connectivity is the second-smallest eigenvalue of a graph's Laplacian matrix.
  • Algorithm IMED - Algorithm IMED, short for Indexed Minimum Empirical Divergence, is a method for choosing actions in a stochastic multi-armed bandit problem.

Sources

Sources: Aalto Dictionary of Machine Learning, neighbor: https://aaltodictionaryofml.github.io/ADictML_Main.pdf ; NetworkX, Graph.neighbors: https://networkx.org/documentation/stable/reference/classes/generated/networkx.Graph.neighbors.html ; NetworkX, DiGraph.neighbors: https://networkx.org/documentation/stable/reference/classes/generated/networkx.DiGraph.neighbors.html . Primary definition and implementation direction convention were read. Scope is graph adjacency; the example graphs and fictional case are original.

Previous: Negatively skewed Next: Neighborhood

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer