[algogeeks] Re: search a 2d sorted array in less than O(n)

2010-09-27 Thread prodigy
Actual complexity of above algorithm = O(n^1.6) On Sep 27, 8:19 am, Gene gene.ress...@gmail.com wrote: If the array is m by n, pick the element a[m/2][n/2], i.e. the one in the middle.  There are now 3 possibilities: 1) The middle element is the one you're looking for, so you're done. 2)

Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-27 Thread nishaanth
how about this n+(8-(n7)) On Sun, Sep 26, 2010 at 4:48 AM, Dave dave_and_da...@juno.com wrote: @Ashwath: Thanks for the correction. Dave On Sep 26, 1:20 am, aswath G B aswat...@gmail.com wrote: @Dave Slight change u have to do #includestdio.h main() { int a = 24;

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-27 Thread satish
step1construct heap using siftdown. // time complexity wil be O(n) and space complexity O(1). step2take mindifference=a[1]. step3for i=1 ,i=n/2 do { find the difference of (root,root-left),(root,root-right)and (root-left,root-right).and maintain mindifference is the smallest

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-27 Thread rahul
If their is no constrain on assumptions. 1.Sort the array. 2. check the dif between 2 elements. { 99,35,45,33,88,9098,112,33455,678,3} sorted arrary : { } would be something. now update the min_diff. another example : { 7,8,1,3,5,4} sorted arrary : { 1,3,4,5,7,8} min diff is 1. Please

[algogeeks] Re: next multiple of 8

2010-09-27 Thread nishaanth
try x+8-(x7 ) On Sep 26, 4:47 am, Dave dave_and_da...@juno.com wrote: @Shrevan: I mistyped what I intended. Try answer = (x | 7) + 1; Dave On Sep 26, 5:51 am, Shravan shravann1...@gmail.com wrote: @Dave Your answer will be always 2 irrespective of the value of 'x'. BTW I too didn't

Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-27 Thread Soundar
#includeiostream using namespace std; int main() { int n,temp,ans=1; cin n; temp=n/8; temp++; cout hi temp\n; while(temp--) { temp=temp3; } cout temp; return 0; } -- You received this message because you are subscribed to the Google

Re: [algogeeks] Re: next multiple of 8

2010-09-27 Thread rahul
Please correct. ans = (x|7)+1. Thanks Dave. On Mon, Sep 27, 2010 at 5:42 PM, saurabh agrawal saurabh...@gmail.comwrote: This problem is already solved. ans=(x|1)+1 On Mon, Sep 27, 2010 at 5:15 PM, nishaanth nishaant...@gmail.com wrote: try x+8-(x7 ) On Sep 26, 4:47 am, Dave

[algogeeks] Re: search a 2d sorted array in less than O(n)

2010-09-27 Thread sourav
I feel the binary search approach as given by Saurabh Singh or like moving from top right row, doing binary search in the row 0, find the element being searched (say x) or one less than that (say y), followed by binary search in the column below 'y' and proceeding in this way can give a less than

[algogeeks] Re: sum of primes

2010-09-27 Thread sourav
@Dave I cannot see any code at the links you have provided. I only see the prime numbers. am I missing something here..? Thanks, Sourav On Sep 23, 10:59 pm, Rishi Agrawal rishi.b.agra...@gmail.com wrote: Apart from 1, 2 and 3, all the prime numbers are either of the form (6*n - 1) or (6*n +

[algogeeks] Re: finding largest and second largest elements

2010-09-27 Thread sourav
Very Nice Simple approach @Dave On Sep 24, 12:56 am, Dave dave_and_da...@juno.com wrote: Do a single-elimination tournament of the numbers, where the larger wins each game. This will take n/2 + n/4 + ... + 1 = n-1 comparisons. The second largest will be among the numbers that lost to the

[algogeeks] Re: BST in BT

2010-09-27 Thread sourav
For solution to this problem see http://groups.google.co.in/group/algogeeks/browse_thread/thread/adc95dcf96020a7/2943fd3c5a116fee?hl=enlnk=gstq=binary+tree+to+binary+serach+tree# In that thread, I have a doubt regarding solution posted by @Algoose Chase. The code posted is good as I feel except

Re: [algogeeks] Re: BST in BT

2010-09-27 Thread Chonku
@Prodigy As per your example, 8 15 20 25 which is the is indeed the maximum binary search tree in this binary tree is only a solution to smaller problem used to solve a bigger problem. The solution to smaller problem can be translated directly to the solution of the bigger problem. On Mon, Sep

[algogeeks] Re: sum of primes

2010-09-27 Thread Dave
@Sourav: What you are missing is that the algorithm is a manual one that will answer the question asked in a few moments without writing any computer code. Looking in the first file, you find that there are 1229 prime numbers less than 10,000. Looking in the second file, you find that the sum of

Re: [algogeeks] Re: sum of primes

2010-09-27 Thread radha krishnan
These are called Twin Primes ...:))) On Thu, Sep 23, 2010 at 11:29 PM, Rishi Agrawal rishi.b.agra...@gmail.com wrote: Apart from 1, 2 and 3, all the prime numbers are either of the form (6*n - 1) or (6*n + 1). Can we use this property to generate the primes till we get 1 primes. -- You

[algogeeks] Iterative Quick sort

2010-09-27 Thread Albert
Hi can any one suggest an efficient algorithm for iterative quick sort Thanks in advance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group,

[algogeeks] Re: ReVerse a string using recursion

2010-09-27 Thread ligerdave
any type of replace would need at least one extra memory space. recursion is the worst, depends how you implement recursion. one iteration might depends on another, which depends one other, and so on.. each iteration hold its own stack On Sep 23, 1:59 pm, Albert alberttheb...@gmail.com

[algogeeks] Re: Amazon Interview

2010-09-27 Thread ligerdave
it's a compression problem. using hex instead of oct saves more space 00aaa0ss yyy = 50 2a 0 1s 3f 1\s ay On Sep 15, 8:21 am, bittu shashank7andr...@gmail.com wrote: A file is given with many 0s stored in continuous way , store it in another file such that when you store try

[algogeeks] Re: arrays

2010-09-27 Thread Chi
Move-To-The-Front. On Sep 27, 11:58 pm, Anand anandut2...@gmail.com wrote:  Given an array of integers, for each index i, you have to swap the value at i with the first value smaller than A[ i ] that comes after index i -- You received this message because you are subscribed to the Google

[algogeeks] Finding hash collisions without storage

2010-09-27 Thread AdrianW
Suppose you have N strings that can be generated on-the-fly, and you wanted to discover if a hash function generates any collisions. Is there a way to do this without O(N) storage? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Finding hash collisions without storage

2010-09-27 Thread saurabh singh
u can use log(n)+1 space to do that by using bit string On Mon, Sep 27, 2010 at 10:37 PM, AdrianW atw...@gmail.com wrote: Suppose you have N strings that can be generated on-the-fly, and you wanted to discover if a hash function generates any collisions. Is there a way to do this without

Re: [algogeeks] finding largest and second largest elements

2010-09-27 Thread sharad kumar
hey isn't it suppposed to be tournament problem.. On Fri, Sep 24, 2010 at 12:06 AM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: finding largest and second largest elements from a set of n elements by means of Minimum comparison of n+celling(log n) +2 -- You received

[algogeeks] Re: search a 2d sorted array in less than O(n)

2010-09-27 Thread Gene
Well, friend, we're both wrong. The algorithm will find 6 just fine. It will choose 3 as the middle element. Since 6 is bigger, it will throw away the subarray 1 2 2 3 and check the other 3 subarrays. When it checks 6 7 7 8 It will find the 6 on the first try. I just verified this by

[algogeeks] Re: sum of primes

2010-09-27 Thread Dave
Twin primes are a pair of prime numbers that differ by 2. Dave On Sep 27, 11:26 am, radha krishnan radhakrishnance...@gmail.com wrote: These are called Twin Primes ...:))) On Thu, Sep 23, 2010 at 11:29 PM, Rishi Agrawal rishi.b.agra...@gmail.com wrote: Apart from 1, 2 and 3, all the

Re: [algogeeks] search a 2d sorted array in less than O(n)

2010-09-27 Thread saurabh singh
Thanks for pointing out. I was wrong because I assumed that numbers would be in continuous increasing order when numbers in each row are written in a line taking each row at a time. On Mon, Sep 27, 2010 at 5:49 PM, Nikhil Jindal fundoon...@yahoo.co.inwrote: @saurabh.nsit: Consider the