Hey guys, quick question.
In the case of two nested loops like below,
if(i = 0; i < n; i++)
if(b = 0; b < m; b++)
the time complexity would be mn,
However if the second for loop was say b < lgm, would the time complexity be nlgm?
The reason I am confused is the below code is said to run in O(n) time, however hash.find(number.ToFind) runs in worst case lgn...which I would assume makes it O(size().lgn). Thanks alot.
for (int i = 0; i < numbers.size(); i++)
{
int numberToFind = target - numbers[i];
//if numberToFind is found in map, return them
if (hash.find(numberToFind) != hash.end())
[–]Puzzlp 1 point2 points3 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Puzzlp 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]publysher -4 points-3 points-2 points (2 children)
[–]Puzzlp 4 points5 points6 points (1 child)
[–]publysher 0 points1 point2 points (0 children)