CSSE 230
Data Structures and Algorithm Analysis

Written Assignment 4 - 40 points

To Be Turned In

  1. (20 points) Weiss Exercise 5.26 [5.20]. Calculate the average-case time complexity of the binary search algorithm. In order to make the calculations simpler, you may assume that N = 2k - 1 for some integer k ≥ 0, and that all elements are equally likely to be the one we are searching for. Note that the problem only deals with successful searches (where the item we are looking for is actually in the array).

    Hint: For each i, count how many of the array elements will be found after binary search examines exactly i array elements. (For example, the middle element is the only one to be found after examining one array element, and there are two elements that can be found after two probes into the array.) Use a summation to help you find the average.

    Potentially useful fact: Depending on how you work this problem, you may find the following useful:

  2. (deleted)
  3. (10 points) It is useful to have a unique representation of binary trees that can be written compactly. For simplicity, we assume that each node of the tree will contain one Character. We represent a tree by a pair of strings, which I call chars and children. The chars is a pre-order listing of the contents of the nodes. The children string tells about the children of the corresponding node from chars as follows:

    2 The node has two children.
    0 The node has no children.
    L The node only has a left child.
    R The node only has a right child.

    For example:

    chars = "+a*-bcd"; children = "2022000";
    represents the tree in Weiss Figure 18.11 (a)

    chars = "7215349"; children = "220LR00";
    represents the tree in Weiss Figure 19.4 (a).

    1. What are the values of chars and children for the tree below?

    2. For a different tree we have:

         chars = "THEQUICKBROWN";
      children = "2R220002R0RL0";
      

      Show the order of the nodes in an in-order traversal of the tree.

  4. (10 points)

    THEQUICKLAZYFOX is the pre-order traversal of a tree (one character per node).

    QIUCEHLAZKFYTXO is the in-order traversal of the same tree.

    What is the order of the nodes in the level-order traversal of this tree?

  5. (deleted)
  6. (deleted)
  7. (deleted)
  8. (deleted)

For Your Consideration

These problems are for you to think about and convince yourself that you could do them. It would be good practice to actually do them, but you are not required to turn them in.