Second Sample Exam 1 - Data Structures and Software Principles | CS 225, Exams of Data Structures and Algorithms

Material Type: Exam; Professor: Earls; Class: Data Structures; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Spring 2011;

Typology: Exams

2010/2011

Uploaded on 06/14/2011

koofers-user-kuc
koofers-user-kuc 🇺🇸

4.7

(3)

7 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
University of Illinois at Urbana-Champaign
Department of Computer Science
Second Examination
CS 225 Data Structures and Software Principles
Sample Exam 1
75 minutes permitted
Print your name, netID, and lab section day/time neatly in the space provided below; print
your name at the upper right corner of every page.
Name:
NetID:
Lab Section (Day/Time):
This is a closed book and closed notes exam. In addition, you are not allowed to use any
electronic aides of any kind.
Do all 4 problems in this booklet. Read each question very carefully.
You should have 7 sheets total (the cover sheet, plus numbered pages 1-12). The last sheet is
scratch paper; you may detach it while taking the exam, but must turn it in with the exam
when you leave.
Unless otherwise stated in a problem, assume the best possible design of a particular imple-
mentation is being used.
Unless the problem specifically says otherwise, (1) assume the code compiles, and thus any
compiler error is an exam typo (though hopefully there are not any typos), and (2) assume
you are NOT allowed to write any helper methods to help solve the problem, nor are you
allowed to use additional arrays, lists, or other collection data structures unless we have said
you can.
Problem Points Score Grader
1 20
2 20
3 20
4 30
Total 90
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Second Sample Exam 1 - Data Structures and Software Principles | CS 225 and more Exams Data Structures and Algorithms in PDF only on Docsity!

University of Illinois at Urbana-Champaign

Department of Computer Science

Second Examination

CS 225 Data Structures and Software Principles

Sample Exam 1

75 minutes permitted

Print your name, netID, and lab section day/time neatly in the space provided below; print your name at the upper right corner of every page.

Name:

NetID:

Lab Section (Day/Time):

  • This is a closed book and closed notes exam. In addition, you are not allowed to use any electronic aides of any kind.
  • Do all 4 problems in this booklet. Read each question very carefully.
  • You should have 7 sheets total (the cover sheet, plus numbered pages 1-12). The last sheet is scratch paper; you may detach it while taking the exam, but must turn it in with the exam when you leave.
  • Unless otherwise stated in a problem, assume the best possible design of a particular imple- mentation is being used.
  • Unless the problem specifically says otherwise, (1) assume the code compiles, and thus any compiler error is an exam typo (though hopefully there are not any typos), and (2) assume you are NOT allowed to write any helper methods to help solve the problem, nor are you allowed to use additional arrays, lists, or other collection data structures unless we have said you can.

Problem Points Score Grader

Total 90

  1. [Analysis – 20 points (10 points each)].

(a) You are given a BinarySearchTree class whose insert method inserts its parameter into the binary search tree, using the usual algorithm. Express, using big-O notation, the order of growth of the worst-case running time of the following code, as n increases. Justify your answer. BinarySearchTree bst; // creates an empty binary search tree for (int i = 1; i <= n; i++) // this is the n we are talking about above bst.insert(i);

  1. [Verifier – 20 points].

Given the following two classes:

class IntTriple { class TreeNode { public: public: int first; int element; int second; TreeNode* left; int third; TreeNode* right; }; };

you want a function Verify that takes one parameter, a pointer to a TreeNode. This function should return an object of type IntTriple, whose member variable first will hold 1 if the parameter pointer points to a binary search tree, and which will instead hold 0 if the parameter pointer points to a binary tree that is NOT a binary search tree. You can use the other two variables of the IntTriple however you like. Please note that if the parameter pointer is NULL, then that is considered to be a binary search tree (although an empty one).

IntTriple Verify(TreeNode* ptr) { // your code goes here

(Verifier, continued)

(List of Tree Values, continued)

  1. [Algorithms – 30 points (6 points each)].

(a) Explain convincingly that Level-Order traversal on a binary tree of n nodes is O(n).

(c) The AVL Tree balance property was that for any node, the two subtrees of that node differed by at most 1 in height. Why not 0? That is, explain convincingly that requiring each node to have two subtrees of equal height would be problematic.

(d) In the red-black tree insertion algorithm, all the cases for handling a red-parent-with- red-child conflict (we’ll refer to this as a “red-red conflict”) assume that there is another level above the red-red conflict – i.e. they assume that the upper red node in the red-red conflict has a parent. We did not have any case to handle the situation where you have a red node, and the parent of that node happens to be red, but that red parent node has no parent itself. Explain convincingly why we do not need such a case.

(scratch paper)