{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

final_practice

# final_practice - ECE 190 Final Exam Practice exam Problem 1...

This preview shows pages 1–4. Sign up to view the full content.

1 ECE 190 Final Exam Practice exam Problem 1: MP5-related Problem 2: LC-3 Problem 3: Debugging Problem 4: Linked data structures Problem 5: Multi-dimensional arrays Please note You are allowed to bring four handwritten 8.5 x 11" sheets of notes. Printed notes will be confiscated! On the real exam, we will provide you with the actual codes to work on as well as details about compiling, executing, and testing. For the practice exam, we provide you with just a handout and some limited examples of how to use the functions that you are required to implement. It will be a good exercise for you to write the rest of the code.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Problem 1: MP5 - related For this problem, you will be implementing the destroy search tree function which tears down an AI search tree data structure. Each node on the tree has a distance associated with it, and an array of four pointers to child nodes, each element corresponding to the four cardinal directions. A NULL pointer means no child node in that direction. Implementation Requirements You are required to implement the following recursive function that destroys the tree: void destroy_search_tree(tree_node * node); Tree node structure is defined as follows: typedef struct tree_node { int distance; /*! Pointers to the four child nodes: N,S,E,W */ struct tree_node * branches[4]; } tree_node; We highly recommend running your code with valgrind to verify that the tree is de-allocated correctly. Example /* create some tree */ tree_node *root=calloc(1, sizeof(tree_node)); for (i=0; i < 4; i++) root->branches[i] = calloc(1, sizeof(tree_node)); for (i=0; i < 4; i++) root->branches[1]->branches[i] = calloc(1, sizeof(tree_node)); /* destroy it */ destroy_search_tree(root);
3 Problem 2: LC - 3 The following code computes the depth of a binary tree. Convert it from C to LC-3 assembly: typedef struct s_node { int value; struct s_node *left; struct s_node *right; } node; int max_depth(node *node) { int ldepth, rdepth; if (node == NULL) { return 0; } else { ldepth = max_depth(node->left); rdepth = max_depth(node->right); if (ldepth > rdepth) { return ldepth + 1; } else { return rdepth + 1; } } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}