Re: [algogeeks] Nested Function C

2012-10-03 Thread srikanth reddy malipatel
@rahul In Standard C you cant define a function inside another function but
you can declare a function inside another function. (so the function can be
defined outside the function).
Eg:-
#include
void abc()
{
printf("bac");
void abf();
abf();
}

void abf()
{
printf("bas");
getchar();
}

int main()
{
abc();
getchar();
}

coming to Gcc has a language extension that allows nested functions. so
this is entirely compiler dependent.

On Wed, Oct 3, 2012 at 12:39 PM, kranthi kumar wrote:

> In C, there is no difference between rules for declaring and defining
> function and variable. So we can define the functions inside another
> function, but their scope is limited to that function only,
> In this example abf() is local function to abc(), it can't be
> accessed outside environment.
>
>
> On Wed, Oct 3, 2012 at 1:06 AM, rahul sharma wrote:
>
>> Guys i have read that we cant define function in another function in c
>> Then why this followung program running fine on gcc
>>
>> #include
>> void abc()
>> {
>>  printf("bac");
>>  void abf()
>>  {
>>  printf("bas");
>>  getchar();
>>  }
>> }
>> int main()
>> {
>> abc();
>> getchar();
>> }
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards:
> 
> Kranthi Kumar D
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

Regards,
Srikanth.

-- 
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] array problem

2012-09-06 Thread srikanth reddy malipatel
post the logic not the code!
BTW this  problem can be done using segment trees.

http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAncestor


On Thu, Sep 6, 2012 at 4:51 PM, bharat b wrote:

> Its better to write an O(n) solution for this problem as the # test cases
> are very high and #elements are also very huge..
> use visited array for distinct numbers ... space--O(n).. time--O(n)
>
>
> On Sat, Aug 25, 2012 at 2:39 AM, michael miller <
> wentworth.miller6...@gmail.com> wrote:
>
>> Hi,
>> You are given N numbers. You have to perform two kinds of operations:
>> U x y - x-th number becomes equal to y.
>> Q x y - calculate the sum of distinct numbers from x-th to y-th. It means
>> that the sum for the set {1, 2, 3, 2, 7} will be equal to 13 (1+2+3+7).
>>
>> 1<=N<=5 and
>> t is the number of test cases where   1<=t<=10
>>
>> all numbers fit in the 32 bit integer range...
>>
>> suggest some solution..
>>
>> here is my solution
>> but it is giving wrong answer fo some unknown test case...plz suggest me
>> the test case where i am getting wrong answer
>>
>>
>> #include
>> #include
>> int main()
>> {
>> int list[5],i,n,j,sum,k,l;char c;long t;
>> scanf 
>> ("%d",&n);
>> for(i=0;i> {
>> scanf 
>> ("%d",&list[i]);
>>
>> }
>> scanf 
>> ("%ld",&t);
>>
>> t=2*t;
>> while(t)
>> {
>> sum=0;
>> scanf 
>> ("%c",&c);
>>
>> fflush(stdin);
>> scanf 
>> ("%d 
>>%d",&k,&l);
>>
>> if(c=='Q')
>> {
>> for(i=k-1;i> {
>> for(j=i+1;j> {
>>if(list[i]==list[j])
>>   break;
>>else if((j==l-1) &&(list[i]!=list[j]))
>>
>>{
>>   sum=sum+list[i];
>>
>>}
>> }
>>  }
>>
>>  printf 
>> ("%d\n",sum+list[l-1]);
>>
>>  }
>>  if(c=='U')
>>  {
>>  list[k-1]=l;
>>
>>  }
>>  t--;
>> }
>> return 0;
>> }
>>
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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.
>



-- 
Srikanth Reddy M
(M.Sc Tech.) Information Systems
BITS-PILANI

-- 
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] Finding largest zigzag subsequence

2012-06-08 Thread srikanth reddy malipatel
#include

int main()
{
int Seq[100],i,j,n,Max,tmp;
int zzlen[100][2];
scanf("%d",&n);
for(i = 0 ; i < n ; i++) { scanf("%d",&Seq[i]); zzlen[i][0] =
1;zzlen[i][1] = 0;}
Max = 1;
for(i = 1 ; i < n ; i++)
{
for(j = i-1 ; j >= 0 ; j--)
{
if(Seq[i] >= Seq[j])
{
tmp = 1;
if(zzlen[j][1] == -1 || zzlen[j][1] == 0)
{
if(zzlen[i][0] < zzlen[j][0]+1) { zzlen[i][0] =
zzlen[j][0]+1; zzlen[i][1] = tmp; }
}
}
if(Seq[i] < Seq[j])
{
tmp = -1;
if(zzlen[j][1] == 1 || zzlen[j][1] == 0)
{
if(zzlen[i][0] < zzlen[j][0]+1) { zzlen[i][0] =
zzlen[j][0]+1; zzlen[i][1] = tmp;}
}
}
}
if(zzlen[i][0] > Max) Max = zzlen[i][0];
}
printf("Length of longest zig-zag subsequence is : %d\n",Max);
    return 0;
}

On Fri, Jun 8, 2012 at 5:40 PM, srikanth reddy malipatel  wrote:

> we should use dp
>
>
> On Fri, Jun 8, 2012 at 5:39 PM, Ratan  wrote:
>
>> Thats what the question is about  to find the maximum subsequence.
>> i too tried your code with the sample "10,4,12,4,1,43,21,4,1,5,7,23,9"
>> ur code gave the result "10 12  4   43  21  23";
>> but the correct optimized o/p should have been with length 7 as
>> "4,12,1,43,21,23,9"
>>
>> On Fri, Jun 8, 2012 at 5:26 PM, Ashish Goel  wrote:
>> > my solution will not provide the largest eg 2,4,6,5 should have largest
>> as
>> > 2,6,5 not 2,4..
>> >
>> > Best Regards
>> > Ashish Goel
>> > "Think positive and find fuel in failure"
>> > +919985813081
>> > +919966006652
>> >
>> >
>> > On Fri, Jun 8, 2012 at 4:15 PM, Ashish Goel  wrote:
>> >>
>> >> O(n) is straight forward
>> >>
>> >> bool increase = true;
>> >> int j = 0;
>> >> result[j++]=a[0];
>> >> for (int i=1;i> >> {
>> >>   if ((increase)
>> >>   {
>> >> if (result[j-1]> >> {
>> >>   result[j++] = a[i];
>> >>   increase = false;
>> >> }
>> >>   }
>> >>   else {
>> >> if (result[j-1] >a[i]))
>> >> {
>> >>   result[j++] = a[i];
>> >>   increase = true;
>> >> }
>> >>   }
>> >> }
>> >>
>> >> What i was thinking is to find the number of peaks and valleys through
>> >> binary search thereby using log(n) solution not able
>> to conceptualize it
>> >> this way (:.
>> >> Best Regards
>> >> Ashish Goel
>> >> "Think positive and find fuel in failure"
>> >> +919985813081
>> >> +919966006652
>> >>
>> >>
>> >>
>> >> On Fri, Jun 8, 2012 at 3:47 PM, Ratan 
>> wrote:
>> >>>
>> >>> Given a list of integers n, we have to find the length of largest
>> >>> zigazg subsequence in the list i.e,zigzag subsequence is defined
>> >>> as  "if the first number is increasing then the 2nd one should be
>> >>> decreasing or vice versa.. "
>> >>>
>> >>> for eg : if list[n]={1,10,5,9,8,12,20} then,
>> >>>
>> >>>  largest zigzag subsequence will be : {1,10,5,9,8,12} or
>> >>> {1,10,5,9,8,20} and length will be=6;
>> >>>
>> >>>
>> >>> --
>> >>> --
>> >>>
>> >>> --
>> >>> 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.
>>
>>
>>
>> --
>> --
>> Ratan | 3rd Year | Information Technology | NIT ALLAHABAD
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> Srikanth Reddy M
> (M.Sc Tech.) Information Systems
> BITS-PILANI
>
>


-- 
Srikanth Reddy M
(M.Sc Tech.) Information Systems
BITS-PILANI

-- 
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] Finding largest zigzag subsequence

2012-06-08 Thread srikanth reddy malipatel
we should use dp

On Fri, Jun 8, 2012 at 5:39 PM, Ratan  wrote:

> Thats what the question is about  to find the maximum subsequence.
> i too tried your code with the sample "10,4,12,4,1,43,21,4,1,5,7,23,9"
> ur code gave the result "10 12  4   43  21  23";
> but the correct optimized o/p should have been with length 7 as
> "4,12,1,43,21,23,9"
>
> On Fri, Jun 8, 2012 at 5:26 PM, Ashish Goel  wrote:
> > my solution will not provide the largest eg 2,4,6,5 should have largest
> as
> > 2,6,5 not 2,4..
> >
> > Best Regards
> > Ashish Goel
> > "Think positive and find fuel in failure"
> > +919985813081
> > +919966006652
> >
> >
> > On Fri, Jun 8, 2012 at 4:15 PM, Ashish Goel  wrote:
> >>
> >> O(n) is straight forward
> >>
> >> bool increase = true;
> >> int j = 0;
> >> result[j++]=a[0];
> >> for (int i=1;i >> {
> >>   if ((increase)
> >>   {
> >> if (result[j-1] >> {
> >>   result[j++] = a[i];
> >>   increase = false;
> >> }
> >>   }
> >>   else {
> >> if (result[j-1] >a[i]))
> >> {
> >>   result[j++] = a[i];
> >>   increase = true;
> >> }
> >>   }
> >> }
> >>
> >> What i was thinking is to find the number of peaks and valleys through
> >> binary search thereby using log(n) solution not able to conceptualize it
> >> this way (:.
> >> Best Regards
> >> Ashish Goel
> >> "Think positive and find fuel in failure"
> >> +919985813081
> >> +919966006652
> >>
> >>
> >>
> >> On Fri, Jun 8, 2012 at 3:47 PM, Ratan 
> wrote:
> >>>
> >>> Given a list of integers n, we have to find the length of largest
> >>> zigazg subsequence in the list i.e,zigzag subsequence is defined
> >>> as  "if the first number is increasing then the 2nd one should be
> >>> decreasing or vice versa.. "
> >>>
> >>> for eg : if list[n]={1,10,5,9,8,12,20} then,
> >>>
> >>>  largest zigzag subsequence will be : {1,10,5,9,8,12} or
> >>> {1,10,5,9,8,20} and length will be=6;
> >>>
> >>>
> >>> --
> >>> --
> >>>
> >>> --
> >>> 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.
>
>
>
> --
> --
> Ratan | 3rd Year | Information Technology | NIT ALLAHABAD
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Srikanth Reddy M
(M.Sc Tech.) Information Systems
BITS-PILANI

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



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

2012-03-19 Thread srikanth reddy malipatel
hii supraja can u mail me the link for your blog plz.

On Sun, Mar 18, 2012 at 6:38 PM, Supraja Jayakumar  wrote:

> Hi
> Others are also welcome to comment on the code. If links are allowed in
> algogeeks, I might send my wordpress blog link that explains this problem
> in detail and in picture.
>
> BinaryTree* VerticalSum(BinaryTree *bt) {
> if(!bt) return;
> BinaryTree *left = bt->left;
> BinaryTree *right = bt->right;
> bt->VerticalSumValue += right(left)->value+left(right)->value;
> VerticalSum(left);
> VerticalSum(right);
> }
>
> BinaryTree* right(BinaryTree *left) {
> if(!left) return;
> sum+=right(left->right);
> return sum;
> }
>
> BinaryTree *left(BinaryTree *right) {
> if(!right) return;
> sum+=left(right->left);
> return sum;
> }
>
> Thanks
>
> Supraja J
>
>
> On Sun, Mar 18, 2012 at 5:50 AM, rahul sharma wrote:
>
>> plz some one explain...i hav read online but getting the code and same
>> explanaiton...need it urgent...thnx in advance
>>
>>
>> On Sun, Mar 18, 2012 at 12:38 AM, rahul sharma 
>> wrote:
>>
>>> @anna..plz elaborate more...
>>>
>>>
>>> On Sun, Mar 18, 2012 at 12:26 AM, Supraja Jayakumar <
>>> suprajasank...@gmail.com> wrote:
>>>
 Hi

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

 Thanks


 On Sat, Mar 17, 2012 at 9:31 AM, rahul sharma 
 wrote:

> plz explain...i m nt able to get the concept.
>
>
> On Sat, Mar 17, 2012 at 8:50 PM, rahul sharma  > wrote:
>
>> how come 2,3,7 in vertical sum?
>>
>>
>> On Sat, Mar 17, 2012 at 3:48 PM, prashant thorat <
>> prashantnit...@gmail.com> wrote:
>>
>>> First , Do recursive traverse from root node and assign vertical
>>> level for each node. like this,
>>> for root node level = 0 , root->left level = -1 , root->left->right
>>> = 0 , root->left->left = -2, like this
>>>
>>>
>>> so below tree becomes,
>>>
>>>   1(0)
>>>/\
>>> 2(-1)3(1)
>>>  /  \   /\
>>> 4(-2)   5(0)  6(1)   7(2)
>>>
>>>
>>>
>>> After this again, take an array to store sum initialize to 0, and
>>> traverse tree again , while traversing store the value of that node in 
>>> it's
>>> level.
>>>
>>> This way u'll be able to calculate vertical sum.
>>>
>>>
>>> Thanks
>>>
>>> On Sat, Mar 17, 2012 at 3:29 PM, rahul sharma <
>>> rahul23111...@gmail.com> wrote:
>>>

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

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

 Examples:

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

 The tree has 5 vertical lines

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

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

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

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



 --
 U

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

Re: [algogeeks] Puzzle

2012-02-28 Thread srikanth reddy malipatel
{39,41,43,45}incremented by 2
{49,51,53,55}incremented by 2
{64,?,?,?}

first number in each set is considered as base number.
3 is for the number of numbers in each set other than base number.
so in final set base number is 64 and other 3 numbers are incremented by 2.

On Tue, Feb 28, 2012 at 1:48 PM, payal gupta  wrote:
> one option cud be reverse the digits...i.e
> (bt the first n d last do not satisfy d pattern howeva)
> 93 , 14,34,54,94,15,35,35,55
> an increment is applied to the last 4th no each tme...
> not very sure if its crckt...
>
> Regards,
> PAYAL GUPTA
>
>
>
>
> On Tue, Feb 28, 2012 at 12:48 PM, Kartik Sachan 
> wrote:
>>
>> I think logic is the difference is
>> 2 2 4 2 2 2 8 so next will be 2 2  2 2 2 16
>>
>> so ans will be 66 68 70
>>
>>
>> but first number 3 making some problem
>>
>> --
>> 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.



-- 
Srikanth Reddy M
(M.Sc Tech.) Information Systems
BITS-PILANI

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

2012-02-27 Thread srikanth reddy malipatel
66,68,70

On Mon, Feb 27, 2012 at 6:54 PM, karthikeya s  wrote:
> 3, 39, 41, 43, 45, 49, 51, 53, 55, 64, ?, ?, ...
> (These are successive numbers sharing a common property. No math or
> outside knowledge is needed.)
>
> --
> 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.
>



-- 
Srikanth Reddy M
(M.Sc Tech.) Information Systems
BITS-PILANI

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