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
GraphSearching 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
- Take the identifier of the node being searched for.
- Check the graph's vertex collection (e.g. a hash table of adjacency lists) for that identifier.
- 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}
- Look up 'B' in the vertex collection
- Found — B exists
Output: true (B exists in the graph)
Press ▶ Run to watch it step by step.
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: searchBehind 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
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
Ready for the next step?
See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.