Ad
  • Default User Avatar
    def decodeMorse(morse_code):
        morse_W = '.--'
        letter_W = MORSE_CODE[morse_W]
        print(f'letter = {letter_W}')
    
  • Custom User Avatar

    Probably. Nested loops grow extremely fast when the input grows, while flat loops just grow proportionnally.
    See:

    • 3 + 3 + 3 = 9
    • 3 * 3 * 3 = 27
    • 10 + 10 + 10 = 30
    • 10 * 10 * 10 = 1000

    etc.

    I think your question has received an answer :)

  • Custom User Avatar

    Really? if i will have third but not nested loop, will not it time out?

  • Custom User Avatar

    You can also technically still have O(n) time with mutliple loops, as long as they are NOT nested. This would be O(2n), which is still considered O(n).

  • Custom User Avatar

    Roughly saying, yes. If both of nested loops have linearly more iterations if n gets linearly larger, it's indeed O(n^2).