the big O notation for this function

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

Hi, could you pease tell me the big O notation for this function? Thanks!

# takes in an array as an argument
def
cocktail_sort(my_data):
num_ops = 0
1
n = Len(my_data)
num_ops += 4
for i in range(n):
num_ops += 6
swapped = False
for j in range(0, n - i - 1):
num_ops += 6
if my_data[j] > my_data[j + 1]:
my_data[j], my_data[j + 1] = my_data[j + 1], my_data[j]
swapped = True
num_ops += 7
for k in range (n i - 1, 0, -1):
num_ops += 6
if my_data[k] < my_data[k 1]:
my_data[k], my_data[k
swapped = True
num_ops += 7
num_ops += 3
if (not swapped):
break
# print (num_ops)
return my_data
-
1] = my_data[k - 1], my_data[k]
Transcribed Image Text:# takes in an array as an argument def cocktail_sort(my_data): num_ops = 0 1 n = Len(my_data) num_ops += 4 for i in range(n): num_ops += 6 swapped = False for j in range(0, n - i - 1): num_ops += 6 if my_data[j] > my_data[j + 1]: my_data[j], my_data[j + 1] = my_data[j + 1], my_data[j] swapped = True num_ops += 7 for k in range (n i - 1, 0, -1): num_ops += 6 if my_data[k] < my_data[k 1]: my_data[k], my_data[k swapped = True num_ops += 7 num_ops += 3 if (not swapped): break # print (num_ops) return my_data - 1] = my_data[k - 1], my_data[k]
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT