spring04finalexa

# spring04finalexa - 1.00/1.001 Introduction to Computers and...

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

1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - May 19, 2004 Name: E-mail Address: TA: Section: You have 3 hours to complete this exam. For coding questions, you do not need to include comments, and you should assume that all necessary files have already been imported. Good luck! Question Points Question 1 / 10 Question 2 / 10 Question 3 / 20 Question 4 / 20 Question 5 /15 Question 6 / 25 Total / 100

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

View Full Document
Page 1 of 19 Question 1. Tree traversal (10 points) After several terms of 1.00, the TAs decided they were tired of the inorder and postorder traversals taught in the course. After much thought, they developed new, modified inorder and postorder traversals. These new traversals are: A modified inorder traversal performs the following, recursively: - Traverse the right subtree - Visit the node - Traverse the left subtree A modified postorder traversal performs the following, recursively: - Traverse the right subtree - Traverse the left subtree - Visit the node 3 99 33 22 66 11 55 a) If the tree shown is traversed in modified inorder, starting at the root of the tree, what is the sequence of nodes visited? Answer: b) If the tree shown is traversed in modified postorder, starting at the root of the tree, what is the sequence of nodes visited? Answer: 5 88 77 44

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

View Full Document
Page 2 of 19 Question 2. Circular linked list (10 points) A circular linked list is a linked list in which the last node refers to the first node. By convention, first is a reference to the first node in the linked list. The program below builds a circular list and manipulates it. Your task is to predict the output at three stages in the program. Hint : Trace the program by drawing the linked list at intermediate steps (draw the list with the data and next fields for every node, and with the first and last references) public class CircularList { public static class Node { int data; Node next; Node (int d, Node n) { data = d; next = n; } } public static void main(String[] args) { int i; int N = 5, M = 3; // Step (a) Node first = new Node(1, null); first.next = first; Node last = first; // End of Step (a) // Step (b) for (i = 2; i<= N ; i++) { last.next = new Node (i,first); last= last.next; } // End of Step (b) // Step (c): What’s happening here? while (last!= last.next) { for (i=1; i<M; i++) last= last.next; last.next = last.next.next; } // End of Step (c)
Page 3 of 19 // Output the result System.out.println (last.data); } } // Draw the list after step (a) finishes // Draw the list after step (b) finishes // What is the final output from step (c)?

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

View Full Document
Page 4 of 19 Question 3. Computing grade ranges (20 points) In order to assign overall letter grades for 1.00, the teaching staff needs to organize students’ numerical scores. First, the staff places all student scores into an
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/29/2011 for the course CIVIL 1.00 taught by Professor Georgekocur during the Spring '05 term at MIT.

### Page1 / 19

spring04finalexa - 1.00/1.001 Introduction to Computers and...

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

View Full Document
Ask a homework question - tutors are online