Ch 7. Trees

Ch 7. Programming Exercises

Exercise 1: Binary Search Tree Builder

The objective of this exercise is to practice constructing and traversing binary search trees.

Your task is to write a program (using pseudocode or a programming language of your choice) that accepts a list of integers and builds a binary search tree. Then, implement an in-order traversal to print the values in ascending order.

 

Exercise 2: Tree Search Simulator

The objective of this exercise is to simulate search operations in a tree.

Your task is to create a function (using pseudocode or a programming language of your choice) that takes a binary search tree and a target value, and returns whether the value exists in the tree. Include a counter to track the number of comparisons made during the search.

 

Exercise 3: Decision Tree Classifier

The objective of this exercise is to model decision-making using a tree structure.

Your task is to implement a simple decision tree (using pseudocode or a programming language of your choice) that classifies whether a user should be granted access based on three Boolean inputs: isAuthenticated, isAdmin, and isRequestSecure. Print the decision path and outcome.

 

Exercise 4: Tree Insertion and Deletion Tool

The objective of this exercise is to reinforce tree modification operations.

Your task is to write a program (using pseudocode or a programming language of your choice) that allows users to insert and delete nodes from a binary search tree. After each operation, display the tree using in-order traversal.

 

Exercise 5: File System Tree Simulator

The objective of this exercise is to apply tree structures to a real-world scenario.

Your task is to simulate a file system using a tree, where each node represents a folder or file. Implement functions (using pseudocode or a programming language of your choice) to add folders/files, delete them, and display the structure using a depth-first traversal.