Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Find the error in the following python code: def partition ( array , low, high ) : pivot = array [ high ] i =

Find the error in the following python code:
def partition(array, low, high):
pivot = array[high]
i = low -1
for j in range(low, high):
if array[j]<= pivot:
i = i +1
(array[i], array[j])=(array[j], array[i])
(array[i +1], array[high])=(array[high], array[i +1])
return i +1
def quickSort(array, low, high):
if low < high:
pi = partition(array, low, high)
quickSort(array, low, pi -1)
quickSort(array, pi +1, high)
# load data
data =[]
with open("p2.txt",'r') as fin:
for line in fin:
data.append(int(line))
print("Unsorted Array")
print(len(data), "items")
size = len(data)
quickSort(data,0, size -1)
duplicates ={}
for i in range(0, len(data)):
if data[i]== data[i+1]:
if i not in duplicates:
duplicates[i]=1
else:
duplicates[i]+=1
count_duplicates =0
for c in duplicates.values():
count_duplicates += c
print("Found", count_duplicates, "duplicates")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago