3 Pages

hw3

Course: CS 46, Fall 2009
School: San Jose State
Rating:
 
 
 
 
 

Word Count: 1475

Document Preview

46B CS Introduction to Data Structures Fall 2007 November 4, 2007: 3 page(s) Programming Assignment 3: due before 7:00 p.m. November 9, 2007 So far in class, we have seen several data structures which can be used to store and look up elements. Fundamentally, many of these data structures can be used to do many of the same tasks: store items, add items to be stored, nd items, remove items, etc. In this homework...

Register Now

Unformatted Document Excerpt

Coursehero >> California >> San Jose State >> CS 46

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.
46B CS Introduction to Data Structures Fall 2007 November 4, 2007: 3 page(s) Programming Assignment 3: due before 7:00 p.m. November 9, 2007 So far in class, we have seen several data structures which can be used to store and look up elements. Fundamentally, many of these data structures can be used to do many of the same tasks: store items, add items to be stored, nd items, remove items, etc. In this homework assignment, we will try to compare how several of the dierent data structures perform against each other. The homework will consist of running the data structures through a series of tests, in order to see how quickly they work. In a future assignment, you will be asked some questions related to the test results. Most of these data structures are already dened for generic types, but for this assignment, you will only be storing Integers. You will compare the runtimes of several classes: 1. LinkedList 2. OrderedList (You need to implement this, but see Section 4.7 of the text, where you will need the add, and contains methods. It isnt really a subclass of LinkedList, since some LinkedList operations dont make sense here: for instance, adding can only go to the correct sorted order, not an arbitrary order. Instead, delegate to the LinkedList class. Note, most of the code for this can be downloaded directly from the textbook student companion website. You may use that if you wish.) In the case of the contains method, do not simply delegate it to the LinkedList class: instead, if you are searching from the front of the list, once you get past where the element should have been, you can exit without looking at the rest of the objects. (That is, if the list has 1, 5, 57, 89, 100, 176, 225, . . . , and we are looking for 95, we know 95 is not in the list once we see 100.) 3. ArrayList 4. OrderedArrayList (You need to implement this. Again, you will delegate to the ArrayList class, rather than being a subclass of it.) The contains method should use binary search, but not the one in the Java Arrays class; to use that one, things need to be in an actual array. Instead, you can modify the binarySearch in Komann chapter 7 (also at the student website) to work on your OrderedArrayList rather than just on an Array. You cannot copy it over to an array before using binary search, because the copy will take too long. 5. BinarySearchTree (You need to implement, See Section 8.4 of the text, you will need the add and contains methods. Note, most of the code for this can be downloaded directly from the textbook student companion website. You may use that if you wish. You will need to code the contains method.) We would like to time how long the calls take. To get this, we will use the Date class (java.util.Date). (There may be other, better ways to do this, but lets go with this one.) Here, a call to constructor Date() will allocate a Date object with the current time, at millisecond accuracy. The idea is basically the following: Do any initialization work you want to here Date startDate = new Date(); run some code here Date endDate = new Date(); long runtimeInMilliseconds = endDate.getTime() - startDate.getTime(); will leave the variable runtimeInMilliseconds as the runtime of the middle part of code. In our case, this middle part will have the test we are currently timing. To be fair, we should really run each test several times, and consider a median runtime: running a test just once leaves the possibility that the machine was slow at that moment due to other events taking place. (We might consider more sophisticated tests which actually measure how much CPU is being used by a particular process, but here, we will just use time.) To further make our tests fair, we should only run them with minimal other things happening on the machine while they run. (No watching videos while you benchmark your data structures.) We should also think about just testing one data structure at a time: if several are tested, the rst ones may have an advantage, as they use up some memory that was free, while later tests may have the disadvantage of needing to swap to get new memory. Or, later data structures may have an advantage, in that maybe the kernel scheduler devotes more resources to the java program after it uses a certain amount of CPU. These issues are out of your control, and beyond the scope of this class. To take them of out the equation, lets just test one data structure at a time. So, pseudocode for one test case might look like the following. Assume that NUM TRIALS= 5 is a nal integer, dened to be the number of trials you will have for each data structure for each test, and DataStructure is the data structure you are testing, such as BinarySearchTree. ll up the array toBeInserted here for your given test case. ll up the toBeTested array for your given test case here. Date startDate; Date endDate; 1 DataStructure Test = new DataStructure Integer (); int trials = 0; int successes = 0; long results[NUM TRIALS]; for(int i = 0; i <NUM TRIALS; i + +) { startDate = new Date(); for(j : toBeInserted) Test.add((Integer) j); for(j : toBeTested) { trials++; if(Test.contains((Integer) j)) successes++; } endDate = new Date(); long results[i] = endDate.getTime() - startDate.getTime(); } Give average runtime (from results) Give median runtime (from results) For the above tests, the assumption is that the Integer[] toBeInserted contains n items that you are about to insert. You should run it for each data structure type. You should do this without coding it once for each type, but instead by reusing code. For instance, based on command-line arguments, you could use conditionals (if statements) to decide what type of data structure Test is, and then the rest of the code would run regardless of what data structure it is. (Also, for each test, print the number of successes and the number of trials, ask kept in those integers.) For each data structure, you should try the following test cases: 1. Add, in order, the odd integers 1 to 9999. Lookup each of those (odd) numbers twice each. 2. Add, in order, the odd integers 1 to 9999. Lookup each even number, 2 to 10000, twice each. 3. Add, in order, the odd integers 1 to 1999. Lookup each of those (odd) numbers 10 times each. 4. Add, in order, the odd integers 1 to 1999. Lookup each even number, 2 to 2000, 10 times each. 5. Add, in order, the odd integers 1 to 1999. Lookup just the number 3, 10000 times. 6. Add, in order, the odd integers 1 to 1999. Lookup just the number 4, 10000 times. 7. Add, in order, the odd integers 1 to 1999. Lookup just the number 1997, 10000 times. 8. Add, in order, the odd integers 1 to 1999. Lookup just the number 1998, 10000 times. 9-16 The same tests as above, except that the integers should not be added in order. (They can still be looked up in whatever order is easiest.) Instead, use the following code to ll up an array called toBeInserted, and then just insert items from the array, where n is the number of items in the array (5...

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:

San Jose State - CS - 46
Linux is a Unix-like operating system. The installation here will meet most of the nneds for assignments in this department.A few basics for the novice user.* When you complete your Linux session, reboot using the Ctrl-Alt-Del key combinatio
San Jose State - CS - 46
This is just a test file named Chap1.txt
San Jose State - CS - 46
This is just a test file named Chap2.txt
San Jose State - CS - 123
Biology/CS 123B Bioinformatics IISpring 20091001001100001 0100001110100 0100001110100Homework OnePlease hand in the solutions to the following problems on Thursday, February 12, 2009. Hand in a hard copy and a disk or CD containing your solut
San Jose State - CS - 157
Chapter 5.1 and 5.2Brian Cobarrubia Database Management Systems II January 31, 2008Agenda5.1 Functional Dependencies Between Attributes Superkeys and Keys Inferring Functional Dependencies Determining Keys from Functional Dependencies5
San Jose State - CS - 147
CACHE MEMORYCS 147 October 2, 2008 Sampriya ChandraLOCALITYPRINCIPAL OF LOCALITY is the tendency to reference data items that are near other recently referenced data items, or that were recently referenced themselves. TEMPORAL LOCALITY : memory l
San Jose State - CS - 146
Introduction Definition of B-trees Properties Specialization Examples 2-3 trees Insertion of B-tree Remove items from B-treeB-Trees DefinitionA balanced search tree in which every node has between m/2 and m children, where m&gt;1 is a fixed
San Jose State - CS - 157
Data Mining: Association RuleBy: Thanh Truong Association RulesIn Association Rules, we look at the associations between different items to draw conclusions from. In sales, we look at purchases: Example in book Someone who buys bread is
San Jose State - CS - 147
Lecture 11 Sequential Logic,ISA, ALUProf. Sin-Min Lee Department of Computer ScienceRegisters Two independent flip-flops with clear and presetRegisters Missing Q, preset, clocks ganged Inversion bubbles cancelled, so loaded with rising Can
San Jose State - CS - 157
Indexing and Hashing(emphasis on B+ trees)By Huy Nguyen Cs157b 0900-1015 TR Lee, Sin-MinStorage We have been studying database languages and queries and have yet to study how data is stored. We will look at how data is accessed and the differen
San Jose State - CS - 157
Data MiningKelby Lee3-1Overviewp p p p p p p p p pTransaction Database What is Data Mining Data Mining Primitives Data Mining Objectives Predictive Modeling Knowledge Discovery Other Objectives to Data Mining What Data Mining is Not Other Fa
San Jose State - CS - 157
Translation of ERD to Relational Scheme, Relational AlgebraProf. Sin-Min LEE Department of Computer ScienceRelation schema Named relation defined by a set of attribute and domain name pairs. Relational database schema Set of relation schemas, eac
San Jose State - CS - 146
InsertionSort&amp; ShellsortBy: Andy Le CS146 Dr. Sin Min Lee Spring 2004Outline Importance of Sorting Insertion Sort Explanation Runtime Advantage and Disadvantage Walk through example History Explanation Runtime Advantage and Disadvantag
San Jose State - CS - 147
Virtual Memory(Section 9.3)The Need For Virtual Memory Many computers dont have enough memory in RAM to accommodate all the programs a user wants to run. By using virtual memory, the computer appears to have more memory than it actually does.O
San Jose State - CS - 157
2003Spring CS 146 Data Structures and Algorithms Study GuideProf. Sin-Min LeeTechnical skill is mastery of complexity while creativity is mastery of simplicity. - - Christopher E. ZeemanWhat we want is to see the student in pursuit of knowledge,
San Jose State - CS - 157
Class Presentation: Normal FormBy Wen Ying Gao CS157A Section 2 October 20, 2005Database NormalizationDatabase normalization relates to the level of redundancy in a relational databases structure. The key idea is to reduce the chance of having
San Jose State - CS - 157
4TH NORMAL FORMBy: Karen McVayREVIEW OF NFs1NF All values of the columns are atomic. That is, they contain no repeating values. 2NF it is in 1NF and every nonkey column is fully dependent upon the primary key.REVIEW OF NF Cont3NF it i
San Jose State - CN - 64
San Jose State - CN - 102
San Jose State - CS - 157
SQLSangeeta Devadiga CS157A, Fall 2006Outline Background Data Definition Basic Structure Set OperationBackground IBM developed the original version named sequel in early 1970s Sequel language has evolved into SQL SQL (Structured Query
San Jose State - CS - 157
SQL (DQL, DDL, DML)Prof. Sin-Min Lee Alina Vikutan CS 157A Fall 2005Structured Query Language featuresDQL (Data Query Language) Used to get data from the database and impose ordering upon it. DML (Data Manipulation Language) Used to change dat
San Jose State - CS - 157
QBE Query-By-ExamplePresented by Angela TongCS157A Dr. Sin Min LeeIntroductionQuery By Example (QBE) QBE and its variants are widely used in database system on PCs. QBE is the name of both a datamanipulation language and an early database that
San Jose State - CS - 157
Relational Algebra and My SQL(II)Prof. Sin Min Lee Deparment of Computer Science San Jose State UniversityFurther relational algebra, further SQLwww.cl.cam.ac.uk/Teaching/current/Databases/Today's lectureWhere does SQL differ from relat
San Jose State - CS - 157
1Chapter 1File Systems and DatabasesProf. Sin-Min Lee Dept. of Computer ScienceIntroducing the DatabaseMajor Database Concepts1xData and informationq qData - Raw facts Information - Processed datax x x xData management Database M
San Jose State - CS - 123
Biology/CS 123B Bioinformatics IISpring 20091001001100001 0100001110100 0100001110100HomeworkOnePleasehandinthesolutionstothefollowingproblemsonThursday,February12,2009.Handin ahardcopyandadiskorCDcontainingyoursolutions.ProblemOneProblemsf
San Jose State - PHYSICS - 51
Chapter 24 Capacitance and DielectricsCapacitanceanddielectrics (sec.24.1) Capacitorsinseriesandparallel (sec.24.2) Energystorageincapacitors andelectricfieldenergy (sec.24.3) Dielectrics (sec.24.4) Molecularmodel/polarization (sec.24.5) RCcircuits
San Jose State - PHYSICS - 52
PHYSICS 52 HEAT AND OPTICS Fall 2005 MW 3:00 PM Sci-253 Dr. Joseph F. Becker OFFICE HOURS: SCI-322 MW 1620-1730, T 1330-1520 OFFICE PHONE: 408-924-5284; e-mail beckerj@jupiter.sjsu.edu PHYSICS DEPARTMENT PHONE: 408-924-5210 PHYSICS WALK-IN TUTORING C
San Jose State - PHYS - 50
Physics 50Dr. Michael Kaufman Office: SCI 248 Phone: (408) 924-5265 Spring 2004 Office Hours: MWF 9:30-10:30 or by appointment email: mkaufman@email.sjsu.eduCourse Description: A four-unit course in calculus-based introductory physics, emphasizing
San Jose State - ASTR - 10
Astronomy 10Dr. Michael Kaufman Office: SCI 248 Phone: (408) 924-5265 Spring 2004 Office Hours: MWF 9:30-10:30 or by appointment email: mkaufman@email.sjsu.eduCourse Description: A general introduction to our present understanding of the origin an
San Jose State - PHYSICS - 52
San Jose State - PHYSICS - 51
Q25.14 a) The current flowing through each bulb in series is the same (and the resistance of each identical bulb is the same). Since bulb brightness is related to power dissipated in the bulb (P = I2 R), the brightness of each bulb is the SAME. b) Wh
San Jose State - PHYSICS - 51
Continuation of Green Sheet (SJSU Requirements S05-14)Academic integrity statement (from Office of Judicial Affairs): Your own commitment to learning, as evidenced by your enrollment at San Jose State University, and the Universitys Integrity Policy
San Jose State - PHYSICS - 51
Continuation of Green SheetStudents successfully completing this course will be able to: Describe how concepts of electric field and electric charge can be used to evaluate the value of the electric field caused by individual charges and continuous
San Jose State - PHYSICS - 51
GREEN SHEET for PHYSICS 51 (Sec. 2) Spring 2007 TTh 1030-1145 Sci-258ELECTRICITY AND MAGNETISM Dr. Joseph F. BeckerOFFICE HOURS: SCI-322 MTh 1330-1420, T 1140-1420 OFFICE PHONE: 408-924-5284; email beckerj@jupiter.sjsu.edu &gt;subject: Physics 51(2)
San Jose State - PHYSICS - 51
GREEN SHEET for PHYSICS 51 (Sec. 3) Fall 2007 TTh 1500-1615 Sci-253ELECTRICITY AND MAGNETISM Dr. Joseph F. BeckerOFFICE HOURS: SCI-322 MW 1345-1445, TTh 1340-1445 OFFICE PHONE: 408-924-5284; email beckerj@jupiter.sjsu.edu &gt;subject: &quot;Physics 51(3)
San Jose State - PHYSICS - 51
San Jose State - PHYSICS - 51
San Jose State - PHYSICS - 52
San Jose State - PHYSICS - 51
GREEN SHEET for PHYSICS 51 (Sec. 2) Fall 2007 MW 1230-1345 Sci-253ELECTRICITY AND MAGNETISM Dr. Joseph F. BeckerOFFICE HOURS: SCI-322 MW 1345-1445, TTh 1340-1445 OFFICE PHONE: 408-924-5284; email beckerj@jupiter.sjsu.edu &gt;subject: Physics 51(2) P
San Jose State - PHYSICS - 51
San Jose State - PHYSICS - 51
ChaptersChapters I ELECTRIC FIELDS CH. 21A Electric Charge and Electric Field (Basic Concepts) CH. 25 Current, Resistance, and Electromotive Force (The flow of electric charge) CH. 26 Direct Current Circuits (Direct, or constant, current flow) CH.
San Jose State - PHYSICS - 52
Physics 52 Final Exam ReviewURemember: For each problem Draw a carefully labeled diagram, Write the necessary equations in terms of variables, and Explicitly show all steps in calculations including units. THERMODYNAMICS Ch. 17 Thermal expansio
San Jose State - PHYSICS - 51
GREEN SHEET for PHYSICS 51 (Sec. 4) FALL 2006 TTh 1330-1445 Sci-253ELECTRICITY AND MAGNETISM Dr. Joseph F. BeckerOFFICE HOURS: SCI-322 M 1100-1150, TTh 1445-1630 OFFICE PHONE: 408-924-5284; email beckerj@jupiter.sjsu.edu &gt;subject: Physics 51(4) P
San Jose State - PHYSICS - 51
Physics 51 HW Chapter 24 24Q.7 The key here is the fact that the capacitor is disconnected from the battery after it is charged. (If the capacitor remained connected the voltage across the capacitor would remain constant at the battery voltage.) The
San Jose State - PHYSICS - 52
Physics 52 - He and Optics at Dr. Jose F. Be r ph cke Physics De partm nt e S JoseS Unive an tate rsity 2005 J. F. Be r ckeC hapte 35 r Interference 2005 J. F. Be r ckeS JoseS Unive an tate rsityPhysics 52 He and Optics atA snapshot of wav
San Jose State - PHYSICS - 51
Ele ctrom tic I nduction C 29 agne h.I nduction e rim nts xpe e Faraday's law Le law nz's Motional e ctrom le otiveforce I nduce e ctric fie d le lds Eddy curre nts Displace e C nt m nt urreC2008 J. Be r cke(se 29.1) c. (se 29.2) c. (se 29.3) c.
San Jose State - PHYSICS - 51
Ele ctrom tic Wave C 32 agne s h.Maxwe e lls quations wave &amp; spe d of light s e (se 32.6) c. (se 32.1) PlaneEM c. (se 32.2) TheEM spe c. ctrumC2009 J. Be r ckeMAXWELLS EQUATIONSThere lationships be e e ctric and m tic twe n le agne fie and the
San Jose State - PHYSICS - 52
Physics 52 - He and Optics at Dr. Jose F. Be r ph cke Physics De partm nt e S JoseS Unive an tate rsity 2005 J. F. Be r ckeC hapte 18 r Thermal Properties of Matter 2005 J. F. Be r cke S JoseS Unive an tate rsity Physics 52 He and Optics atTher
San Jose State - PHYSICS - 52
Physics 52 - He and Optics at Dr. Jose F. Be r ph cke Physics De partm nt e S JoseS Unive an tate rsity 2005 J. F. Be r ckeC hapte 19 r The First Law of ThermodynamicsC 19 First Law of The odynam h. rm ics 1. The odynam syste s rm ic m 2. Work d
San Jose State - PHYSICS - 51
Chapter 22 Gauss's Lawctric chargeand flux (se 22.2 &amp; .3) c. Ele (se 22.4 &amp; .5) c. Gauss's Law harge on conductors (se 22.6) s c. CC2009 J. F. Be r ckeA charge inside a box can be probed with a test charge qo to m asureE field outside the box
San Jose State - PHYSICS - 51
Current, resistance, and electromotive force (emf): Chapter 25C harge (e ctrons) m s le oving in a conductors sistanceto flow of charge Ohm Law &amp; re rgy r le Ene and powe in e ctrical circuitsC2009 J. F. Be r ckeELEC TRON MOTION IN A C ONDUCT
San Jose State - PHYSICS - 52
Fig.2710THINFILMINTERFERENCE Whenlightshinesonathin filmofoilfloatingona layerofwater,twolight waves(#1and#2),enterthe eyeafterreflectionand refraction. Theoilthicknessn oil = vac / nt=several s oflightintheoilC2001Wiley,PhysicsCutnell&amp;Johnson
San Jose State - PHYSICS - 52
Physics 52 - He and Optics at Dr. Jose F. Be r ph cke Physics De partm nt e S JoseS Unive an tate rsity 2003 J. F. Be r ckeC hapte 20 r The Second Law of ThermodynamicsS m e rgyche atic ne flow diagramfor a he e at ngine .C of a four-stroke in
San Jose State - PHYSICS - 51
Alte rnating C nt C 31 urre h.Phasors and AC (se 31.1) Re c. sistanceand re actance (se 31.2) RLCse s circuit c. rie (se 31.3) Powe in ACcircuits c. r (se 31.4) c. Re sonancein ACcircuits (se 31.5) c. Transform rs e (se 31.6) c.C2008 J. Be r ckeP
San Jose State - PHYSICS - 51
M agneti c Fi el d &amp; For ces Ch. 27M agneti sm (sec. 27.1) M agneti c fi el d (sec. 27.2) M agneti c fi el d l i nes and magneti c fl ux (sec. 27.3) M oti on of char ges i n a B fi el d (sec. 27.4) Appl i cati ons - movi ng char ged par ti cl es (se
San Jose State - PHYSICS - 51
DC CIRCUITS: Chapter 26e s l sistors S rie and paralle re s twork proble s m Kirchhoffs Rule for ne ctrical m te and house e rs hold circuits EleC2009 J. F. Be r ckeDIRECT-CURRENT (DC) CIRCUITS I n this chapte wewill study m thods of analyzin
San Jose State - PHYSICS - 52
Fig. 35-5 Re ction of an obje (y) froma planem fle ct irror. Late ral m agnification m= y / y 2003 J. F. Be r ckeS JoseS Unive an tate rsityPhysics 52 He and Optics atS GN RULESFOR ALL REFLEC ON AND REFRAC ON I TI TI S TUATI ONS I 1. S GN RU
San Jose State - PHYSICS - 52
Fig. 35-20 (C ontinue d) Re fraction at a sphe rical surface position of im . age a = + , = + btan ~ ,e so tc. = h / s, = h / s, = h / R S lls Law: na sin a = nb sin b ne na a = nb b b = ( + ) na / nb na + nb = ( nb na) a 2003
San Jose State - PHYSICS - 52
Physics 52 - He and Optics at Dr. Jose F. Be r ph cke Physics De partm nt e S JoseS Unive an tate rsity 2005 J. F. Be r ckeC hapte 32 r Electromagnetic Waves 2005 J. F. Be r ckeS JoseS Unive an tate rsityPhysics 52 He and Optics atDispe rs
San Jose State - PHYSICS - 52
Fig.387Phasordiagramsusedto findtheamplitudeoftheEfieldin singleslitdiffraction.(a)All phasorsareinphase.(b)Each phasordiffersinphaseslightly fromtheprecedingone.(c)Limit reachedwhentheslitissubdivided intoinfinitelymanystrips.Fig.388(a)Intensity d
San Jose State - PHYSICS - 52
Fig. 36-6 Ove ad proje rhe ctor. Theine nsive xpe plastic Fre l le is likean ordinary thick le sne ns ns with theinte m rial re ove rnal ate m d. 2003 J. F. Be r ckeS JoseS Unive an tate rsityPhysics 52 He and Optics atFig. 36-7 Thee . Them y