{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSC 17 Final FALL 1999

# CSC 17 Final FALL 1999 - CSc 17 Final Saturday 18 December...

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

CSc 17 Final Saturday 18 December 1999 >>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<, 1. (25 pts) a. Provide the missing documentation for the function below. b. Determine the complexity of the algorithm used in the function and state the complexity in terms of the O() notation. // Purpose: Determine whether any two adjacent entries in data[0], data[1],. ..,data[n] are duplicates. // Preconditions: n>=0 // Postconditions: data, and n left unchanged // return true if and only if two entries are the // same. bool one(int data[],int n){ int j; bool d; d=false; j=0; d=data[j]==data[j+1]; j++; } n--; } return d; } The number of iterations of the loop is 1+2+. ..+(n-1)=n(n-1)/2 =n*n/2-n/2 ==>O(n^2) 2. (25 pts) Write a private recursive member function for the class Tree which returns true if and only if every entry in the tree is even. Assume the function is named EVEN and is called by other member functions as follows, EVEN(root), where the class Tree is defined as follows: class Tree{ class BinaryNode{ public: int key; BinaryNode *child[2]; }; public: //other stuff private: BinaryNode *root; //other stuff }; You need not write the prototype of EVEN. EVEN can assume that root is either NULL or the root of a properly built binary tree. private: bool EVEN(); //prototype bool Tree::EVEN(BinaryNode *root){ if(root==NULL) return true; return root->key %2 ==0 && EVEN(root->child[0])&&EVEN(root->child[1]);

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

View Full Document
} 3. (15 pts) a. Write the prototype for the function GLOG so that the following code will compile (Tree is defined in 2). Tree a[5];
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

CSC 17 Final FALL 1999 - CSc 17 Final Saturday 18 December...

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

View Full Document
Ask a homework question - tutors are online