Skip to main content
edited tags
Link
user40980
user40980
Fix curly braces, indent, 'i'.
Source Link
user40980
user40980

I have an ArrayList<LinkedHashSet<String>> setOfStrings for example this arraylist internally is composed like:

positionX[hello,car,three,hotel,beach]
positionY[.....]
...

I want to find car inside this data-structure, so iI did it

for (Iterator<LinkedHashSet<String>> iterator = setOfStrings.iterator(); iterator.hasNext();) { 
        LinkedHashSet<String> subSet = iterator.next();
        if (subSet.contains("hotel"))
         System.out.println("found");
        }
}

The for iterate over the entire arrayList and the complexity in the worst-case is O(n), but i'mI'm confused on the complexity of the method contains() of set. In according of javadocs this method is executed in constant time, but I've heard that in certain cases the complexity might become O(n). Saying that, I'm not sure about the complexity of this snippet algorithm.

Can someone provide me an explanation of that?

I have an ArrayList<LinkedHashSet<String>> setOfStrings for example this arraylist internally is composed like:

positionX[hello,car,three,hotel,beach]
positionY[.....]
...

I want to find car inside this data-structure, so i did it

for (Iterator<LinkedHashSet<String>> iterator = setOfStrings.iterator(); iterator.hasNext();) { 
        LinkedHashSet<String> subSet = iterator.next();
        if (subSet.contains("hotel"))
         System.out.println("found");
        }
}

The for iterate over the entire arrayList and the complexity in the worst-case is O(n), but i'm confused on the complexity of the method contains() of set. In according of javadocs this method is executed in constant time, but I've heard that in certain cases the complexity might become O(n). Saying that, I'm not sure about the complexity of this snippet algorithm.

Can someone provide me an explanation of that?

I have an ArrayList<LinkedHashSet<String>> setOfStrings for example this arraylist internally is composed like:

positionX[hello,car,three,hotel,beach]
positionY[.....]
...

I want to find car inside this data-structure, so I did it

for (Iterator<LinkedHashSet<String>> iterator = setOfStrings.iterator(); iterator.hasNext();) { 
    LinkedHashSet<String> subSet = iterator.next();
    if (subSet.contains("hotel"))
        System.out.println("found");
}

The for iterate over the entire arrayList and the complexity in the worst-case is O(n), but I'm confused on the complexity of the method contains() of set. In according of javadocs this method is executed in constant time, but I've heard that in certain cases the complexity might become O(n). Saying that, I'm not sure about the complexity of this snippet algorithm.

Can someone provide me an explanation of that?

iI have an arrayList<LinkedHashSet<String>>ArrayList<LinkedHashSet<String>> setOfStrings for example this arraylist internally is composed like:

positionX[hello,car,three,hotel,beach]
positionY[.....]
...

iI want to find car inside this data-structure, so i did it

for (Iterator<LinkedHashSet<String>> iterator = setOfStrings.iterator(); iterator.hasNext();) { 
        LinkedHashSet<String> subSet = iterator.next();
        if (subSet.contains("hotel"))
         System.out.println("found");
        }
}

the for iterate over the entire arrayList and the complexity in the worst-case is O(n),but i'm confused on the complexity of the method contains() of set. In according of javadocs this method is executed in constant time, but i' ve heard that in certain cases the complexity might become O(n). Saying that, i'm not sure about the complexity of this snippet algorithm. The for iterate over the entire arrayList and the complexity in the worst-case is O(n), but i'm confused on the complexity of the method contains() of set. In according of javadocs this method is executed in constant time, but I've heard that in certain cases the complexity might become O(n). Saying that, I'm not sure about the complexity of this snippet algorithm.

canCan someone provide me an explanation of that?

i have an arrayList<LinkedHashSet<String>> setOfStrings for example this arraylist internally is composed like:

positionX[hello,car,three,hotel,beach]
positionY[.....]
...

i want to find car inside this data-structure, so i did it

for (Iterator<LinkedHashSet<String>> iterator = setOfStrings.iterator(); iterator.hasNext();) { 
        LinkedHashSet<String> subSet = iterator.next();
        if (subSet.contains("hotel"))
         System.out.println("found");
        }
}

the for iterate over the entire arrayList and the complexity in the worst-case is O(n),but i'm confused on the complexity of the method contains() of set. In according of javadocs this method is executed in constant time, but i' ve heard that in certain cases the complexity might become O(n). Saying that, i'm not sure about the complexity of this snippet algorithm.

can someone provide me an explanation of that?

I have an ArrayList<LinkedHashSet<String>> setOfStrings for example this arraylist internally is composed like:

positionX[hello,car,three,hotel,beach]
positionY[.....]
...

I want to find car inside this data-structure, so i did it

for (Iterator<LinkedHashSet<String>> iterator = setOfStrings.iterator(); iterator.hasNext();) { 
        LinkedHashSet<String> subSet = iterator.next();
        if (subSet.contains("hotel"))
         System.out.println("found");
        }
}

The for iterate over the entire arrayList and the complexity in the worst-case is O(n), but i'm confused on the complexity of the method contains() of set. In according of javadocs this method is executed in constant time, but I've heard that in certain cases the complexity might become O(n). Saying that, I'm not sure about the complexity of this snippet algorithm.

Can someone provide me an explanation of that?

Source Link
OiRc
  • 127
  • 1
  • 1
  • 9
Loading