Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5740677

Browse files
Add kthSmallestEle
1 parent 11fe5e5 commit 5740677

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#Python program to find the kth smallest element from a list
2+
#Without doing sorting
3+
4+
5+
''' Eg: list is 61, 32, 80, 59, 20
6+
When sorted: 20, 32, 59, 61, 80
7+
3rd smallest element is: 59'''
8+
9+
N = int(input('Enter size of list: '))
10+
11+
print('Enter elements in list: ')
12+
l = [int(x) for x in input().split()]
13+
14+
K = int(input('kth element to search: '))
15+
x = max(l)+1
16+
ch = [0] *x
17+
18+
for j in range(0, N):
19+
ch[l[j]] += 1
20+
for j in range(0, len(ch)):
21+
if ch[j] >= 1:
22+
K -= 1
23+
if K == 0:
24+
print('Element is: ', j)
25+
break

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /