c17f05f - CSE 17 FINAL TUESDAY 20 DECEMBER 2005

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

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. f <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 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) return a; return b;
Image of page 1

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

} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • varies
  • public class

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern