3 ms·
Specifically the original double loop example also has this behavior and complexity. If the loops were written as for y in a2: if cond: break
by henrydark 4y ago
Specifically the original double loop example also has this behavior and complexity.
If the loops were written as
for y in a2:
if cond:
break
for x in a1:
# something
then they would have O(|a2|) complexity instead of O(|a1||a2|), but then we also don't need break break