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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern