Re: [algogeeks] Google-Puzzle

2012-02-25 Thread Ashish Goel
max subsum problem
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Sat, Feb 25, 2012 at 1:03 PM, karthikeya s karthikeya.a...@gmail.comwrote:

 You have a circular track containing fuel pits at irregular intervals.
 The total amount of fuel available from all the pits together is just
 sufficient to travel round the track and finish where you started.
 Given the the circuit perimeter, list of each fuel pit location and
 the amount of fuel they contain, find the optimal start point on the
 track such that you never run out of fuel and complete circuit.

 my logic:
 we can use an array having element as
 fuel(in km)-dist to next pit

 so now aim is to traverse the array as always having some +ve
 resultant sum.nd plz we cant use here kadane's algo.there are
 cases in which it will not hold here

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



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



[algogeeks] Re: Google-Puzzle

2012-02-25 Thread karthikeya s
buddy i said that kadane's algo(max subsum) wouldn't work..

On Feb 25, 1:31 pm, Ashish Goel ashg...@gmail.com wrote:
 max subsum problem
 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652

 On Sat, Feb 25, 2012 at 1:03 PM, karthikeya s 
 karthikeya.a...@gmail.comwrote:







  You have a circular track containing fuel pits at irregular intervals.
  The total amount of fuel available from all the pits together is just
  sufficient to travel round the track and finish where you started.
  Given the the circuit perimeter, list of each fuel pit location and
  the amount of fuel they contain, find the optimal start point on the
  track such that you never run out of fuel and complete circuit.

  my logic:
  we can use an array having element as
  fuel(in km)-dist to next pit

  so now aim is to traverse the array as always having some +ve
  resultant sum.nd plz we cant use here kadane's algo.there are
  cases in which it will not hold here

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

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



[algogeeks] google question

2012-02-25 Thread Ravi Ranjan
|_|
|_| |_|
|_| |_| |_|
|_| |_| |_| |_|
|_| |_| |_| |_| |_|

Each cup has capacity C and once a cup gets full, it drops half extra
amount to left child and half extra amount to right child

for Eg : let' first cups get 2C amount of liquid then extra amount C(2C-C)
will be divided equally to left and right child cup of next level

i.e. C/2 to left child and C/2 to right child

Write a function which takes input parameter as amount of liquid poured at
top (L) and height of particular cup (h) index of that cup (i) and it
should return amount of liquid absorbed in that cup.

source

http://www.careercup.com/question?id=12770661


whats exactly the qestion???

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



Re: [algogeeks] Re: Google-Puzzle

2012-02-25 Thread Ashish Goel
it will

the diff is of fuel and dist forms the content of array which moves from 1
to 2n-1 elements(break the circle and instead of elem like 1,2,n have
1,2,n,1,2,...n-1
i.e. total 2n-1 so that mod stuff is not required.

now find maxsubSum such that sum=0 and count of nodes is n

not clear ehy it wont work.
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Sat, Feb 25, 2012 at 2:54 PM, karthikeya s karthikeya.a...@gmail.comwrote:

 buddy i said that kadane's algo(max subsum) wouldn't work..

 On Feb 25, 1:31 pm, Ashish Goel ashg...@gmail.com wrote:
  max subsum problem
  Best Regards
  Ashish Goel
  Think positive and find fuel in failure
  +919985813081
  +919966006652
 
  On Sat, Feb 25, 2012 at 1:03 PM, karthikeya s karthikeya.a...@gmail.com
 wrote:
 
 
 
 
 
 
 
   You have a circular track containing fuel pits at irregular intervals.
   The total amount of fuel available from all the pits together is just
   sufficient to travel round the track and finish where you started.
   Given the the circuit perimeter, list of each fuel pit location and
   the amount of fuel they contain, find the optimal start point on the
   track such that you never run out of fuel and complete circuit.
 
   my logic:
   we can use an array having element as
   fuel(in km)-dist to next pit
 
   so now aim is to traverse the array as always having some +ve
   resultant sum.nd plz we cant use here kadane's algo.there are
   cases in which it will not hold here
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

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



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



Re: [algogeeks] Re: array problem

2012-02-25 Thread Amol Sharma
interesting discussion going on the question, check this link--

http://stackoverflow.com/questions/9442958/find-the-element-occurring-b-times-in-an-an-array-of-size-nkb


--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
 http://gplus.to/amolsharma99
http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/






On Fri, Feb 17, 2012 at 12:25 PM, atul anand atul.87fri...@gmail.comwrote:

 @Siddhartha : doing bitwise addtiton may result into overflow if values
 are large.
 correct me if i am wrong.

 On Fri, Feb 17, 2012 at 10:04 AM, Siddhartha Banerjee 
 thefourrup...@gmail.com wrote:

 convert the numbers into base k... and do bitwise addition of numbers,
 where
 bit(a)+bit(b)=bit(a+b)mod(k)
 of you convert all the numbers into base k and add them bitwise in a
 variable say x, then the numbers occuring nk times vanish, and the final
 result stored in x is a+a++a(b times) where a is the number repeating b
 times...
 next time go through the array again and see whether any number when
 added with itself b times gives the same result as x, if yes, out put that
 number.

 I had seen a solution to a problem where in an array of size 3n+1, each
 element except one repeating thrice, we need to find the non repeating
 element in O(n) time O(1) space, i tried to generalize the proof to fit
 this case...

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


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


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



Re: [algogeeks] Re: ARICENT PATTERN

2012-02-25 Thread vivek kumar
can u provide me some question

On Thu, Feb 23, 2012 at 1:59 AM, saurabh tripathi sonu6...@gmail.comwrote:

 Question in each section varies from 20-25.If u clear this round u
 have 95% chances because after this round there will b no elimination round.
So, all the best.


 On Wed, Feb 22, 2012 at 10:51 AM, vivek kumar kumarvivek1...@gmail.comwrote:

 thanks bro ...
 plz tell me no of question in each section

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


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


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



Re: [algogeeks] google question

2012-02-25 Thread atul anand
i guess this would work...
n=number of nodes
h=height;
pour=quantity poured;
capacity = capacity of each cup

n=pow(2,h+1) -1;
call(capacity,pour,0,n)

node* fillCup(float capacity,float pour,int left,int right)
{
node *root;
int mid;
if(left  right)
return NULL;

root=(node *)malloc(sizeof(node));
if(left==right)
{
if(pour =capacity)
root-data=capacity;
else
root-data=pour;
root-left=root-right=NULL;
}
else
{
mid=left+(right-left)/2;
if(pour = capacity)
{
root-data=capacity;
pour=pour-capacity;
pour=pour/2;
}
else
{
root-data=pour;
root-left=root-right=NULL;
return root;

}
root-left=fillCup(capacity,pour,left,mid-1);
root-right=fillCup(capacity,pour,mid+1,right);

}
return root;

}

On Sat, Feb 25, 2012 at 5:05 PM, Ravi Ranjan ravi.cool2...@gmail.comwrote:

 |_|
 |_| |_|
 |_| |_| |_|
 |_| |_| |_| |_|
 |_| |_| |_| |_| |_|

 Each cup has capacity C and once a cup gets full, it drops half extra
 amount to left child and half extra amount to right child

 for Eg : let' first cups get 2C amount of liquid then extra amount C(2C-C)
 will be divided equally to left and right child cup of next level

 i.e. C/2 to left child and C/2 to right child

 Write a function which takes input parameter as amount of liquid poured at
 top (L) and height of particular cup (h) index of that cup (i) and it
 should return amount of liquid absorbed in that cup.

 source

 http://www.careercup.com/question?id=12770661


 whats exactly the qestion???

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


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



[algogeeks] difference b/w static global variables and global variables

2012-02-25 Thread AMAN AGARWAL
Hi ,

Is there any difference b/w static global variables and global variables ???

(apart from that static variables will be limited to that file only and
global variables will be visible for other files also.)


Regards,
Aman.

-- 
AMAN AGARWAL
Success is not final, Failure is not fatal: It is the courage to continue
that counts!

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



Re: [algogeeks] difference b/w static global variables and global variables

2012-02-25 Thread Akanksha .
Global variable are accessible from other file as well but static global
variables are only accessible in that particular file.


On Sat, Feb 25, 2012 at 10:21 PM, AMAN AGARWAL mnnit.a...@gmail.com wrote:

 Hi ,

 Is there any difference b/w static global variables and global variables
 ???

 (apart from that static variables will be limited to that file only and
 global variables will be visible for other files also.)


 Regards,
 Aman.

 --
 AMAN AGARWAL
 Success is not final, Failure is not fatal: It is the courage to continue
 that counts!

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


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



Re: [algogeeks] difference b/w static global variables and global variables

2012-02-25 Thread rajat ahuja
Scope might be diferent if u define static in function . it will be
intilaized once when u call it first time but scope of that variable will
be limited to that function only but they live throught out the programe
though scope is limited
in case of global it can be used in ny function

On Sat, Feb 25, 2012 at 10:35 PM, Akanksha . akanksha...@gmail.com wrote:

 Global variable are accessible from other file as well but static global
 variables are only accessible in that particular file.


 On Sat, Feb 25, 2012 at 10:21 PM, AMAN AGARWAL mnnit.a...@gmail.comwrote:

 Hi ,

 Is there any difference b/w static global variables and global variables
 ???

 (apart from that static variables will be limited to that file only and
 global variables will be visible for other files also.)


 Regards,
 Aman.

 --
 AMAN AGARWAL
 Success is not final, Failure is not fatal: It is the courage to
 continue that counts!

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


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


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



Re: [algogeeks] difference b/w static global variables and global variables

2012-02-25 Thread atul anand
@abv : question sayss..
(apart from that static variables will be limited to that file only and
global variables will be visible for other files also.)

On Sat, Feb 25, 2012 at 10:44 PM, rajat ahuja catch.rajatah...@gmail.comwrote:

 Scope might be diferent if u define static in function . it will be
 intilaized once when u call it first time but scope of that variable will
 be limited to that function only but they live throught out the programe
 though scope is limited
 in case of global it can be used in ny function


 On Sat, Feb 25, 2012 at 10:35 PM, Akanksha . akanksha...@gmail.comwrote:

 Global variable are accessible from other file as well but static global
 variables are only accessible in that particular file.


 On Sat, Feb 25, 2012 at 10:21 PM, AMAN AGARWAL mnnit.a...@gmail.comwrote:

 Hi ,

 Is there any difference b/w static global variables and global variables
 ???

 (apart from that static variables will be limited to that file only and
 global variables will be visible for other files also.)


 Regards,
 Aman.

 --
 AMAN AGARWAL
 Success is not final, Failure is not fatal: It is the courage to
 continue that counts!

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


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


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


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



[algogeeks] whats the o/p of the code snippet

2012-02-25 Thread AMAN AGARWAL
Hi,

int main()
{
int i;

int*p=malloc(4);
*p=2;
printf(%d\n,*p);
free(p);
*p=5;
printf(%d\n,*p);
scanf(%d,i);
return 0;
}

Even though I have freed the memory using free(p) when I am dereferencing
it I dont get any seg fault.
Can anybody explain me why???

Regards,
Aman.
-- 
AMAN AGARWAL
Success is not final, Failure is not fatal: It is the courage to continue
that counts!

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



Re: [algogeeks] whats the o/p of the code snippet

2012-02-25 Thread Rahul
Please insert a code snippet in between free and usage

That's what I can refer
http://stackoverflow.com/questions/9124672/array-desctruction-at-the-end-of-funtion-call

On 2/25/12, AMAN AGARWAL mnnit.a...@gmail.com wrote:
 Hi,

 int main()
 {
 int i;

 int*p=malloc(4);
 *p=2;
 printf(%d\n,*p);
 free(p);
 *p=5;
 printf(%d\n,*p);
 scanf(%d,i);
 return 0;
 }

 Even though I have freed the memory using free(p) when I am dereferencing
 it I dont get any seg fault.
 Can anybody explain me why???

 Regards,
 Aman.
 --
 AMAN AGARWAL
 Success is not final, Failure is not fatal: It is the courage to continue
 that counts!

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



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



[algogeeks] output C

2012-02-25 Thread Ravi Ranjan
#include stdio.h
#include stdlib.h

#define SIZEOF(arr) (sizeof(arr)/sizeof(arr[0]))

  #define PrintInt(expr) printf(%s:%d\n,#expr,(expr))

int main(int argc, char *argv[])
{

  /* The powers of 10 */
  int pot[] = {
  0001,
  0010,
  0100,
  1000
  };
  int i;

  for(i=0;iSIZEOF(pot);i++)
   PrintInt(pot[i]);

  system(PAUSE);
  return 0;
}


howz dat output come plz explain??

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



[algogeeks] Constructing Binary Tree from a sorted Doubly Linked List

2012-02-25 Thread Supraja Jayakumar
Hi All

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

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

Btree* ConstructTreeFromDLList(DLList *dll) {


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

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

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

Thank You
Supraja J
--
U

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



Re: [algogeeks] Constructing Binary Tree from a sorted Doubly Linked List

2012-02-25 Thread atul anand
you do the same using bottom up approach...complexity would O(n)
 On 26 Feb 2012 03:54, Supraja Jayakumar suprajasank...@gmail.com wrote:

 Hi All

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

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

 Btree* ConstructTreeFromDLList(DLList *dll) {



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


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


 Btree * BuildTree(DLList *dll, DLLNode * head, DLLNode *tail) {
 // Find mid node using two pointers from head and tail.
 // Boundary cases - no head ? no tail ? - handle here.
 Node *this = head;
 Node *that = tail;

 int mid = 0;
 while(this != that  || this-prev != that || that-next != this) {// 
 Until they have not crossed
   this=this-next;
   that=that-prev;
 mid++;
 }
 printf(“Mid Node Index=%d \n”, mid);

 BTree *root = this = that;
 root-left = BuildTree(head, that-prev);
 root-right = BuildTree(this-next, tail);
 return root;
 }

 Thank You
 Supraja J
 --
 U

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


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



Re: [algogeeks] Constructing Binary Tree from a sorted Doubly Linked List

2012-02-25 Thread atul anand
here how you can do it :-
call construct(head,0,n-1); n=length of linked list

node* construct(node *head,int start,int end)
{
int mid;
if(start  end)
   return NULL;

   mid=(start+end)/2;
   node * tleft=construct(dll,start,mid-1);
   head-next=tleft;
   head=head-next;
   head-prev=construct(dll,mid+1,end);

  return head;

}

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



Re: [algogeeks] output C

2012-02-25 Thread atul anand
 0001,
 0010,
 0100,
these number are represented in octal ..so u r getting decimal of the same.
1000 - this is a decimal value;

preceding number by 0 means you are representing it in octal format

similarly preceding 0x means representing in hexa format.

On Sun, Feb 26, 2012 at 3:38 AM, Ravi Ranjan ravi.cool2...@gmail.comwrote:

 #include stdio.h
 #include stdlib.h

 #define SIZEOF(arr) (sizeof(arr)/sizeof(arr[0]))

   #define PrintInt(expr) printf(%s:%d\n,#expr,(expr))

 int main(int argc, char *argv[])
 {

   /* The powers of 10 */
   int pot[] = {
   0001,
   0010,
   0100,
   1000
   };
   int i;

   for(i=0;iSIZEOF(pot);i++)
PrintInt(pot[i]);

   system(PAUSE);
   return 0;
 }


 howz dat output come plz explain??

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


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