OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Big O of Four Double-Nested for loops

  • Thread starter Thread starter DonJon
  • Start date Start date
D

DonJon

Guest
I'm trying to figure out what the Big O notation of this is. I know that the if this = n and that = m, the big O is O(mn), but if I have 4 in a row like this and worst case scenario it would run through all of them what would that do to my Big O notation.

Code:
def get_winner(self):      
    for this in range(self._this):
        for that in range(self._that - 2):
            # If statement here
                return

    for that in range(self._that):
        for this in range(self._this - 2):
            # If statement here
                return

    for this in range(self._this - 2):
        for that in range(self._that - 2):
            # If statement here
                return

    for this in range(self._this - 2):
        for that in range(self._that - 2):
            # If statement here
                return
<p>I'm trying to figure out what the Big O notation of this is. I know that the if this = n and that = m, the big O is O(mn), but if I have 4 in a row like this and worst case scenario it would run through all of them what would that do to my Big O notation.</p>

<pre><code>def get_winner(self):
for this in range(self._this):
for that in range(self._that - 2):
# If statement here
return

for that in range(self._that):
for this in range(self._this - 2):
# If statement here
return

for this in range(self._this - 2):
for that in range(self._that - 2):
# If statement here
return

for this in range(self._this - 2):
for that in range(self._that - 2):
# If statement here
return
</code></pre>
 

Latest posts

Top