4 Pages

quiz5-questions

Course: EE 322C, Spring 2010
School: University of Texas
Rating:
 
 
 
 
 

Word Count: 994

Document Preview

322C EE Data Structures Spring 2009 Quiz 5 Instructor: Ramesh Yerraballi Grader: Vinoth Chandar Due : Wednesday 4/29 in class Total : 100 points Student: Anirudh Pande Date: 4/29/09 1) Collections.sort(List<T>) method takes any list and sorts it according to the type of objects held in the list. For example, Strings are sorted alphabetically, Integers are sorted by value and Date objects...

Register Now

Unformatted Document Excerpt

Coursehero >> Texas >> University of Texas >> EE 322C

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
322C EE Data Structures Spring 2009 Quiz 5 Instructor: Ramesh Yerraballi Grader: Vinoth Chandar Due : Wednesday 4/29 in class Total : 100 points Student: Anirudh Pande Date: 4/29/09 1) Collections.sort(List<T>) method takes any list and sorts it according to the type of objects held in the list. For example, Strings are sorted alphabetically, Integers are sorted by value and Date objects chronologically. [15 points ] a) How is this behavior implemented? Collections.sort is implemented as a modified mergesort, where the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist. The method sorts the specified list into ascending order, according to the natural ordering of its elements. The implementation of the method dumps the specified list into an array, sorts the array, and iterates over the list resetting each element from the corresponding position in the array. The best case of the algorithm offers a n log(n) performance. For the method to work, all elements in the list must implement the Comparable interface. Furthermore, all elements in the list must be mutually comparable, meaning, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the list. Finally, the specified list must be modifiable, but not resizeable. b) List<Integer> lst = new ArrayList<Integer> (); Write java code to provide you a sorted list of integers, lst, in the descending order, using the Collections.sort method. [You cannot use the Collections.reverse method] class sortList implements Comparator { for(int i=0;i<lst.size();i++) { int smaller = list.compare((lst.get(i)),(lst.get(i+1))); lst.add(i,smaller); public int compare(int i1, int i2) { return new Integer(i1).compareTo(new Integer(i2)); } } 2) Implement a generic queue class , MyQueue<T> using two stacks [Stack class in the Collections API]. The class should have a default constructor, enqueue method that takes an element as argument and adds it to the end of the queue and dequeue method that removes an element from the front of the queue. [30 points ] An example usage is given below. public class MyQueue { public static void main(String[] args){ public MyQueue() { Stack <Integer> inboxStack = new Stack<Integer>; Stack<Integer> outboxStack = new Stack<Integer>; } void Enqueue(int element) { inboxStack.push(element); } int Dequeue() { if(outboxStack.Count > 0) { return outboxStack.Pop(); } else { while(inboxStack.Count > 0) { outboxStack.Push(inboxStack.Pop()); } if(outboxStack.Count > 0) { return outboxStack.Pop(); } } } } } MyQueue<Integer> queue = new MyQueue<Integer>(); queue.enqueue(2); queue.enqueue(4); System.out.println(queue.dequeue()); System.out.println(queue.dequeue()); 3) What is the difference between the Iterator interface and the ListIterator interface? [ 5 points] ListIterator is a sub-interface of Iterator and so the difference between these interfaces is that ListIterator has a specific usage within lists whereas Iterator does not. ListIterator can perform operations such as remove, set elements within a list whereas Iterator the works on any collection as well as on lists. 4) You have a stream of float values coming to your computer from an external sensor every minute. Design an appropriate data structure such that 1) Given the date, you should be able to retrieve the sensor reading as fast as you can 2) In addition to 1, given any time range, you must be able to retrieve all the values in that interval with minimal programming effort. [10 points] 5) Joe is a typical lazy programmer. He wants to store some extra information about objects in his program [say they are encapsulated in an ExtraInformation class ]. He wants to retrieve the extra information, given the object, as fast as possible. Also, he requires that this extra information be garbage collected from the data store automatically [I.e he does not have to invoke any methods on the data structure representing the extra information store] when the original object is no longer in use, in his program. Suggest a suitable data structure for joe and also explain how it will solve his problem [15 points] Joe should use a hash table for his program. Hash tables have a big-Oh time of logN so if Joe wants to retrieve information the fastest, the hash table would be ideal for his job. Also hash tables store data without any methods being invoked when the original object is not in use so it would ideal for Joes needs. 6) What is referred to as the fail fast behavior of Iterators in the Collections API? [ 5 Points ] Fail-fast term is about Java collections and theirs iteration and modification, which are not synchronized. The iterator returned by a class's iterator method is named fail-fast if: the set is modified at any time after the iterator is created, in any way except through the iterator's own remove method. This causes the Iterator to throw a ConcurrentModificationException. 7) The RandomAccess interface has no methods. Why do you think that such an interface is required? [10 points] The RandomAccess interface is not required but it is useful in allowing generic algorithms to alter their behavior to provide good performance when applied to either random or sequential access lists. This interface is encouraged to be used if a list implementation provides asymptotically linear access times if they get huge, but constant access times in practice. Also, the best algorithms for manipulating random access lists can produce quadratic behavior when applied to sequential access lists so this algorithm is encouraged to check whether the given list is an instanceof this interface before applying an algorithm that would provide poor performance if it were applied to a sequential access list, and to alter their behavior if necessary to guarantee acceptable performance. 8) As a continuation of problem 4, assume that you do not know the exact times of that day that the sensor reported values at. Can you use some Collections API class to perform lookups given anytime of the day, with minimal programming effort? Write code to implement a search such that given a time of the day, we obtain the nearest sensor reading in time. If there are ties, choose the latest reading of the two. [10 points]
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Texas - EE - 322C
Anirudh Pande EE322C- Dr. Y 2/4/09 Quiz #1 Snippet # 1 Guess: 1 # 2 Reality: Error: Possible loss of precision. To fix error, do type conversionint i1 = (int)5.0 * 2 / 4;Now, the result is 1 # 2. Reasoning: This code snippet returns the correct predicte
University of Louisville - BIO - 240
BIO24075Fall2009 EXAM1FORMB CORRECTANSWERSAREBOLDED1.Thelowestlevelofbiologicalorganizationthatcanperformalltheactivitiesrequiredforlifeis the a.organsystemforexample,thereproductivesystem b.organelleforexample,achloroplast c.tissueforexample,nervoustis
University of Louisville - BIO - 240
BIO24075Fall2009 Vocabulary,ConceptsandTermsforChapter1 Introduction:ThemesintheStudyofLife EvolutiontheprocessofchangethathastransformedlifeonEarthfromitsearliest beginningstothediversityoforganismstoday. NaturalSelectionorganismswithcertaininheritedchar
University of Louisville - BIO - 240
BIO24075Fall2009 Vocabulary,ConceptsandTermsforChapter6 ATouroftheCell Cellcollectionmakesuporganism,thecellisthesimplestcollectionofmatterthatcan live. Eukaryotic&quot;truekernal&quot;mostoftheDNAisinnucleusboundedbyadoublemembrane. Prokaryotic&quot;beforekernal&quot;theDNA
University of Louisville - BIO - 240
B IO 240-75 Fall 2009 Vocabulary, Concepts and Terms for Chapter 3 Water and the Fitness of the Environment Electronegativity- the attraction of a given atom for the electrons of a covalent bond. Polar molecule-the unequal distribution of electons; the tw
University of Louisville - BIO - 240
BIO 240-75 Fall 2009 Vocabulary, Concepts and Terms for Chapter 2 The Chemical Context of Life Matter-anything that takes up space and has mass(amount of matter in a given object) Element-a substance that cannot be broken down to other substances by chemi
University of Louisville - BIO - 240
BIO24075Fall2009ANSWERSEXAM2FormACorrectanswersarebolded: 1.Whowas/werethefirsttoproposethatcellmembranesarecomposedofa phospholipidbilayer? a.Davson&amp;Danielli b.Singer&amp;Nicholson c.Gorter&amp;Grendel d.HansKrebs e.PeterMitchell 2.Whichofthefollowingisoneway
University of Louisville - BIO - 240
BIO 240-75 Fall 2009 Vocabulary, Concepts and Terms for Chapter 11 Cell Communication Signal transduction-the process by which a signal on a cell's surface is converted to a specific cellular response in a series of steps. Cell junctions-directly connect
University of Louisville - BIO - 240
BIO24075Fall2009EXAM3FormAANSWERS CorrectAnswersarebolded1.Whichofthefollowingdoesnotoccurduringmitosis? a.condensationofchromosomes b.replicationofDNA c.separationofsisterchromatids d.spindleformation e.separationofthecentrosomes 2.Thephaseofmitosisdur
University of Louisville - BIO - 240
BIO 240-75 Fall 2009 Vocabulary, Concepts and Terms for Chapter 12 The Cell Cycle Cell division-the reproduction of cells; the continuity of life is based on cell division. Zygote-the diploid product of the union of haploid gametes during fertilization; a
University of Louisville - BIO - 240
BIO 240-75 Fall 2009 Vocabulary, Concepts and Terms for Chapter 13 Meiosis and Sexual Life Cycles Heredity-the transmission of traits from one generation to the next. Variation-differences between members of the same species. Genetics-the scientific study
University of Louisville - BIO - 240
BIO 240-75 Fall 2009 Vocabulary, Concepts and Terms for Chapter 14 Mendel and the Gene Idea Blending hypothesis-the idea that genetic material contributed by the two parents mixes in a manner analogous to the way blue and yellow paints blend to make green
University of Louisville - BIO - 240
BIO24075Fall2009 Vocabulary,ConceptsandTermsforChapter16 TheMolecularBasisofInheritance DNAdeoxyribonucleicacid RNAribonucleicacid THMorgan FGriffith Transformation Avery McCarty&amp;MacLoed Bacteriophage(phage) Hershey&amp;Chase ChargaffsRule Wilkins&amp;Franklin Xr
University of Louisville - BIO - 240
B IO 240-75 Fall 2009 Vocabulary, Concepts and Terms for Chapter 17 From Gene to Protein GeneGene expression RNA DNA Transcription Pre-mRNA Translation mRNA ribosome primary transcript codon triplet code template strand non-template strand coding strand g
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
York UK - CIVIL - 66
Anewyearisaremindertocelebrate Allthethingsthataregoodinyourworld Thepeopleyoulove, Theplaceyouareapartof, Thememoriesyouholdonto, Andthoseunforgettablemoments Whenyoucloseyoureyesandbreatheinlife withasmile Mayyourheartbefilledwithlotsofreasonsto celebra
York UK - CIVIL - 66
Dearmembers, IreallyneedtoacknowledgeMr.ArashV.Niaforhisorganizedandprecise email(PersianClubMinuets)whichshowsthecompetencyandcapabilityof thenewgroupofofficers.Wetryourbesttomakethissemesterworthwhile andvaluableforourmembers. PERSIDENTOFWVCPERSIANCLUB
York UK - CIVIL - 66
Members of WVC Persian club;Probably you guys have received an e-mail regardless of not seeing any actives in WVC Persian Club from Mr. Ashkan Zargari. Which; I do not know why he didnt call me or the club advisor at first time before sending his e-mail
York UK - CIVIL - 66
Brand new Baby Girl A new baby Girl has arrived to make your family feel complete. Today you have something unique and Brand new. Each time you look into new Babys face lots of blessing and wishes are sent your way. On behalf of the student of WVC Persian
York UK - CIVIL - 66
West Valley College Persian ClubCertificate of AppreciationOur thanks to Firoozeh Dumas for taking the chance on writing about the Persian community and the subject of immigrant experiences. We would like to congratulate you on your best seller book. Wi
York UK - CIVIL - 66
West Valley College Persian ClubCertificate of AppreciationOur thanks to EOPS for helping and giving theopportunity of convenient education to the students of West Valley College. We know that your students have complex lives with many different obliga
York UK - CIVIL - 66
West Valley College Persian ClubCertificate of AppreciationPresented toHelen KhalouyanIn recognition of your outstanding contribution,hard work, and dedication to your job. We want to assure you that members of WVC Persian Club appreciate your hard w
York UK - CIVIL - 66
T he celebration of Chaharshanbeh Soori is a yearly event of the Persian New Year. It is one of Berkeley largest annual celebrations, w ith this year was no exception. Chaharshanbeh Soori was attended by over 1000 adults and children at Persian Center in
York UK - CIVIL - 66
Dearmembers; March8thevent(FiroozehDumaspresentation)showsthatthe abilityandcompetencyofWVCPersianclubiswaybeyondof whatpeoplethink.Wehaveshownthatweworkbeyondofthe surface.Ipersonallyappreciatethetimeandeffortwhichallthe membersputforthisevent. Rod:Print