Re: [algogeeks] ds

2010-06-07 Thread sharad kumar
@ anand all input is in 1 array n in ur approach u hve used 2 arrays ,bt that is not d ques -- 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] ds

2010-06-07 Thread Anurag Sharma
@anand. Perhaps, its not correct. Does not work for larger inputs. Anurag Sharma On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote: Here is my approach is o(n). http://codepad.org/YAFfZpxO http://codepad.org/YAFfZpxO On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar

Re: [algogeeks] divisible by 3

2010-06-07 Thread jaladhi dave
how abt using FSA ? consider state as a remainder when the given no. is divided by 3. Then we get a FSA for any length no. as [image: fsa.JPG] On Sun, Jun 6, 2010 at 12:15 AM, divya sweetdivya@gmail.com wrote: Find if a number is divisible my 3, without using %,/ or *. You can

[algogeeks] Re: array question

2010-06-07 Thread souravsain
@Anand: Your solution will take huge space and can easily be made to run out of memory! If arr5[] = {12,12,6,6,635}, you will run into n^3 space complexity. For arr[5]={12,12,6,6,390625} it will be n^6. Sain On Jun 7, 3:27 am, Anand anandut2...@gmail.com wrote: Here is my approch which runs in

Re: [algogeeks] Re: divisible by 3

2010-06-07 Thread Sundeep Singh
@Anand and @Minotaurus The code seems to fail for 15. Am I missing something? On Mon, Jun 7, 2010 at 2:20 AM, Minotauraus anike...@gmail.com wrote: @Anand: Thanks for the code. I knew you could do it by bit shifting. :-) On Jun 5, 10:21 pm, Anand anandut2...@gmail.com wrote: Here is a

[algogeeks] Puzzle:

2010-06-07 Thread sharad
: Three containers are of 15,10 and 6 ltrs capacity. Initially its in configuration (15,0,0). Make it to configuration (2,8,5) -- 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

[algogeeks] Pointer to a constant

2010-06-07 Thread Raj N
Can someone tell me the difference between 1) const int i=5; 2) int i=5; int *ptr=i; const int *ptr=i; In the first case i can be modified via ptr i.e *ptr++ is valid. In the second case *ptr++ is illegal. Why is that so? Aren't

Re: [algogeeks] ds

2010-06-07 Thread Raj N
@sain: But the question demands O(n) time On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote: Here is my approach is o(n). http://codepad.org/YAFfZpxO http://codepad.org/YAFfZpxO On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar sharad20073...@gmail.comwrote: this is ques by

Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
Ok this is just counting now how to do the same to print all possibilities? On Mon, Jun 7, 2010 at 1:14 PM, Raj N rajn...@gmail.com wrote: @Dave: Hey i'm finding little difficulty in understanding the 3rd condition - p(*k*,*n*) = 0 if *k* *n* - p(*k*,*n*) = 1 if *k* = *n* -

Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
@Dave: Hey i'm finding little difficulty in understanding the 3rd condition - p(*k*,*n*) = 0 if *k* *n* - p(*k*,*n*) = 1 if *k* = *n* - p(*k*+1,*n*)+p(*k*,*n*-*k*) otherwise Can you explain me p(k+1,n) partition. I understood p(k,n-k) On Mon, Jun 7, 2010 at 6:16 AM, Dave

Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
@Dave: Thanks it really helped !! On Mon, Jun 7, 2010 at 6:16 AM, Dave dave_and_da...@juno.com wrote: In number theory, a partition of a positive integer n is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered to be the

Re: [algogeeks] Explain the output

2010-06-07 Thread Jitendra Kushwaha
changing vfork with fork gives the correct output but in case of vfork the loop behaviour is unpredictable @harit : I guess the child is simply reading the value of i from the same data area of the parent. First time it showed a garbage, after which it shows the value inputted in the

Re: [algogeeks] Re: array question

2010-06-07 Thread Raj N
@Anand :Your approach will turn out very crude if elements are something like 1000, 2000 keeping an array i.e count[1000] is not feasible. I think souravsain's approach is better. On Mon, Jun 7, 2010 at 3:57 AM, Anand anandut2...@gmail.com wrote: Here is my approch which runs in O(n).

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

2010-06-07 Thread Senthilnathan Maadasamy
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 straight-forward. Here is an even better O(N) algorithm which is very elegant: Consider the

[algogeeks] constraints satisfied?

2010-06-07 Thread divya
Here's a problem that occurs in automatic program analysis. For a set of variables x1; .. ; xn, you are given some equality constraints, of the form xi = xj and some dis equality constraints, of the form xi != xj Is it possible to satisfy all of them? Give an efficient algorithm that takes as

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

2010-06-07 Thread saurabh gupta
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 series which is interesting. On Sat, Jun 5, 2010 at 11:40 AM, Raj N rajn...@gmail.com wrote: @sharad: What about 101 even

Re: [algogeeks] Re: array question

2010-06-07 Thread Dheeraj Jain
The link http://geeksforgeeks.org/?p=1488 has many different solutions and implementation of hashing method. On Mon, Jun 7, 2010 at 12:59 AM, Raj N rajn...@gmail.com wrote: @Anand :Your approach will turn out very crude if elements are something like 1000, 2000 keeping an array i.e

Re: [algogeeks] matix flipping

2010-06-07 Thread Amit Jaspal
#includeiostream using namespace std; int main(){ int a[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; int i=0,j,n=3,l=0,m=n; j=n; while(i=n){ int i1=i,j1=j,k=0,l=n; for(;kj1;i1++,j1--){ swap(a[k][i1],a[j1][l]); if(i!=0){

Re: [algogeeks] ds

2010-06-07 Thread vadivel selvaraj
Hi guys d soln z quite easy by swapping the variables.. consider a1a2a3a4b1b2b3b4 In the first iteration, swap (a2,b1),(a4,b3) giving a1b1a3b3a2b2a4b4 In the second iteration, swap (a3b3,a2b2) which gives d soln... a1b1a2b2a3b3a4b4... Any comments on dis?? On Mon, Jun 7, 2010 at 1:51 PM, Raj N

Re: [algogeeks] matix flipping

2010-06-07 Thread mohit ranjan
@Sharad, 3 4 5 A= 6 7 9 1 2 8 If B[i,j] = A[n-j, n-i] then --- 8 9 5 B = 2 7 4 1 6 3 Mohit Ranjan On Mon, Jun 7, 2010 at 8:26 AM, sharad sharad20073...@gmail.com wrote: write

Re: [algogeeks] Puzzle:

2010-06-07 Thread mohit ranjan
is it possible ? if we say nth state is [2, 8, 5] I could not find possible (n-1)th state Mohit Ranjan On Mon, Jun 7, 2010 at 2:02 PM, sharad sharad20073...@gmail.com wrote: : Three containers are of 15,10 and 6 ltrs capacity. Initially its in configuration (15,0,0). Make it to

[algogeeks] Knapsack - 0-1 - Brute force

2010-06-07 Thread Jean Carlo Mendes
Hello Guys Anyone have a implementation of knapsack 0-1 using brute force approach ? Or. Do you have some link with a sample in C language? Thanks jean -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

[algogeeks] min no of policemen

2010-06-07 Thread divya
consider a tree. policemen is to be placed such that for each edge of tree, there is a policeman on atleast one side of each edge. tell the min no. of policemen and their locatn in time O(n) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] matix flipping

2010-06-07 Thread divya jain
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, sharad sharad20073...@gmail.com wrote: write a c routine to flip an nXn matrix about its non major diagnol 3 4 5 6 7 9

Re: [algogeeks] Re: divisible by 3

2010-06-07 Thread Anand
Here is another approach. Example: 23 (00..10111) 1) Get count of all set bits at odd positions (For 23 it’s 3). 2) Get count of all set bits at even positions (For 23 it’s 1). 3) If difference of above two counts is a multiple of 3 then number is also a multiple of 3. (For 23 it’s 2 so 23 is not

[algogeeks] circularly sorted array

2010-06-07 Thread divya
u r given a circularly sorted array of n integers ie the array was 1st sorted nd then left or right shifted any no. of times. search for a given integer k in the array in O(logn) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Pointer to a constant

2010-06-07 Thread mohit ranjan
@Raj, no they are not same case 1: i is const case 2: ptr is const and whatever is const cann't be modified Mohit Ranjan On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote: Can someone tell me the difference between 1) const int i=5; 2) int i=5;

[algogeeks] binary nos

2010-06-07 Thread divya
write an efficient algo to compute no. of sequences of n binary digits that do not contain 2 1's in a row. eg 111 is invalid whereas 1001001 is valid.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Veer: Kth element in binary tree

2010-06-07 Thread Veer Sharma
Given a Binary Search Tree, write a program to print the kth smallest element without using any static/global variable. You can’t pass the value k to any function also -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Pointer to a constant

2010-06-07 Thread Raj N
1) const int i=5;2) int i=5; int *ptr=i; const int*ptr=i; On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote: Can someone tell me the difference between 1) const int i=5;

Re: [algogeeks] Re: array question

2010-06-07 Thread Anand
@souravsain :Your approach works really well.. Here is the Implementation: http://codepad.org/ricAcQtu On Sun, Jun 6, 2010 at 11:40 AM, souravsain souravs...@gmail.com wrote: @divya:go through the elements and keep inserting them in a BST. While inserting if elements already exists in BST,

Re: [algogeeks] binary nos

2010-06-07 Thread Rohit Saraf
So u want efficient algo for fibonacci numbers? -- -- 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] constraints satisfied?

2010-06-07 Thread Rohit Saraf
A simple solution : Use the union find data structure and add notes for x1...xn and the negation of all these. Every constraint makes one union. Finally check if for any i , xi and !xi are connected. It is worst case O(n lg n) for sure where n is the number of equations. Average case is much

[algogeeks] Re: binary nos

2010-06-07 Thread Dave
Hmmm. The first few Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ... Of these, 3, 13, and 55 have binary representations with two 1-bits in a row. And 9, 10, 17, 18, etc are not included. So what was your question? Dave On Jun 7, 9:28 pm, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:

Re: [algogeeks] Re: array question

2010-06-07 Thread Mayur
@Anand Depending upon the sequence of data in the input, an insertion/search into the (unbalanced) BST will take O(n) time causing the overall complexity to shoot up to O(n^2) for each element counted once. Sourav's approach requires a balanced binary search tree. @Divya.. If you know something

Re: [algogeeks] Re: binary nos

2010-06-07 Thread Rohit Saraf
getting fibonacci nos is trivial using matrix multiplication in almost constant time. -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14 -- You received this message

Re: [algogeeks] ds

2010-06-07 Thread Rohit Saraf
Of course you should do it via swappings.. why would one think of anything else :) -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14 On Mon, Jun 7, 2010 at 10:39 PM,