Skip to content

Commit 506c094

Browse files
committed
Explain the complexity for the new improvement with precomputing.
1 parent f040003 commit 506c094

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎Sprint-2/improve_with_precomputing/common_prefix/common_prefix.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ 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+
# The original code compares every pair of strings, giving it (O(m^2)) pair comparisons.
31+
# The new version sorts the strings and compares only neighbouring pairs, reducing the number of comparisons.
32+
# Its approximate time complexity improves from (O(m^2L)) to (O(mL\log m)).

‎Sprint-2/improve_with_precomputing/count_letters/count_letters.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ def count_letters(s: str) -> int:
1313

1414
def is_upper_case(letter: str) -> bool:
1515
return letter == letter.upper()
16+
17+
#
18+
# The original code searches the string repeatedly, giving it (O(n^2)) time complexity.
19+
# The new version stores lowercase letters in a set first, so it can check them faster.
20+
# This reduces the expected time complexity to (O(n)), but uses extra memory.

0 commit comments

Comments
 (0)