Skip to content

Commit 387bfb8

Browse files
committed
explaine complexity
1 parent 65cf7b2 commit 387bfb8

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Sprint-2/improve_with_precomputing/common_prefix/common_prefix.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ def find_common_prefix(left: str, right: str) -> str:
2626
if left[i] != right[i]:
2727
return left[:i]
2828
return left[:min_length]
29+
30+
# Complexity for old version code where we hade a nested loop and slicer, and compared every string with other string is
31+
# leading to O(n^2*m+n^2), while on the new script we have complexity sorting O(n log n *m) and comparison O(n*m). Even after using sorting
32+
# which is consuming and costly, the overall complexity is lower because we compare fewer pairs.
33+
# O(n^2*m) and O(n log n *m)

0 commit comments

Comments
 (0)