we enqueue the root node and keep list of the visited nodes in the list_of_nodes list the dequeue class is used to maintain queuewhile len(traversal_queue node traversal_queue popleft(list_of_nodes append(node dataif node left_childtraversal_queue append(node left_childif node right_childtraversal_queue append(node right_childreturn list_of_nodes if the number of elements in the traversal_queue is greater than zerothe body of the loop is executed the node at the front of the queue is popped off and appended to the list_of_nodes list the first if statement will enqueue the left child node of the node provided left node exists the second if statement does the same for the right child node the list_of_nodes is returned in the last statement benefits of binary search tree we shall now briefly look at what makes bst better idea than using list for data that needs to be searched let us assume that we have the following dataset and using listthe worst-case scenario would require you to search through the entire list of seven elements before finding the search termsearching for requires six jumps