java - What is the time complexity of stream filter obtained from HashSet? -
set<integer> set = new hashset<>(); set.add(1); set.add(2); ... what time complexity of below operation? o(n) or o(1)?
set.stream().filter(e -> e == 1).findfirst();
you can understand better if see side, solution same :
for(integer : set){ if(i == 1){ break; } } so o(n) because loop on set, , check 1 one, if condition correct return value else continue until n elsement
Comments
Post a Comment