[algogeeks] Re: SPOJ:RRSCHED

2010-06-18 Thread Shravan

Even I have implemented it using arrays, but I am getting a TLE.
Here's the code
http://ideone.com/EfYRa
On Jun 19, 8:15 am, Anand  wrote:
> It can be done using simple array data structure why do we need complex data
> structure.
>
> Here is how I did. Let me know if I understood 
> correctly.http://codepad.org/rMbTI8PJ
>
>
>
> On Fri, Jun 18, 2010 at 8:15 AM, Shravan  wrote:
> > I am trying to solve the problemhttp://www.spoj.pl/problems/RRSCHED/
> > . And a naive approach doesn't seem to work .What sort of data
> > structure do I need.
>
> > --
> > 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 > .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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] OS problems

2010-06-18 Thread harit agarwal
@amit

1. calloc gives contiguos allocated space and it is not necessary that  it
can find 1gb in a row that's why it failed after allocating some memory...
 it is not necessary that it will always allocate 800mb of space as in this
case...


2. whenever a process is executed in critical sectionit is means that it
raises it execution level so that it can't be interrupted while the other
processors are still on the same execution level they can be interrupted

-- 
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] Width of the tree

2010-06-18 Thread harit agarwal
do a bfs traversal and insert a null marker after each traversal keep a
variable max for maximum nodes at any level..

O(n)

-- 
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] Width of the tree

2010-06-18 Thread sharad kumar
@anand:diameter is 4 bhaiya its the widththe shortest distance between
the leftmost nodein left subtree and right most node in right subtree

On Sat, Jun 19, 2010 at 8:07 AM, Anand  wrote:

> Here is the example tree.
>
>  1
> /  \
>23
>  /  \ \
> 45 8
>   /  \
>  67
>
> For the above tree,
> width of level 1 is 1,
> width of level 2 is 2,
> width of level 3 is 3
> width of level 4 is 2.
>
> So the maximum width of the tree is 3.
>
>
> On Thu, Jun 17, 2010 at 5:07 PM, sharad kumar wrote:
>
>> do u meand diameter of tree?? if it is so then start from the left most
>> node in tree and traverse upto root and traverse to the rightmost node in
>> tree..this u can do by having extra field in tree which is parent
>> pointer
>>
>>  On Fri, Jun 18, 2010 at 4:25 AM, Anand  wrote:
>>
>>>  Any guys suggest any algo on how to find the width of the tree.
>>>
>>>
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> 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.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.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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Iterative postorder inorder and preorder tree traversal algorithm

2010-06-18 Thread Gene
On Jun 18, 9:13 am, november  wrote:
> please explain the algo for iterative inorder postorder and pre-order
> tree traversals using stack.(no code only algo plzz :) )

Okay so here is the stripped down code.  It does all 3 kinds of
visits.  Take your pick.

search_iterative(tree) {
 start:
  if (tree is not empty) {
preorder visit
push 
tree = tree.left
goto start
  L0:
inorder visit
push 
tree = tree.right
goto start
  L1:
postorder visit
  }
  // simulate return to last call site
  if (stack not empty) {
 = pop()
goto label;
  }
}

Now if you want to clean up the gotos, you can start rewriting. I'll
begin by eliminating the gotos at the end by substitution:

search_iterative(tree) {
 start:
  if (tree is not empty) {
preorder visit
push 
tree = tree.left
goto start
  L0:
inorder visit
push 
tree = tree.right
goto start
  L1:
postorder visit
  }
  // simulate return to last call site
end:
  if (stack not empty) {
 = pop()
if (label = L0) {
  inorder visit
  push 
  tree = tree.right
  goto start
}
else {
  postorder visit
  goto end
}
  }
}

Now notice that you don't need the labels L0 an L1 any more, including
the code associated with them.  It's all dead. So eliminate it:

search_iterative(tree) {
 start:
  if (tree is not empty) {
preorder visit
push 
tree = tree.left
goto start
  }
end:
  if (stack not empty) {
 = pop()
if (label = L0) {
  inorder visit
  push 
  tree = tree.right
  goto start
}
else {
  postorder visit
  goto end
}
  }
}

Now the top 2 if ()'s can be converted to while loops:


search_iterative(tree) {
 start:
  while (tree is not empty) {
preorder visit
push 
tree = tree.left
  }
  while (stack not empty) {
 = pop()
if (label = L0) {
  inorder visit
  push 
  tree = tree.right
  goto start
}
postorder visit
  }
}

Finally, we replace the inner "if" with a loop and flag:

search_iterative(tree) {
  do {
restart = false;
while (tree is not empty) {
  preorder visit
  push 
  tree = tree.left
}
while (stack not empty and not restart) {
   = pop()
  if (label = L0) {
inorder visit
push 
tree = tree.right
restart = true;
  }
  else {
postorder visit
  }
}
  } while (restart);
}

I guess you don't like code, but here is code:

#define PUSH(Tree, Site) do { \
  stack[sp].tree = Tree; \
  stack[sp++].site = Site; } while (0)

#define POP() (tree = stack[--sp].tree, stack[sp].site)

void si(NODE *tree)
{
  int restart;
  do {
restart = 0;
while (tree) {
  printf("preorder %d\n", tree->val);
  PUSH(tree, 0);
  tree = tree->left;
}
while (sp && !restart) {
  if (POP() == 0) {
printf("inorder %d\n", tree->val);
PUSH(tree, 1);
tree = tree->right;
restart = 1;
  }
  else {
printf("postorder %d\n", tree->val);
  }
}
  } while (restart);
}

Or if you are willing to tolerate one goto, it's even simpler:

void si(NODE *tree)
{
  restart:
while (tree) {
  printf("preorder %d\n", tree->val);
  PUSH(tree, 0);
  tree = tree->left;
}
while (sp) {
  if (POP() == 0) {
printf("inorder %d\n", tree->val);
PUSH(tree, 1);
tree = tree->right;
goto restart;
  }
  printf("postorder %d\n", tree->val);
}
}

Now if you look at this, you can see what it's doing.

-- 
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] SPOJ:RRSCHED

2010-06-18 Thread Anand
It can be done using simple array data structure why do we need complex data
structure.

Here is how I did. Let me know if I understood correctly.
http://codepad.org/rMbTI8PJ


On Fri, Jun 18, 2010 at 8:15 AM, Shravan  wrote:

> I am trying to solve the problem http://www.spoj.pl/problems/RRSCHED/
> . And a naive approach doesn't seem to work .What sort of data
> structure do I need.
>
> --
> 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.
>
>

-- 
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] Width of the tree

2010-06-18 Thread Anand
Here is the example tree.

 1
/  \
   23
 /  \ \
45 8
  /  \
 67

For the above tree,
width of level 1 is 1,
width of level 2 is 2,
width of level 3 is 3
width of level 4 is 2.

So the maximum width of the tree is 3.


On Thu, Jun 17, 2010 at 5:07 PM, sharad kumar wrote:

> do u meand diameter of tree?? if it is so then start from the left most
> node in tree and traverse upto root and traverse to the rightmost node in
> tree..this u can do by having extra field in tree which is parent
> pointer
>
>  On Fri, Jun 18, 2010 at 4:25 AM, Anand  wrote:
>
>>  Any guys suggest any algo on how to find the width of the tree.
>>
>>
>>
>> --
>> 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.
>>
>
>
>
> --
> 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.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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] binary tree

2010-06-18 Thread Anand
1) Pick an element from Preorder. Increment a Preorder Index Variable
(preIndex in below code) to pick next element in next recursive call.
2) Create a new tree node tNode with the data as picked element.
3) Find the picked element’s index in Inorder. Let the index be inIndex.
4) Call buildTree for elements before inIndex and make the built tree as
left subtree of tNode.
5) Call buildTree for elements after inIndex and make the built tree as
right subtree of tNode.
6) return tNode.

Code: http://codepad.org/SUPy54kY

On Fri, Jun 18, 2010 at 4:07 AM, jalaj jaiswal wrote:

> use recursion
>
> On Fri, Jun 18, 2010 at 8:53 AM, Anurag Sharma wrote:
>
>> Here is the link which fits your need.
>>
>> http://www.coders2020.com/construct-a-tree-given-its-inorder-and-preorder-traversal-strings-similarly-construct-a-tree-given-its-inorder-and-post-order
>>
>> Anurag Sharma
>>
>>
>>
>> On Thu, Jun 17, 2010 at 4:34 PM, divya  wrote:
>>
>>> write a code to construct tree from inorder nd preorder traversal..
>>>
>>> --
>>> 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.
>>>
>>>
>> --
>> 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.
>>
>
>
>
> --
> With Regards,
> Jalaj Jaiswal
> +919026283397
> B.TECH IT
> IIIT ALLAHABAD
>
> --
>  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.
>

-- 
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: Iterative postorder inorder and preorder tree traversal algorithm

2010-06-18 Thread Gene
On Jun 18, 9:13 am, november  wrote:
> please explain the algo for iterative inorder postorder and pre-order
> tree traversals using stack.(no code only algo plzz :) )

Code is algorithm.  What don't you understand?  You can convert any
recursive algorithm to iterative by replacing the recursive call with
instructions that save the current state on a stack along with a flag
that shows where the call is, and finally a goto the start of the
recursive procedure.  At the return for the procedure, you check the
stack to see if it has anything on it. If it does, you restore the
state and use the flag to goto the spot just after the call site.  In
other words, you are doing the same thing as the compiled code for the
recursive call would have.  After you are done, if you want, you can
replace the gotos with equivalent loop structures.


-- 
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] SPOJ:RRSCHED

2010-06-18 Thread Shravan
I am trying to solve the problem http://www.spoj.pl/problems/RRSCHED/
. And a naive approach doesn't seem to work .What sort of data
structure do I need.

-- 
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] palindrome substring

2010-06-18 Thread Amir hossein Shahriari
here's a linear time solution:
http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/

On Fri, Jun 18, 2010 at 4:58 PM, Chunyuan Ge  wrote:

> good point, i am wrong, sorry
>
>
>
> On Fri, Jun 18, 2010 at 5:54 PM, Rohit Saraf 
> wrote:
>
>> abcqwertycba
>>
>> So is abc a palindrome??
>> --
>> Rohit Saraf
>> Second Year Undergraduate,
>> Dept. of Computer Science and Engineering
>> IIT Bombay
>> http://www.cse.iitb.ac.in/~rohitfeb14
>>
>>
>>   On Fri, Jun 18, 2010 at 3:08 PM, Chunyuan Ge  wrote:
>>
>>>   Origin string a, reverse the string to get b
>>> get the longest common string between a and b
>>>
>>> that's it.
>>>
>>> Chunyuan
>>>
>>>
>>> On Thu, Jun 17, 2010 at 8:38 PM, debajyotisarma <
>>> sarma.debajy...@gmail.com> wrote:
>>>
 Find the longest palindrome in the given string.
 Minimum time-space complexity required
 (i have not solved it so don't know what is min)

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


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

-- 
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] palindrome substring

2010-06-18 Thread Ratnesh Thakur
check this
http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/

On Fri, Jun 18, 2010 at 3:36 PM, Manzoor Ahmed  wrote:

> What do you mean by origin string?
>
>
> On Fri, Jun 18, 2010 at 2:38 PM, Chunyuan Ge  wrote:
>
>> Origin string a, reverse the string to get b
>> get the longest common string between a and b
>>
>> that's it.
>>
>> Chunyuan
>>
>>
>> On Thu, Jun 17, 2010 at 8:38 PM, debajyotisarma <
>> sarma.debajy...@gmail.com> wrote:
>>
>>> Find the longest palindrome in the given string.
>>> Minimum time-space complexity required
>>> (i have not solved it so don't know what is min)
>>>
>>> --
>>> 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.
>>>
>>>
>>  --
>> 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.
>>
>
>
>
> --
> Manzoor Ahmed
>
> --
> 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.
>

-- 
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] binary tree

2010-06-18 Thread jalaj jaiswal
use recursion

On Fri, Jun 18, 2010 at 8:53 AM, Anurag Sharma wrote:

> Here is the link which fits your need.
>
> http://www.coders2020.com/construct-a-tree-given-its-inorder-and-preorder-traversal-strings-similarly-construct-a-tree-given-its-inorder-and-post-order
>
> Anurag Sharma
>
>
>
> On Thu, Jun 17, 2010 at 4:34 PM, divya  wrote:
>
>> write a code to construct tree from inorder nd preorder traversal..
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>



-- 
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD

-- 
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] Iterative postorder inorder and preorder tree traversal algorithm

2010-06-18 Thread november
please explain the algo for iterative inorder postorder and pre-order
tree traversals using stack.(no code only algo plzz :) )

-- 
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] palindrome substring

2010-06-18 Thread Chunyuan Ge
good point, i am wrong, sorry



On Fri, Jun 18, 2010 at 5:54 PM, Rohit Saraf wrote:

> abcqwertycba
>
> So is abc a palindrome??
> --
> Rohit Saraf
> Second Year Undergraduate,
> Dept. of Computer Science and Engineering
> IIT Bombay
> http://www.cse.iitb.ac.in/~rohitfeb14
>
>
>   On Fri, Jun 18, 2010 at 3:08 PM, Chunyuan Ge  wrote:
>
>>   Origin string a, reverse the string to get b
>> get the longest common string between a and b
>>
>> that's it.
>>
>> Chunyuan
>>
>>
>> On Thu, Jun 17, 2010 at 8:38 PM, debajyotisarma <
>> sarma.debajy...@gmail.com> wrote:
>>
>>> Find the longest palindrome in the given string.
>>> Minimum time-space complexity required
>>> (i have not solved it so don't know what is min)
>>>
>>> --
>>> 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.
>>>
>>>
>> --
>> 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.
>>
>
> --
>  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.
>

-- 
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: Variant Of Dutch National Flag Problem

2010-06-18 Thread Amit Jaspal
@ above We have to do this inplace.

On Fri, Jun 18, 2010 at 10:30 AM, Gaurav Singh  wrote:

> You may apply Radix sort here.
> Sort on the basis of color first and then apply stable sort on the
> digits. So on the whole you will be applying radix sort.
>
> --
> 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.
>
>

-- 
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] OS problems

2010-06-18 Thread Amit Jaspal
It means the program crashed while it was trying to allocate more memory .
Now can u guess why that happened?

On Fri, Jun 18, 2010 at 1:29 PM, jaladhi dave wrote:

> can you explain what you meant when you said "the program fails after
> allocationg about 800mg(appx. i dont remember).
> This is the excerpt from calloc man page, Calloc will either fail or
> succeed but there is no way you can tell so much was alloted and then it
> failed.
> *Return Value***For calloc() and malloc(), the value returned is a pointer
> to the allocated memory, which is suitably aligned for any kind of variable,
> or NULL if the request fails.
>
> On Fri, Jun 18, 2010 at 1:09 AM, amit  wrote:
>
>> 1. a mad user tries to allocate 1 gb memory using calloc.
>> but the program fails after allocationg about 800mg(appx. i dont
>> remember). Tell me what could have gone wrong?
>>
>> 2.
>> We know disabling interrupts works only if it is single processor(i.e
>> local disabling of interrupts).
>>
>> Consider this case where we have a SMP(symmetric multi proc) the
>> processor. Processor-1 wants to perform some critical operation so it
>> disables all the interrupts.
>>
>> What will happen when processor-2 throws an interrupt.
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>

-- 
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] lowest common ancestor

2010-06-18 Thread jaladhi dave
very nice and informative link. Thanks a lot :)

On Thu, Jun 17, 2010 at 4:08 PM, Vivek Sundararajan  wrote:

>
> http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAncestor
>
> The above link gives a detailed explanation about LCA and RMQ
>
> On 17 June 2010 15:30, jalaj jaiswal  wrote:
>
>> write an algo which gives the lowest common ancestor of two nodes in a
>> general tree(not binary specifically)
>>
>> --
>> With Regards,
>> Jalaj Jaiswal
>> +919026283397
>> B.TECH IT
>> IIIT ALLAHABAD
>>
>> --
>> 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.
>>
>
>
>
> --
> "Reduce, Reuse and Recycle"
> Regards,
> Vivek.S
>
>  --
> 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.
>

-- 
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] palindrome substring

2010-06-18 Thread Manzoor Ahmed
What do you mean by origin string?

On Fri, Jun 18, 2010 at 2:38 PM, Chunyuan Ge  wrote:

> Origin string a, reverse the string to get b
> get the longest common string between a and b
>
> that's it.
>
> Chunyuan
>
>
> On Thu, Jun 17, 2010 at 8:38 PM, debajyotisarma  > wrote:
>
>> Find the longest palindrome in the given string.
>> Minimum time-space complexity required
>> (i have not solved it so don't know what is min)
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>



-- 
Manzoor Ahmed

-- 
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] palindrome substring

2010-06-18 Thread Rohit Saraf
abcqwertycba

So is abc a palindrome??
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Fri, Jun 18, 2010 at 3:08 PM, Chunyuan Ge  wrote:

> Origin string a, reverse the string to get b
> get the longest common string between a and b
>
> that's it.
>
> Chunyuan
>
>
> On Thu, Jun 17, 2010 at 8:38 PM, debajyotisarma  > wrote:
>
>> Find the longest palindrome in the given string.
>> Minimum time-space complexity required
>> (i have not solved it so don't know what is min)
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>

-- 
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] palindrome substring

2010-06-18 Thread Chunyuan Ge
Origin string a, reverse the string to get b
get the longest common string between a and b

that's it.

Chunyuan


On Thu, Jun 17, 2010 at 8:38 PM, debajyotisarma
wrote:

> Find the longest palindrome in the given string.
> Minimum time-space complexity required
> (i have not solved it so don't know what is min)
>
> --
> 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.
>
>

-- 
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: Variant Of Dutch National Flag Problem

2010-06-18 Thread Gaurav Singh
You may apply Radix sort here.
Sort on the basis of color first and then apply stable sort on the
digits. So on the whole you will be applying radix sort.

-- 
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] OS problems

2010-06-18 Thread jaladhi dave
can you explain what you meant when you said "the program fails after
allocationg about 800mg(appx. i dont remember).
This is the excerpt from calloc man page, Calloc will either fail or succeed
but there is no way you can tell so much was alloted and then it failed.
*Return Value***For calloc() and malloc(), the value returned is a pointer
to the allocated memory, which is suitably aligned for any kind of variable,
or NULL if the request fails.

On Fri, Jun 18, 2010 at 1:09 AM, amit  wrote:

> 1. a mad user tries to allocate 1 gb memory using calloc.
> but the program fails after allocationg about 800mg(appx. i dont
> remember). Tell me what could have gone wrong?
>
> 2.
> We know disabling interrupts works only if it is single processor(i.e
> local disabling of interrupts).
>
> Consider this case where we have a SMP(symmetric multi proc) the
> processor. Processor-1 wants to perform some critical operation so it
> disables all the interrupts.
>
> What will happen when processor-2 throws an interrupt.
>
> --
> 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.
>
>

-- 
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]Numbers search in an array

2010-06-18 Thread Ashish Mishra
take one pointer to start n another to the end say a n b
now if
a +b > X
shift b towards left n so on




On Fri, Jun 18, 2010 at 9:03 AM, sharad kumar wrote:

> @arun:find out the difference  x-arr[i] for all i=0..n hash it ...next
> search for a number with difference .u can get it in O(n)
>
> On Fri, Jun 18, 2010 at 8:05 AM, Arunkumar Sreenivasan <
> thegame.a...@gmail.com> wrote:
>
>> Hi,
>>You are given a set of numbers and another number 'x'. You have to find
>> if there exists any two numbers, whose sum is equal to 'x'. I have done this
>> is o(n)log n. Need a more optimized solution.
>>
>> regards,
>> Arun kumar S
>>
>> --
>> 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.
>>
>
>
>
> --
> 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.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Thanking You
Ashish Mishra

-- 
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] palindrome substring

2010-06-18 Thread Avinash Dubey
check two types of palindromes..
even and odd and as soon as u get one. just expand on both sides to get the
longest one..

even palindromes are
arr[i]==arr[i+1]
and odd palindromes are
arr[i]==arr[i=2]

On Fri, Jun 18, 2010 at 9:20 AM, Antony Vincent Pandian.S. <
sant...@gmail.com> wrote:

> I remember this question under discussion recently. Please check the
> existing threads...
>
> On 6/17/10, debajyotisarma  wrote:
> > Find the longest palindrome in the given string.
> > Minimum time-space complexity required
> > (i have not solved it so don't know what is min)
> >
> > --
> > 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.
> >
> >
>
> --
> Sent from my mobile device
>
> Luv,
> S.Antony Vincent Pandian
>
> --
> 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.
>
>


-- 
Avinash Dubey
+91-7799562235

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