SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler offline
For easy Ctrl C+Ctrl V, Below is the same code that is described above.
import java.util.Iterator;
/**
* Write a description of class MyArrayList here.
*
* @author (your name)
* @version (a version number or a date)
*/
// Do not modify the given code.
@SuppressWarnings("unchecked") // Given
public class MyArrayList<T> {
private T[] data; // Given
private int size; // Given
/*
Implement. You must provide a comment block!
*/
public MyArrayList(int inCapacity) {
}
/*
Implement. You must provide a comment block!
*/
public boolean isEmpty() { }
/*
Implement. You must provide a comment block!
*/
public boolean add(T obj) {
// This method appends obj toward the back of data
// Always return true
}
/*
Implement. You must provide a comment block!
Implement this method so that a sequence of add operations
executes as efficiently as possible.
*/
private void grow() { }
/*
Implement. You must provide a comment block!
*/
public boolean remove(Object obj) {
// Return true if obj was removed from data
// and false otherwise.
}
/*
The rest of the code is given.
I will use it for testing purposes.
Do not modify!
*/
// Given. Do not provide a comment block!
public String toString() {
if (size == 0)
return "[ ]";
String retStr = "[ ";
for (int i = 0; i < size - 1; i++)
retStr += data[i] + ", ";
retStr += data[size - 1] + " ]";
return retStr;
}
// Given. Do not provide a comment block!
public boolean equals(Object obj) {
if (obj instanceof MyArrayList) {
MyArrayList<T> rhs = (MyArrayList<T>)obj;
if (size != rhs.size)
return false;
for (int i = 0; i < size; i++)
if (!rhs.contains(data[i]))
return false;
return true;
}
return false;
}
// Given. Do not provide a comment block!
private int find(Object obj) {
for (int i = 0; i < size; i++)
if (data[i].equals(obj))
return i;
return -1;
}
// Given. Do not provide a comment block!
public boolean contains(Object obj) {
return find(obj) >= 0;
}
// Given. Do not provide a comment block!
public void addAll(MyArrayList<T> inList) {
for (int i = 0; i < inList.size; i++)
add(inList.data[i]);
}
// Given. Do not provide a comment block!
private class MyArrayListIterator implements Iterator<T> {
private int index = 0;
// Given. Do not provide a comment block!
public void remove() { } // No implementation
// Given. Do not provide a comment block!
public T next() {
T temp = data[index];
index++;
return temp;
}
// Given. Do not provide a comment block!
public boolean hasNext() {
return index < size;
}
}
// Given. Do not provide a comment block!
public Iterator<T> iterator() {
return new MyArrayListIterator();
}
}
troduction: In this lab, you will get some practice implementing certain methods of expandable,
generic MyArrayList data structure and doing an amortized analysis of one the methods thereof.
Basically, in addition to the parameterized constructor, you have implement the operations of
isEmpty, add, grow and remove. Then, you will do a very mple amortized analysis, using empirical
methods, to derive the worst-case running time add when executed in a sequence of several add
operations. ote that there is a lot of "extra" code that is given. Don't modify any of the given code. I
ll need this for testing purposes. etting started: 1. Create a new project in NetBeans called Lab5.
Make sure you uncheck Create Main Class in the New Java Application window. 2. Within the
default package of your Lab5 project, create a new Java class called MyArrayList and use the
following code to get started (the following code is also available for download on Canvas as
MyArrayList. java): import java. util. Iterator; // Given / * Write a description of class MyArrayList
here. * * Qauthor (your name) * @version (a version number or a date) */ // Do not modify the
given code. @SuppressWarnings("unchecked") // Given public class MyArrayList { private T[]
data; // Given private int size; // Given /* Implement. You must provide a comment block! */ public
MyArrayList(int inCapacity) { }/* Implement. You must provide a comment block! */ public boolean
isEmpty() {} /* Implement. You must provide a comment block! */ public boolean add(T obj) { //
This method appends obj toward the back of data // Always return true Implement. You must
provide a comment block! Implement this method so that a sequence of add operations executes
as efficiently as possible. */ private void grow() {} /* Implement. You must provide a comment
block! */ public boolean remove(Object obj) { // Return true if obj was removed from data // and
otherwise. / The rest of the code is given. I will use it for testing purposes. Do not modify! /Follow
the instructions in the Requirements section to see exactly what you have to do for this lab.
Requirements: Ensure that your lab satisfies the following technical requirements: 1. For the first
part, fill in the missing details in the MyArrayList class, as indicated by the comments. It is your
responsibility to ensure that the formatting guidelines are followed. For example, make sure you
have a consistent indentation scheme. The only exception is that you do not have to provide
comment blocks for certain methods. Do not modify any of the given code. 2. In the comment
block for add, give the best possible big- O of the worst-case running time for executing a single
add operations. Briefly justify your answer. 3. Also in the comment block for add, give the best
possible big- O of the total worst-case running time of executing a sequence of N add operations.
Hint: take your previous answer and multiply it by N. Briefly justify your answer. 4. Depending on
what you put for the previous two parts, your answer for the previous step might be a bit too
"pessimistic". In other words, even though the worst-caserunning time of a single add is O(??),
such worst-case behavior does not happen all the time. So, for this final part, compute the worst-
case running time of a single call to add, assumed to be executed during a sequence of N calls to
add. Use empirical methods to derive your answer. For example, compute the total amount of time
it takes to call add N times, and then divide by N and see what you get. Do this for several
increasing values of N and try to spot a pattern. Or, you can count the the number of simple
operations executed across a sequence N add operations and then divide the total by N. In the
comment block for add, give the best possible big- O of the worst-case running time per call to
add, assuming each call to add is one call in a sequence of N calls. 5. Finally, in the comment
block for add, clearly and concisely justify the answer you gave in the previous part. Are you
surprised by your findings in the previous part?

Mais conteúdo relacionado

Semelhante a For easy Ctrl C+Ctrl V Below is the same code that is descr.pdf

Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureSriram Raj
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsTomek Kaczanowski
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMockYing Zhang
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsTomek Kaczanowski
 
03-inheritance.ppt
03-inheritance.ppt03-inheritance.ppt
03-inheritance.pptSaiM947604
 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Featurestarun308
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdffirstchoiceajmer
 
U3 JAVA.pptx
U3 JAVA.pptxU3 JAVA.pptx
U3 JAVA.pptxmadan r
 

Semelhante a For easy Ctrl C+Ctrl V Below is the same code that is descr.pdf (20)

Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
J Unit
J UnitJ Unit
J Unit
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
3 j unit
3 j unit3 j unit
3 j unit
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
03-inheritance.ppt
03-inheritance.ppt03-inheritance.ppt
03-inheritance.ppt
 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Features
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
 
U3 JAVA.pptx
U3 JAVA.pptxU3 JAVA.pptx
U3 JAVA.pptx
 

Mais de rchopra4

For effect of temperature on microbial growth exercise 28 w.pdf
For effect of temperature on microbial growth exercise 28 w.pdfFor effect of temperature on microbial growth exercise 28 w.pdf
For effect of temperature on microbial growth exercise 28 w.pdfrchopra4
 
For Eosin Methylene Blue Agar what results would you be loo.pdf
For Eosin Methylene Blue Agar what results would you be loo.pdfFor Eosin Methylene Blue Agar what results would you be loo.pdf
For Eosin Methylene Blue Agar what results would you be loo.pdfrchopra4
 
For each of the languages L a b below use the pumping l.pdf
For each of the languages L  a b below use the pumping l.pdfFor each of the languages L  a b below use the pumping l.pdf
For each of the languages L a b below use the pumping l.pdfrchopra4
 
For each of the following scenarios state whether the situa.pdf
For each of the following scenarios state whether the situa.pdfFor each of the following scenarios state whether the situa.pdf
For each of the following scenarios state whether the situa.pdfrchopra4
 
For each of the below items be sure to write your code in S.pdf
For each of the below items be sure to write your code in S.pdfFor each of the below items be sure to write your code in S.pdf
For each of the below items be sure to write your code in S.pdfrchopra4
 
For customer service providers information learned about be.pdf
For customer service providers information learned about be.pdfFor customer service providers information learned about be.pdf
For customer service providers information learned about be.pdfrchopra4
 
For Apple Inc AAPL Caterpillar CAT Consolidated Edis.pdf
For Apple Inc AAPL Caterpillar CAT Consolidated Edis.pdfFor Apple Inc AAPL Caterpillar CAT Consolidated Edis.pdf
For Apple Inc AAPL Caterpillar CAT Consolidated Edis.pdfrchopra4
 
For bacteria the primary issue with UV light exposure is th.pdf
For bacteria the primary issue with UV light exposure is th.pdfFor bacteria the primary issue with UV light exposure is th.pdf
For bacteria the primary issue with UV light exposure is th.pdfrchopra4
 
For any of the questions below do not do math If there ar.pdf
For any of the questions below do not do math  If there ar.pdfFor any of the questions below do not do math  If there ar.pdf
For any of the questions below do not do math If there ar.pdfrchopra4
 
For a test of H0p050 the z test statistic equals 251 U.pdf
For a test of H0p050 the z test statistic equals 251 U.pdfFor a test of H0p050 the z test statistic equals 251 U.pdf
For a test of H0p050 the z test statistic equals 251 U.pdfrchopra4
 
For a review session in preparation for an animal diversity .pdf
For a review session in preparation for an animal diversity .pdfFor a review session in preparation for an animal diversity .pdf
For a review session in preparation for an animal diversity .pdfrchopra4
 
For a random variable XVX was calculated to be 1 Is the.pdf
For a random variable XVX was calculated to be 1  Is the.pdfFor a random variable XVX was calculated to be 1  Is the.pdf
For a random variable XVX was calculated to be 1 Is the.pdfrchopra4
 
For 37 years Janet saved 250 at the beginning of every mon.pdf
For 37 years Janet saved 250 at the beginning of every mon.pdfFor 37 years Janet saved 250 at the beginning of every mon.pdf
For 37 years Janet saved 250 at the beginning of every mon.pdfrchopra4
 
For 21 years Janet saved 850 at the beginning of every mon.pdf
For 21 years Janet saved 850 at the beginning of every mon.pdfFor 21 years Janet saved 850 at the beginning of every mon.pdf
For 21 years Janet saved 850 at the beginning of every mon.pdfrchopra4
 
For 39 years Janet saved 450 at the beginning of every mon.pdf
For 39 years Janet saved 450 at the beginning of every mon.pdfFor 39 years Janet saved 450 at the beginning of every mon.pdf
For 39 years Janet saved 450 at the beginning of every mon.pdfrchopra4
 
Following is the pea plant characteristics and the location .pdf
Following is the pea plant characteristics and the location .pdfFollowing is the pea plant characteristics and the location .pdf
Following is the pea plant characteristics and the location .pdfrchopra4
 
For 20Y2 McDade Company reported a decline in not income A.pdf
For 20Y2 McDade Company reported a decline in not income A.pdfFor 20Y2 McDade Company reported a decline in not income A.pdf
For 20Y2 McDade Company reported a decline in not income A.pdfrchopra4
 
For 27 years Janet saved 900 at the beginning of every mon.pdf
For 27 years Janet saved 900 at the beginning of every mon.pdfFor 27 years Janet saved 900 at the beginning of every mon.pdf
For 27 years Janet saved 900 at the beginning of every mon.pdfrchopra4
 
For 14 years Janet saved 800 at the beginning of every mon.pdf
For 14 years Janet saved 800 at the beginning of every mon.pdfFor 14 years Janet saved 800 at the beginning of every mon.pdf
For 14 years Janet saved 800 at the beginning of every mon.pdfrchopra4
 
For 100 births P exactly 57 girls 00301 and P57 or mor.pdf
For 100 births P exactly 57 girls 00301 and P57 or mor.pdfFor 100 births P exactly 57 girls 00301 and P57 or mor.pdf
For 100 births P exactly 57 girls 00301 and P57 or mor.pdfrchopra4
 

Mais de rchopra4 (20)

For effect of temperature on microbial growth exercise 28 w.pdf
For effect of temperature on microbial growth exercise 28 w.pdfFor effect of temperature on microbial growth exercise 28 w.pdf
For effect of temperature on microbial growth exercise 28 w.pdf
 
For Eosin Methylene Blue Agar what results would you be loo.pdf
For Eosin Methylene Blue Agar what results would you be loo.pdfFor Eosin Methylene Blue Agar what results would you be loo.pdf
For Eosin Methylene Blue Agar what results would you be loo.pdf
 
For each of the languages L a b below use the pumping l.pdf
For each of the languages L  a b below use the pumping l.pdfFor each of the languages L  a b below use the pumping l.pdf
For each of the languages L a b below use the pumping l.pdf
 
For each of the following scenarios state whether the situa.pdf
For each of the following scenarios state whether the situa.pdfFor each of the following scenarios state whether the situa.pdf
For each of the following scenarios state whether the situa.pdf
 
For each of the below items be sure to write your code in S.pdf
For each of the below items be sure to write your code in S.pdfFor each of the below items be sure to write your code in S.pdf
For each of the below items be sure to write your code in S.pdf
 
For customer service providers information learned about be.pdf
For customer service providers information learned about be.pdfFor customer service providers information learned about be.pdf
For customer service providers information learned about be.pdf
 
For Apple Inc AAPL Caterpillar CAT Consolidated Edis.pdf
For Apple Inc AAPL Caterpillar CAT Consolidated Edis.pdfFor Apple Inc AAPL Caterpillar CAT Consolidated Edis.pdf
For Apple Inc AAPL Caterpillar CAT Consolidated Edis.pdf
 
For bacteria the primary issue with UV light exposure is th.pdf
For bacteria the primary issue with UV light exposure is th.pdfFor bacteria the primary issue with UV light exposure is th.pdf
For bacteria the primary issue with UV light exposure is th.pdf
 
For any of the questions below do not do math If there ar.pdf
For any of the questions below do not do math  If there ar.pdfFor any of the questions below do not do math  If there ar.pdf
For any of the questions below do not do math If there ar.pdf
 
For a test of H0p050 the z test statistic equals 251 U.pdf
For a test of H0p050 the z test statistic equals 251 U.pdfFor a test of H0p050 the z test statistic equals 251 U.pdf
For a test of H0p050 the z test statistic equals 251 U.pdf
 
For a review session in preparation for an animal diversity .pdf
For a review session in preparation for an animal diversity .pdfFor a review session in preparation for an animal diversity .pdf
For a review session in preparation for an animal diversity .pdf
 
For a random variable XVX was calculated to be 1 Is the.pdf
For a random variable XVX was calculated to be 1  Is the.pdfFor a random variable XVX was calculated to be 1  Is the.pdf
For a random variable XVX was calculated to be 1 Is the.pdf
 
For 37 years Janet saved 250 at the beginning of every mon.pdf
For 37 years Janet saved 250 at the beginning of every mon.pdfFor 37 years Janet saved 250 at the beginning of every mon.pdf
For 37 years Janet saved 250 at the beginning of every mon.pdf
 
For 21 years Janet saved 850 at the beginning of every mon.pdf
For 21 years Janet saved 850 at the beginning of every mon.pdfFor 21 years Janet saved 850 at the beginning of every mon.pdf
For 21 years Janet saved 850 at the beginning of every mon.pdf
 
For 39 years Janet saved 450 at the beginning of every mon.pdf
For 39 years Janet saved 450 at the beginning of every mon.pdfFor 39 years Janet saved 450 at the beginning of every mon.pdf
For 39 years Janet saved 450 at the beginning of every mon.pdf
 
Following is the pea plant characteristics and the location .pdf
Following is the pea plant characteristics and the location .pdfFollowing is the pea plant characteristics and the location .pdf
Following is the pea plant characteristics and the location .pdf
 
For 20Y2 McDade Company reported a decline in not income A.pdf
For 20Y2 McDade Company reported a decline in not income A.pdfFor 20Y2 McDade Company reported a decline in not income A.pdf
For 20Y2 McDade Company reported a decline in not income A.pdf
 
For 27 years Janet saved 900 at the beginning of every mon.pdf
For 27 years Janet saved 900 at the beginning of every mon.pdfFor 27 years Janet saved 900 at the beginning of every mon.pdf
For 27 years Janet saved 900 at the beginning of every mon.pdf
 
For 14 years Janet saved 800 at the beginning of every mon.pdf
For 14 years Janet saved 800 at the beginning of every mon.pdfFor 14 years Janet saved 800 at the beginning of every mon.pdf
For 14 years Janet saved 800 at the beginning of every mon.pdf
 
For 100 births P exactly 57 girls 00301 and P57 or mor.pdf
For 100 births P exactly 57 girls 00301 and P57 or mor.pdfFor 100 births P exactly 57 girls 00301 and P57 or mor.pdf
For 100 births P exactly 57 girls 00301 and P57 or mor.pdf
 

Último

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Último (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

For easy Ctrl C+Ctrl V Below is the same code that is descr.pdf

  • 1. For easy Ctrl C+Ctrl V, Below is the same code that is described above. import java.util.Iterator; /** * Write a description of class MyArrayList here. * * @author (your name) * @version (a version number or a date) */ // Do not modify the given code. @SuppressWarnings("unchecked") // Given public class MyArrayList<T> { private T[] data; // Given private int size; // Given /* Implement. You must provide a comment block! */ public MyArrayList(int inCapacity) { } /* Implement. You must provide a comment block! */ public boolean isEmpty() { } /* Implement. You must provide a comment block! */ public boolean add(T obj) { // This method appends obj toward the back of data // Always return true } /* Implement. You must provide a comment block! Implement this method so that a sequence of add operations executes as efficiently as possible. */ private void grow() { } /* Implement. You must provide a comment block! */ public boolean remove(Object obj) { // Return true if obj was removed from data // and false otherwise. }
  • 2. /* The rest of the code is given. I will use it for testing purposes. Do not modify! */ // Given. Do not provide a comment block! public String toString() { if (size == 0) return "[ ]"; String retStr = "[ "; for (int i = 0; i < size - 1; i++) retStr += data[i] + ", "; retStr += data[size - 1] + " ]"; return retStr; } // Given. Do not provide a comment block! public boolean equals(Object obj) { if (obj instanceof MyArrayList) { MyArrayList<T> rhs = (MyArrayList<T>)obj; if (size != rhs.size) return false; for (int i = 0; i < size; i++) if (!rhs.contains(data[i])) return false; return true; } return false; } // Given. Do not provide a comment block! private int find(Object obj) { for (int i = 0; i < size; i++) if (data[i].equals(obj)) return i; return -1; } // Given. Do not provide a comment block! public boolean contains(Object obj) { return find(obj) >= 0; } // Given. Do not provide a comment block! public void addAll(MyArrayList<T> inList) { for (int i = 0; i < inList.size; i++)
  • 3. add(inList.data[i]); } // Given. Do not provide a comment block! private class MyArrayListIterator implements Iterator<T> { private int index = 0; // Given. Do not provide a comment block! public void remove() { } // No implementation // Given. Do not provide a comment block! public T next() { T temp = data[index]; index++; return temp; } // Given. Do not provide a comment block! public boolean hasNext() { return index < size; } } // Given. Do not provide a comment block! public Iterator<T> iterator() { return new MyArrayListIterator(); } } troduction: In this lab, you will get some practice implementing certain methods of expandable, generic MyArrayList data structure and doing an amortized analysis of one the methods thereof. Basically, in addition to the parameterized constructor, you have implement the operations of isEmpty, add, grow and remove. Then, you will do a very mple amortized analysis, using empirical methods, to derive the worst-case running time add when executed in a sequence of several add operations. ote that there is a lot of "extra" code that is given. Don't modify any of the given code. I ll need this for testing purposes. etting started: 1. Create a new project in NetBeans called Lab5. Make sure you uncheck Create Main Class in the New Java Application window. 2. Within the default package of your Lab5 project, create a new Java class called MyArrayList and use the following code to get started (the following code is also available for download on Canvas as MyArrayList. java): import java. util. Iterator; // Given / * Write a description of class MyArrayList here. * * Qauthor (your name) * @version (a version number or a date) */ // Do not modify the given code. @SuppressWarnings("unchecked") // Given public class MyArrayList { private T[] data; // Given private int size; // Given /* Implement. You must provide a comment block! */ public MyArrayList(int inCapacity) { }/* Implement. You must provide a comment block! */ public boolean isEmpty() {} /* Implement. You must provide a comment block! */ public boolean add(T obj) { // This method appends obj toward the back of data // Always return true Implement. You must provide a comment block! Implement this method so that a sequence of add operations executes
  • 4. as efficiently as possible. */ private void grow() {} /* Implement. You must provide a comment block! */ public boolean remove(Object obj) { // Return true if obj was removed from data // and otherwise. / The rest of the code is given. I will use it for testing purposes. Do not modify! /Follow the instructions in the Requirements section to see exactly what you have to do for this lab. Requirements: Ensure that your lab satisfies the following technical requirements: 1. For the first part, fill in the missing details in the MyArrayList class, as indicated by the comments. It is your responsibility to ensure that the formatting guidelines are followed. For example, make sure you have a consistent indentation scheme. The only exception is that you do not have to provide comment blocks for certain methods. Do not modify any of the given code. 2. In the comment block for add, give the best possible big- O of the worst-case running time for executing a single add operations. Briefly justify your answer. 3. Also in the comment block for add, give the best possible big- O of the total worst-case running time of executing a sequence of N add operations. Hint: take your previous answer and multiply it by N. Briefly justify your answer. 4. Depending on what you put for the previous two parts, your answer for the previous step might be a bit too "pessimistic". In other words, even though the worst-caserunning time of a single add is O(??), such worst-case behavior does not happen all the time. So, for this final part, compute the worst- case running time of a single call to add, assumed to be executed during a sequence of N calls to add. Use empirical methods to derive your answer. For example, compute the total amount of time it takes to call add N times, and then divide by N and see what you get. Do this for several increasing values of N and try to spot a pattern. Or, you can count the the number of simple operations executed across a sequence N add operations and then divide the total by N. In the comment block for add, give the best possible big- O of the worst-case running time per call to add, assuming each call to add is one call in a sequence of N calls. 5. Finally, in the comment block for add, clearly and concisely justify the answer you gave in the previous part. Are you surprised by your findings in the previous part?