Re: [algogeeks] Longest Palindrome

2011-01-03 Thread Rishi Agrawal
The blogsite referred is unavailable.


On Fri, Dec 31, 2010 at 3:49 AM, Anand anandut2...@gmail.com wrote:


 http://anandtechblog.blogspot.com/2010/06/find-longest-palindromic-substring-in.html


 On Thu, Dec 30, 2010 at 1:10 PM, Aniket aniket...@gmail.com wrote:

 How do you find the longest palindrome in a given string in O(n) time?

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Regards,
Rishi Agrawal

-- 
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.



Re: [algogeeks] Amazon Interview Question about Linked Lists

2010-12-20 Thread Rishi Agrawal
See inline ..

On Sat, Dec 18, 2010 at 12:09 PM, siva viknesh sivavikne...@gmail.comwrote:

  Given a linked list structure where every node represents a linked list
 and contains two pointers of its type:
 (i) pointer to next node in the main list.
 (ii) pointer to a linked list where this node is head.

 Write a C function to flatten the list into a single linked list.

 Eg.

 If the given linked list is
  1 -- 5 -- 7 -- 10
  |   |  |
  2 6 8
  |   |
  3 9
  |
  4

 then convert it to


  1 - 2 - 3 - 4 - 5 - 6 - 9 - 7 - 8 -10



 My solution - not tested :


 struct node
 {

   int data;

   struct node *fwd; //pointer to next node in the main list.


   struct node *down; //pointer to a linked list where this node is head.


 }*head,*temp,*temp2;


 temp=head;
 while(temp-fwd!=NULL)

 {
 temp2=temp-fwd;


 while(temp-down!=NULL)
 {

 temp=temp-down;
 }

 temp-down=temp2;


// how will the code access the flattened linked list by down or by fwd ? In
this case there in no particular pointer by which the code can access the
linked list. Try to write a function to print the flattened linked list.

 temp-fwd=NULL;

 temp=temp2;

 }



 plz notify me if anything...other solutions and optimizations are welcome








 --
 Regards,
 $iva

  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Regards,
Rishi Agrawal

-- 
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.



Re: [algogeeks] Re: for loop performace in terms of speed makes any difference when we run from max to min and min to max

2010-11-24 Thread Rishi Agrawal
I think the compiler today can identify this optimization and thus the final
code will be the same.

You can check the assembly code generated by the gcc compiler for both the
loops.

On Wed, Nov 24, 2010 at 4:29 PM, shiva shivanand.kadwad...@gmail.comwrote:

 After googling i came to know that comparison with 0 takes less time
 than comparing with some other number.So decremental loop is
 fast(difference is very very low)

 On Nov 22, 5:42 pm, rahul patil rahul.deshmukhpa...@gmail.com wrote:
  Might be its is due to the comparison operation which takes many cycles
 
  i  max takes more cycles of cpu than just simply checking i
 
  On Sun, Nov 21, 2010 at 6:50 PM, shiva shivanand.kadwad...@gmail.com
 wrote:
 
 
 
   I want to know is there any difference between following two loop in
   terms of speed.
 
   1.
   for(i=0;imax;i++)
   {
 
   //Some operation
   }
   2.
   for(i=max; i; i--)
   {
 
   /Some operation
 
   }
 
   I heard second one is faster but don't have any proof
 
   Please comment.
 
   --
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Regards,
  Rahul Patil

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Regards,
Rishi Agrawal

-- 
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.



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

2010-09-24 Thread Rishi Agrawal
 Printing the Array:
 99  35  45  33  88  9098  112  33455  678  3

Min elements are 1: 3 2: 33
 Absolute difference between two minimum elements are 30


On Fri, Sep 24, 2010 at 9:39 AM, Dave dave_and_da...@juno.com wrote:

 @Rishi: Try it on the original data with a[1] changed from 12 to 35:

int array[10]={99,35,45,33,88,9098,112,33455,678,3};

 What do you get as a result?

 Dave

 On Sep 23, 12:36 pm, Rishi Agrawal rishi.b.agra...@gmail.com wrote:
  @Dave, I check for the values you suggested but the code worked fine.
 There
  were other errors in the code. I have rectified them now.
 
  The following code seems to be working fine and in O(n) time.
 
  #include stdio.h
  #include stdlib.h
  void find_two_mins(int array[], int size)
  {
  int i,t;
  int min1, min2;
  if(array[0] = array[1]) {
  min1=array[0];
  min2=array[1];
  } else {
  min2=array[0];
  min1=array[1];
  }
  for (i=2; isize; i++){
  t=array[i];
  if(t=min1) {
  min2=min1;
  min1=t;
  continue;
  }
  if(t=min2) {
  min2=t;
  }
  }
  printf(\nMin elements are 1: %d 2: %d, min1,min2);
  printf(\n Absolute difference between two minimum elements are
 %d\n\n,
  abs(min1-min2));
 
  }
 
  int main()
  {
  //int array[10]={ 9,2,3,4,1,7,5,6,8,0};
  //
  //int array[10]={3,3,1,33,88,9098,112,33455,678,1};
  //int array[10]={5,3,1,33,88,9098,112,33455,678,1};
  //int array[10]={2,3,21,33,88,9098,112,33455,678,12};
  int array[10]={3,2,21,33,88,9098,112,33455,678,12};
 
  find_two_mins(array,10);
  return 0;
 
 
 
  }- Hide quoted text -
 
  - Show quoted text -

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Regards,
Rishi Agrawal

-- 
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.



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

2010-09-23 Thread Rishi Agrawal
@Dave, I check for the values you suggested but the code worked fine. There
were other errors in the code. I have rectified them now.

The following code seems to be working fine and in O(n) time.

#include stdio.h
#include stdlib.h
void find_two_mins(int array[], int size)
{
int i,t;
int min1, min2;
if(array[0] = array[1]) {
min1=array[0];
min2=array[1];
} else {
min2=array[0];
min1=array[1];
}
for (i=2; isize; i++){
t=array[i];
if(t=min1) {
min2=min1;
min1=t;
continue;
}
if(t=min2) {
min2=t;
}
}
printf(\nMin elements are 1: %d 2: %d, min1,min2);
printf(\n Absolute difference between two minimum elements are %d\n\n,
abs(min1-min2));
}


int main()
{
//int array[10]={ 9,2,3,4,1,7,5,6,8,0};
//
//int array[10]={3,3,1,33,88,9098,112,33455,678,1};
//int array[10]={5,3,1,33,88,9098,112,33455,678,1};
//int array[10]={2,3,21,33,88,9098,112,33455,678,12};
int array[10]={3,2,21,33,88,9098,112,33455,678,12};

find_two_mins(array,10);
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.



Re: [algogeeks] Re: sum of primes

2010-09-23 Thread Rishi Agrawal
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 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.



Re: [algogeeks] Re: hashing

2010-06-11 Thread Rishi Agrawal
Hi All,

For if max is 1 then we do not need to read the bits after 14th place.


1(dec) = 1001110001 (bin) that is 14 bits.

On Fri, Jun 11, 2010 at 12:08 AM, kirubakaran kirubakaran1...@gmail.comwrote:


 When it is a stream of data,counting is a best way to go !

 On Jun 10, 7:54 am, Anurag Sharma anuragvic...@gmail.com wrote:
  Even if you use bucket sort, you will have to store the numbers arriving,
 or
  atleast 1..1 numbers along with their count. If you reduce the size
 of
  the bucket further you will have to make a list associated with the
 buckets.
  So asymptotically you will again reach the same space complexity.
 
  Anurag Sharma
 
  On Thu, Jun 10, 2010 at 5:16 AM, sharad kumar aryansmit3...@gmail.com
 wrote:
 
 
 
   can u reduce the size by making use of bucket sort
 
   On Wed, Jun 9, 2010 at 5:01 PM, sharad sharad20073...@gmail.com
 wrote:
 
   I have a stream of numbers coming one by one from a computer generated
   program. I know that these numbers will be between 0 and 1. In
   minimum time how can I sort them. Space is no constraint.
   Later we have to try and optimize the space to as minimum as possible
 
   --
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups .com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
   --
   yezhu malai vaasa venkataramana Govinda Govinda
 
--
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups .com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

 Kirubakaran.S
 GSoC -2010

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Regards,
Rishi B. Agrawal
http://www.linkedin.com/in/rishibagrawal
http://code.google.com/p/fscops/

-- 
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.



Re: [algogeeks] Re: os

2010-06-11 Thread Rishi Agrawal
So can we say that a mutex is a binary semaphore.

On Thu, Jun 10, 2010 at 11:26 PM, souravsain souravs...@gmail.com wrote:


 Originally semaphore is a concept given by Dijkstra who says it is
 something that can have two operations P and V both atomic. In an OS
 (for example Unix) we have kernal objects called semaphore which
 have the same two atomic oprerations. It is used to control
 communication between 2 things (it can be 2 thread, 2 processes) as
 you have rightly mentioned. You can 'wait' for a semaphore. Someone
 else (thread/process) can broadcast a message that it has freed a
 semaphore. So emphasis is on communication.

 Mutex is more for controlling access to some resource. I do not know
 how many threads will access an object, say a linked list. What I only
 know is that the linked list should not be manipulated simultaneously
 by 2 or more threads. So my focus is on makeing sure than the shared
 object 'linked list'  is in good shape. So a Mutex is in itself an
 object which sort of guards the resoure. So the mutex says If a thread
 wants to access / change the linked list, first lock me, then do ur
 changes and unlock me.

 Having said this, Binary semaphore is one which can change value
 between 2 states (enerally 1 and 0) and most interestingly, we
 implement a mutex object by having a binary semaphore inside the Mutex
 object.

 class Mutex
 {
 private BinSem MySem;
 lock()
 {
 if MySem is 0 then lock or wait
 }
 unlock()
 {
 if MySem is 1 broadcast all am releasing and release.
 }
 }


 On Jun 10, 8:56 pm, sharad kumar sharad20073...@gmail.com wrote:
  @sharad but when it is binary semaphore then only one process is
 accessing
  the resource,rest all are blockedwhich means that only that process
 who
  locked bin. sem will unlock it .plzzz correct me if i m wrong

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Regards,
Rishi B. Agrawal
http://www.linkedin.com/in/rishibagrawal
http://code.google.com/p/fscops/

-- 
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.