the big O notation for this function
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 5RQ
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]](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F442cdeaf-d6f5-4c90-9eca-defd0049fe9f%2F09225d8f-7e30-4f2c-80ab-751ffc4f49b5%2F04dlyon_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images

Knowledge Booster
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.Recommended textbooks for you

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr