c17f99f - CSc 17 Final Saturday 18 December 1999 >SUGGESTED...

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

View Full Document Right Arrow Icon
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]); }
Background image of page 1

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

View Full DocumentRight Arrow Icon
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];
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2008 for the course CSE 17 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 4

c17f99f - CSc 17 Final Saturday 18 December 1999 >SUGGESTED...

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

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