liveBook · Manning

Node

As explained in Grokking AI Algorithms, Second Edition

A node, also called a vertex, is an individual state or object represented within a graph.

A node, also called a vertex, is one state or object in a graph. An edge connects two nodes. Picture a road trip: each stop is a node, each route between stops is an edge, and an edge’s weight can record the distance traveled. section 2.5

A node directly connected to another is its neighbor, or adjacent node. Algorithms can store these relationships as arrays of edges, an adjacency matrix, or an adjacency list. The useful question is: from this node, which nodes can I reach next? section 2.6

In a tree, nodes also have family-like roles:

  • The root is the topmost node. A parent connects to children below it; a node with no children is a leaf. section 2.7
  • A path follows nodes and edges from one point to another. A tree has no cycles, so its hierarchy offers a clear way to trace a route. section 2.7

Following nodes through a maze

Depth-first search starts by putting the root node on a stack. It pops a node, marks it visited, checks for the goal, then adds its neighbors to the stack. Each neighbor records the current node as its parent. If the goal is found, those parent links trace a path back to the root; if the stack empties first, no path was found. section 2.12

def run_dfs(maze_game, current_point):
    visited_points = [] #A
    stack = [current_point] #A
    while stack: #B
        next_point = stack.pop() #C
        if not is_in_visited_points(next_point,
        ➥visited_points): #D
            visited_points.append(next_point) #D
            if maze_game
            ➥.get_current_point_value(next_point)
            ➥== '*': #E
                return next_point #E
            else:
                neighbors =
                ➥maze_game.get_neighbors(next_point) #F
                for neighbor in neighbors: #F
                    neighbor.set_parent(next_point) #F
                    stack.append(neighbor) #F
return 'No path to the goal found.'

The Python listing shows nodes moving through a DFS stack, a visited list, and parent links in a maze search. section 2.12

Node also appears in artificial neural network descriptions: input nodes can represent pixel values, while output nodes can represent possible digit results. Here, the term identifies parts of a network rather than stops on a route. section 9.12

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines node relationships and walks through their use in depth-first search, without developing graph theory proofs.
Examples
Illustrates nodes with road-trip stops, a maze-search Python listing, and pixel inputs for handwritten-digit recognition.
What it assumes
Introduces graph and tree terms from basic definitions before showing a Python search listing.
What you can do after
Build it from scratch: represent connected states and use a stack, visited list, and parent links to search a maze.
How it connects
Connects nodes to edges, adjacency, trees, paths, depth-first search, and artificial neural networks.

Also explained in

Compare how 19 books explain node →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.