how to find the kth smallest element in the given list of
array elemnts.

Answer Posted / khaja moulali shiak

int kmin(int a[],int n,int k)
{
int i;
int j;
int l;
int u;
int x;
int t;
l=1;
u=n;
while(l<u)
{
i=l;
j=u;
x=a[k];
while((i<=k)&&(j>=k))
{
while(a[i]<x) i++;
while(a[j]>x) j--;
swap(a[i],a[j]);
i++;
j--;
}
if(j<k) l=i;
if(i>k) u=j;
}
return(a[k]);
}

Is This Answer Correct ?    10 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are header files in c?

839


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

874


What is the difference between Printf(..) and sprint(...) ?

1111


When was c language developed?

941


What is the maximum length of an identifier?

929


Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.

1028


How can I prevent another program from modifying part of a file that I am modifying?

855


In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.

2910


int i=10; printf("%d %d %d", i, i=20, i);

1334


What is the difference between struct and union in C?

919


What are structure members?

851


What is #error and use of it?

940


Explain do array subscripts always start with zero?

971


What is substring in c?

893


Why is not a pointer null after calling free?

804