Verilog N-bit Binary Search Tree Node Insertion
/* * Module: bst_node_insert * Description: Inserts a node with a given N-bit value into a Binary Search Tree. * This implementation simulates recursion using state machines and explicit pointers. * Assumes nodes are dynamically allocated or managed externally. */ module bst_node...
This Verilog module implements the logic for inserting a node into an N-bit Binary Search Tree (BST). It simulates the recursive nature of BST insertion using a finite state machine (FSM) and explicit pointer management....
The `bst_node_insert` module uses a state machine to manage the insertion process into a Binary Search Tree. The states include `IDLE`, `TRAVERSE`, `INSERT_NEW`, and `HANDLE_DUPLICATE`. In the `IDLE` state, it waits for an insertion request. Upon receiving `insert_en`, it transitions to `TRAVERSE`. In `TRAVERSE`, it compares the `insert_val` with the `current_node_val`. If they match, it moves to `HANDLE_DUPLICATE`. If `insert_val` is smaller, it attempts to move to the left child; otherwise, it attempts to move to the right child. If a null child pointer is encountered during traversal, it transitions to `INSERT_NEW`. In `INSERT_NEW`, logic for allocating a new node and linking it to its parent would be implemented (abstracted here). `HANDLE_DUPLICATE` signals that the value already exists. The time complexity for insertion in a balanced BST is O(log N), where N is the number of nodes, but in the worst case (a skewed tree), it can be O(N). The space complexity is O(1) for the FSM and pointer management logic itself, excluding the space occupied by the BST nodes.
module bst_node_insert(clk, reset, insert_val, insert_en, insert_done, duplicate_found) parameter N = 8 input clk, reset, insert_en input signed [N-1:0] insert_val output insert_done, duplicate_found state_t current_stat...