Im wondering could you help me to solve this questionand you
I\'m wondering could you help me to solve this question?and you don\'t have to write the whole code with main function ?it is enough
to make the following function valid combined with the given hint ?1.divide-and-conquer type algorithm similar to quick sort 2.Choose A[0] as the
Pivot you cannot omit these)Anyway?thank you so much?
I\'m wondering could you help me to solve this question?and you don\'t have to write the whole code with main function ?it is enough
to make the following function valid combined with the given hint ?1.divide-and-conquer type algorithm similar to quick sort 2.Choose A[0] as the
Pivot you cannot omit these)Anyway?thank you so much?
9. (10 pts) Consider a problem of finding the k-th smallest element from vector A. Complete the following function. Hint Think of a divide-and-conquer type algorithm similar to quick sort. You may simply choose A[0] as the pivot. float kthsmailest (const vectorsfloat:t A, int k) Solution
[1]
public int Kth_smallest_element1(int k)
{
Node node = Root;
int count = k;
int sizeOfLeftSubtree = 0;
while(node != null)
{
/*Run untill the last node of the link_list*/
sizeOfLeftSubtree = node.SizeOfLeftSubtree();
if (sizeOfLeftSubtree + 1 == count)
return node.Value;
else if (sizeOfLeftSubtree < count)
{
node = node.Right;
count -= sizeOfLeftSubtree+1;
}
else
{
node = node.Left;
}
}
return -1;
}
