SlideShare a Scribd company logo
1 of 3
Download to read offline
I need help with two things. First I'd like someone to check over my code for the 3 //TODO
statements below to verify that they're correct
public static HashSet doHashSetInsertMedian(int numItems) {
System.out.print("doHashSetInsertMedian: ");
HashSet set = new HashSet<>();
// TODO Write code that adds integers 0 through (numItems - 1)
// to set, inside a loop.
for(int i=0; i doLinkedHashSetRemoveMedian(int numItems) {
System.out.print("doLinkedHashSetRemoveMedian: ");
LinkedHashSet set = new LinkedHashSet<>();
// TODO Write code that adds integers 0 through (numitems - 1)
// to set.
long startTime = getTimestamp();
// TODO Write code that removes the median element
// from set, repeatedly until the set is empty.
long endTime = getTimestamp();
long totalTime = endTime - startTime;
System.out.println(totalTime);
return set;
}
Solution
PART 1
Hi friend, first part you have done correctly except a small mistake. In first TODO you missed
'=' sign:
public static HashSet doHashSetInsertMedian(int numItems) {
System.out.print("doHashSetInsertMedian: ");
HashSet set = new HashSet<>();
// TODO Write code that adds integers 0 through (numItems - 1)
// to set, inside a loop.
for(int i=0; i<=numItems-1; i++){
set.add(i);
}
// TODO Write code that removes integer (numItems / 2)
// from set.
int median = numItems / 2;
set.remove(median);
long startTime = getTimestamp();
// TODO Write code that adds integer (numItems / 2)
// to set.
set.add(median);
long endTime = getTimestamp();
long totalTime = endTime - startTime;
System.out.println(totalTime);
return set;
}
PART 2:
public static LinkedHashSet doLinkedHashSetRemoveMedian(int numItems) {
System.out.print("doLinkedHashSetRemoveMedian: ");
LinkedHashSet set = new LinkedHashSet<>();
// TODO Write code that adds integers 0 through (numitems - 1)
// to set.
for(int i=0; i<=numitems-1; i++)
set.add(i);
long startTime = getTimestamp();
// TODO Write code that removes the median element
// from set, repeatedly until the set is empty.
int median;
int current_size = set.size();
while(set.size() > 0){
current_size = set.size(); //getting current size of set
median = current_size/2; // finding current median
set.remove(median); // removing median
}
long endTime = getTimestamp();
long totalTime = endTime - startTime;
System.out.println(totalTime);
return set;
}

More Related Content

Similar to I need help with two things. First Id like someone to check over m.pdf

Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical FileFahad Shaikh
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdfinfo30292
 
An object of class StatCalc can be used to compute several simp.pdf
 An object of class StatCalc can be used to compute several simp.pdf An object of class StatCalc can be used to compute several simp.pdf
An object of class StatCalc can be used to compute several simp.pdfaravlitraders2012
 
Merge Sort java with a few details, please include comments if possi.pdf
Merge Sort java with a few details, please include comments if possi.pdfMerge Sort java with a few details, please include comments if possi.pdf
Merge Sort java with a few details, please include comments if possi.pdffeelinggifts
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfarri2009av
 
Data structures lab
Data structures labData structures lab
Data structures labRagu Ram
 
Describe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfDescribe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfarihantstoneart
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answersQuratulain Naqvi
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfkarymadelaneyrenne19
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxamrit47
 
for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...hwbloom14
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfSHASHIKANT346021
 

Similar to I need help with two things. First Id like someone to check over m.pdf (18)

Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdf
 
An object of class StatCalc can be used to compute several simp.pdf
 An object of class StatCalc can be used to compute several simp.pdf An object of class StatCalc can be used to compute several simp.pdf
An object of class StatCalc can be used to compute several simp.pdf
 
Merge Sort java with a few details, please include comments if possi.pdf
Merge Sort java with a few details, please include comments if possi.pdfMerge Sort java with a few details, please include comments if possi.pdf
Merge Sort java with a few details, please include comments if possi.pdf
 
Java calculator
Java calculatorJava calculator
Java calculator
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
Data structures lab
Data structures labData structures lab
Data structures lab
 
Describe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfDescribe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdf
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 

More from info998421

If Mendel had chosen factors to follow in his pea plants poorly,.pdf
If Mendel had chosen factors to follow in his pea plants poorly,.pdfIf Mendel had chosen factors to follow in his pea plants poorly,.pdf
If Mendel had chosen factors to follow in his pea plants poorly,.pdfinfo998421
 
If the significance level of a test is increased (i.e. increased fr.pdf
If the significance level of a test is increased (i.e.  increased fr.pdfIf the significance level of a test is increased (i.e.  increased fr.pdf
If the significance level of a test is increased (i.e. increased fr.pdfinfo998421
 
I need an inttroduction for my paper on Conducting and Analyzing Sta.pdf
I need an inttroduction for my paper on Conducting and Analyzing Sta.pdfI need an inttroduction for my paper on Conducting and Analyzing Sta.pdf
I need an inttroduction for my paper on Conducting and Analyzing Sta.pdfinfo998421
 
Identify the contributions to Microbiology made by Redi, Tyndall, an.pdf
Identify the contributions to Microbiology made by Redi, Tyndall, an.pdfIdentify the contributions to Microbiology made by Redi, Tyndall, an.pdf
Identify the contributions to Microbiology made by Redi, Tyndall, an.pdfinfo998421
 
Explain Internal Controls and Corporate Governance.SolutionInt.pdf
Explain Internal Controls and Corporate Governance.SolutionInt.pdfExplain Internal Controls and Corporate Governance.SolutionInt.pdf
Explain Internal Controls and Corporate Governance.SolutionInt.pdfinfo998421
 
Environmental Laws and Acts Project Research all of the following law.pdf
Environmental Laws and Acts Project Research all of the following law.pdfEnvironmental Laws and Acts Project Research all of the following law.pdf
Environmental Laws and Acts Project Research all of the following law.pdfinfo998421
 
discuss the drawbacks of programmed and interrupt driven io and des.pdf
discuss the drawbacks of programmed and interrupt driven io and des.pdfdiscuss the drawbacks of programmed and interrupt driven io and des.pdf
discuss the drawbacks of programmed and interrupt driven io and des.pdfinfo998421
 
do it on excel and please kindly upload the excel file. or explain m.pdf
do it on excel and please kindly upload the excel file. or explain m.pdfdo it on excel and please kindly upload the excel file. or explain m.pdf
do it on excel and please kindly upload the excel file. or explain m.pdfinfo998421
 
Describe the structure and location of the parathyroid glands.Desc.pdf
Describe the structure and location of the parathyroid glands.Desc.pdfDescribe the structure and location of the parathyroid glands.Desc.pdf
Describe the structure and location of the parathyroid glands.Desc.pdfinfo998421
 
Describe how the composition of MALT tissue bypasses the need for.pdf
Describe how the composition of MALT tissue bypasses the need for.pdfDescribe how the composition of MALT tissue bypasses the need for.pdf
Describe how the composition of MALT tissue bypasses the need for.pdfinfo998421
 
C. wye D. delta E. not defined Question 6 What is the configuration o.pdf
C. wye D. delta E. not defined Question 6 What is the configuration o.pdfC. wye D. delta E. not defined Question 6 What is the configuration o.pdf
C. wye D. delta E. not defined Question 6 What is the configuration o.pdfinfo998421
 
A bullet that lodges in the heart would a. be located in the ventra.pdf
A bullet that lodges in the heart would  a. be located in the ventra.pdfA bullet that lodges in the heart would  a. be located in the ventra.pdf
A bullet that lodges in the heart would a. be located in the ventra.pdfinfo998421
 
Year d) interactions with other species for space or resources-classi.pdf
Year d) interactions with other species for space or resources-classi.pdfYear d) interactions with other species for space or resources-classi.pdf
Year d) interactions with other species for space or resources-classi.pdfinfo998421
 
Write a program that creates a linked list of families. Each family .pdf
Write a program that creates a linked list of families. Each family .pdfWrite a program that creates a linked list of families. Each family .pdf
Write a program that creates a linked list of families. Each family .pdfinfo998421
 
Why do Radicals maintain capitalism will always tend to enter into c.pdf
Why do Radicals maintain capitalism will always tend to enter into c.pdfWhy do Radicals maintain capitalism will always tend to enter into c.pdf
Why do Radicals maintain capitalism will always tend to enter into c.pdfinfo998421
 
Write a C program that converts an NFA file to a DFA, where the lang.pdf
Write a C program that converts an NFA file to a DFA, where the lang.pdfWrite a C program that converts an NFA file to a DFA, where the lang.pdf
Write a C program that converts an NFA file to a DFA, where the lang.pdfinfo998421
 
Which of these hypotheses cannot be tested by an experiment Biologi.pdf
Which of these hypotheses cannot be tested by an experiment  Biologi.pdfWhich of these hypotheses cannot be tested by an experiment  Biologi.pdf
Which of these hypotheses cannot be tested by an experiment Biologi.pdfinfo998421
 
Which is the mode of inheritance that is most likely [That is the mo.pdf
Which is the mode of inheritance that is most likely [That is the mo.pdfWhich is the mode of inheritance that is most likely [That is the mo.pdf
Which is the mode of inheritance that is most likely [That is the mo.pdfinfo998421
 
Which of the following is a good example of homoplasy (convergent ev.pdf
Which of the following is a good example of homoplasy (convergent ev.pdfWhich of the following is a good example of homoplasy (convergent ev.pdf
Which of the following is a good example of homoplasy (convergent ev.pdfinfo998421
 
What happens at the mid-blastula transition in Xenopus Which part o.pdf
What happens at the mid-blastula transition in Xenopus  Which part o.pdfWhat happens at the mid-blastula transition in Xenopus  Which part o.pdf
What happens at the mid-blastula transition in Xenopus Which part o.pdfinfo998421
 

More from info998421 (20)

If Mendel had chosen factors to follow in his pea plants poorly,.pdf
If Mendel had chosen factors to follow in his pea plants poorly,.pdfIf Mendel had chosen factors to follow in his pea plants poorly,.pdf
If Mendel had chosen factors to follow in his pea plants poorly,.pdf
 
If the significance level of a test is increased (i.e. increased fr.pdf
If the significance level of a test is increased (i.e.  increased fr.pdfIf the significance level of a test is increased (i.e.  increased fr.pdf
If the significance level of a test is increased (i.e. increased fr.pdf
 
I need an inttroduction for my paper on Conducting and Analyzing Sta.pdf
I need an inttroduction for my paper on Conducting and Analyzing Sta.pdfI need an inttroduction for my paper on Conducting and Analyzing Sta.pdf
I need an inttroduction for my paper on Conducting and Analyzing Sta.pdf
 
Identify the contributions to Microbiology made by Redi, Tyndall, an.pdf
Identify the contributions to Microbiology made by Redi, Tyndall, an.pdfIdentify the contributions to Microbiology made by Redi, Tyndall, an.pdf
Identify the contributions to Microbiology made by Redi, Tyndall, an.pdf
 
Explain Internal Controls and Corporate Governance.SolutionInt.pdf
Explain Internal Controls and Corporate Governance.SolutionInt.pdfExplain Internal Controls and Corporate Governance.SolutionInt.pdf
Explain Internal Controls and Corporate Governance.SolutionInt.pdf
 
Environmental Laws and Acts Project Research all of the following law.pdf
Environmental Laws and Acts Project Research all of the following law.pdfEnvironmental Laws and Acts Project Research all of the following law.pdf
Environmental Laws and Acts Project Research all of the following law.pdf
 
discuss the drawbacks of programmed and interrupt driven io and des.pdf
discuss the drawbacks of programmed and interrupt driven io and des.pdfdiscuss the drawbacks of programmed and interrupt driven io and des.pdf
discuss the drawbacks of programmed and interrupt driven io and des.pdf
 
do it on excel and please kindly upload the excel file. or explain m.pdf
do it on excel and please kindly upload the excel file. or explain m.pdfdo it on excel and please kindly upload the excel file. or explain m.pdf
do it on excel and please kindly upload the excel file. or explain m.pdf
 
Describe the structure and location of the parathyroid glands.Desc.pdf
Describe the structure and location of the parathyroid glands.Desc.pdfDescribe the structure and location of the parathyroid glands.Desc.pdf
Describe the structure and location of the parathyroid glands.Desc.pdf
 
Describe how the composition of MALT tissue bypasses the need for.pdf
Describe how the composition of MALT tissue bypasses the need for.pdfDescribe how the composition of MALT tissue bypasses the need for.pdf
Describe how the composition of MALT tissue bypasses the need for.pdf
 
C. wye D. delta E. not defined Question 6 What is the configuration o.pdf
C. wye D. delta E. not defined Question 6 What is the configuration o.pdfC. wye D. delta E. not defined Question 6 What is the configuration o.pdf
C. wye D. delta E. not defined Question 6 What is the configuration o.pdf
 
A bullet that lodges in the heart would a. be located in the ventra.pdf
A bullet that lodges in the heart would  a. be located in the ventra.pdfA bullet that lodges in the heart would  a. be located in the ventra.pdf
A bullet that lodges in the heart would a. be located in the ventra.pdf
 
Year d) interactions with other species for space or resources-classi.pdf
Year d) interactions with other species for space or resources-classi.pdfYear d) interactions with other species for space or resources-classi.pdf
Year d) interactions with other species for space or resources-classi.pdf
 
Write a program that creates a linked list of families. Each family .pdf
Write a program that creates a linked list of families. Each family .pdfWrite a program that creates a linked list of families. Each family .pdf
Write a program that creates a linked list of families. Each family .pdf
 
Why do Radicals maintain capitalism will always tend to enter into c.pdf
Why do Radicals maintain capitalism will always tend to enter into c.pdfWhy do Radicals maintain capitalism will always tend to enter into c.pdf
Why do Radicals maintain capitalism will always tend to enter into c.pdf
 
Write a C program that converts an NFA file to a DFA, where the lang.pdf
Write a C program that converts an NFA file to a DFA, where the lang.pdfWrite a C program that converts an NFA file to a DFA, where the lang.pdf
Write a C program that converts an NFA file to a DFA, where the lang.pdf
 
Which of these hypotheses cannot be tested by an experiment Biologi.pdf
Which of these hypotheses cannot be tested by an experiment  Biologi.pdfWhich of these hypotheses cannot be tested by an experiment  Biologi.pdf
Which of these hypotheses cannot be tested by an experiment Biologi.pdf
 
Which is the mode of inheritance that is most likely [That is the mo.pdf
Which is the mode of inheritance that is most likely [That is the mo.pdfWhich is the mode of inheritance that is most likely [That is the mo.pdf
Which is the mode of inheritance that is most likely [That is the mo.pdf
 
Which of the following is a good example of homoplasy (convergent ev.pdf
Which of the following is a good example of homoplasy (convergent ev.pdfWhich of the following is a good example of homoplasy (convergent ev.pdf
Which of the following is a good example of homoplasy (convergent ev.pdf
 
What happens at the mid-blastula transition in Xenopus Which part o.pdf
What happens at the mid-blastula transition in Xenopus  Which part o.pdfWhat happens at the mid-blastula transition in Xenopus  Which part o.pdf
What happens at the mid-blastula transition in Xenopus Which part o.pdf
 

Recently uploaded

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

I need help with two things. First Id like someone to check over m.pdf

  • 1. I need help with two things. First I'd like someone to check over my code for the 3 //TODO statements below to verify that they're correct public static HashSet doHashSetInsertMedian(int numItems) { System.out.print("doHashSetInsertMedian: "); HashSet set = new HashSet<>(); // TODO Write code that adds integers 0 through (numItems - 1) // to set, inside a loop. for(int i=0; i doLinkedHashSetRemoveMedian(int numItems) { System.out.print("doLinkedHashSetRemoveMedian: "); LinkedHashSet set = new LinkedHashSet<>(); // TODO Write code that adds integers 0 through (numitems - 1) // to set. long startTime = getTimestamp(); // TODO Write code that removes the median element // from set, repeatedly until the set is empty. long endTime = getTimestamp(); long totalTime = endTime - startTime; System.out.println(totalTime); return set; } Solution PART 1 Hi friend, first part you have done correctly except a small mistake. In first TODO you missed '=' sign: public static HashSet doHashSetInsertMedian(int numItems) { System.out.print("doHashSetInsertMedian: "); HashSet set = new HashSet<>(); // TODO Write code that adds integers 0 through (numItems - 1) // to set, inside a loop. for(int i=0; i<=numItems-1; i++){
  • 2. set.add(i); } // TODO Write code that removes integer (numItems / 2) // from set. int median = numItems / 2; set.remove(median); long startTime = getTimestamp(); // TODO Write code that adds integer (numItems / 2) // to set. set.add(median); long endTime = getTimestamp(); long totalTime = endTime - startTime; System.out.println(totalTime); return set; } PART 2: public static LinkedHashSet doLinkedHashSetRemoveMedian(int numItems) { System.out.print("doLinkedHashSetRemoveMedian: "); LinkedHashSet set = new LinkedHashSet<>(); // TODO Write code that adds integers 0 through (numitems - 1) // to set. for(int i=0; i<=numitems-1; i++) set.add(i); long startTime = getTimestamp(); // TODO Write code that removes the median element // from set, repeatedly until the set is empty. int median; int current_size = set.size(); while(set.size() > 0){ current_size = set.size(); //getting current size of set median = current_size/2; // finding current median set.remove(median); // removing median
  • 3. } long endTime = getTimestamp(); long totalTime = endTime - startTime; System.out.println(totalTime); return set; }