CSE 17 FINAL FALL 2005

CSE 17 FINAL FALL 2005 - CSE 17 FINAL TUESDAY 20 DECEMBER...

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

View Full Document Right Arrow Icon
CSE 17 FINAL TUESDAY 20 DECEMBER 2005 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>>>>>>>>> 1. For the following scenarios, what would be the best data structure to use as the primary data structure in a Java implementation? Justify your choice. Choose from the following data structures: array, two-dimensional array, linked list, stack, queue, binary tree, B-tree, hash table. Note that you DO NOT have to write code - just pick the best data structure and justify that it is indeed the best of these choices! a. A tic tac toe game b. A program that evaluates arithmetic expressions where *, / have precedence over +,-. c. A grocery chain wants to run a simulation to see how the average customer wait time would be affected by changing the number of checkout lines in its store. d. A data structure used to keep track of the return addresses for nested method calls while a program is running. e. A major online shopping company that gives each customer a confirmation number that can be used to determine the status of recent or past orders. f. A dictionary of words used by a spelling checker. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< a. two dimensional array b. Stack c. Queue d. Stack e. Hash Table f. Binary Tree/B Tree >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2a. Below is the data structure developed in class for a linked list. Write a recursive method in class LinkedList, called min(), that returns the minimum value in an unsorted linked list. public class LinkedList <T extends Comparable>{ private class Link {public Link(){this(null,null);} public Link(T t){this(t,null);}; public Link(T t, Link nxt){data=t; next=nxt;} private Link next; private T data; } private Link head; public LinkedList(){head=new Link();} <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< public T min() {if(head.next==null) return null; ///this is the case of an empty list return min(head.next);} public T min(Link hd){ if(hd.next==null) return hd.data; return min(hd.data,min(hd.next)); } public T min(T a, T b) {if(a.compareTo(b)<0)
Background image of page 1

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

View Full DocumentRight Arrow Icon
return a; return b; } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2b. Given the following function: public static int Func (int num) { if (num == 0) return 0; else return num*num + Func(num + 1); } a. Is there a constraint on the values that can be passed as a parameter for this function to work properly. b. Is Func(5) a good call? If not, why not? If so, what does Func(5) return?
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 05/05/2008 for the course CSC 017 taught by Professor Edkay during the Spring '08 term at Lehigh University .

Page1 / 7

CSE 17 FINAL FALL 2005 - CSE 17 FINAL TUESDAY 20 DECEMBER...

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