[algogeeks] NEW PAGES ARE WAITING FOR YOU!!!! CLICK HERE!!!!

2010-06-15 Thread kiruthiga viji

http://123maza.com/25/data759/


-- 
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] Cycle in Undirected and Directed Graphs

2010-06-15 Thread Vivek Sundararajan
@above:

Any Undirected Graph trivially has a cycle!

Consider any two adjacent vertex A and B, I can go from A to B and then from
B to A (since they are connected by an undirected edge).

Hence, any Undirected Graph trivially has a cycle.

Any contradictory views? please let me know :)

Thank you,
Vivek.S

On 14 June 2010 06:49, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:

 In any directed graph just check if dfs has a back edge. For
 undirected, check if there is a nontree edge

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

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] unique number in an array

2010-06-15 Thread Sundeep Singh
use a hash map

On Mon, Jun 14, 2010 at 12:14 AM, jalaj jaiswal
jalaj.jaiswa...@gmail.comwrote:

 give an algo to find a unique number in an array

 for eg a[]={1,3,4,1,4,5,6,1,5}

 here 3 is the unique number as it occur only once... moreover array
 contains only 1 unique number



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


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Mirroring Binary Tree Pattern Problem

2010-06-15 Thread divya jain
This C code will create a new mirror copy tree.
mynode *copy(mynode *root)
{
mynode *temp;
if(root==NULL)return(NULL);
temp = (mynode *) malloc(sizeof(mynode));
temp-value = root-value;
temp-left = copy(root-right);
temp-right = copy(root-left);
return(temp);
}

On 13 June 2010 17:07, BALARUKESH SIVARAMAN sbalarukesh1...@gmail.comwrote:

 try this one..
 make a level order traversal and store the elements in array... on the
 other system reconstruct it using right element for the left and left
 element for the right...

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] stack

2010-06-15 Thread Anurag Sharma
Why not just pop all elements from stack ( O(n) )  and insert it in a self
balancing Binary Search Tree (like RB Tree) (O(log(n) ) and then do and
inorder traversal ( O(n) )and push elements in stack again.
Time = O(nlog(n) + n)
Space=O(n) (for storing the tree)

Anurag Sharma


On Sun, Jun 13, 2010 at 9:25 PM, Jitendra Kushwaha jitendra.th...@gmail.com
 wrote:

 Stack can be sorted in O(n^2).

 @sankalp:
  Stack can always be sorted. Why do you think it cant be in some cases ?

 One can think like insertion sort
 algo :
 1. for i in (1,n)
   2. Pop up the top n-1 element and keep nth element in global variable say
 hold
   3. while pushing get the position for hold and push it there

 for loop will take O(n) and step 2 will take take O(n) time. So overall
 O(n^2) complexity
 Program can be done with recursion using a variable (hence O(1) space). But
 it will use system stack :)


 Any comments OR better solution is welcomed??

 --
 Regards
 Jitendra Kushwaha
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] unique number in an array

2010-06-15 Thread Anurag Sharma
Are all the numbers within some given range?
If so then keep a count of all and later find out the non repeating one.

otherwise, make  a balanced BST and insert every element in it and increment
the counter of the node if already present in the tree and then do inorder
traversal to find out the non repeating element.

Anurag Sharma


On Sun, Jun 13, 2010 at 11:44 PM, jalaj jaiswal
jalaj.jaiswa...@gmail.comwrote:

 give an algo to find a unique number in an array

 for eg a[]={1,3,4,1,4,5,6,1,5}

 here 3 is the unique number as it occur only once... moreover array
 contains only 1 unique number



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


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] trees

2010-06-15 Thread Anand
Here is an implementation for BST and search an element in BST in O(logn )
time

On Sun, Jun 13, 2010 at 8:04 PM, Lekha lek...@gmail.com wrote:

 Inorder traversal till u reach the kth element(If it is sorted in
 descending order, otherwise go till (n-k)th element)..


 On Sun, Jun 13, 2010 at 9:24 PM, Rohit Saraf 
 rohit.kumar.sa...@gmail.comwrote:

 Repeated q. Search in the group

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

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Lekha

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Towers of hanoi

2010-06-15 Thread Jitendra Kushwaha
Even your own stack will give TLE :)
Try solving this question with binary solution of tower of hanoi and you
will definately pass the time limit.

-- 
Regards
Jitendra Kushwaha
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 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 doubt

2010-06-15 Thread Anand
Uninitialized global variables are stored in .bss section of the process
memory and initialised global variables are stored in .data section of the
memory. In the linking stage, they get the actually physical address. But
since x and y are local variables they are just stored in stack while
execution and will get flushed out later from stack after its execution. So
they don't have any physical address for debugging.

On Sat, Jun 12, 2010 at 1:22 AM, amit amitjaspal...@gmail.com wrote:

 OS doubt:

 I have read many times that say a 24 KB process enters the Main Memory
 selected by the Long Term Scheduler.
 But I don't understand what it exactly means.
 As far as I know Process consists of ( Code + Data(Static) +
 Stack(Local Data) + Heap)

 So doubt1: Is this 24 KB the size of this whole process or just the
 size of the code segment.

 doubt2: Now lets say this process starts getting executed by the
 CPU ,Suppose the main() contains
main(){
int x;
int y;
x=10;
...
}
So x,y will be allocated the memory in the Stack.
But when x=10 is encountered , how will the CPU know the
 address of
 x. In short how is x accessed??


 doubt 3: If x and y are just address of a memory location in the
 stack , can their logical address be determined by the compiler or it
 will be generated by the CPU??

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] trees

2010-06-15 Thread sharad kumar
On Mon, Jun 14, 2010 at 8:35 AM, sharad kumar sharad20073...@gmail.comwrote:

 @rohit..i m not able to find this ques in this group so plzz help

-- 
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] towers of hanoi O(1) time

2010-06-15 Thread ANUJ KUMAR
how can we print the reconstructed configuration of the towers after k
steps in towers of hanoi problem in O(1) time.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] tower of hanoi variation

2010-06-15 Thread Anurag Sharma
I think there should be additional constraint added that atmost 1 disk can
be placed in ground. Otherwise one can place all disks on ground and put
them in order in the last peg :D

Anurag Sharma

On Mon, Jun 14, 2010 at 2:01 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote:

 give the algorithm for toi if... the a disk can be placed on top the disk
 just larger then it and on the ground..

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


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] unique number in an array

2010-06-15 Thread Chonku
xor all the elements. Similar elements would become 0. Remaining would be
unique element.

On Mon, Jun 14, 2010 at 12:14 AM, jalaj jaiswal
jalaj.jaiswa...@gmail.comwrote:

 give an algo to find a unique number in an array

 for eg a[]={1,3,4,1,4,5,6,1,5}

 here 3 is the unique number as it occur only once... moreover array
 contains only 1 unique number



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


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Towers of hanoi

2010-06-15 Thread Anurag Sharma
Use iterative version :http://en.wikipedia.org/wiki/Tower_of_Hanoi

Anurag Sharma

On Mon, Jun 14, 2010 at 12:36 AM, ANUJ KUMAR kumar.anuj...@gmail.comwrote:

 http://www.spoj.pl/problems/HAN01/
 i implemented it using stack but am getting tle someone please help

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Array Increment Problem

2010-06-15 Thread Anand
Using Segment tree below is the implementation.

http://codepad.org/5jVxLmsA

On Sat, Jun 12, 2010 at 6:14 AM, Jitendra Kushwaha jitendra.th...@gmail.com
 wrote:

 This is direct question of segment tree. read the topcoder's tutorial for
 segment tree



 --
 Regards
 Jitendra Kushwaha
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: union- c

2010-06-15 Thread jaladhi dave
I second this opinion. Lets keep discussion limited to algorithms only.

On Mon, Jun 14, 2010 at 5:47 AM, Roshan Mathews rmath...@gmail.com wrote:

 On Sun, Jun 13, 2010 at 18:36, souravsain souravs...@gmail.com wrote:
  Lets keep discussions in t his group limited to Algos and problems
  neutral to any language.
 
 Yes, please.

 --
 http://roshan.mathews.in/

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] trees

2010-06-15 Thread divya jain
reverse in order traversal till u reach kth node. reverse inorder means
first visit right child then print data nd then left.

On 14 June 2010 08:34, Lekha lek...@gmail.com wrote:

 Inorder traversal till u reach the kth element(If it is sorted in
 descending order, otherwise go till (n-k)th element)..


 On Sun, Jun 13, 2010 at 9:24 PM, Rohit Saraf 
 rohit.kumar.sa...@gmail.comwrote:

 Repeated q. Search in the group

 --
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombay
 http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Lekha

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: bits

2010-06-15 Thread Anurag Sharma
@jalaj
endian specific.

Anurag Sharma

On Sun, Jun 13, 2010 at 11:54 PM, Modeling Expert 
cs.modelingexp...@gmail.com wrote:

 @jalaj

 Yes , this is endian ness specific. On windows/x86 linux which are
 little endian, ch[0] would be lower 8 bits. On solaris/power pc which
 are big endian this would be upper 8 bits. e.g.
 union a temp;
 temp.i = 0x12345678   //! here big end is 0x12 and little end is 0x78
 then temp.ch[0] = 78 //! Little end first for little endian

 and temp.ch[0] = 0x12 for big endian



 On Jun 13, 9:18 pm, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
  hey i too have a doubt... and its just 1 ... i'll not ask c/c++ again,,,
 
  we have a union a{
 int i;
 char ch[4];
  }
  int here is of 4 bytes.
  i initialise i=512...
  what value will ch[0] get the upper 8 bits or the lower 8 bits... is it
 big
  endian or little endian dependent... please explain this ??
 
  On Sun, Jun 13, 2010 at 9:43 PM, Rohit Saraf 
 rohit.kumar.sa...@gmail.comwrote:
 
 
 
   I agree mass bombarding with such questions is not very good.. but one
   doesn't join groups and all for getting a few doubts cleared.
   Anyways, i have no problem with anything. :D
 
   --
   Rohit Saraf
   Second Year Undergraduate,
   Dept. of Computer Science and Engineering
   IIT Bombay
  http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14
 http://www.cse.iitb.ac.in/%7Erohitfeb14
 
   On Sun, Jun 13, 2010 at 9:26 PM, souravsain souravs...@gmail.com
 wrote:
 
   and @rohit you will get better insight into the topic by more expert
   people by posting the question in right forum. I guess thats a win-win
   situation for one who has the question as he is get to know more and
   for people you are interested in going through C++ questions as they
   will read views from many more experts :)
 
   On Jun 13, 7:31 pm, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
@Souravsain : Is there any serious problem in this. Anyone can just
 add
   a
[C++] in the subject and uninterested people can make filters in
 gmail
   :)
 
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT 
Bombayhttp://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14
 http://www.cse.iitb.ac.in/%7Erohitfeb14
 
On Sun, Jun 13, 2010 at 6:35 PM, souravsain souravs...@gmail.com
   wrote:
 @divya
 
 Lets keep discussions in t his group limited to Algos and problems
 neutral to any language.
 
 Request you to post these C++ / C language specific questions to
 those
 language specific groups. This will not only help this group
 remain
 confined to its core purpose but will help you get better insights
 to
 ur problem by language specific geeks there. For C++ I would
 recommend
 you to try the group

 http://groups.google.co.in/group/comp.lang.c++.moderated/topics?hl=en.
 
 Regards,
 Sourav
 
 On Jun 13, 2:29 pm, divya sweetdivya@gmail.com wrote:
  tell the o/p of following with explanations
 
  1. #includestdio.h
  int main()
  {
struct value
  {
  int bit1:1;
  int bit3:4;
  int bit4:4;
 
  }bit;
 
  printf(%d\n,sizeof(bit));
  return 0;
 
  }
 
  2.
  #includestdio.h
  int main()
  {
  struct value
  {
  int bit1: 1;
  int bit3: 4;
  int bit4: 4;} bit={1,2,2};
 
  printf(%d %d %d\n,bit.bit1,bit.bit3,bit.bit4);
  return 0;
 
  }
 
  3 can bit field be used in union??
 
 --
 You received this message because you are subscribed to the Google
   Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   algogeeks%2bunsubscr...@googlegroups­.com
 .
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.-Hide quoted text -
 
- Show quoted text -
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@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 

Re: [algogeeks] trees

2010-06-15 Thread sharad kumar
@rohit..i m not able to find this ques in this g

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: sum to x

2010-06-15 Thread Anand
Using segment tree: it does using O(logn) complexity
just check it out:
http://codepad.org/5jVxLmsA

On Sat, Jun 12, 2010 at 2:10 AM, Modeling Expert 
cs.modelingexp...@gmail.com wrote:

 My previous post went unfinished :((
 anyway this is summary of algo . (as N is very large , sorting could
 be costly so this method doesn't do that )

 algo ::
 have a mapint,bool

 1. For given number , if its less than Sum S , make map[S-number] =
 true  only if map[number] does not exist
 2. for Next  number , if map[number] is true , we got a pair
 ( number , map[number]) else do 1

 For exampe S = 100 , if we get 20 , let's make map[80] = true ;
 next if we get 80 , we will first check map[80] and if its true , we
 get a pair.

 If there are repetations , we can take map of int,int where second
 argument is count of first element ,
 say of 20 comes 4 times we will store map[20] = 4




 On Jun 12, 11:40 am, Chakravarthi Muppalla chakri...@gmail.com
 wrote:
  I would use an array.
 
  a[] = 1 3 7 8 9 78 67 23
  a[] = 1 3 7 8 9 23 67 78 //sort the array
  reqSum = 30;
  for i :a.length-1; i=0; i--
   t = reqSum - a[i];
   if(t is negative) continue;
find(t);//in the rest of the array;(binary search)
if(t found in the array) return index of t, current value of i;
   I guess it works.(we may have to use a hash map to speed it up in the
 long
  run).
 
  On Sat, Jun 12, 2010 at 10:29 AM, Rohit Saraf
  rohit.kumar.sa...@gmail.comwrote:
 
 
 
   I guess it can be done in efficiently using a simple divide and conquer
   scheme almost imitating mergesort.
   Can you think of it now? :D
 
   --
   Rohit Saraf
   Second Year Undergraduate,
   Dept. of Computer Science and Engineering
   IIT Bombay
  http://www.cse.iitb.ac.in/~rohitfeb14
 
   On Fri, Jun 11, 2010 at 10:07 PM, sharad kumar 
 sharad20073...@gmail.comwrote:
 
   all possible pairs
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
--
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Thanks,
  Chakravarthi.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] trees

2010-06-15 Thread sharad kumar
@lekha u dont noe total elements in bst...for finding that 1 more traversal
is required...can it be done in 1 pass only

-- 
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] Stack Space for Quick Sort vs Merge Sort.

2010-06-15 Thread Anurag Sharma
Seems correct to me :)

Anurag Sharma


On Sun, Jun 13, 2010 at 11:23 PM, amit amitjaspal...@gmail.com wrote:

 Can anyone tell what is Stack Space required for Quick Sort and Merge
 Sort.And how in each case it can be modified.

 Correct me if I am wrong on this.
 Space Complexity of Merge Sort ( Not Inplace) - O(n)
 Space Complexity of Quick Sort  - O(1)

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: file handing

2010-06-15 Thread divya jain
why a.c gets closed. well comma operator has left to right associativity.
for eg
a=(2,3,4) ;
here is a=4 after the statement is executed so similarly why not here. y c.c
is not closed here?

On 13 June 2010 22:16, souravsain souravs...@gmail.com wrote:

 For Problem 3 see section 4.2 Using feof() incorrectly in
 http://www.drpaulcarter.com/cs/common-c-errors.php

 On Jun 13, 8:36 pm, divya jain sweetdivya@gmail.com wrote:
  sorry i pasted wrong questn unser 2..
 
  the real question is
  which file will get closed through fclose()
  #includestdio.h
  int main()
  {
  FILE *fp,*fs,*ft;
  fp=fopen(a.c,r);
  fs=fopen(b.c,r);
  ft=fopen(c.c,r);
  fclose(fp,fs,ft);
  return 0;
 
  }
 
  3. yes it is feof..srry typed it wrong... nd fgets(str,80,fp) is
 perfectly
  fine.. now the ans to this questn is that last line of the file will be
  printed twice...( which i m unable to get why)...plzz explain...
 
  @ souravsain plzz ignore this mail..srry for the inconvenience..
 
  On 13 June 2010 17:37, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
 
 
 
   in question 1... ch gets the value of EOF... so first kicit 44-a
   gokulpeth\0 nagpur will get printed and then the value of EOF..
 
question number 2 .. seems to me as nrml ...i think myfile.c only gets
   closed
 
   in question number 3..it shld be fgets(str,79,fp)
 
   On Sun, Jun 13, 2010 at 2:49 PM, divya sweetdivya@gmail.com
 wrote:
 
   1. wat ll be the o/p. plz explain y?
   // abc.c contains kicit 44-a gokulpeth\0 nagpur
   #includestdio.h
#includestdlib.h
int main()
{
unsigned char ch;
FILE *fp;
fp=fopen(abc.c,r);
if(fp==NULL)
{
printf(unable to open the file \n);
exit(1);
}
while((ch=getc(fp))!=EOF)
printf(%c,ch);
fclose(fp);
printf(\n,ch);
return 0;
}
 
2.which file will get closed through fclose() in the following
   program and why?
   #includestdio.h
int main()
{FILE *fp;
char ch;
int i=1;
fp=fopen(myfile.c,r);
while((ch=getc(fp)!=EOF))
{
if(ch=='\n')
i++;
}
 
fclose(fp);
return 0;
}
 
3.point out the error if any in following
 
   #includestdio.h
int main()
{
FILE *fp;
char str[80];
fp=fopen(trial,r);
while(!eof(fp))
{
fgets(str,80,fp);
puts(str);
}
fclose(fp);
return 0;
}
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups­.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
 
  - Show quoted text -

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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] tower of hanoi variation

2010-06-15 Thread Chonku
Create a recurrence and then the algorithm.

On Mon, Jun 14, 2010 at 2:31 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote:

 give the algorithm for toi if... the a disk can be placed on top the disk
 just larger then it and on the ground..

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


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] sorting

2010-06-15 Thread sharad kumar
@ vadivel,yes i mean the former  has got unused space in which the latter
can occupy

-- 
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: Array Problem

2010-06-15 Thread divya jain
i meant make an array of indexes.. index[]={0,1...,n-1}

now sort the original array and move the elements of index array
accordingly..

now follow modelling expert's algo nd while taking largest-smallest check if
the index of largest in index array  index of smallest in index array.

On 13 June 2010 08:38, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:

 @Satya: I don't think what you have coded will work.. though i have not
 read the whole code.

 Don't you think a simple divide and conquer scheme would work...(almost
 like the mergesort)

 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombay
 http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14



 On Sat, Jun 12, 2010 at 9:06 PM, Satya satya...@gmail.com wrote:

 This problem seems to be finding the maxdiff in an array.

 int maxdiff ( int A[], int n ) {
 // write your code here
 int max_diff = A[1] - A[0];
   int min_element = A[0];
   int i;
   for(i = 1; i  n; i++)
   {
 if(A[i] - min_element  max_diff)
   max_diff = A[i] - min_element;
 if(A[i]  min_element)
  min_element = A[i];
   }
   if(max_diff  0)
 max_diff  = 0;
   return max_diff;
 }

 .
 Satya



 On Sat, Jun 12, 2010 at 3:18 PM, divya jain sweetdivya@gmail.comwrote:

 i think we need to maintain an array of index as well such that while
 subtracting smallest element from largest element of sorted array we need to
 check if index of largest is greater than index of smallest. if no..then
 this is not the solution..


 On 12 June 2010 14:20, Modeling Expert cs.modelingexp...@gmail.comwrote:

 Let's say array A , 1 till n

 s_index = 1;  e_index = n ;
 start  = A[s_index] ;
 end = A[e_index];
 result = 0;  //!  j - i
 if ( *end  *start ){
result =  index(end) - index(start)  ( only of its greater than
 previous value of result )
break ;
 }else{
 end-- ;  //! till you reach start
 }

 now increment start , and repeat the process but only from A[n] till
 A[++result] , going further
 down is not required now.

 Average time  o(n^2)

 Worst case : let's say we have descending array of ints, theno(n^2)

 Please suggest improvements










 On Jun 12, 12:14 am, amit amitjaspal...@gmail.com wrote:
  given an array A of n elements.
  for indexes j , i such that ji
  maximize( j - i )
  such that A[j] - A [ i ] 0 .
 
  Any Algorithm less than O(n^2) would do.

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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: Cycle in Undirected and Directed Graphs

2010-06-15 Thread souravsain
@sharad: Do you have some article that explains cycle detection in
bfs? Will be of help if you can share that or book or so which
explains cycle detection via bfs.

@amit: Both in directed and undirected graphs you can find a cycle in
O(|v|) time using a dfs. See Algorithm Design Manual Second Edition,
chapter 5 by Stiev. S. Skiena. Its a very good explanation.

On Jun 14, 6:19 am, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
 In any directed graph just check if dfs has a back edge. For
 undirected, check if there is a nontree edge

 --
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombayhttp://www.cse.iitb.ac.in/~rohitfeb14

-- 
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: unique number in an array

2010-06-15 Thread Navin Naidu
use XOR

On Mon, Jun 14, 2010 at 1:49 PM, kunzmilan kunzmi...@atlas.cz wrote:

 Write the array as a vector string S, eg
 (1,0,0,0...)
 (0,0,1,0...)
 (0,0,0,1...)
 etc.
 Find the quadratic form S^T.S. On its diagonal, occurences of all
 numbers are counted.
 kunzmilan


 On 13 čvn, 20:44, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
  give an algo to find a unique number in an array
 
  for eg a[]={1,3,4,1,4,5,6,1,5}
 
  here 3 is the unique number as it occur only once... moreover array
 contains
  only 1 unique number
 
  --
  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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Thanks  Regards,

- NMN

-- 
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: unique number in an array

2010-06-15 Thread jalaj jaiswal
range of numbers is not given..so cannot find maxnum without sorting..which
is nlogn

On Tue, Jun 15, 2010 at 12:21 AM, asit lipu...@gmail.com wrote:



 Let's assume array contains only +ve numbers and maximum number is
 MAXNUM

 Take an array arr[MAXNUM]

 for(i=1; i=MAXNUM; i++)
arr[i]=0;


 for(i=1; i=MAXNUM; i++)
arr[a[i]]++;

 now print the indexes whose array value is 1

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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.



Re: [algogeeks] trees

2010-06-15 Thread Anand
http://codepad.org/ricAcQtu

On Sun, Jun 13, 2010 at 9:13 PM, Anand anandut2...@gmail.com wrote:

 Here is an implementation for BST and search an element in BST in O(logn )
 time


 On Sun, Jun 13, 2010 at 8:04 PM, Lekha lek...@gmail.com wrote:

 Inorder traversal till u reach the kth element(If it is sorted in
 descending order, otherwise go till (n-k)th element)..


 On Sun, Jun 13, 2010 at 9:24 PM, Rohit Saraf rohit.kumar.sa...@gmail.com
  wrote:

 Repeated q. Search in the group

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

 --
  You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Lekha

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Endian-ness check

2010-06-15 Thread Sundeep Singh
@saurav: your code will always print 2 irrespective of the system's
endianness!

correct thing to do is:
printf(%d, *(char *) (0x0002))

--Sundeep.

On Mon, Jun 14, 2010 at 3:02 AM, Minotauraus anike...@gmail.com wrote:

 How about a pointer? :D

 On Jun 13, 5:56 am, debajyotisarma sarma.debajy...@gmail.com wrote:
  Is it possible to check endianness of a system in C without creating
  variable?
   i.e. Program should not contain any variable.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] trees

2010-06-15 Thread vadivel selvaraj
Dis'd do :-D
int klargest_recur(int k,List* head)
{
if(!head || !k) return -1;
int rsize = 0;
if(head-right) rsize = size(head-right);
if(k == rsize + 1) return head-data;
if(k = rsize) return klargest_recur(k, head-right);
else return klargest_recur(k - rsize - 1, head-left);
}


On Mon, Jun 14, 2010 at 8:34 AM, Lekha lek...@gmail.com wrote:

 Inorder traversal till u reach the kth element(If it is sorted in
 descending order, otherwise go till (n-k)th element)..


 On Sun, Jun 13, 2010 at 9:24 PM, Rohit Saraf 
 rohit.kumar.sa...@gmail.comwrote:

 Repeated q. Search in the group

 --
 --
 Rohit Saraf
 Second Year Undergraduate,
 Dept. of Computer Science and Engineering
 IIT Bombay
 http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Lekha

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Simplicity is prerequisite for reliability.
– Edsger W. Dijkstra

-- 
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] op

2010-06-15 Thread sharad
#includemalloc.h
  char *f()
  {char *s=malloc(8);
strcpy(s,goodbye);
 }

  main()
  {
   *f()='A';
  printf(%c,*f()); }


find o/p n explain it

-- 
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] finding nearest neighbour

2010-06-15 Thread Jitendra Kushwaha
Given n points in the space. Now given a new point you have to find
the nearest neigbour to it from initial n points
This can be done in O(n), a trivial solution.
This can also be accomplished in O(logn) by space partioning. here is
a link:
 http://en.wikipedia.org/wiki/Nearest_neighbor_search#Space_partitioning

can anybody give a pseudo code or commented C code to impliment it. I
do not understood how to implement it.

this is a google interview question and its variation is a amazon's
question. :)

-- 
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] copy

2010-06-15 Thread sharad
CopyBits(x,p,n,y)
write  c code to copy n LSBs from y to x starting LSB at 'p'th
position using bitwi se.

-- 
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: unique number in an array

2010-06-15 Thread Jitendra Kushwaha
Using Hashing
space :  O(n)
time :  O(n)

Using sorting
space : O(1)
time : O(nlogn)

special case: (all elements are of the range of the array then using count
sort)
space : O(1)
time : O(n)

any better solutions???

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



Re: [algogeeks] Re: OS doubt

2010-06-15 Thread mandy4u4ever
Which book are you studying for OS ?

-- 
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: Endian-ness check

2010-06-15 Thread Debajyoti Sarma
@ souravsain
Don't understand your solution.
if u type convert to char how u can say that msb is in higher memory address?
i think (char) will alway give the value of the lsb.
How u r checking endian ness?

normal endian ness check program
main()
{
int i=1;
char *p=(char*)i;
if(*p==1)
printf(Small endian);
else
printf(Big endian);
}

Here suppose int is of 2 byets.
so content at the memory location of i will be

  0001
(MSB)(LSB) in Big endian machine

0001  
(LSB)(MSB) in small endian machine

as after pointing to the 1st memory location by *p we r checking if
the value is 1 or not.
if it is 1 then small endian or else big endian.


@Minotauraus
if u r creating pointer u r creating variable .

On 6/14/10, Minotauraus anike...@gmail.com wrote:
 How about a pointer? :D

 On Jun 13, 5:56 am, debajyotisarma sarma.debajy...@gmail.com wrote:
 Is it possible to check endianness of a system in C without creating
 variable?
  i.e. Program should not contain any variable.

 --
 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] Max Area of a Triangle

2010-06-15 Thread amit
Given N points how can we find a triangle formed using any of the
three points with maximum area?

-- 
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: unique number in an array

2010-06-15 Thread Sathaiah Dontula
Using XOR, you can do in one pass, does it have any problem ?

Like, element  = element XOR array[i], for each i = 1,2, ..., N. What
'element' contains at the end will be the unique element.

Thanks,
Sathaiah

On Mon, Jun 14, 2010 at 1:49 PM, kunzmilan kunzmi...@atlas.cz wrote:

 Write the array as a vector string S, eg
 (1,0,0,0...)
 (0,0,1,0...)
 (0,0,0,1...)
 etc.
 Find the quadratic form S^T.S. On its diagonal, occurences of all
 numbers are counted.
 kunzmilan


 On 13 čvn, 20:44, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
  give an algo to find a unique number in an array
 
  for eg a[]={1,3,4,1,4,5,6,1,5}
 
  here 3 is the unique number as it occur only once... moreover array
 contains
  only 1 unique number
 
  --
  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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] unique number in an array

2010-06-15 Thread Priyanka Chatterjee
XOR all the elements of array, the remaining value is the required unique
number.
(XORing two same numbers results in zero)





-- 
Thanks  Regards,
Priyanka Chatterjee
Third Year Undergraduate Student,
Computer Science  Engineering,
National Institute Of Technology,Durgapur
India
http://priyanka-nit.blogspot.com/

-- 
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] Best method to choose a quadrant

2010-06-15 Thread siddharth srivastava
I have this code snippet:
This code snippet defines a boundary coordinates on the screen wrt to the
center(of the screen).

if( x  x_center )
x_border = x_center - x_shift;
else
x_border = x_center + x_shift;

if( y  y_center )
y_border = y_center - y_shift;
else
y_border = y_center + y_shift;

//x_shift and y_shift are constants.

What is the best possible way to determine in which quadrant( wrt to the
center) the point (x,y) lies ?


Siddharth Srivastava

-- 
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: unique number in an array

2010-06-15 Thread Modeling Expert
use hash table , and if you find for a number , a entry already
exists , mark it unwanted !
in the end , hash table entries are unique numbers .

@kunzmilan : could you explain a bit more, couldn't get full idea of
what you wrote

-Manish

On Jun 14, 1:19 pm, kunzmilan kunzmi...@atlas.cz wrote:
 Write the array as a vector string S, eg
 (1,0,0,0...)
 (0,0,1,0...)
 (0,0,0,1...)
 etc.
 Find the quadratic form S^T.S. On its diagonal, occurences of all
 numbers are counted.
 kunzmilan

 On 13 čvn, 20:44, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:

  give an algo to find a unique number in an array

  for eg a[]={1,3,4,1,4,5,6,1,5}

  here 3 is the unique number as it occur only once... moreover array contains
  only 1 unique number

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



Re: [algogeeks] Re: unique number in an array

2010-06-15 Thread Debajyoti Sarma
@jalaj jaiswal

given array contain 3,6 both r unique.
Is this the exact question?

if array is 6,3,4,1,4,5,6,1,5 than we can solve using xor properties.

int a,b=5;
a=b^b;   //value of a is 0 convert in binery form and do u will get
a=0^a;//value of a is a itselt

Program:

#includestdio.h
int unique(int array[],int size)
{
int i,x=0;
for(i=0;isize;i++)
x^=array[i];
return x;
}
int main()
{
int array[]={6,3,4,1,4,5,6,1,5};
int size=sizeof(array)/sizeof(array[0]);
printf(%d,unique(array,size));
}


this will give the result bcoz

0^6^3^4^1^4^5^6^1^5 = 3
as xor is associative .

On 6/14/10, kunzmilan kunzmi...@atlas.cz wrote:
 Write the array as a vector string S, eg
 (1,0,0,0...)
 (0,0,1,0...)
 (0,0,0,1...)
 etc.
 Find the quadratic form S^T.S. On its diagonal, occurences of all
 numbers are counted.
 kunzmilan


 On 13 čvn, 20:44, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
 give an algo to find a unique number in an array

 for eg a[]={1,3,4,1,4,5,6,1,5}

 here 3 is the unique number as it occur only once... moreover array
 contains
 only 1 unique number

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



Re: [algogeeks] Re: Cycle in Undirected and Directed Graphs

2010-06-15 Thread Rohit Saraf
@vivek : was that a joke?
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14


On Mon, Jun 14, 2010 at 11:40 AM, souravsain souravs...@gmail.com wrote:

 @sharad: Do you have some article that explains cycle detection in
 bfs? Will be of help if you can share that or book or so which
 explains cycle detection via bfs.

 @amit: Both in directed and undirected graphs you can find a cycle in
 O(|v|) time using a dfs. See Algorithm Design Manual Second Edition,
 chapter 5 by Stiev. S. Skiena. Its a very good explanation.

 On Jun 14, 6:19 am, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
  In any directed graph just check if dfs has a back edge. For
  undirected, check if there is a nontree edge
 
  --
  --
  Rohit Saraf
  Second Year Undergraduate,
  Dept. of Computer Science and Engineering
  IIT Bombayhttp://www.cse.iitb.ac.in/~rohitfeb14

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Endian-ness check

2010-06-15 Thread Lego Haryanto
On Mon, Jun 14, 2010 at 5:13 AM, Sundeep Singh singh.sund...@gmail.comwrote:

 @saurav: your code will always print 2 irrespective of the system's
 endianness!

 correct thing to do is:
 printf(%d, *(char *) (0x0002))

 --Sundeep.



... dereferencing a very low address pointer, are you sure?

-- 
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: unique number in an array

2010-06-15 Thread BALARUKESH SIVARAMAN
XOR has the following problem...
 assume array is 2,3,3,2,1,2
here the unique element is 1 but using XOR we get
2^3^3^2^1^2=3

XOR works only when all the elements except the unique element occur even
number of times.

-- 
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] towers of hanoi O(1) time

2010-06-15 Thread Jitendra Kushwaha
Dear Anuj,

Its easy to do.
lets take an example
say we have 4 disks. We will require 2^4-1 = 15 steps to solve it.
Now suppose we are at 6th step..
write it binary form using 4 bits(since we have 4 disks)   0110
now from left 0 means 4th disk is on initial peg
second bit 1 means disk 3 is on left of the previous disk
third bit 1 means it is above previous disk
fourth bit 0 means it is on right of previuos disk

so the solution is something like
1: 4|1
2:
3: 3|2

1: is initial peg   (left of 1 means 3 and right means 2)
2: is final peg

hope it is clear how to solve this in O(no_of_disk) complexity
you can refer this link :
http://britton.disted.camosun.bc.ca/jbhanoi.htm
http://britton.disted.camosun.bc.ca/jbhanoi.htm


comment for any related doubts :)

-- 
Regards
Jitendra Kushwaha
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 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: Max Area of a Triangle

2010-06-15 Thread Minotauraus
Suppose points are given in the form (a1, b1) (a2, b2). (an, bn).

- find the point furthest away from the origin by maximizing a^2 +
b^2  [ will take O(n) time]
- Find the point at maximum distance from this point. Use distance
formula. Sqrt( (a2-a1)^2 + (b2-b1)^2) [will take O(n) time]
- Find third point by maximizing the perimeter. We already have the
length of one side obtained from the distance formula above.
  Repeat the same procedure for the other two
sides.[will take O(n) time]

These three points should form a triangle with max. area. (Max.
perimeter, (please correct me if I'm wrong) = Max. area.)
I chose to use perimeter as it's quicker to calculate than area (= 1/2
*b * h, where h will have to be calculated).
This should run in O(n) time. I've tried thinking of scenarios where
this algorithm will not yield the max. area, but can't
seem to find such a case. If you think this won't work or isn't
optimum, please present such a case.

-Minotauraus.

On Jun 14, 4:27 am, amit amitjaspal...@gmail.com wrote:
 Given N points how can we find a triangle formed using any of the
 three points with maximum area?

-- 
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] BST...doubt.......

2010-06-15 Thread ajay kumar
Write a pseudo code 4 that..using c/c++...

how can we find the depth(height) of BST ?

-- 
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] Best method to choose a quadrant

2010-06-15 Thread Debajyoti Sarma
Don't understand the question.
explain differently.

On 6/14/10, siddharth srivastava akssps...@gmail.com wrote:
 I have this code snippet:
 This code snippet defines a boundary coordinates on the screen wrt to the
 center(of the screen).

 if( x  x_center )
 x_border = x_center - x_shift;
 else
 x_border = x_center + x_shift;

 if( y  y_center )
 y_border = y_center - y_shift;
 else
 y_border = y_center + y_shift;

 //x_shift and y_shift are constants.

 What is the best possible way to determine in which quadrant( wrt to the
 center) the point (x,y) lies ?


 Siddharth Srivastava

 --
 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: unique number in an array

2010-06-15 Thread Jitendra Kushwaha
@Sathaiah :
offcourse XOR have problem . All tha other numbers are not repeated even
nuber of times so its not necessary that they cut out to give 0
for eg a[]={1,3,4,1,4,5,6,1,5,6}

XOR will give output as 1^3 which is not done
If every other element is repeated even times then XOR is OK

@jalaj :
You cant find the unique element in a unsorted array any less than O(n).
Minimum complexity will be O(n).
One have to traverse the whole array atleast once to find the distinct
element

comments are welcomed...

-- 
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] o/p of strlen()

2010-06-15 Thread mohit ranjan
Hi All,

char s[]={'a', 'b', 'c', 'd'};

printf(%d\n, strlen(s));


o/p is 8

can anybody plz explain why 8 ?

Mohit

-- 
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: unique number in an array

2010-06-15 Thread Anurag Sharma
Guys, XOR operation you are suggesting wont work, as a number can be
repeated more than 2 times or may not be even number of times. Check the
example given by him:-
*a[]={1,3,4,1,4,5,6,1,5}*
Here 1 is repeated 3 times, and which certainly is not the unique element
but will leave its affect on XOR thing :)


Anurag Sharma


On Mon, Jun 14, 2010 at 5:14 PM, Modeling Expert 
cs.modelingexp...@gmail.com wrote:

 use hash table , and if you find for a number , a entry already
 exists , mark it unwanted !
 in the end , hash table entries are unique numbers .

 @kunzmilan : could you explain a bit more, couldn't get full idea of
 what you wrote

 -Manish

 On Jun 14, 1:19 pm, kunzmilan kunzmi...@atlas.cz wrote:
  Write the array as a vector string S, eg
  (1,0,0,0...)
  (0,0,1,0...)
  (0,0,0,1...)
  etc.
  Find the quadratic form S^T.S. On its diagonal, occurences of all
  numbers are counted.
  kunzmilan
 
  On 13 čvn, 20:44, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
 
   give an algo to find a unique number in an array
 
   for eg a[]={1,3,4,1,4,5,6,1,5}
 
   here 3 is the unique number as it occur only once... moreover array
 contains
   only 1 unique number
 
   --
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] copy

2010-06-15 Thread mohit ranjan
@Sharad

assuming p(n-1)

o/p=
x  [ ~ {  (~((~0)n))  (p-n+1) } ]  |  [ y  [~((~0)n)]]



Mohit

On Tue, Jun 15, 2010 at 2:10 PM, sharad sharad20073...@gmail.com wrote:

 CopyBits(x,p,n,y)
 write  c code to copy n LSBs from y to x starting LSB at 'p'th
 position using bitwi se.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: file handing

2010-06-15 Thread sharad kumar
@divya
u r correct that in a=(2,3,4) 4 gets in a
but if u remove parenthesis then u get 2 in a
here although parenthesis is there bt that is for function call i.e f(1,2,3)
but effectively its written 1,2,3
so a.c get closed
i hope i m clear...plzzz correct me if i m wrong sumwhere

-- 
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: unique number in an array

2010-06-15 Thread Piyush Verma
XORing the numbers can not give the correct result, this will give correct
result if repeation is in even times otherwise it will give incorrect
result.

-- 
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] op

2010-06-15 Thread Anurag Sharma
did you forget to return any value from function f() ?

Anurag Sharma


On Mon, Jun 14, 2010 at 7:19 PM, sharad sharad20073...@gmail.com wrote:

 #includemalloc.h
  char *f()
  {char *s=malloc(8);
strcpy(s,goodbye);
 }

  main()
  {
   *f()='A';
  printf(%c,*f()); }


 find o/p n explain it

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Endian-ness check

2010-06-15 Thread Piyush Verma
printf(%d,12424);
will give the efficient solution
if it print 1 then little indian otherwise big endian.

-- 
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] unique number in an array

2010-06-15 Thread Krishan Malik
Priyanka,

will XOR work for

{1,1,1,3,3,4,5}

Thanks
Sri

On Mon, Jun 14, 2010 at 7:02 PM, Priyanka Chatterjee
dona.1...@gmail.com wrote:

 XOR all the elements of array, the remaining value is the required unique
 number.
 (XORing two same numbers results in zero)




 --
 Thanks  Regards,
 Priyanka Chatterjee
 Third Year Undergraduate Student,
 Computer Science  Engineering,
 National Institute Of Technology,Durgapur
 India
 http://priyanka-nit.blogspot.com/

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




-- 
SK Malik

-- 
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] Best method to choose a quadrant

2010-06-15 Thread Anurag Sharma
just check the signs of the i, j components of vector from the centre of
screen to (x,y)

pseudo code:-
getQuadrant(x,y){
   string Q[]={1st,4th,2nd, 3rd};
   vx=(x=midx)?0:1
   vy=(y=midy)?0:1
   return Q[(vx1)|vy]
}

Anurag Sharma


On Mon, Jun 14, 2010 at 5:55 PM, siddharth srivastava
akssps...@gmail.comwrote:

 I have this code snippet:
 This code snippet defines a boundary coordinates on the screen wrt to the
 center(of the screen).

 if( x  x_center )
 x_border = x_center - x_shift;
 else
 x_border = x_center + x_shift;

 if( y  y_center )
 y_border = y_center - y_shift;
 else
 y_border = y_center + y_shift;

 //x_shift and y_shift are constants.

 What is the best possible way to determine in which quadrant( wrt to the
 center) the point (x,y) lies ?


 Siddharth Srivastava


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] unique number in an array

2010-06-15 Thread Bharath
Xor works only if a number is repeated is repeated even number of times. It
will not work in other case.

On Mon, Jun 14, 2010 at 7:02 PM, Priyanka Chatterjee dona.1...@gmail.comwrote:


 XOR all the elements of array, the remaining value is the required unique
 number.
 (XORing two same numbers results in zero)





 --
 Thanks  Regards,
 Priyanka Chatterjee
 Third Year Undergraduate Student,
 Computer Science  Engineering,
 National Institute Of Technology,Durgapur
 India
 http://priyanka-nit.blogspot.com/

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Bharath

-- 
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] Stack Space for Quick Sort vs Merge Sort.

2010-06-15 Thread Amit Jaspal
But what about the Stack Space Used while doing Merge and Quick Sort?

On Mon, Jun 14, 2010 at 9:30 AM, Anurag Sharma anuragvic...@gmail.comwrote:

 Seems correct to me :)

 Anurag Sharma



 On Sun, Jun 13, 2010 at 11:23 PM, amit amitjaspal...@gmail.com wrote:

 Can anyone tell what is Stack Space required for Quick Sort and Merge
 Sort.And how in each case it can be modified.

 Correct me if I am wrong on this.
 Space Complexity of Merge Sort ( Not Inplace) - O(n)
 Space Complexity of Quick Sort  - O(1)

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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] sum to 0

2010-06-15 Thread sharad kumar
plzzz comment on this question

-- 
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: unique number in an array

2010-06-15 Thread jalaj jaiswal
@debajyoti sharma

your method works only if a number is repeated even number of times ...try
for this int array[]={6,3,4,1,4,5,6,1,1,5};... so xor method fails... or can
dere be any modofication in it ??

On Mon, Jun 14, 2010 at 6:18 PM, Debajyoti Sarma
sarma.debajy...@gmail.comwrote:

 @jalaj jaiswal

 given array contain 3,6 both r unique.
 Is this the exact question?

 if array is 6,3,4,1,4,5,6,1,5 than we can solve using xor properties.

 int a,b=5;
 a=b^b;   //value of a is 0 convert in binery form and do u will get
 a=0^a;//value of a is a itselt

 Program:

 #includestdio.h
 int unique(int array[],int size)
 {
int i,x=0;
for(i=0;isize;i++)
x^=array[i];
return x;
 }
 int main()
 {
int array[]={6,3,4,1,4,5,6,1,5};
int size=sizeof(array)/sizeof(array[0]);
printf(%d,unique(array,size));
 }


 this will give the result bcoz

 0^6^3^4^1^4^5^6^1^5 = 3
 as xor is associative .

 On 6/14/10, kunzmilan kunzmi...@atlas.cz wrote:
  Write the array as a vector string S, eg
  (1,0,0,0...)
  (0,0,1,0...)
  (0,0,0,1...)
  etc.
  Find the quadratic form S^T.S. On its diagonal, occurences of all
  numbers are counted.
  kunzmilan
 
 
  On 13 čvn, 20:44, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
  give an algo to find a unique number in an array
 
  for eg a[]={1,3,4,1,4,5,6,1,5}
 
  here 3 is the unique number as it occur only once... moreover array
  contains
  only 1 unique number
 
  --
  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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




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



Re: [algogeeks] Max Area of a Triangle

2010-06-15 Thread Vivek Sundararajan
can only think of O(N^3) brute force solution - any better ideas? :)

On 14 June 2010 16:57, amit amitjaspal...@gmail.com wrote:

 Given N points how can we find a triangle formed using any of the
 three points with maximum area?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




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



Re: [algogeeks] Re: Array Problem

2010-06-15 Thread Piyush Verma
@BALARUKESH
i think the problem is to maximize the diffrence j-i according to condition
and in your solution j can be less than i.

This problem can be solved by sorting the array first, then taking
diffrence.
this solution is done in O(nlogn).

-- 
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] unique number in an array

2010-06-15 Thread Rohit Saraf
Just to point out :
how many times have you all repeated this --
Xor works only -- even number of times. It will not
work...

Why don't you all read some earlier posts before posting. :P


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


On Tue, Jun 15, 2010 at 4:52 PM, Krishan Malik srikrishanma...@gmail.comwrote:

 Priyanka,

 will XOR work for

 {1,1,1,3,3,4,5}

 Thanks
 Sri

 On Mon, Jun 14, 2010 at 7:02 PM, Priyanka Chatterjee
 dona.1...@gmail.com wrote:
 
  XOR all the elements of array, the remaining value is the required unique
  number.
  (XORing two same numbers results in zero)
 
 
 
 
  --
  Thanks  Regards,
  Priyanka Chatterjee
  Third Year Undergraduate Student,
  Computer Science  Engineering,
  National Institute Of Technology,Durgapur
  India
  http://priyanka-nit.blogspot.com/
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 



 --
 SK Malik

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] BST...doubt.......

2010-06-15 Thread Amir hossein Shahriari
here's a recursive solution

int depth(Node n){
   if (n==NULL)
   return 0;
   else
  return 1 + max( depth( n.right ) , depth( n.left ) );
}

calling depth(root) will yield the height of the tree

On 6/15/10, ajay kumar ajaykr@gmail.com wrote:
 Write a pseudo code 4 that..using c/c++...

 how can we find the depth(height) of BST ?

 --
 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] op

2010-06-15 Thread sharad kumar
ya i forgot that...considering that plz explain o/p
i.e
#includemalloc.h
 char *f()
 {char *s=malloc(8);
   strcpy(s,goodbye);
   return s;

}

 main()
 {
  *f()='A';
 printf(%c,*f());
}

-- 
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] o/p of strlen()

2010-06-15 Thread Amir hossein Shahriari
you didn't put an '\0' at the end of the string
strlen looks for a '\0' in the string and here it happened to be 8
bytes after the starting position of s

On 6/15/10, mohit ranjan shoonya.mo...@gmail.com wrote:
 Hi All,

 char s[]={'a', 'b', 'c', 'd'};

 printf(%d\n, strlen(s));


 o/p is 8

 can anybody plz explain why 8 ?

 Mohit

 --
 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] doubly linked list

2010-06-15 Thread Ratnesh Thakur
how to implement doubly linked list using only one pointer ?

-- 
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] sum to 0

2010-06-15 Thread Amir hossein Shahriari
sort all arrays
for each number in A , A[k]
find two numbers in B and C such that their sum is -A[k]
this can be done in O(n) time:

set i at the beginning of B and j at the end of C
while in or j=0
   if ( B[i] + C[j] == -A[k] ) return true
   if ( B[i] + C[j]  -A[k] ) increase i
   else decrease j

we have to do this for each element of A so the overall complexity is:
O(n2) time O(1) space

correct me if I'm wrong

On 6/15/10, sharad kumar sharad20073...@gmail.com wrote:
 plzzz comment on this question

 --
 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] BST...doubt.......

2010-06-15 Thread sharad kumar
@ajay:recursively count the number of nodes then use formula  h=log2(number
of nodes)

On Wed, Jun 16, 2010 at 5:39 AM, Amir hossein Shahriari 
amir.hossein.shahri...@gmail.com wrote:

 here's a recursive solution

 int depth(Node n){
   if (n==NULL)
   return 0;
   else
  return 1 + max( depth( n.right ) , depth( n.left ) );
 }

 calling depth(root) will yield the height of the tree

 On 6/15/10, ajay kumar ajaykr@gmail.com wrote:
  Write a pseudo code 4 that..using c/c++...
 
  how can we find the depth(height) of BST ?
 
  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




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



Re: [algogeeks] BST...doubt.......

2010-06-15 Thread Anurag Sharma
height of current node = max(height of left child, height of right child) +1


Hope now you get that? :)

Anurag Sharma

On Tue, Jun 15, 2010 at 5:31 PM, ajay kumar ajaykr@gmail.com wrote:

 Write a pseudo code 4 that..using c/c++...

 how can we find the depth(height) of BST ?

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] doubly linked list

2010-06-15 Thread sharad kumar
u have to use XOR linked list

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.