I think there is a problem in this solution.
U r accessing stack elements from 1 to n in the outer loop. It is not
possible. 1st element cannot be accessed without popping first n-1 elements
out.
On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote:
My iterative approach
to k
min_index = i
for j i+1 to n
if a[j] a[min_index]
min_index = j
swap(a[i],a[min_index])
required element : a[k]
On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote:
Give an array of unsorted elements, find the kth smallest element in the
array
The arguments in printf are evaluated from right to left.
first ++a gives 11 , then a is 11 and a++(bcoz postfix) is also 11
But the final value is copied to the prefix argument (++a) and just 'a'.
The postfix argument(a++) will retain the value it obtained.
On Sat, Jun 16, 2012 at 3:49 PM,
Give an array of unsorted elements, find the kth smallest element in the
array.
The expected time complexity is O(n) and no extra memory space should be
used.
Quickselect algorithm can be used to obtain the solution. Can anyone
explain how quickselect works?
--
You received this message
+919985813081
+919966006652
On Sun, Jun 17, 2012 at 8:13 AM, Prem Nagarajan
prem.cmna...@gmail.comwrote:
Give an array of unsorted elements, find the kth smallest element in the
array.
The expected time complexity is O(n) and no extra memory space should be
used.
Quickselect algorithm can
Short-circuiting
On Sun, Jun 17, 2012 at 10:02 PM, rn rnjailamb...@gmail.com wrote:
But the precedence of || hence ++j++k should be dealt with first ?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion on the web