Re: [algogeeks] Re: Sub-array problem

2011-12-01 Thread Ankit Sinha
0; } Complexity O(n) Cheers, Ankit Sinha On Thu, Dec 1, 2011 at 4:58 PM, sourabh sourabhd2...@gmail.com wrote: @atul... thanks dude for ur thorough screening of the algo and pointing out the mistakes... I think that's y its always said that until and unless we don't turn an algo to a working

Re: [algogeeks] Finding the repeated element

2011-11-23 Thread Ankit Sinha
Only possible best solution seems to be sorting the array using median selection algorithm ( a varient of quicksort) and then comparing to find the elements. Cheers, Ankit!!! On Thu, Nov 24, 2011 at 11:32 AM, kumar raja rajkumar.cs...@gmail.com wrote: In the given array all the elements occur

Re: [algogeeks] Amazon Interview Question

2011-09-24 Thread Ankit Sinha
; i 9; i++) printf([%d], a[i]); system(PAUSE); return 0; } Please comment. Cheers, Ankit Sinha On Sat, Sep 24, 2011 at 4:10 PM, malay chakrabarti m1234...@gmail.com wrote: dutch national flag problem :) On Sat, Sep 24, 2011 at 3:45 PM, Dheeraj Sharma

Re: [algogeeks] array sum

2011-08-27 Thread Ankit Sinha
Algo: 1. Sort the array 2. modify binary search on the set comparing average of both the set. 3. if aveage (start, mid) average (mid , end) then go to left sub set else right subset. This could lead to solution in o(nlogn) time. Please comment futher!! Cheers, Ankit Sinha On Sat, Aug 27

Re: [algogeeks] Re: Find the first K smallest element from 1 million sized array ...Amazon Question..

2011-03-24 Thread Ankit Sinha
. If there are N numbers in the file, the work is O(N * log k). Dave On Mar 23, 11:22 pm, Ankit Sinha akki12...@gmail.com wrote: Guys, My intention was to understand how to manage max heap of k size into memory. Means we have millions of numbers that we can't load into RAM then how in the very first go

Re: [algogeeks] Re: Find the first K smallest element from 1 million sized array ...Amazon Question..

2011-03-23 Thread Ankit Sinha
Guys, My intention was to understand how to manage max heap of k size into memory. Means we have millions of numbers that we can't load into RAM then how in the very first go we going to load only k size and how will track of rest numbers. Can anybody code it? Do we need file to store million

[algogeeks] Find the first K smallest element from 1 million sized array ...Amazon Question..

2011-03-15 Thread Ankit Sinha
Asked in Amazon interview.. Find the first K smallest element from 1 million sized array . Assume your ram memory is so small that it cannot accommodate all 1 Million element at once. Guys provide your inputs on the same... Thanks, Ankit -- You received this message because you are

Re: [algogeeks] Amazon Question

2011-03-03 Thread Ankit Sinha
Hi, Here is the code to do this using Bsearch in o(logn) time. int BsearchElemEqualIndex (int *a, int start, int end) { int mid = (((end - start) 1) + start); if (a[mid] == mid) return a[mid]; else if (a[mid] != mid) { if (mid ==

Re: [algogeeks] Amazon Question

2011-03-03 Thread Ankit Sinha
should be the answer for this: if A={0,1,2,4,5} 0 or 1 or 2 On Thu, Mar 3, 2011 at 6:26 PM, Ankit Sinha akki12...@gmail.com wrote: Hi, Here is the code to do this using Bsearch in o(logn) time. int BsearchElemEqualIndex (int *a, int start, int end) {        int mid = (((end - start) 1

Re: [algogeeks] Amazon Question

2011-03-03 Thread Ankit Sinha
@rahul, they are right as binary search is made on sorted array only. think of array as 0,2,3,8, 10, 12, 14., 15. here a[mid ] = 10 mid(4) hence next search should happen between 0 till 4 subarrray.. In my code the input array is also not correct as it is not a sorted array and that's why I made

Re: [algogeeks] Amazon Question

2011-03-03 Thread Ankit Sinha
It is funny but right input is as mentioned earlier to rahul. 0,2,3,8, 10, 12, 14., 15 :).. Sorry for unnecessarily flooding your mail accounts. Please ignore previous post thanks, ankit!! On Thu, Mar 3, 2011 at 8:15 PM, rajul jain rajuljain...@gmail.com wrote: i think he is wrong bcoz this

Re: [algogeeks] Re: find duplicate and missing element

2010-09-03 Thread Ankit Sinha
@kartheek, thanks for ur input!! Certainly, ur soln is fine but only will cater when array is 1...n but what if it ranges for 0...n-1. The algo given by dhritiman fits in all the scenario. but ofcourse for given question ( 1 to 100) your mathematical approach is good. :)... Cheers, Ankit Sinha

Re: [algogeeks] Re: find duplicate and missing element

2010-09-02 Thread Ankit Sinha
; i++; } else { t= a[i]; a[i] = a[a[i]]; a[t] = t; } } printf (\nmissing element is [%d], pos); Cheers, Ankit Sinha On Thu, Sep 2, 2010