Re: [algogeeks] Vertical Sum in a given Binary Tree

2012-03-18 Thread Supraja Jayakumar
Hi
Others are also welcome to comment on the code. If links are allowed in
algogeeks, I might send my wordpress blog link that explains this problem
in detail and in picture.

BinaryTree* VerticalSum(BinaryTree *bt) {
if(!bt) return;
BinaryTree *left = bt-left;
BinaryTree *right = bt-right;
bt-VerticalSumValue += right(left)-value+left(right)-value;
VerticalSum(left);
VerticalSum(right);
}

BinaryTree* right(BinaryTree *left) {
if(!left) return;
sum+=right(left-right);
return sum;
}

BinaryTree *left(BinaryTree *right) {
if(!right) return;
sum+=left(right-left);
return sum;
}

Thanks

Supraja J

On Sun, Mar 18, 2012 at 5:50 AM, rahul sharma rahul23111...@gmail.comwrote:

 plz some one explain...i hav read online but getting the code and same
 explanaiton...need it urgent...thnx in advance


 On Sun, Mar 18, 2012 at 12:38 AM, rahul sharma rahul23111...@gmail.comwrote:

 @anna..plz elaborate more...


 On Sun, Mar 18, 2012 at 12:26 AM, Supraja Jayakumar 
 suprajasank...@gmail.com wrote:

 Hi

 I think its the sum of all the right children of the left subtree and
 left children of the right subtree. (Note: this does NOT apply recursively)

 Thanks


 On Sat, Mar 17, 2012 at 9:31 AM, rahul sharma 
 rahul23111...@gmail.comwrote:

 plz explain...i m nt able to get the concept.


 On Sat, Mar 17, 2012 at 8:50 PM, rahul sharma 
 rahul23111...@gmail.comwrote:

 how come 2,3,7 in vertical sum?


 On Sat, Mar 17, 2012 at 3:48 PM, prashant thorat 
 prashantnit...@gmail.com wrote:

 First , Do recursive traverse from root node and assign vertical
 level for each node. like this,
 for root node level = 0 , root-left level = -1 , root-left-right =
 0 , root-left-left = -2, like this


 so below tree becomes,

   1(0)
/\
 2(-1)3(1)
  /  \   /\
 4(-2)   5(0)  6(1)   7(2)



 After this again, take an array to store sum initialize to 0, and
 traverse tree again , while traversing store the value of that node in 
 it's
 level.

 This way u'll be able to calculate vertical sum.


 Thanks

 On Sat, Mar 17, 2012 at 3:29 PM, rahul sharma 
 rahul23111...@gmail.com wrote:


  what is vertical sum in binayr tree...i dnt need the algo for
 this..just need the concept...that what is vertical sum???

 Given a Binary Tree, find vertical sum of the nodes that are in same
 vertical line. Print all sums through different vertical lines.

 Examples:

   1
 /   \
   2  3
  / \/ \
 4   5  6   7

 The tree has 5 vertical lines

 Vertical-Line-1 has only one node 4 = vertical sum is 4
 Vertical-Line-2: has only one node 2= vertical sum is 2
 Vertical-Line-3: has three nodes: 1,5,6 = vertical sum is 1+5+6 = 12
 Vertical-Line-4: has only one node 3 = vertical sum is 3
 Vertical-Line-5: has only one node 7 = vertical sum is 7

 So expected output is 4, 2, 12, 3 and 7

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




 --
 Yours affectionately,
 Prashant Thorat


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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 algogeeks@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.




 --
 U

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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 algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Vertical Sum in a given Binary Tree

2012-03-17 Thread Supraja Jayakumar
Hi

I think its the sum of all the right children of the left subtree and left
children of the right subtree. (Note: this does NOT apply recursively)

Thanks

On Sat, Mar 17, 2012 at 9:31 AM, rahul sharma rahul23111...@gmail.comwrote:

 plz explain...i m nt able to get the concept.


 On Sat, Mar 17, 2012 at 8:50 PM, rahul sharma rahul23111...@gmail.comwrote:

 how come 2,3,7 in vertical sum?


 On Sat, Mar 17, 2012 at 3:48 PM, prashant thorat 
 prashantnit...@gmail.com wrote:

 First , Do recursive traverse from root node and assign vertical level
 for each node. like this,
 for root node level = 0 , root-left level = -1 , root-left-right = 0
 , root-left-left = -2, like this


 so below tree becomes,

   1(0)
/\
 2(-1)3(1)
  /  \   /\
 4(-2)   5(0)  6(1)   7(2)



 After this again, take an array to store sum initialize to 0, and
 traverse tree again , while traversing store the value of that node in it's
 level.

 This way u'll be able to calculate vertical sum.


 Thanks

 On Sat, Mar 17, 2012 at 3:29 PM, rahul sharma 
 rahul23111...@gmail.comwrote:


  what is vertical sum in binayr tree...i dnt need the algo for
 this..just need the concept...that what is vertical sum???

 Given a Binary Tree, find vertical sum of the nodes that are in same
 vertical line. Print all sums through different vertical lines.

 Examples:

   1
 /   \
   2  3
  / \/ \
 4   5  6   7

 The tree has 5 vertical lines

 Vertical-Line-1 has only one node 4 = vertical sum is 4
 Vertical-Line-2: has only one node 2= vertical sum is 2
 Vertical-Line-3: has three nodes: 1,5,6 = vertical sum is 1+5+6 = 12
 Vertical-Line-4: has only one node 3 = vertical sum is 3
 Vertical-Line-5: has only one node 7 = vertical sum is 7

 So expected output is 4, 2, 12, 3 and 7

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




 --
 Yours affectionately,
 Prashant Thorat


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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 algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Hi

2012-03-12 Thread Supraja Jayakumar
Hi

Yes I will do that. I posted it to interview-str...@googlegroups.com. I do
not find this group's id right. Pls tell me the id to which I have to
subscribe.

Thanks

On Mon, Mar 12, 2012 at 10:09 AM, rahul sharma rahul23111...@gmail.comwrote:

 plz put these on interview street

 On Mon, Mar 12, 2012 at 2:59 AM, Supraja Jayakumar 
 suprajasank...@gmail.com wrote:

 Hi

 Has anyone here given a VMWare interview. Could someone tell me about it.

 Thanks

 --
 U

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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 algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Hi

2012-03-11 Thread Supraja Jayakumar
Hi

Has anyone here given a VMWare interview. Could someone tell me about it.

Thanks

-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Constructing Binary Tree from a sorted Doubly Linked List

2012-02-25 Thread Supraja Jayakumar
Hi All

A sorted doubly linked list is given. We are asked to construct a balanced
binary tree.

I have designed an n^2 solution. Kindly comment on it and also suggest
possible improvements and definitely let me know if something is wrong.

Btree* ConstructTreeFromDLList(DLList *dll) {


// Assuming there is a head and tail
DLLNode *head = dll-head;
DLLNode *tail = dll-tail;

Btree *root = BuildTree(DLList *dll, head, tail);
return root;
}

Btree * BuildTree(DLList *dll, DLLNode * head, DLLNode *tail) {
// Find mid node using two pointers from head and tail.
// Boundary cases - no head ? no tail ? - handle here.
Node *this = head;
Node *that = tail;
int mid = 0;
while(this != that  || this-prev != that || that-next != this) {  //
Until they have not crossed
this=this-next;
that=that-prev;
mid++;
}
printf(“Mid Node Index=%d \n”, mid);
BTree *root = this = that;
root-left = BuildTree(head, that-prev);
root-right = BuildTree(this-next, tail);
return root;
}

Thank You
Supraja J
--
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Finding closest double in a Btree

2012-02-20 Thread Supraja Jayakumar
Hi

Question is given a binary tree and a key K, code to find the node with the
closest value.

I'd be happy to receive some feedback about my solution too.

Pls find the code below:

class FindingClosestNodeInTree {
private static double difference = 0.0;
private static doule key = 0.0;
int main() {
BinaryTree bt;
bt.insert(20.43);
bt.insert(12.78);
bt.insert(19.89);
bt.insert(32.69);
bt.insert(2.54);
cout  Please provide the key value  endl;
cin  key;
const Node closestNode = closestValue(bt);
cout   Node that has the closest value to
closestNode.value;
return 1;
}
const Node  closestValue(const BinaryTree node) {
if(node==null)
return;

int val = node.value;
int currDiff = val  key ? val-key:key-val;
difference = currDiff  difference ? currDiff:difference;
if(node.left!=null)
closestValue(node.left);
if(node.right!=null)
closestValue(node.right);
return difference;
}
}

Thanks
Supraja J

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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: Finding closest double in a Btree

2012-02-20 Thread Supraja Jayakumar
Hi Don,

Thanks for your feedback.

Yea. makes sense to be comparing only right or left.

Thanks All
Supraja

On Mon, Feb 20, 2012 at 9:44 AM, Don dondod...@gmail.com wrote:

 Supraja,

 I think that your solution will work, but it does more work than is
 necessary. You don't need to traverse the entire tree.

 node findClosest(node root, double k)
 {
  node result = root;
  double diff = fabs(root-value - k);
  for(node loc = root; loc; loc = (loc-value  k) ? loc-left : loc-
 right)
  {
double newDiff = fabs(loc-value - k);
if (newDiff  diff)
{
  result = loc;
  diff = newDiff;
}
  }
  return result;
 }

 On Feb 20, 5:24 am, Supraja Jayakumar suprajasank...@gmail.com
 wrote:
  Hi
 
  Question is given a binary tree and a key K, code to find the node with
 the
  closest value.
 
  I'd be happy to receive some feedback about my solution too.
 
  Pls find the code below:
 
  class FindingClosestNodeInTree {
  private static double difference = 0.0;
  private static doule key = 0.0;
  int main() {
  BinaryTree bt;
  bt.insert(20.43);
  bt.insert(12.78);
  bt.insert(19.89);
  bt.insert(32.69);
  bt.insert(2.54);
  cout  Please provide the key value  endl;
  cin  key;
  const Node closestNode = closestValue(bt);
  cout   Node that has the closest value to
  closestNode.value;
  return 1;}
 
  const Node  closestValue(const BinaryTree node) {
  if(node==null)
  return;
 
  int val = node.value;
  int currDiff = val  key ? val-key:key-val;
  difference = currDiff  difference ? currDiff:difference;
  if(node.left!=null)
  closestValue(node.left);
  if(node.right!=null)
  closestValue(node.right);
  return difference;
 
  }
  }
 
  Thanks
  Supraja J

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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: Finding closest double in a Btree

2012-02-20 Thread Supraja Jayakumar
@Don hmm, this problem, though it seems simple, is a bit twisted. probably
because of the double. Thanks for the explanation.

Supraja

On Mon, Feb 20, 2012 at 4:13 PM, Don dondod...@gmail.com wrote:

 Yes, I am assuming a binary search tree. The problem is trivial
 otherwise.
 If it is just a binary tree, you visit each node and keep track of the
 closest.
 Don

 On Feb 20, 5:02 pm, Dave dave_and_da...@juno.com wrote:
  @Don: Aren't you assuming a binary _search_ tree? Only a binary tree
  was specified by the OP.
 
  Dave
 
  On Feb 20, 10:44 am, Don dondod...@gmail.com wrote:
 
 
 
   Supraja,
 
   I think that your solution will work, but it does more work than is
   necessary. You don't need to traverse the entire tree.
 
   node findClosest(node root, double k)
   {
 node result = root;
 double diff = fabs(root-value - k);
 for(node loc = root; loc; loc = (loc-value  k) ? loc-left :
 loc-right)
 
 {
   double newDiff = fabs(loc-value - k);
   if (newDiff  diff)
   {
 result = loc;
 diff = newDiff;
   }
 }
 return result;
 
   }
 
   On Feb 20, 5:24 am, Supraja Jayakumar suprajasank...@gmail.com
   wrote:
 
Hi
 
Question is given a binary tree and a key K, code to find the node
 with the
closest value.
 
I'd be happy to receive some feedback about my solution too.
 
Pls find the code below:
 
class FindingClosestNodeInTree {
private static double difference = 0.0;
private static doule key = 0.0;
int main() {
BinaryTree bt;
bt.insert(20.43);
bt.insert(12.78);
bt.insert(19.89);
bt.insert(32.69);
bt.insert(2.54);
cout  Please provide the key value  endl;
cin  key;
const Node closestNode = closestValue(bt);
cout   Node that has the closest value to
closestNode.value;
return 1;}
 
const Node  closestValue(const BinaryTree node) {
if(node==null)
return;
 
int val = node.value;
int currDiff = val  key ? val-key:key-val;
difference = currDiff  difference ? currDiff:difference;
if(node.left!=null)
closestValue(node.left);
if(node.right!=null)
closestValue(node.right);
return difference;
 
}
}
 
Thanks
Supraja J- 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 algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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: Finding closest double in a Btree

2012-02-20 Thread Supraja Jayakumar
:) Apologize for the mistake - it is a BST.

Thank You

On Mon, Feb 20, 2012 at 7:46 PM, Gene gene.ress...@gmail.com wrote:

 The topic of the discussion is:

 Finding closest double in a Btree

 A binary tree that is also a B-Tree is (roughly) a Binary Search
 Tree.



 On Feb 20, 9:37 pm, Dave dave_and_da...@juno.com wrote:
  @Gene: I don't know what is confusing about the OP's problem
  statement:
 
  Question is given a binary tree and a key K, code to find the node
  with the
  closest value.
 
  What do you find confusing about that?
 
  Are you opposed to using shorthand in the subject line that is then
  clarified in the body of the posting?
 
  Dave
 
  On Feb 20, 8:19 pm, Gene gene.ress...@gmail.com wrote:
 
 
 
 
 
 
 
   Sure the algorithm works for any binary tree, but a B-Tree is a more
   general data structure. So the problem statement is confusing.  This
   is probably the reason some people gave alternatives that only work
   with a BST.  A BST is a special case of a B-Tree.
 
   On Feb 20, 8:58 pm, saurabh singh saurab...@gmail.com wrote:
 
@gene probably you are saying this on the basis of the subject of the
mail?Please read the problem statement stated in the mail.Even its
  a B
tree doesn't effects the algorithm proposed by don which says
 *traverse
each node and keep track of minimum.*
So irrespective of the data structure used this solution is bound to
work
closest:
arguments: dataStructure T,int number
 
tmp:=getelem(T);
min=tmp.value
while( getelem returns non null values)
 do
 nxt:=getelem(T);
 
if(abs(nxt.value-number)min) then
tmp=nxt
min=nxt.value
done
 
done
 
return tmp
 
The nextelem function can be written according to the data structure
 used.
 
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com
 
On Tue, Feb 21, 2012 at 6:06 AM, Gene gene.ress...@gmail.com
 wrote:
 Not to mention the subject line seems to be asking about B-Trees,
 which is no kind of binary tree, so the OP gets it wrong, too.
 
 On Feb 20, 7:28 pm, Dave dave_and_da...@juno.com wrote:
  @Don: By that measure, it also is trivial if the tree is a BST.
 You
  just find the largest node  x and the smallest one  x and
 choose
  between them.
 
  But since the original problem did not specify a BST, your
 solution is
  non-responsive. If I were grading a test, I'd have to count your
  solution as wrong, figuring that you do not know the difference
  between a binary tree and a binary search tree.
 
  Dave
 
  On Feb 20, 5:13 pm, Don dondod...@gmail.com wrote:
 
   Yes, I am assuming a binary search tree. The problem is trivial
   otherwise.
   If it is just a binary tree, you visit each node and keep
 track of the
   closest.
   Don
 
   On Feb 20, 5:02 pm, Dave dave_and_da...@juno.com wrote:
 
@Don: Aren't you assuming a binary _search_ tree? Only a
 binary tree
was specified by the OP.
 
Dave
 
On Feb 20, 10:44 am, Don dondod...@gmail.com wrote:
 
 Supraja,
 
 I think that your solution will work, but it does more
 work than is
 necessary. You don't need to traverse the entire tree.
 
 node findClosest(node root, double k)
 {
   node result = root;
   double diff = fabs(root-value - k);
   for(node loc = root; loc; loc = (loc-value  k) ?
 loc-left :
 loc-right)
 
   {
 double newDiff = fabs(loc-value - k);
 if (newDiff  diff)
 {
   result = loc;
   diff = newDiff;
 }
   }
   return result;
 
 }
 
 On Feb 20, 5:24 am, Supraja Jayakumar 
 suprajasank...@gmail.com
 wrote:
 
  Hi
 
  Question is given a binary tree and a key K, code to
 find the
 node with the
  closest value.
 
  I'd be happy to receive some feedback about my solution
 too.
 
  Pls find the code below:
 
  class FindingClosestNodeInTree {
  private static double difference = 0.0;
  private static doule key = 0.0;
  int main() {
  BinaryTree bt;
  bt.insert(20.43);
  bt.insert(12.78);
  bt.insert(19.89);
  bt.insert(32.69);
  bt.insert(2.54);
  cout  Please provide the key value  endl;
  cin  key;
  const Node closestNode = closestValue(bt);
  cout   Node that has the closest value to  
  
  closestNode.value;
  return 1;}
 
  const Node  closestValue(const BinaryTree node) {
  if(node==null)
  return;
 
  int val = node.value;
  int currDiff = val  key ? val-key:key-val;
  difference = currDiff  difference ? currDiff:difference;
  if(node.left!=null

Re: [algogeeks] MS Question

2012-01-12 Thread Supraja Jayakumar
Hi

Normal string will not work I think. Because it is avriable length encoding
scheme.

On Fri, Jan 13, 2012 at 11:11 AM, b.kisha...@gmail.com b.kisha...@gmail.com
 wrote:

 Is there anything called in-place reversal ??
 UTF-8 is only encoding similar to ASCII but with a huge charecter set.
 So normal string reversal would work fine..



 On Thu, Jan 12, 2012 at 2:02 AM, Ankur Garg ankurga...@gmail.com wrote:

 How to do this

 Write a function to reverse a UTF-8 encoded string in-place ??



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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 algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Microsoft Internship

2011-08-02 Thread Supraja Jayakumar
Hi

I want to know if I should be thorough C and C++ and Java.
My kind of rusty with C now. I am brushing my C++ because
they say MS prefers you code in C++ than Java.
But C ?

Cheers
Supraja J

On Tue, Aug 2, 2011 at 2:33 AM, Anu anu.anurag@gmail.com wrote:

 Microsoft visited our campus today , an advice for everybody preparing
 for it , make sure you know all the recently asked questions(posted on
 algogeeks) , they repeat some questions .

 Written Round:
 objective round , 30 minutes , 10 questions(easy) .
 subjective round , 45 minutes , 2 questions (easy)

 The questions of subjective round were
 1.Find the first non repeating character in a string , do it in O(n)
 time and O(1) space , use one bit per character for checking
 repeatedness.
 2.Write test cases for find and replace function of notepad .

 The questions of objective round were:
 1.Some address calculation in array
 2.Input-Output
 3.A question involving classes , we were asked what a function was
 doing ( very simple )
 4.A question involving some set operations
 5.Find the percentage of occupancy in a disk ( this is the one that
 was repeated )
 6.A question involving the use of scanset in scanf .
 7.What gcc stands for ( yes , they actually asked it )
 8.A function involving use of this statement (int)(x + 0.5) , again a
 repeated question :)

 Thats all i remember :)

 Anurag Atri
 Delhi College Of Engineering

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] [offtopic] Something to share for those preparing for Amazon Campus Interviews!

2011-08-01 Thread Supraja Jayakumar
Thanks Rahul. Very kind of you.
I wish you crack Google.

All the best !

Best
Supraja J

On Thu, Jul 28, 2011 at 6:24 AM, Rahul Menon menonrahul1...@gmail.comwrote:

 Hello friends,

 Recently I appeared for placement interviews for Amazon in my
 campus.Unfortunately though I couldn't make it, still want to share
 something for others here preparing for amazon interviews!

 First of all though it is very hard to crack, here are a few things
 which can make your preparation easier and effective!

 In the interview, I have found that most of the questions asked are
 repeated questions which are available online rather than any new
 questions they have made. A few examples are loop in a linked list,
 print all permuations of a string, binary search in a rotated array
 etc.. These all questions are very commonly found in websites like
 careercup.com and also in this google group. Instead of just going
 through hundreds of question be sure that you can perform the best of
 100% if you are given from these frequently asked questions.

 Just to add, if you are very good in coding it's fine , else make sure
 that you can also code these above questions very well rather than
 just explaining the algos!. They will definitely ask you to code
 these!

 In  Cracking the coding interview all the questions are very very
 important. To my astonishment most of the questions in the sections
 like Linked LIsts, Arrays, Trees and Graph, Recursion from the
 aforesaid book were asked in our interview!  So never miss reading and
 coding these questions before going to your interview.

 Though it's very weird to say, I would say that if you are very very
 good with these around 40 most frequently repeated questions, which
 can be collected through googling, your performance is almost 80%
 guaranteed in the interview. It's sure that you will have to face only
 a very few question outside from this. And if you are somewhat more
 good enough , you can easily make through to the AMAZON!

 All the best for all :)
 Repeating once again, rather than just reading through hundreds of
 questions it would be best if you practice coding and studying the few
 30 interview questions! Else you will have to regret like me :|


 #We will be having Google on our campus soon! I'm totally strange to
 their selection process,tests and intreview, so if anyone have any
 idea please do share here! Thanks!

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Hi

2011-06-14 Thread Supraja Jayakumar
Hi All

I tried going through the code here for constructing suffix tires -
http://marknelson.us/1996/08/01/suffix-trees/

But I am not sure I get it well. If its ok, can we discuss this
implementation.

Thanks
Supraja J

-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] MS Question

2011-06-13 Thread Supraja Jayakumar
Question:

An array is of size N with integers between 0 and 1024(repetitions allowed).
Another array of integers is of size M with no constraints on the numbers.
Find which elements of first array are present in the second array. (If you
are using extra memory, think of minimizing that still, using bitwise
operators)

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] a doubt..

2011-06-13 Thread Supraja Jayakumar
Is it right to say iteration is resource(time) intensive and recursion is
not. On
the other hand, recursion is space intensive (with stacks) and iteration is
not ?

Thanks

On Mon, Jun 13, 2011 at 2:08 PM, ADITYA KUMAR aditya...@gmail.com wrote:

 its always better to have iterative program than recursive
 since iterative program doesn't rely on system stack..
 but recursive program are easy to write and gives a clear view of program


 On Tue, Jun 14, 2011 at 1:13 AM, snehi jain snehijai...@gmail.com wrote:

 hi,
 we try to implement many programs using Recursion
 and its said that this is better than iterative procedure.

 if i am right then
 i cant understand why is it so?
  can anybody explain ...
 and are there situations when iterative procedure is better than
 recursion.


 Snehi

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




 --
 Regards
 Aditya Kumar
 B-tech 3rd year
 Computer Science  Engg.
 MNNIT, Allahabad.

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Swapping two variables without using a temporary variable

2011-06-13 Thread Supraja Jayakumar
@Wladimir:
Can you kindly explain the overflow and underflow you mentioned.

Thanks
Supraja J

On Fri, Jun 10, 2011 at 9:58 PM, Wladimir Tavares wladimir...@gmail.comwrote:

 Swapping two variables without using a temporary variable using the + and
 -:

 x = a;
 y = b;

 x = x + y / / x = a + b;
 y = x - y / / y = a + b-b = a;
 x = x - y / / x = a + b-a = b;

 y = b;
 x = a;

 Problems with this approach:
 1) It can cause overflow in the operation (+)
 2) It can cause underflow on operation (-)

 Swapping two variables without using variables
 Temporary using XOR:

 x = a;
 y = b;

 x = x ^ y;
 y = x ^ y / / y = (x xor y) xor y = x xor (y xor y) xor x = 0 = x
 x = x ^ y / / x = (x xor y) xor x = (x xor y) xor y xor x = (x xor x) = y
 xor y = 0

 Note that we use some properties of XOR:

 1) Associativity
 2) Commutativity
 3) X = X 0 XOR

 We have no problems neither underflow nor overflow!

 Wladimir Araujo Tavares
 *Federal University of Ceará

 *



 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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: MS Interview

2011-06-12 Thread Supraja Jayakumar
Hi

But does this work on bigger numbers ?

I mean with [11-15] say 14 is missing.

It is:

1011
1100
1101


0101
---
which is 5 ?

Supraja J

On Sat, Jun 11, 2011 at 8:14 AM, Wladimir Tavares wladimir...@gmail.comwrote:

 You can use the same idea:

 Suppose you want to find out what the missing number in the list [1 .. 5]:
   1 = 001
   2 = 010
   3 = 011
   4 = 100
   5 = 101
 XOR = 001

 If the number 4 is missing:
   XOR = 001
   1 = 001
   2 = 010
   3 =
 011
   4 = 100
   5 = 101
   3 = 011
 XOR = 011


 Wladimir Araujo Tavares
 *Federal University of Ceará

 *




 On Thu, Jun 9, 2011 at 8:34 AM, Ashim Kapoor ashimkap...@gmail.comwrote:

 Could someone illustrate the XOR for question 2. I am a beginner to this.

 Many thanks!


 On Thu, Jun 9, 2011 at 4:58 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 Xoring it twice ...once with the elements in the file and then from i=1
 to 4,000,000,000..the answer left is the missing number

 On Thu, Jun 9, 2011 at 4:46 PM, Dumanshu duman...@gmail.com wrote:

 I dont think numbers are sorted in the 1st question. btw
 @sunny: how will xor-ing give the ans? for 1st ques?


 On Jun 9, 3:34 pm, sunny agrawal sunny816.i...@gmail.com wrote:
  yes, but using xor no need of ULL :)
 
  2011/6/9 • » νιρυℓ « • vipulmehta.1...@gmail.com

 
 
 
 
 
 
 
 
 
   Sum wont overflow, ULL range will include sum.
 
   On Thu, Jun 9, 2011 at 3:52 PM, sunny agrawal 
 sunny816.i...@gmail.comwrote:

 
   sum can overflow
   Xor method can also be applied to Q1. no need of numbers to be
 sorted.
 
   2011/6/9 • » νιρυℓ « • vipulmehta.1...@gmail.com

 
   For 1.
   sum the numbers in the file, subtract it from sum of first 4
 billion
   numbers.
 
   On Thu, Jun 9, 2011 at 3:44 PM, Navneet Gupta 
 navneetn...@gmail.comwrote:

 
   The answer to second question is simple. XORing all the elements
   should do it for you.
 
On Thu, Jun 9, 2011 at 3:15 PM, Dumanshu duman...@gmail.com
 wrote:
Q1. I  have a file in which there are supposed to be 4 billion
numbers,
starting from 1 to 4,000,000,000 but unfortunately one number
 is
missing,
i.e there are only 3,999,999,999 numbers, I need to find the
 missing
number.
 
Q2.  I have an array consisting of 2n+1 elements. n elements in
 it are
married, i.e they occur twice in the array, however there is
 one
element
which only appears once in the array. I need to find that
 number in a
single pass using constant memory. {assume all are positive
 numbers}
Eg :- 3 4 1 3 1 7 2 2 4
Ans:- 7
 
--
You received this message because you are subscribed to the
 Google
   Groups Algorithm Geeks group.
To post to this group, send email to
 algogeeks@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.
 
   --
   --Navneet
 
   --
   You received this message because you are subscribed to the
 Google
   Groups Algorithm Geeks group.
   To post to this group, send email to algogeeks@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.
 
   --
   Regards,
   Vipul
 
--
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@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.
 
   --
   Sunny Aggrawal
   B-Tech IV year,CSI
   Indian Institute Of Technology,Roorkee
 
--
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@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.
 
   --
   Regards,
   Vipul
 
--
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@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.
 
  --
  Sunny Aggrawal
  B-Tech IV year,CSI
  Indian Institute Of Technology,Roorkee

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 

[algogeeks] Cloud Project

2011-06-12 Thread Supraja Jayakumar
Hi All

Can someone suggest a simple application that I can develop and host on
Azure.
I have very little web based programming experience and have some knowledge
with
.net but nothing major.
I am trying to do a small nice project using azure but not sure about the
application.

Thanks
Supraja J

-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] How to remove duplicate element from array in one pass.

2011-06-02 Thread Supraja Jayakumar
Hi

Mere removal is enough ? Shifting not necessary ?

If yes, then

we can have something like this. But let me know if this sounds ok and any
further improvements.

int chars = new int[256];
int values = new int[10]; // say 10 chars
for(i = 0; i  10; i++) {
int charVal = toascii(values[i]);
chars[charValue]++;
if(chars[charValue]  1)
  // remove from array.
  values[i] = 0; // some other sentinel value ?
}


Rgds
Supraja J

On Thu, Jun 2, 2011 at 12:19 PM, D.N.Vishwakarma@IITR deok...@gmail.comwrote:

 better than O(n2) algo

 --
 **With Regards
 Deoki Nandan Vishwakarma
 IITR MCA
 Mathematics Department*
 *

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] How to remove duplicate element from array in one pass.

2011-06-02 Thread Supraja Jayakumar
Hi

Inserting into BST and break on same element will detect duplicates.
But in any case, this is still O(2n) ? - once for inserting them in to the
tree
and another for the inorder read.

Correct me if wrong.

Rgds
Supraja J

On Thu, Jun 2, 2011 at 1:11 PM, Harshal hc4...@gmail.com wrote:

 @Anurag: XOR wont work here, 1 element is repeated, not 1 element is
 unique. Read the question again.

 Keep inserting elements in a BST and break once you find the same element.
 O(nlogn)


 On Fri, Jun 3, 2011 at 12:38 AM, Anurag Narain anuragnar...@gmail.comwrote:

 take X-OR of all the elements.the one which has no duplicate will be
 left and rest all will be reduced to zero.

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




 --
 Harshal Choudhary,
 III Year B.Tech CSE,
 NIT Surathkal, Karnataka, India.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] How to remove duplicate element from array in one pass.

2011-06-02 Thread Supraja Jayakumar
Hi

I think multi hash table will solve this problem.

Thanks
Supraja J

On Thu, Jun 2, 2011 at 1:37 PM, Harshal hc4...@gmail.com wrote:

 But I think the solution required is O(n) (one pass). So, O(nlogn) is not
 what the author wants anyway. Hashing is an option but we dont know the
 range of the elements in the array. So, in case when all keys hash into the
 same place, the worst case is still O(n^2).
 suppose our hash function is h(n) = n mod 10.
 array: 2,12,32,52,42.



 On Fri, Jun 3, 2011 at 1:01 AM, Harshal hc4...@gmail.com wrote:

 you can check if the element to be inserted next is same as the node value
 while inserting itself. Why to do a separate inorder traversal..


 On Fri, Jun 3, 2011 at 12:56 AM, Supraja Jayakumar 
 suprajasank...@gmail.com wrote:

 Hi

 Inserting into BST and break on same element will detect duplicates.
 But in any case, this is still O(2n) ? - once for inserting them in to
 the tree
 and another for the inorder read.

 Correct me if wrong.

 Rgds
 Supraja J


 On Thu, Jun 2, 2011 at 1:11 PM, Harshal hc4...@gmail.com wrote:

 @Anurag: XOR wont work here, 1 element is repeated, not 1 element is
 unique. Read the question again.

 Keep inserting elements in a BST and break once you find the same
 element. O(nlogn)


 On Fri, Jun 3, 2011 at 12:38 AM, Anurag Narain 
 anuragnar...@gmail.comwrote:

 take X-OR of all the elements.the one which has no duplicate will
 be left and rest all will be reduced to zero.

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




 --
 Harshal Choudhary,
 III Year B.Tech CSE,
 NIT Surathkal, Karnataka, India.


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




 --
 U

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




 --
 Harshal Choudhary,
 III Year B.Tech CSE,
 NIT Surathkal, Karnataka, India.





 --
 Harshal Choudhary,
 III Year B.Tech CSE,
 NIT Surathkal, Karnataka, India.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Design questions practice

2011-06-02 Thread Supraja Jayakumar
Hi

Design patterns by Erich Gamma ?

Supraja J

On Thu, Jun 2, 2011 at 3:02 PM, Sachin Agarwal sachinagarwa...@gmail.comwrote:

 Hi,
 Can someone recommend me good resources (books/websites etc.) for
 design interview questions.

 Thanks

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Reversing a string

2011-05-31 Thread Supraja Jayakumar
Hi

Pls see below. This is only with indexing. I am not sure how to do it w/o
indexing if its not a C-style string or w/o pointer arithmetic.
Pls let me know if there is such a technique. I would be very eager to know.

Thanks.

#includestdio.h
#includestring.h

void reverse(char s[]) {

int len = sizeof(s)/sizeof(char);
printf(%d\n,  len);
if(len == 1 || len == 0)
  return;
int i,j;
for(i = 0, j = len-1; i  len, j = 0; i++, j--) {
 if(i =j)
break;
char temp = s[i];
s[i] = s[j];
s[j] = temp;
printf(%c%c\n, s[i], s[j]);
}
}

int main() {
char s[7] = {'a','b','x','c', 'l', 'm', 'y'};
reverse(s);
int i;
for(i = 0; i  7;  i++)
printf(%c, s[i]);
return 0;
}


On Tue, May 31, 2011 at 12:04 PM, nagajyothi gunti 
nagajyothi.gu...@gmail.com wrote:

 Hope this logic looks better.
 class Program
 {
 static void Main(string[] args)
 {
 string str = string;
 char[] char_str=str.ToCharArray();
 char temp;
 int string_length = char_str.Length;
 int mid = string_length / 2;
 int j=0;
 for(int i=0;imid;i++){
 j = str.Length-1-i;
 temp = char_str[i];
 char_str[i] = char_str[j];
 char_str[j] = temp;
 }

 Console.Write(char_str.ToString());

 Console.Read();

 }
 }

 On Sat, May 28, 2011 at 7:53 AM, adityasir...@gmail.com wrote:

 In java you can do this, take O(n) time. Is that correct?

 -Adi

 public class ReverseString {

 public static void main(String[] args){
  String name = Aditya;
 String reverse = ;
  for(int i=0;iname.length();i++){

   System.out.println(name.charAt(i) + reverse);
   reverse = name.charAt(i) + reverse;
   }
 }
 }


 On Sat, May 28, 2011 at 6:40 AM, abc abc may.i.answ...@gmail.com wrote:

 *Given an array of characters. How would you reverse it. ? How would you
 reverse it without using indexing in the array.*
 *
 *

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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 algogeeks@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.




 --
 Jyothi

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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 online test

2011-05-27 Thread Supraja Jayakumar
Hi All

Is this online test open to all aspirants ie.., is it a screening or only to
filtered candidates ?
Can I take it as for practice ?

Please tell me more about it.

Thanks
Supraja J

On Fri, May 27, 2011 at 12:27 AM, balaji a peshwa.bal...@gmail.com wrote:

 I actually attended on-campus through my college...

 On 26 May 2011 16:24, jagannath prasad das jpdasi...@gmail.com wrote:

 how to register for amazon ol exm .can  you plz mention ?

 On Sun, Apr 24, 2011 at 6:46 PM, balaji a peshwa.bal...@gmail.com wrote:

 
  yeah i did.,...there were two section
  Section 1 - some aptitude question + predicting output ...

 --

  You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group



 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks gr...

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Google Interview Question

2011-05-27 Thread Supraja Jayakumar
Hi

Isnt this the Kadane's (largest subarray) problem ?

Rgds
Supraja J

On Fri, May 27, 2011 at 9:41 AM, anshu mishra anshumishra6...@gmail.comwrote:

 @all go through this code

 #includeiostream
 #includealgorithm

 using namespace std;
 bool compare(int a, int b)
 {
 string u, v;
 u = v = ;
 while (a)
 {
 u += (a % 10 + '0');
 a/=10;
 }
 while (b)
 {
 v += (b % 10 + '0');
 b/=10;
 }
 int i = 0, j = 0;
 reverse(u.begin(), u.end());
 reverse(v.begin(), v.end());
 while (i  u.size() || j  v.size())
 {
 if (i == u.size()) i = 0;
 if (j == v.size()) j = 0;
 for (; i  u.size()  j  v.size(); i++, j++)
 {
 if (u[i] == v[j]) continue;
 return (u[i]  v[j]);
 }
 }
 if (u.size() == v.size()) return true;
 }
 int main()
 {
 int n;
 cin  n;
 int ar[n];
 int i;
 for (i = 0; i  n; i++)
 {
 cin  ar[i];
 }
 sort (ar, ar +n, compare);
 for (i = 0; i  n; i++) cout  ar[i];
 cout  endl;
 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 algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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] Problem

2011-05-11 Thread Supraja Jayakumar
isnt this  a DP problem ?
I think its there in CLRS.

Let me know.

Cheers
Supraja J

On Wed, May 11, 2011 at 7:55 AM, Harshit Gangal harshit.gan...@gmail.comwrote:

 How can we calculate the number of divisors a number have in minimum time
 or having minimum Time Complexity.

 --
 Harshit Gangal
 Fourth Year Undergraduate Student
 Dept. of Computer Science
 JIIT, Noida , India

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@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.




-- 
U

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.