[algogeeks] Re: Modified Binary Search

2010-08-08 Thread Gene
Very sorry the mistake. I'm not familiar with your name, and few computer science students where I live are women. The first detail is that binary search will only work if you assume no duplicates. This is easy to see if you envision an input that is all 1's except for a single 2. In order to d

[algogeeks] Re: bitwise operator confusion

2010-08-08 Thread Dave
In both C and C++, the result of a right shift of a signed value is implementation specific. The vacated bits can be filled either with zeros or with copies of the sign bit. Portable code must not depend on the implementation, but must work with either implementation choice. Thus, the result could

Re: [algogeeks] bitwise operator confusion

2010-08-08 Thread sharad kumar
in case of -ve numbers irrspectiveof size of compilerits repesented as in remanig space apart from the space of binaryequivalent of number.hence u get On Sun, Aug 8, 2010 at 9:37 PM, navin wrote: > Assunming, integer is 2 byte, What will be the output of the program? > > #include > > i

Re: [algogeeks] bitwise operator confusion

2010-08-08 Thread jalaj jaiswal
sign bit gets extended in case of negative numbers On Sun, Aug 8, 2010 at 9:37 PM, navin wrote: > Assunming, integer is 2 byte, What will be the output of the program? > > #include > > int main() > { >printf("%x\n", -1>>1); >return 0; > } > > [A]. > [B].0fff > [C]. >

[algogeeks] Re: Doubly linklist to Singly linklist...........

2010-08-08 Thread Rahul Verma
XOR Linked list tutorial http://en.wikipedia.org/wiki/XOR_linked_list On Aug 8, 11:49 am, Pramod Negi wrote: > Search XoR List on Wiki > > On Sun, Aug 8, 2010 at 10:19 AM, UMESH KUMAR wrote: > > > how to convert Doubly Link list to a Singly link list without changes > > the Structure of the list

Re: [algogeeks] Dynamic Programming Problem on Strings

2010-08-08 Thread Amir hossein Shahriari
@ankur: dp[i][j] number of (prefix) strings that have i As and j Bs is: dp[i-1][j] number of (prefix) strings that have i-1 As and j Bs appended by "A" + dp[i][j-1] number of (prefix) strings that have i As and j-1 Bs appended by "B" @ashish: wikipedia has some nice proofs for catalan number form

Re: [algogeeks] Dynamic Programming Problem on Strings

2010-08-08 Thread Nikhil Jindal
Let the problem be represented as f(i,j) for i A's and jB's. Amir represented it correctly as: f(i,j) = f(i,j-1) + f(j,i-1) Lets try another representation: Let t(i,j) is the number of strings of length i+j with iA's and jB's in any order. Hence, t(i, j) = (i+j)Ci Now some valid strings for our p

Re: [algogeeks] Re: Modified Binary Search

2010-08-08 Thread jalaj jaiswal
check out this link guys,,, for more implementation details On Sun, Aug 8, 2010 at 7:59 PM, ashita dadlani wrote: > first of all Gene..this is not "he" but "she" :P > and secondly,can you please mention the details you are talking about so > that we can reach to a solution? > > > On Sun, Aug 8,

[algogeeks] bitwise operator confusion

2010-08-08 Thread navin
Assunming, integer is 2 byte, What will be the output of the program? #include int main() { printf("%x\n", -1>>1); return 0; } [A]. [B].0fff [C]. [D].fff0 Answer: Option A i dont understand why it produces actually -1 = there shoud be one bit zero ( i

Re: [algogeeks] Re: amezan interview.........

2010-08-08 Thread jalaj jaiswal
if the array is numbered from 0..(2n-1) i= initial position of int/char f= final position of int/char if (i < (2n-1)/2) #for integer f = i+i else #for char f = i - ((2n-1)-i) so iterate through the array in the following way choose first element determine it final position put the element in th

Re: [algogeeks] Modified Binary Search

2010-08-08 Thread Amir hossein Shahriari
array:4,5,1,2,3 index: 0,1,2,3,4 real index: 3,4,0,1,2 suppose the index of the least element is k (here k=2) then when you're applying the binary search the only modification you need to have is each time you're going to access the ith element of array look at (i+k)%n th element --

Re: [algogeeks] Modified Binary Search

2010-08-08 Thread jalaj jaiswal
first find out the element around which array is rotated. i.e find the first element of original array( using modified binary search ) then compare the element to be searched with the first elent of given array, if it is greater than it then binary search in first half of array else in second half

Re: [algogeeks] BST Problem

2010-08-08 Thread Priyanka Chatterjee
@Manjunath : We can't assume the structure of BST has parent pointers , if that is explicitly mentioned , then we will have to keep in mind two pointers one for inorder successor in the left subtree and another for inorder predecessor in the right subtree and traverse the pointers to find the

Re: [algogeeks] Re: Modified Binary Search

2010-08-08 Thread ashita dadlani
first of all Gene..this is not "he" but "she" :P and secondly,can you please mention the details you are talking about so that we can reach to a solution? On Sun, Aug 8, 2010 at 7:48 PM, Gene wrote: > Well, then, you must say that in the problem! To to find k, ashita > dadlani's solution works

[algogeeks] Re: Modified Binary Search

2010-08-08 Thread Gene
Well, then, you must say that in the problem! To to find k, ashita dadlani's solution works fine, except he has left out important details. This binary search is a bit tricker that the one to find a value. On Aug 8, 2:34 am, Manjunath Manohar wrote: > hey wait a sec,.. we wont be given the k va

Re: [algogeeks] Re: Modified Binary Search

2010-08-08 Thread ashita dadlani
its possible.first apply binary search to find the index where the array is rotated. eg.a=[8,9,1,2,3,4,56,7] first apply binary search to find the value i=2. now we have 2 sub sorted arrays,ie, from i=0 to i=1 and from i=2 to i=8. apply binary search to these sub sorted arrays each of which will ta