2-25 - Problem Solving with Computers-II CS 24 February 25,...

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

View Full Document Right Arrow Icon
Problem Solving with Computers-II CS 24 February 25, 2010 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Printing all the Nodes in Order
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Code for Recursive InOrder Print void PrintTree(TreeNode* tree,  {   if (tree != NULL)   {     PrintTree(tree->left, outFile);        outFile << tree->info;     PrintTree(tree->right, outFile);     } }
Background image of page 6
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))
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 31

2-25 - Problem Solving with Computers-II CS 24 February 25,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online