[algogeeks] Re: wiki issue on dijkstra's algorithm

2010-10-11 Thread Krunal Modi
Each edge will have a cost not the nodes(vertices).
Upload an image of the graph.

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: iTS aLL gOOGLE- iNTERVIEW

2010-10-03 Thread Krunal Modi
If we are pressing n numbers, the it should be (26)^N.
As each time we press the number it is going to be any character.

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Bitwise operator - Adobe

2010-09-25 Thread Krunal Modi
Q: Write an algorithm to compute the next multiple of 8 for a given
positive integer using bitwise operators.

Example,
(a) For the number 12, the next multiple of 8 is 16.
(b) For the number 16, the next multiple of 8 is 24.
-
I have written a code using bitwise operators...but, I am not happy
with the solutionIs there any ONE LINE solution ?
Here, is my code.
Approach: shift left till LSB is 0 (say n number of times) then, OR
with 1, finally shift right (same number of times).


#includestdio.h

int main(){
int count,m,n,ans,t;


printf(Enter any number :);
scanf(%d,n);

m=8; //multiple of 8 !!
ans=0;
while(ans=n){
t = m;
while(t){
count=0;
while(ans1){
count++;
ans = ans1;
}
ans = ans|1;
ans = anscount;
t--;
}
}

printf([%d]\n,ans);

return 0;
}

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread Krunal Modi
Basically, I am starting from (ans=)0  checking if it has become
greater than n, if not repeat(means, add 8) else answer is found.

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: ReVerse a string using recursion

2010-09-25 Thread Krunal Modi
I agree with Nishant.
For inplace replacement we need to swap two place for that we need
index, which is not possible without additional variables.

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Adobe Question

2010-09-23 Thread Krunal Modi
for(k=1 ; kn ; k++){
  j=k;
  while(j0){
 j=j/2;
  }
}


How many times while loop gets executed (for any n) ?

I don't want answer in terms of series (i.e, don't want any sigma, I
have that)

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Adobe Question

2010-09-23 Thread Krunal Modi
@Apoorve : All are integer int.

@Dave: Can you explain how u arrived at this equation ?

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Adobe Question

2010-09-23 Thread Krunal Modi
But, how was it derived ? :(
What is the intuition behind ? :( :(

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: print largest continue subsequent in int array

2010-09-20 Thread Krunal Modi
@Dave :
We have to find any element.
So whichever is larger has to be the answer.Hence, -1

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: print largest continue subsequent in int array

2010-09-20 Thread Krunal Modi
@LG JAYARAM:

It is 7.

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
@LG JAYARAM :

Your code is not even compiling. If you are including header that
means you have made a code and successfully run it.
I have the code readybut just wanted to check with your program
for some exception conditions...

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
@Minotauraus:

This is not the thing that Raj Jagvanshi wants.
See, what he has mentioned.
a[] = {4,1,2,3,4,5,40,41,19,20};
print = 40 , 41
sum  = 81;

We need to find max sum such that they are of consecutive numbers (a,a
+1,a+2,)


I have implemented Kadane's Algo : and the result is
4 1 2 3 4 5 40 41  19 20
4   1   2   3   4   5   40  41
19  20
Max : [139]
which is wrong

Here is the code of Kadane's Algorithm, u can check it on your own :
#includestdio.h

int main(){
int n;
int max,a,b;
int curr,aa,bb;
int arr[1000];
int i;

printf(Enter numbers (-1 to stop taking input) :);
for(i=0 ; i1000 ; i++){
scanf(%d,arr[i]);
if(arr[i] == -1){
n=i;
break;
}
}

max = -9;
a = b = 0;

curr = 0;
aa = 0;

for(bb=0 ; bbn ; bb++){
curr = curr + arr[bb];

if(curr  max){
max = curr;
a = aa;
b = bb;
}

if(curr  0){
curr = 0;
aa = bb + 1;
}
}

for(i=a ; i=b ; i++){
printf(%d\t,arr[i]);
}
printf(\nMax : [%d]\n,max);

return 0;
}



===

On Sep 18, 10:29 pm, Minotauraus anike...@gmail.com wrote:
 I was looking into this problem the other day and found 
 this:http://www.algorithmist.com/index.php/Kadane's_Algorithm
 Kadane's algorithm to find the maximum continuous subarray.

 The basic idea is to maintain the largest sum ending at each location
 in the array. and max which holds the maximum so far.

 On Sep 17, 11:41 am, Raj Jagvanshi raj.jagvan...@gmail.com wrote:



  a[] = {4,1,2,3,4,5,40,41,19,20};

  print = 40 , 41
  sum  = 81;

  give me code

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
@Raj Jagvanshi:

Test 1 :
Enter numbers (-1 to stop taking input)
4 1 2 3 4 5 40 41  19 20
-1

Largest sequence is : 40 to 41
40  41
Sum: 81
--
Test 2:
Enter numbers (-1 to stop taking input)
-5 -4 -3
-1

Largest sequence is : -3 to -3
-3
Sum: -3
---



Here is my code:
#includestdio.h

int main(){
int arr[100],i,N;

int max,smax,emax;
int curr,scurr;

printf(Enter numbers (-1 to stop taking input)\n\n);
for(i=0 ; i100 ; i++){
scanf(%d,arr[i]);
// Enter -1 to stop entering the numbers
if(arr[i] == -1){
N=i;
break;
}
}

//
max = arr[0];
curr = arr[0];
smax = emax = scurr = 0;

for(i=1 ; iN ; i++){
if( (arr[i-1]+1 == arr[i])  (curr  curr + arr[i]) )
{
curr = curr + arr[i];
}else{
scurr=i;
curr = arr[i];
}

if(max  curr){
smax = scurr;
emax = i;

max = curr;
}
}
// end

printf(\n\nLargest sequence is : %d to %d
\n,arr[smax],arr[emax]);
for(i=smax ; i=emax ; i++){
printf(%d\t,arr[i]);
}
printf(\nSum: %d\n,max);

return 0;
}

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
@LG Jayaram :

check for -5 -4 -3 -2 -1

answer should be : -1

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
no
we have to find consecutive numbers such that there some is largest...
here -3  -1

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Yahoo Question

2010-09-18 Thread Krunal Modi
@umesh kewat :

In worst case it will be O(nk) in case of your solution.

check for this case:
01-06-11-16
02-07-12-17
03-08-13-18
04-09-14-19
05-10-15-20
--
Krunal

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Yahoo Question

2010-09-18 Thread Krunal Modi
@umesh kewat:

In worst case it will be O(n*k), by your solution.

01-06-11-16
02-07-12-17
03-08-13-18
04-09-14-19
05-10-15-20
--
Krunal


By umesh kewat:
Create binary search tree using n nodes of K list den do in-order and
make a
single 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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: do this: sorting using reverse()

2010-09-18 Thread Krunal Modi
@Minotauras:

There are some problems in you swap(x,y)
in your example : for reverse(3) you have considered 0 based indexing
and for reverse(2) 1 based index !!
see:
Original array : 1 8 3 4 5 and we want to swap(2,3) // swap 3 and 4.
Means, 0 BASED INDEX

reverse(3): 4 3 8 1 5
reverse(2): 8 3 4 1 5 
reverse(3): 1 4 3 8 5

AND

If you meant swap(x,y)  = rev(y) ; rev(1) ; rev(y) then, your
swap(x,y) can't be used in ALL sorting algos.

For example,
Original array : 1 4 3 2
and we want to swap(1,3) // because we want 1 2 3 4
so
rev(3) - 2 3 4 1
rev(1) - 3 2 4 1
rev(3) - 1 4 2 3

So we have a restriction of swapping only two consecutive numbers
so...In swap(x,y) x is not needed because {xy  x+1=y}

On Sep 17, 12:17 am, Minotauraus anike...@gmail.com wrote:
 write a function swap(x, y)
 which does:
 reverse(y)
 reverse(1)
 reverse(y)

 so 1 8 3 4 5, swap (2, 3) // swap 3 and 4
 reverse(3) gives: 4 3 8 1 5
 reverse(2) : 3 4 8 1 5
 reverse(3): 1 8 3 4 5 //thus we have swapped 3, 4 using the reverse(x)
 function.

 Use any sorting algorithm and you'll need 3k * n(log n)
 assuming reverse(x) takes O(k)

 I guess there is a way to optimize the number of reverse(x) calls

 On Sep 16, 8:41 am, Srinivas lavudyasrinivas0...@gmail.com wrote:



  You have been given a function rev(x) which works as follows:
  It reverses a[0] to a[x] elements of a.
  e.g. Given array is
  a : 1 8 3 4 5
  rev(3) will convert the array to
  a : 4 3 8 1 5
  Use this function only (and comparison, of course) to sort given array
  'a'. The only criterion is
  that the number of times this function is called should be minimum.

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Google Interview Question

2010-09-17 Thread Krunal Modi
Your solutions are pretty impressive.
Which place(country) are you from ?
where are you studying (or done :) ) ?

Keep it up...
Good Wishes..
--Krunal

On Sep 14, 9:29 pm, Gene gene.ress...@gmail.com wrote:
 You can approach this the same way you'd do it by hand.  Build up the
 string of brackets left to right.  For each position, you have a
 decision of either ( or ) bracket except for two constraints:
 (1) if you've already decided to use n left brackets, then you can't
 use a another left bracket and
 (2) if you've already used as many right as left brackets, then you
 can't use another right one.

 This suggests the following alorithm. Showing what happens on the
 stack is a silly activity.

 #include stdio.h

 // Buffer for strings of ().
 char buf[1000];

 // Continue the printing of bracket strings.
 //   need is the number of ('s still needed in our string.
 //   open is tne number of ('s already used _without_ a matching ).
 //   tail is the buffer location to place the next ) or (.
 void cont(int need, int open, int tail)
 {
   // If nothing needed or open, we're done.  Print.
   if (need == 0  open == 0) {
     printf(%s\n, buf);
     return;
   }

   // If still a need for (, add a ( and continue.
   if (need  0) {
     buf[tail] = '(';
     cont(need - 1, open + 1, tail + 1);
   }

   // If still an open (, add a ) and continue.
   if (open  0) {
     buf[tail] = ')';
     cont(need, open - 1, tail + 1);
   }

 }

 void Brackets(int n)
 {
   cont(n, 0, 0);

 }

 int main(void)
 {
   Brackets(3);
   return 0;

 }

 On Sep 14, 10:57 am, bittu shashank7andr...@gmail.com wrote:



  Write a function Brackets(int n) that prints all combinations of well-
  formed brackets. For Brackets(3) the output would be ((())) (()()) (())
  () ()(()) ()()()

  with explaination dat is at every call what is contant of stack during
  pushing and popping

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: On random number generation

2010-09-13 Thread Krunal Modi
So finally which answer is correct ?
There are many answers and I'm doubtful abt there correctness !!

-- 
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, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.