Key Concepts

Review core concepts you need to learn to master this subject

Python Node implementation

class Node: def __init__(self, value, next_node=None): self.value = value self.next_node = next_node def set_next_node(self, next_node): self.next_node = next_node def get_next_node(self): return self.next_node def get_value(self): return self.value

A Node is a data structure that stores a value that can be of any data type and has a pointer to another node. The implementation of a Node class in a programming language such as Python, should have methods to get the value that is stored in the Node, to get the next node, and to set a link to the next node.

Node: An individual part of a larger data structure

class Node: def __init__(self, value, next_node=None): self.value = value self.next_node = next_node def set_next_node(self, next_node): self.next_node = next_node def get_next_node(self): return self.next_node def get_value(self): return self.value

Nodes are a basic data structure which contain data and one or more links to other nodes. Nodes can be used to represent a tree structure or a linked list. In such structures where nodes are used, it is possible to traverse from one node to another node.

Null node link

class Node: def __init__(self, value, next_node=None): self.value = value self.next_node = next_node def set_next_node(self, next_node): self.next_node = next_node def get_next_node(self): return self.next_node def get_value(self): return self.value

Data structures containing nodes have typically two bits of information stored in a node: data and link to next node.

The first part is a value and the second part is an address of sorts pointing to the next node. In this way, a system of nodes is created. A NULL value in the link part of a node’s info denotes that the path or data structure contains no further nodes.

Orphaned nodes

class Node: def __init__(self, value, next_node=None): self.value = value self.next_node = next_node def set_next_node(self, next_node): self.next_node = next_node def get_next_node(self): return self.next_node def get_value(self): return self.value

Nodes that have no links pointing to them except for the head node, are considered “orphaned.” In the illustration, if the nodes a2 and a5 are removed, they will be orphaned.

Chevron Left Icon
Nodes: Conceptual
Lesson 1 of 2
Chevron Right Icon
  1. 1
    Nodes are the fundamental building block of many computer science data structures. They form the basis for linked lists, stacks, queues, trees, and more. An individual node contains data and lin…
  2. 2
    The data contained within a node can be a variety of types, depending on the language you are using. In the previous example, it was an integer (the number 5), but it could be a string (“five”), de…
  3. 3
    Often, due to the data structure, nodes may only be linked to from a single other node. This makes it very important to consider how you implement modifying or removing nodes from a data structure…
  4. 4
    Let’s take a minute to review what we’ve covered about nodes in this lesson. Nodes: - Contain data, which can be a variety of data types - Contain links to other nodes. If a node has no links, or…
  1. 1
    Now that you have an understanding of what nodes are, let’s see one way they can be implemented using Python. We will use a basic node that contains data and one link to another node. The node’s …
  2. 2
    We need methods to access the data and link within the node. For this, we will use two getters, get_value and get_link_node. These should each return their corresponding value on the self object.
  3. 3
    We are only allowing the value of the node to be set upon creation. However, we want to allow updating the link of the node. For this, we will use a setter to modify the self.link_node attribute. …
  4. 4
    We have a few zany characters to keep track of and Python nodes may do just the trick. Let’s get started…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo