Write Python program for finding the smallest and largest elements in an array A of size n using Selection algorithm. Discuss Time complexity

Code:

print("Enter the size of an array")

s=int(input())

i=0

ar=[]

print("Enter the array elements")

while i<s:

    ar.append(int(input("Enter number")))

    i=i+1

print("Array values you entered is")

print(ar)

for i in range(len(ar)):

    min=i

for i in range(i+1,len(ar)):

    if ar[min]>ar[j]:

        min=j;

print("sorted array")

for i in range(len(ar)):

    print("%d"%ar[i]),

print("Smallest element:%d"%ar[0])

print("largest element:%d"%ar[s-1])

O/p:-

Write Python program for finding the smallest and largest elements in an array A of size n using Selection algorithm. Discuss Time complexity

Post a Comment

0 Comments