Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (35)

Q1Program to find kth smallest element(using bubble sort) in the list.

def smallkth(a,lb,ub,k): for i in range(lb,ub): for j in range(lb,ub-i): if(a[j]>a[j+1]): temp=a[j] a[j]=a[j+1] a[j+1]=temp print('list is ',a,'and ',k,'smallest element is', a[k-1]) a=[10,2,3,4,67,8,9,34] ub=len(a) k=int(input("enter kth smallest element you want")) smallkth(a,0,ub-1,k) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter kth smallesest element you want3 list is [2,3,4,8,9,10,34,67] and 3 smallest element is 4

Q2 Find minimum element from the list.

def fm(a,lb,ub): for i in range(lb,ub): mi=a[lb] if(a[i]<=mi): mi=a[i] print(mi) a=[12,3,4,56,7,89,1] ub=len(a) fm(a,0,ub) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== 1



Q3.Program to find maximum element from list.

def fmax(a,lb,ub): for i in range(lb,ub): mi=a[lb] if(a[i]>mi): mi=a[i] print(mi) a=[12,3,4,56,7,89,1] ub=len(a) fmax(a,0,ub) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== 12

Q4.Program to find kth largest element from list.

def smallkth(a,lb,ub,k): for i in range(lb,ub): for j in range(lb,ub-i): if(a[j]>a[j+1]): temp=a[j] a[j]=a[j+1] a[j+1]=temp a.reverse() print('list is',a,'and',k ,'largest element',a[k-1]) a=[10,2,3,4,67,8,9,34] ub=len(a) k=int(input("enter kth largest element you want")) smallkth(a,0,ub-1,3) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter kth largest element you want2 list is [67, 34, 10, 9, 8, 4, 3, 2] and 3 largest element 10

Q5.Program to find list in reverse order.

def rlist(a,lb,ub): for i in range(ub,lb,-1): print(a[i]) a=[10,2,3,4,67,8,9,34] ub=len(a) rlist(a,-1,ub-1) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== 34 9 8 67 4 3 2 10





Python subjective question for competitive exam (34)
Python subjective question for competitive exam (33)
Python subjective question for competitive exam (32)
Python subjective question(recursion) for competitive exam (31)
Python subjective question for competitive exam (30)
Python subjective question for competitive exam (29)
Python subjective question for competitive exam (28)
Python subjective question for competitive exam (27)
Python subjective question for competitive exam (26)
Python subjective question for competitive exam (25)
Python subjective question for competitive exam (24)
Python subjective question for competitive exam (23)
Python subjective question for competitive exam (22)
Python subjective question for competitive exam (21)
Python subjective question for competitive exam (20)
Python subjective question for competitive exam (19)
Python subjective question for competitive exam (18)
Python subjective question for competitive exam (17)
Python subjective question for competitive exam (16)
Python subjective question for competitive exam (15)
Python subjective question for competitive exam (14)
Python subjective question for competitive exam (13)
Python subjective question for competitive exam (12)
Python subjective question for competitive exam (11)
Python subjective question for competitive exam (10)
Python subjective question for competitive exam (9)
Python subjective question for competitive exam (8)
Python subjective question for competitive exam (7)
Python subjective question for competitive exam (6)
Python subjective question for competitive exam (5)
Python subjective question for competitive exam (4)
Python subjective question for competitive exam (3)
Python subjective question for competitive exam (2)
Python subjective question for competitive exam (1)

Post a Comment

0 Comments