samplefinal-sol

# samplefinal-sol - COP 3502 Computer Science I Final Exam...

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

COP 3502 - Computer Science I Final Exam FALL 2002 Lecturer : Nihan Cicekli Name: ______________________ 12/9/02 1) (10 pts) Consider the following recursive function that computes Ackermann’s function for two nonnegative integers m and n : int ackermann(int m, int n){ if (m == 0) return n + 1; else if (n == 0) return ackermann(m-1,1); else return ackermann(m-1, ackermann(m,n-1)); } Indicate the result of each of the following calls to this function: a) ackermann(1,1). Answer: ____3__ b) ackermann(2,1). Answer: ______5_____ 1

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

View Full Document
2) Answer the following questions about binary numbers. a) (3 pts.) What is the decimal representation of the binary number 101110? Answer: ___46________ b) (3 pts.) What is the binary representation of the decimal number 254? Answer:___11111110________ 3) (4 pts.) Calculate the following summation: (2i + 2) Answer:__462____ 4) (10 pts.) Given the following preorder and inorder traversals of a binary tree, draw the tree. Preorder: A B C D E F G H I J Inorder: D C E F B A G I H J A / \ B G / \ C H / \ / \ D E I J \ F 2 20 i =0
5) (15 pts.) Suppose you’re given a queue that is known to contain only positive integers. Use only the fundamental queue operations (i.e. enqueue(), dequeue(), etc.) to write a code that replaces all occurrences of the positive integer num in the queue with the positive integer new . Other than doing this, the queue is to remain unchanged. Use the following declarations and function prototypes: struct queueNode{ int data; struct queueNode * next; }; struct queue{ struct queueNode *front; struct queueNode *rear;

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 06/12/2011.

### Page1 / 8

samplefinal-sol - COP 3502 Computer Science I Final Exam...

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

View Full Document
Ask a homework question - tutors are online