Original Post
I'm in a data structures summer class and we are to find the "..worst-case time bounds for the methods..." in the snipet below. I've made an attempt and would like to know if I am on the right track. This is what I've done: And for each method this is O(g(n)) NumberList O(1) PrintDuplicates O(n^3) I am unsure if I add over the for(...) or multiply Fill O(n) findNumber O(n) summarize O(n) For this one, do I need to add the O(g(n)) for printDuplicates() to the total? Many thanks!!!
public class NumberList
{
int[] number;
int capacity;
public NumberList(int size)
{
number = new int[size];
capacity = size;
}
public void printDuplicates()
{
for(int i =0; i<capacity;i++)
for(int j=0;j<capacity;j++)
if(j!= i && number[j] == number)
System.out.println(number)
}
public void fill(int r)
{
for(int i =0;i<capacity;i++)
number=(i*2+7)%r;
}
public boolean findNumber(int searchNumber)
{
boolean found = false;
for (int i =0;!found & (i<capacity);i++)
{
if(number == searchNumber)
found = true;
}
return found;
}
public void summarize(NumberList otherNumbers)
{
for(int i =0;i<othernumbers.capacity;i++)
{
int currentNumber = otherNumbers.number;
if(findNumber(currentNumber))
System.out.prinln(currenNumber);
}
printDuplicates();
}
}
public class NumberList
{
int[] number;
int capacity;
public NumberList(int size)
{
1 number = new int[size];
1 capacity = size;
}
public void printDuplicates()
{
n+1 for(int i =0; i<capacity;i++)
n+1 for(int j=0;j<capacity;j++)
n if(j!= i && number[j] == number)
p = unknown System.out.println(number)
}
public void fill(int r)
{
n+1 for(int i =0;i<capacity;i++)
n number=(i*2+7)%r;
}
public boolean findNumber(int searchNumber)
{
1 boolean found = false;
n+1 for (int i =0;!found & (i<capacity);i++)
{
n if(number == searchNumber)
1 found = true;
}
1 return found;
}
public void summarize(NumberList otherNumbers)
{
n+1 for(int i =0;i<othernumbers.capacity;i++)
{
1 int currentNumber = otherNumbers.number;
n if(findNumber(currentNumber))
p System.out.prinln(currenNumber);
}
1 printDuplicates();
}
}