spring04finalsol

spring04finalsol - 1.00 Introduction to Computers and...

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

View Full Document Right Arrow Icon
1.00 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
THIS PAGE INTENTIONALLY LEFT BLANK
Background image of page 2
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 55, 33, 44, 11, 3, 77, 66, 99, 88, 22, 5 55, 44, 11, 33, 77, 66, 88, 5, 22, 99, 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
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)
Background image of page 4
// Output the result System.out.println (last.data); } } // Draw the list after step (a) finishes first, last 1 // Draw the list after step (b) finishes A circular list with first pointing to the node containing 1 and last pointing to the node containing 5. Elements are 1 Æ 2 Æ 3 Æ 4 Æ 5 // What is the final output from step (c)? Output is 4 (elements are deleted one at a time)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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

spring04finalsol - 1.00 Introduction to Computers and...

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

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