Re: [algogeeks] Re: sorted 2-d array

2010-06-08 Thread Rohit Saraf
@senthilnathan : very nice indeed -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14 -- You received this message because you are subscribed to the Google Groups

[algogeeks] Re: sorted 2-d array

2010-06-08 Thread Ralph Boland
On Jun 7, 8:49 am, Senthilnathan Maadasamy senthilnathan.maadas...@gmail.com wrote: We can do it in O(n * log n) by individually binary-searching for zero on each of the rows.  Once we get the index of the first position where zero appears, counting the number of negative number is

Re: [algogeeks] Re: Puzzle:

2010-06-08 Thread sharad kumar
@ dheerraj...u cant measure 8 litre...u hve no additional instrument @mohit...what do u mean by n th stageplzz elaborate -- 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

Re: [algogeeks] Explain the output

2010-06-08 Thread harit agarwal
@jitendra u got it right but parent and child are using the same text region that's why control is transferring back and forth.. try running this code and see that line numbers are repeating...because of same text region it is working like a loop... #includestdio.h int main() { int id,i;

[algogeeks] Re: array question

2010-06-08 Thread Minotauraus
How will it be 12 12 5 6 6?? I can understand that the first number in the list is place first so it could be 12 12 6 6 5. How will it be 12 12 5 6 6? On Jun 6, 7:47 am, divya jain sweetdivya@gmail.com wrote: output willl be 12 12 5 6 6 On 6 June 2010 18:27, souravsain souravs...@gmail.com

Re: [algogeeks] min no of policemen

2010-06-08 Thread divya jain
@sharad.. sorry bt i dint get how to use bellman ford or topological sort here... can u plz explain... On 8 June 2010 05:53, sharad kumar aryansmit3...@gmail.com wrote: for placing police man we can use bellman ford bfs.or even make use of topological sort. On Mon, Jun 7, 2010 at 9:59 PM,

[algogeeks] Single ordered list

2010-06-08 Thread Raj N
What is the most efficient way of combining 2 separate ordered list into a single ordered list ? -- 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,

Re: [algogeeks] Knapsack - 0-1 - Brute force

2010-06-08 Thread Varun Nagpal
Why do you want to try a brute force approach, when you have some better algorithms and heuristics available? On Mon, Jun 7, 2010 at 10:07 PM, Jean Carlo Mendes jean.men...@gmail.comwrote: Hello Guys Anyone have a implementation of knapsack 0-1 using brute force approach ? Or… Do you

[algogeeks] Variable number of integers

2010-06-08 Thread Raj N
What do you mean by a stack or a queue in which each item is a variable number number of integers? Is it a queue of a queue, queue of a stack etc -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: sorted 2-d array

2010-06-08 Thread Minotauraus
Actually, this might not always be the best approach. Example: -1 1 2 3 4 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 2*N = 10 steps. With my algo, you'll go: Step 1: top-left: negative, count++, Step2: [0][1] non negative, set limitRow=0 (or 1 depending on how you code) Step3: for([i][j]

Re: [algogeeks] Re: binary nos

2010-06-08 Thread Raj N
@Divya: That was the question i previously asked. If n=3 000,001,010,100,101 are valid. So the solution for this is fib(n+2). If n=4 no. of sequences will be fib(6) i.e 8 On Tue, Jun 8, 2010 at 9:31 AM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote: getting fibonacci nos is trivial using matrix

Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-08 Thread Raj N
@saurabh: Hey u're right this is interesting. I checked for n=5 its giving 13 i.e fib(7) On Mon, Jun 7, 2010 at 9:19 PM, saurabh gupta sgup...@gmail.com wrote: it might be referring to no of sequences (say T(n) ) with no consecutive 1's for n = 3, ans would be 5 viz. 000, 001, 010, 100, 101

Re: [algogeeks] Puzzle:

2010-06-08 Thread divya jain
yes even i dont think its possible as there is no n-1th state..ie there is no state from whr u can come to 2 8 5..so plz check On 7 June 2010 20:23, mohit ranjan shoonya.mo...@gmail.com wrote: is it possible ? if we say nth state is [2, 8, 5] I could not find possible (n-1)th state Mohit

Re: [algogeeks] Pointer to a constant

2010-06-08 Thread divya jain
i think both statements shd give error. as u r trying to change int to const int in 2 and const int to int in 1.. On 7 June 2010 19:59, mohit ranjan shoonya.mo...@gmail.com wrote: @Raj, no they are not same case 1: i is const case 2: ptr is const and whatever is const cann't be modified

Re: [algogeeks] min no of policemen

2010-06-08 Thread Anurag Sharma
Can you expain edge of the tree. I could not get that. Anurag Sharma On Tue, Jun 8, 2010 at 5:53 AM, sharad kumar aryansmit3...@gmail.comwrote: for placing police man we can use bellman ford bfs.or even make use of topological sort. On Mon, Jun 7, 2010 at 9:59 PM, divya

Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-08 Thread divya jain
how do u come to this formula T(n)=fib(n+2).. plz explain On 7 June 2010 21:19, saurabh gupta sgup...@gmail.com wrote: it might be referring to no of sequences (say T(n) ) with no consecutive 1's for n = 3, ans would be 5 viz. 000, 001, 010, 100, 101 T(n) = fib(n+2) where fib = Fibonacci

[algogeeks] Time complexity

2010-06-08 Thread Raj N
What is the time complexity of insertion and deletion in 1. Linked list 2. Queue 3. Queue implemented using a linked list -- 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

Re: [algogeeks] Pointer to a constant

2010-06-08 Thread Raj N
@Mohit: If u're saying that in case 2 ptr is const then what is int *const ptr. I thought this is a constant pointer. Constant pointer is one which can't be made to point to any other address rit? How is *ptr++ coming into the way of constant pointer ? On Mon, Jun 7, 2010 at 7:59 PM, mohit ranjan

[algogeeks] isomorphic trees

2010-06-08 Thread divya
Two binary trees T1 and T2 are isomorphic if T1 can be transformed into T2 swapping left and right children of the nodes in T1.Give an algorithm to report whether 2 given binary trees are isomorphic. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] Pointer to a constant

2010-06-08 Thread Raj N
Actually the first statement i gave const int i=5; int *ptr=i is itself giving an error on gcc and a warning on borland. We have to modify it as const int *ptr=i otherwise it gives illegal pointer conversion error. On Tue, Jun 8, 2010 at 12:11 PM, divya jain sweetdivya@gmail.comwrote: i

Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-08 Thread Raj N
I just checked out with so many possibilities and it is indeed matching. I may not be correct though. On Tue, Jun 8, 2010 at 7:50 PM, divya jain sweetdivya@gmail.com wrote: how do u come to this formula T(n)=fib(n+2).. plz explain On 7 June 2010 21:19, saurabh gupta sgup...@gmail.com

[algogeeks] Re: constraints satisfied?

2010-06-08 Thread Minotauraus
Use a n x n array. initialize with -1 (don't care = no constraints). If there is an equality constraint, set to 1, if explicity non-equality constraint is expected, replace with 0. While doing either of these if you come across a situation where 0 has to be overwritten by 1 or 1 has to be

Re: [algogeeks] circularly sorted array

2010-06-08 Thread Antony Vincent Pandian.S.
Check whether the first element in the array is greater than the last element in the array. If it is true, it means the array is rotated after sorting. Now, take the middle element of the array and check whether it is greater than the last element of the array. If true, it means the first half of

Re: [algogeeks] Single ordered list

2010-06-08 Thread divya jain
merging as in merge sort. On 8 June 2010 19:59, Raj N rajn...@gmail.com wrote: What is the most efficient way of combining 2 separate ordered list into a single ordered list ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-08 Thread Senthilnathan Maadasamy
I found a nice explanation (from some other site) on how to get this formula T(n) = fib(n+2). Consider the set of all binary numbers of length n that end with 0. The first n-1 positions can be anything (0 or 1). So if we take the set of all binary numbers of length n-1 and append 0 to each of

[algogeeks] Re: ds

2010-06-08 Thread Minotauraus
Actually the solution is best thought of with recursion. See, for a simple 4 element array: a1 a2 b1 b2, you can get the result by swapping only the two elements in the middle. Now think, if you had an 8 element array: a1 a2 a3 a4 b1 b2 b3 b4, group these into pairs of 2 like: a1 a2 - b1 b2 / a3

Re: [algogeeks] Time complexity

2010-06-08 Thread Anand
Linked List: Insertion O(n) deletionO(n) Queue using linked list : Insertion O(1) deletion O(n). On Tue, Jun 8, 2010 at 1:38 AM, Raj N rajn...@gmail.com wrote: What is the time complexity of insertion and deletion in 1. Linked list 2. Queue 3. Queue implemented using a linked list --

Re: [algogeeks] Re: sorted 2-d array

2010-06-08 Thread Senthilnathan Maadasamy
*What if there are no zero elements at all?* * * *...@minotauraus Very valid question. The terminating condition for the binary search can be modified to return the count of negative numbers in the array instead. * -- You received this message because you are subscribed to

Re: [algogeeks] isomorphic trees

2010-06-08 Thread Anand
One approach is to parse the element of the two tree in two arrays and compare the arrays to fiind if they are isomorphic. parsing takes O(n). Comparision takes O(n/2) for (i=0;in;i++) { if(2i+1 n) break; if(arr_1[2i] != arr_2[2i+1]) { break; } } if(i == n/2)

Re: [algogeeks] Re: Puzzle:

2010-06-08 Thread mohit ranjan
@Sharad let's say that it will take n steps to reach from [15,0,0] to [2,8,5] then after nth state will be 2,8,5 and (n-1)th state will be say [x,y,z] from which one transfer will lead to o/p [2,8,5] hope it's clear Mohit Ranjan On Tue, Jun 8, 2010 at 6:54 AM, sharad kumar

Re: [algogeeks] ds

2010-06-08 Thread Antony Vincent Pandian.S.
I dont think so This approach is better than O(nlogn) On Tue, Jun 8, 2010 at 9:10 AM, harit agarwal agarwalha...@gmail.comwrote: @vadivel selvaraj your approach is O(nlogn) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] identify the recurring part for a given decimal no

2010-06-08 Thread Veer Sharma
You have a Numerator and Denominator. After division you might get a recurring decimal points float as the answer. Problem is: You need to identify the recurring part for a given decimal no? For example 23.34563456 ... return 3456 -- You received this message because you are subscribed to the

Re: [algogeeks] min no of policemen

2010-06-08 Thread Anand
Min number of police man could be placed on the nodes which does not have leaf nodes. Only things needs to find out is the height of the tree.O(logn). For any given tree: 1. calculate the leaf node: 2^h (h is the height of the tree) 2. Subtract leaft nodes from the

Re: [algogeeks] isomorphic trees

2010-06-08 Thread vadivel selvaraj
bool isIsomorphic(List* h1,List* h2) { if(!h1 !h2) return true; if(h1 h2) return(h1-data == h2-data isIsomorphic(h1-left,h2-right) isIsomorphic(h1-right,h2-left)); else return false; } On Tue, Jun 8, 2010 at 8:31 PM, divya sweetdivya@gmail.com wrote: Two

[algogeeks] Re: Variable number of integers

2010-06-08 Thread Minotauraus
I would say in most situations it is a stack of linked lists (queues). I'd suggest for the sake of simplicity and problem solving, don't think of it that way. Think of it as a stack of 'objects'. These objects can be of any type. Type can be an integer, a float, a pointer or an entire array. Makes

Re: [algogeeks] matix flipping

2010-06-08 Thread Varun Nagpal
This question was asked in a Microsoft interview 2 years back. On Mon, Jun 7, 2010 at 8:05 PM, divya jain sweetdivya@gmail.com wrote: let a[n][n] be the input array nd b[][] be the output for(i=0;in;i++) for(j=0;jn;j++) b[i][j]=a[n-j-1][n-i-1] On 7 June 2010 08:26,

[algogeeks] Re: Single ordered list

2010-06-08 Thread Minotauraus
Divide and Conquer approach works. Look up merge sort. I don't know how the most efficient way. Actually I'm not sure if there are many ways to do this. It will take O(n) time either way (unless there are other specifics given which we can make use of). On Jun 8, 7:29 am, Raj N rajn...@gmail.com

Re: [algogeeks] min no of policemen

2010-06-08 Thread divya jain
edge is the link connecting two nodes of a tree On 8 June 2010 11:23, Anurag Sharma anuragvic...@gmail.com wrote: Can you expain edge of the tree. I could not get that. Anurag Sharma On Tue, Jun 8, 2010 at 5:53 AM, sharad kumar aryansmit3...@gmail.comwrote: for placing police man we

[algogeeks] Re: binary nos

2010-06-08 Thread Minotauraus
Yeah, I didn't get the question either. Do you want to generate these numbers or do you want to be able to tell if the number input is valid or not? And how does Fibo. fit in the picture either way? On Jun 7, 8:13 pm, Dave dave_and_da...@juno.com wrote: Hmmm. The first few Fibonacci numbers

Re: [algogeeks] Pointer to a constant

2010-06-08 Thread mohit ranjan
@Raj, Sorry for the confusion yes, you are right that 1st one is giving warning/error though for 2nd case int i=5; const int *ptr=i; *ptr++; i am nt getting any error/warning (gcc) and i remains 5 but int i=5; const int *ptr=i; (*ptr)++; is giving error Mohit Ranjan On Tue, Jun 8, 2010

Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-08 Thread saurabh gupta
recursion. for length n if the count is T(n) then T(n) = 1st digit 0 + 1st digit 1 = T(n-1) + 1st digit 1 2nd digit 0 = T(n-1) + T(n-2) QED. On Tue, Jun 8, 2010 at 9:03 PM, Raj N rajn...@gmail.com wrote: I just checked out with so many possibilities and it is indeed matching. I may not be

Re: [algogeeks] Re: sorted 2-d array

2010-06-08 Thread Anand
@senthilnathan: Indeed a nice logic. Complexity is O(logn) worst case(if all elements are negative). http://codepad.org/hRbYV287 On Tue, Jun 8, 2010 at 8:18 AM, Minotauraus anike...@gmail.com wrote: Actually, this might not always be the best approach. Example: -1 1 2 3 4 1 2 3 4

Re: [algogeeks] Re: constraints satisfied?

2010-06-08 Thread Rohit Saraf
Your time complexity is not O(c) but O(n^2) -- -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14 -- You received this message because you are subscribed to the

Re: [algogeeks] Re: binary nos

2010-06-08 Thread Rohit Saraf
Fib comes because she wants the number of such sequences -- -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14 -- You received this message because you are

Re: [algogeeks] Re: ds

2010-06-08 Thread Rohit Saraf
which is just the recursive version of the abovementioned iterative solution. P.S. -Please remove this quoted text when you are composing -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay