Data Structures · Visualization

Graph: Search Node

Graph

Searching for a node simply checks whether a given identifier exists among the graph's vertices, which is usually a fast, direct lookup if vertices are stored in a hash table or similar structure. Time: O(1) average with a hash-table-backed structure. Space: O(1).

Big-O: BFS/DFS visit each vertex and edge once: O(V + E).

Graph: Search Node

Graph

Searching for a node simply checks whether a given identifier exists among the graph's vertices, which is usually a fast, direct lookup if vertices are stored in a hash table or similar structure. This is different from searching for a path or reachable node, which requires traversal (BFS/DFS).

How Search Node Works

  1. Take the identifier of the node being searched for.
  2. Check the graph's vertex collection (e.g. a hash table of adjacency lists) for that identifier.
  3. If found, the node exists; if not, it doesn't.

Search Node Worked Example

Input: Search for node 'B' in a graph containing {A, B, C}

  1. Look up 'B' in the vertex collection
  2. Found — B exists

Output: true (B exists in the graph)

Graph: Introduction
A set of nodes connected by edges — edges can be one-way or two-way, and optionally carry a weight (cost/distance).
A
B
C
D
E
Unvisited Visited / discovered Current Start
Graph: Introduction
Press ▶ Run to watch it step by step.
Python · Graphs in Code
def search(graph, start, target):
    seen = {start}
    stack = [start]
    while stack:
        v = stack.pop()
        if v == target:
            return True
        for nxt in graph[v]:
            if nxt not in seen:
                seen.add(nxt)
                stack.append(nxt)
    return False
# example: search
Input: Search for node 'B' in a graph containing {A, B, C}

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Search Node Time & Space Complexity

TimeO(1) average with a hash-table-backed structure
SpaceO(1)

When to Use Search Node

  • Validating a node exists before adding edges to/from it
  • Checking if a user/entity is registered in the system's graph

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.