Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Binary Search - Data Structures - Exam, Exams of Data Structures and Algorithms

Main points of this exam paper are: Binary Search, Preorder Traversal, Leaf Node, Most Precise, Smallest Value, Minimum Height, Java Statement

Typology: Exams

2012/2013

Uploaded on 04/07/2013

sethuraman_h34rt
sethuraman_h34rt 🇮🇳

4.3

(8)

159 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 256 Data Structures Exam 2 Name:____________________________
Questions about binary trees refer to the definitions on the last page for BinaryTree,
BinarySearchTreeInterface, BinarySearchTree, and Node.
1. [4] Briefly explain why the root data member in the BinaryTree class is declared to be
protected?
2. [4] Briefly explain why the Node class is declared to be static?
3. [10] Write a recursive BinaryTree method named count_leaves that returns the number
of leaves in the tree.
pf3
pf4
pf5

Partial preview of the text

Download Binary Search - Data Structures - Exam and more Exams Data Structures and Algorithms in PDF only on Docsity!

CS 256 Data Structures Exam 2 Name:____________________________

Questions about binary trees refer to the definitions on the last page for BinaryTree , BinarySearchTreeInterface , BinarySearchTree , and Node.

  1. [4] Briefly explain why the root data member in the BinaryTree class is declared to be protected?
  2. [4] Briefly explain why the Node class is declared to be static?
  3. [10] Write a recursive BinaryTree method named count_leaves that returns the number of leaves in the tree.
  1. [4] Draw the binary search tree that results from inserting the integers 57, 85, 35, 9, 47, 20, 26, 99, 93, 10 starting with 57 and ending with 10.
  2. [4] What is the preorder traversal of your tree from question 4?
  3. [4] What is the postorder traversal of your tree from question 4?
  4. [4] What is the breadth first traversal of your tree from question 4?
  5. [3] True / False (circle one). Inserting into a binary search tree always inserts a leaf node.
  6. [3] The _______________ data structure is needed for an iterative (non-recursive) function that does a preorder traversal of a binary tree. (I want the best and most precise answer. Don't write binary tree )
  1. [4] Using the binary search tree in question 12, redraw the tree after deleting 70.
  2. [4] If we insert n items into a binary search tree and the resulting tree has a height of n , what does that say about the items?
  3. [4] The minimum number of leaves in a binary search tree of height h is _____________
  4. [4] The maximum number of leaves in a binary search tree of height h is _____________
  5. [4] The minimum height of a binary search tree with 79 nodes is _____________
  6. [3] The worst case time efficiency for inserting into a binary search tree with n nodes and height h is: a) O( log(n) ) b) O( h ) Answer:_____________ c) O(1) (constant time) d) none of the above
  7. [3] The worst case time efficiency for the recursive preorder function on a binary tree with n nodes and height h is: a) O( log(n) ) b) O( h ) Answer:__________ c) O( n ) d) none of the above
  1. [10] Given the mystery function below what is the value of mystery(7263) int mystery( int x) { if (x < 10) return 0; Answer:_____________ else return 1 + mystery(x/10); }

21. [5] Consider the function below that recursively computes the sum of 1 to n. State a

precondition for the function sum. (Looking for the best answer, For example, “n must be an integer” is not a good answer). int sum(int n) { if (n == 0) return 0; else return n + sum(n1); }