# 2-25 - Problem Solving with Computers-II CS 24 1 Recap Tree...

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

Problem Solving with Computers-II CS 24 February 25, 2010 1

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

View Full Document
Recap Tree and BST ADT General idea Shape of a BST depends on the order of insertion Computing the size of a tree Printing the contents of a tree Traversals Preorder can be used for depth-first search for a goal state in AI Evaluation of expressions 2
Lecture Plan Tree and BST ADT Feedback on Lab section Second midterm Topics Sorted list Binary search on arrays Exceptions Memory allocation (dangling pointer etc.) Stack Queue Recursion Activation record and runtime stack Tree and BST ADT Allowed one cheat sheet 3

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

View Full Document
4 Printing all the Nodes in Order
5 Function Print   Definition:     Prints the items in the binary search       tree in order from smallest to largest. Base Case:      If tree = NULL, do nothing. General Case:     Traverse the left subtree in order.      Then print Info(tree).      Then traverse the right subtree in order.

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

View Full Document
6 Code for Recursive InOrder Print void PrintTree(TreeNode* tree,  {   if (tree != NULL)   {     PrintTree(tree->left, outFile);        outFile << tree->info;     PrintTree(tree->right, outFile);     } }
7 Tree Traversals Inorder(tree) if tree is not NULL Inorder(Left(tree)) Visit Info(tree) Inorder(Right(tree)) PostOrder(tree) if tree is not NULL Postorder(Left(tree))

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 ]}

### Page1 / 31

2-25 - Problem Solving with Computers-II CS 24 1 Recap Tree...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online