[algogeeks] Flipkart test

2012-10-08 Thread Avinash Mishra
Hello any one have idea about Flipkart recruitment process for SDE1. Please
guide me what to prepare.
Thanks


-- 
regard's
Avinash

-- 
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] rectangle of max sum MS Q

2012-10-08 Thread atul anand
@Priya : if first row is the max one , then it is actually boundary case
which you can be handled easily,once you are done which above algo.
please note that only first row need to checked if it max not every row ,
above algo is handling this . you can also modify given algo which will
handle this boundary case.
for rest of the cases it will work fine. It is handling cases like...
c2d2
c3d3 etc...
please try to understand idea behind the given algo ,let me know in case
you have any further doubt.

On Mon, Oct 8, 2012 at 10:52 PM, Priya Dhingra wrote:

> @atul  if the largest matrix is [a1  b1  c1  d1 ]  i mean if it is the
> first row or if it is [c2 d2.i think then then ur code wont be giving the
> right answer.
>c3 d3]
>
> correct me if i'm wrong
>
>
> On Monday, January 16, 2012 7:51:46 AM UTC-8, atul007 wrote:
>
>>
>> find cumulative sum of each column.
>> now for each arr[x][y] = sum of arr[i=0 to x] [j] ;
>>
>> a1 b1 c1 d1
>> a2 b2 c2 d2
>> a3 b3 c3 d3
>> a4 d4 c4 d4
>>
>> now we have reduced this problem to find max-subarray . which can
>> be efficiently calculated using kadane's algo for each row.
>>
>> NOTE: now suppose if row = 0  does not participate in calculating max sum
>> matrix so u need to subtract a1 from a2,a3,a4  similarly for other
>> element in row 1,2,3.
>>
>> now updated matrix considered i.e from (row =1 to row =3 ). for this
>> updated matrix,
>>  each[x][y] is the sum of arr[i=1 to x] [j].
>>
>> similarly do for other elements.
>>
>> On Mon, Jan 16, 2012 at 6:55 AM, Ashish Goel  wrote:
>>
>>> given a m*n matrix, find the subset rectangle with max sum (any other
>>> rectangle taken would have lesser sum)
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algo...@googlegroups.com.
>>> To unsubscribe from this group, send email to algogeeks+...@**
>>> 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 view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/4jFUDHYfBqUJ.
>
> 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] using name space std

2012-10-08 Thread Abhishek Patro
if u have seen the iostream file then it begins like this:-

#include 
#include 
#include 
*
*
*namespace std *
{
  /**
   *  @name Standard Stream Objects
   *
   *  The  header declares the eight standard stream
   *  objects.  For other declarations, see
   *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#10 and the
   *  @link s27_2_iosfwd I/O forward declarations @endlink
   *
   *  They are required by default to cooperate with the global C library's
   *  @c FILE streams, and to be available during program startup and
   *  termination.  For more information, see the HOWTO linked to above.
  */
  //@{
  extern istream cin; ///< Linked to standard input
  extern ostream cout; ///< Linked to standard output
  extern ostream cerr; ///< Linked to standard error (unbuffered)

The new implementation is done in C# format. So we use the term "using" to
include the iostream "package".



On Tue, Oct 9, 2012 at 12:01 AM, rahul sharma wrote:

> using name space std
>
> Please explain about this
> thnx
>
> --
> 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.
>



-- 
Abhishek Patro

-- 
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] using name space std

2012-10-08 Thread rahul sharma
using name space std

Please explain about this
thnx

-- 
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] C output

2012-10-08 Thread rahul sharma
@sachin..thnx for explanation..got it..plz tell

#include


int main()
{
   char str[]={'a','b','c'};
   char str1[]={"abc"};
  printf("%d",sizeof(str));
printf("%d",sizeof(str1));
getchar();
}



why str has size 3 and str1 has 4...NUll should also come after c of
str???then y 3??

On Mon, Oct 8, 2012 at 5:07 PM, Sachin  wrote:

> @rahul According to C specification, half filled array will be filled with
> value 0. In your example you are setting str[0] as 'g' and str[1] as 'k'.
> So the compiler sets str[29] as 0. So you string str becomes
> {'g', 'k', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}
>
> Confusion is arising from the fact that you have created an array of 10
> elements.
>
> To answer you original question "gk" is inherently {'g', 'k', '\0'} and
> has size 3 while {'g', 'k'} has size 2.
>
> Regards,
> Sachin
>
>
> On Saturday, October 6, 2012 9:34:30 PM UTC+5:30, rahul sharma wrote:
>
>> #include
>>
>>
>> int main()
>> {
>> char str[10]={'g','k'};
>> char str1[10]="gh";
>> int i;
>> for(i=0;str1[i]!=NULL;i++)
>> printf("%c",str[i]);
>> getchar();
>> }
>>
>> NUll is there in character array also...make clear me...
>>
>> On Sat, Oct 6, 2012 at 9:22 PM, rahul sharma  wrote:
>>
>>> int main()
>>> {
>>> char str[10]={'g','k'};
>>> char str1[10]="gh";
>>>
>>>
>>> printf("%s",str);
>>> printf("%s",str1);
>>> getchar();
>>> }
>>> then how does this work???
>>> str printing gk...then NULL is automatically appended in this also...plz
>>> tell
>>>
>>>
>>> On Sat, Oct 6, 2012 at 6:33 PM, Rathish Kannan wrote:
>>>
 For string, C appends '\0' internally. hence sizeof(str) returned the
 value 3.
 str1 is char array with two character. hence sizeof(str1) returned the
 value 2.

 --  RK :)


 On Sat, Oct 6, 2012 at 5:53 PM, rahul sharma wrote:

> char str[]="ab";
> char str1[]={'a','b'};
>
> sizeof(str) ...o/p is 3
> sizeof(str1)o/p is 2..
>
> Why so
> 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 algo...@googlegroups.com.
> To unsubscribe from this group, send email to algogeeks+...@**
> 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 algo...@googlegroups.com.
 To unsubscribe from this group, send email to algogeeks+...@**
 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 view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/65EsWyTnMlEJ.
>
> 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] Min Edges to be added to DAG to make it Strongly connected?

2012-10-08 Thread Saurabh Kumar
You'd need:  max(#vertices-with-0in-degree, #vertices-with-0out-degree)
edges at least.

On 8 October 2012 20:20, bharat b  wrote:

> @jaspreet: take an ex:
>  B->A
> B->C
> B->D
> Here the no.of zero-indegree is one . But its not the correct ans.
>
>
> On Mon, Oct 8, 2012 at 1:19 AM, Jaspreet Singh 
> wrote:
>
>> count the no. of nodes having 0 in-degree.
>>
>>
>> On Mon, Oct 8, 2012 at 12:44 AM, atul anand wrote:
>>
>>> yeah i read it wrongly .. i thought ques was asking to find total
>>> strongly connected component in the graph
>>>
>>> On 10/7/12, bharat b  wrote:
>>> > @atul : if there is no cut vertex, that doesn't mean that graph is
>>> strongly
>>> > connected ...
>>> >
>>> >
>>> > On Sat, Oct 6, 2012 at 7:37 PM, atul anand 
>>> wrote:
>>> >
>>> >> find no. of cut vertex in the DAGthat will be the ans.
>>> >> On 6 Oct 2012 19:33, "KK"  wrote:
>>> >>
>>> >>> Given a DAG(Directed Acyclic Graph). How to find out the minimum
>>> number
>>> >>> of edges that needs to be added so that the given graph becomes
>>> Strongly
>>> >>> Connected?
>>> >>>
>>> >>> --
>>> >>> You received this message because you are subscribed to the Google
>>> >>> Groups
>>> >>> "Algorithm Geeks" group.
>>> >>> To view this discussion on the web visit
>>> >>> https://groups.google.com/d/msg/algogeeks/-/PbR3j9S5OXUJ.
>>> >>> 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.
>>>
>>>
>>  --
>> 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] Min Edges to be added to DAG to make it Strongly connected?

2012-10-08 Thread Jaspreet Singh
ok the algo will go like this :
count no of nodes having only indegree 0 , only outdegree 0 and both 0. say
in_count,out_count and both_count are the corresponding counts.
now decrease the counts accordingly if u found a matching like u can
decrease in_count by both_count if both_count0 and in
degree>0 your graph is connected !! and i m just making that.

On Mon, Oct 8, 2012 at 8:37 PM, Jaspreet Singh wrote:

> yeah you are correct bharat .. so i think it should be no. of nodes
> having 0 (in-degree + out-degree). what say ?
>
>
> On Mon, Oct 8, 2012 at 8:20 PM, bharat b wrote:
>
>> @jaspreet: take an ex:
>>  B->A
>> B->C
>> B->D
>> Here the no.of zero-indegree is one . But its not the correct ans.
>>
>>
>> On Mon, Oct 8, 2012 at 1:19 AM, Jaspreet Singh > > wrote:
>>
>>> count the no. of nodes having 0 in-degree.
>>>
>>>
>>> On Mon, Oct 8, 2012 at 12:44 AM, atul anand wrote:
>>>
 yeah i read it wrongly .. i thought ques was asking to find total
 strongly connected component in the graph

 On 10/7/12, bharat b  wrote:
 > @atul : if there is no cut vertex, that doesn't mean that graph is
 strongly
 > connected ...
 >
 >
 > On Sat, Oct 6, 2012 at 7:37 PM, atul anand 
 wrote:
 >
 >> find no. of cut vertex in the DAGthat will be the ans.
 >> On 6 Oct 2012 19:33, "KK"  wrote:
 >>
 >>> Given a DAG(Directed Acyclic Graph). How to find out the minimum
 number
 >>> of edges that needs to be added so that the given graph becomes
 Strongly
 >>> Connected?
 >>>
 >>> --
 >>> You received this message because you are subscribed to the Google
 >>> Groups
 >>> "Algorithm Geeks" group.
 >>> To view this discussion on the web visit
 >>> https://groups.google.com/d/msg/algogeeks/-/PbR3j9S5OXUJ.
 >>> 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.


>>>  --
>>> 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] Re: finding element in array with minimum of comparing

2012-10-08 Thread Sachin
@empo I believe you missed the point where Dave is setting arr[0] as elem. 
So this while condition will break at size = 0.

Thanks
Sachin

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/rkfWJrK9N1kJ.
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] Min Edges to be added to DAG to make it Strongly connected?

2012-10-08 Thread Jaspreet Singh
yeah you are correct bharat .. so i think it should be no. of nodes having
0 (in-degree + out-degree). what say ?

On Mon, Oct 8, 2012 at 8:20 PM, bharat b wrote:

> @jaspreet: take an ex:
>  B->A
> B->C
> B->D
> Here the no.of zero-indegree is one . But its not the correct ans.
>
>
> On Mon, Oct 8, 2012 at 1:19 AM, Jaspreet Singh 
> wrote:
>
>> count the no. of nodes having 0 in-degree.
>>
>>
>> On Mon, Oct 8, 2012 at 12:44 AM, atul anand wrote:
>>
>>> yeah i read it wrongly .. i thought ques was asking to find total
>>> strongly connected component in the graph
>>>
>>> On 10/7/12, bharat b  wrote:
>>> > @atul : if there is no cut vertex, that doesn't mean that graph is
>>> strongly
>>> > connected ...
>>> >
>>> >
>>> > On Sat, Oct 6, 2012 at 7:37 PM, atul anand 
>>> wrote:
>>> >
>>> >> find no. of cut vertex in the DAGthat will be the ans.
>>> >> On 6 Oct 2012 19:33, "KK"  wrote:
>>> >>
>>> >>> Given a DAG(Directed Acyclic Graph). How to find out the minimum
>>> number
>>> >>> of edges that needs to be added so that the given graph becomes
>>> Strongly
>>> >>> Connected?
>>> >>>
>>> >>> --
>>> >>> You received this message because you are subscribed to the Google
>>> >>> Groups
>>> >>> "Algorithm Geeks" group.
>>> >>> To view this discussion on the web visit
>>> >>> https://groups.google.com/d/msg/algogeeks/-/PbR3j9S5OXUJ.
>>> >>> 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.
>>>
>>>
>>  --
>> 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] finding element in array with minimum of comparing

2012-10-08 Thread Umer Farooq
@ Mengal.

That's what I thought actually
But, he had set the value of arr[0] = elem
So, it will stop at zeroth element and won't go to -1th element.

On Mon, Oct 8, 2012 at 12:01 AM, Mangal Dev Gupta wrote:

> *@Dave  while( arr[--size] != elem );*
>
> *Exception will come when it will encounter a[-1]*
> *i dont know if this loop will ever end... very poor solution i will say
> *
>
> On Sat, Oct 6, 2012 at 10:00 PM, Umer Farooq  wrote:
>
>> Well actually, I've just gone through Dave's code thoroughly and I
>> believe that his code is most appropriate.
>>
>> Thanks viper11 for providing the explanation.
>>
>> As for my code, I'd like to replace
>>
>> while (i!=j)
>>
>> with
>>
>> while (i < j)
>>
>> because != won't work for middle element if the number of elements are
>> odd ... and it also won't work if the number of elements are even.
>>
>> Anyway, thanks Dave for providing us with such a great solution. Please
>> keep posting! :-)
>>
>> And others, thanks for pointing out the issue in my code.
>>
>> On Sat, Oct 6, 2012 at 9:03 PM, Kalidhakani J wrote:
>>
>>> @umer - what if the element to be searched is at the middle of the
>>> array? your code doesn't handles this. check out.
>>>
>>>
>>> On Sat, Oct 6, 2012 at 3:38 AM, icy`  wrote:
>>>
 nice solution, Dave!

 @Umer -- if the sought ele is first, then Dave's code has it sitting in
 the variable temp for a little while.   Loop will stop when size is 0,
 since arr[0]==elem.  Now he throws temp back into arr[0], which will return
 index 0 from the last compare line.

 On Wednesday, October 3, 2012 2:08:56 AM UTC-4, Umer Farooq wrote:
>
> @Dave Thanks for pointing that out.
>
> But I still can't get what if elem is on first element or it is not
> present in the array? How is your code going to handle that situation?
>
> @Atul, Well yes, In the given question, the number of iterations were
> 2n. Which I have reduced to n+n/2.
>
>
>
>
>
> On Tue, Oct 2, 2012 at 11:13 PM, atul anand wrote:
>
>> @umer : how no. of comparison are reduced to half by moving both
>> sidesyou have 2 if condition inside, so you are making 2
>> comparisons at each iteration + n/2 comparison for while loop so
>> number of comparisons are n+n/2
>>
>> On 10/2/12, Umer Farooq  wrote:
>> > why don't we try it from both ends ... something like this:
>> >
>> > int i = 0; j = size-1;
>> >
>> > while (i != j)
>> > {
>> > if (arr[i] == elem)
>> >   return arr[i];
>> > if (arr[j] == elem)
>> >return arr[j];
>> > }
>> >
>> > this way, we have eliminated half of the comparisons in for loop?
>> What do
>> > you guys say?
>> >
>> > On Tue, Oct 2, 2012 at 12:18 PM, rafi  wrote:
>> >
>> >> Vikas is right!
>> >> while (n) is equal to (while n!=0)
>> >> you have 2n compares!
>> >>
>> >> בתאריך יום שני, 1 באוקטובר 2012 12:12:21 UTC+2, מאת vikas:
>> >>
>> >>> still there is no improvement, compiler will generate the code to
>> >>> compare
>> >>> with zero here. what you have accomplished is , hide it from
>> human eyes
>> >>>
>> >>> On Monday, 1 October 2012 15:25:09 UTC+5:30, Navin Kumar wrote:
>> 
>>  @atul:
>>  still it won't compare 0 th element. Slight modification in your
>> code:
>> 
>>  n=*sizeof(arr)*;
>>  do
>>  {
>>   if(elem==arr[*--n*])
>>   print found;
>> 
>>  }while(n);
>> 
>>  On Mon, Oct 1, 2012 at 9:50 AM, atul anand 
>> wrote:
>> 
>> > yes, but there no need of checking outside the loop
>> >
>> > n=sizeof(arr)-1;
>> > do
>> > {
>> >  if(elem==arr[n])
>> >  print found;
>> > n--;
>> >
>> > }while(n);
>> >
>> >
>> >
>> > On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar
>> > wrote:
>> >
>> >> @atul: keep one more checking outside loop for element at 0 th
>> index.
>> >> Because when n = 0  the your loop come out from the loop
>> without
>> >> comparing
>> >> it.
>> >>
>> >>
>> >> On Mon, Oct 1, 2012 at 8:55 AM, atul anand
>> >> wrote:
>> >>
>> >>> n=sizeof(arr);
>> >>> n--;
>> >>>
>> >>> while(n)
>> >>> {
>> >>>  if(elem=arr[n])
>> >>>   print found;
>> >>>
>> >>> n--;
>> >>>
>> >>> }
>> >>>
>> >>> On Sun, Sep 30, 2012 at 2:56 PM, רפי וינר > >
>> >>> wrote:
>> >>>
>>  Hi
>>  i was in an interview and was given a simple function
>>  int arrExsits(int* arr,int size,int elem){
>>  for (int i=0;i> >>

Re: [algogeeks] C output

2012-10-08 Thread Sachin
@rahul According to C specification, half filled array will be filled with 
value 0. In your example you are setting str[0] as 'g' and str[1] as 'k'. 
So the compiler sets str[29] as 0. So you string str becomes
{'g', 'k', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}

Confusion is arising from the fact that you have created an array of 10 
elements.

To answer you original question "gk" is inherently {'g', 'k', '\0'} and has 
size 3 while {'g', 'k'} has size 2.

Regards,
Sachin

On Saturday, October 6, 2012 9:34:30 PM UTC+5:30, rahul sharma wrote:
>
> #include
>
>
> int main()
> {
> char str[10]={'g','k'};
> char str1[10]="gh";
> int i;
> for(i=0;str1[i]!=NULL;i++)
> printf("%c",str[i]);
> getchar();
> }
>
> NUll is there in character array also...make clear me...
>
> On Sat, Oct 6, 2012 at 9:22 PM, rahul sharma 
> > wrote:
>
>> int main()
>> {
>> char str[10]={'g','k'};
>> char str1[10]="gh";
>>
>>
>> printf("%s",str);
>> printf("%s",str1);
>> getchar();
>> }
>> then how does this work???
>> str printing gk...then NULL is automatically appended in this also...plz 
>> tell
>>
>>
>> On Sat, Oct 6, 2012 at 6:33 PM, Rathish Kannan 
>> 
>> > wrote:
>>
>>> For string, C appends '\0' internally. hence sizeof(str) returned the 
>>> value 3.
>>> str1 is char array with two character. hence sizeof(str1) returned the 
>>> value 2.
>>>
>>> --  RK :)
>>>
>>>
>>> On Sat, Oct 6, 2012 at 5:53 PM, rahul sharma 
>>> 
>>> > wrote:
>>>
 char str[]="ab"; 
 char str1[]={'a','b'};

 sizeof(str) ...o/p is 3
 sizeof(str1)o/p is 2..

 Why so
 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 algo...@googlegroups.com
 .
 To unsubscribe from this group, send email to 
 algogeeks+...@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 algo...@googlegroups.com
>>> .
>>> To unsubscribe from this group, send email to 
>>> algogeeks+...@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 view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/65EsWyTnMlEJ.
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] rectangle of max sum MS Q

2012-10-08 Thread Priya Dhingra
@atul  if the largest matrix is [a1  b1  c1  d1 ]  i mean if it is the 
first row or if it is [c2 d2.i think then then ur code wont be giving the 
right answer.   
   c3 d3]

correct me if i'm wrong

On Monday, January 16, 2012 7:51:46 AM UTC-8, atul007 wrote:
>
>
> find cumulative sum of each column.
> now for each arr[x][y] = sum of arr[i=0 to x] [j] ;
>
> a1 b1 c1 d1
> a2 b2 c2 d2
> a3 b3 c3 d3
> a4 d4 c4 d4
>
> now we have reduced this problem to find max-subarray . which can 
> be efficiently calculated using kadane's algo for each row.
>
> NOTE: now suppose if row = 0  does not participate in calculating max sum 
> matrix so u need to subtract a1 from a2,a3,a4  similarly for other 
> element in row 1,2,3.
>
> now updated matrix considered i.e from (row =1 to row =3 ). for this 
> updated matrix, 
>  each[x][y] is the sum of arr[i=1 to x] [j]. 
>
> similarly do for other elements.  
>
> On Mon, Jan 16, 2012 at 6:55 AM, Ashish Goel 
> > wrote:
>
>> given a m*n matrix, find the subset rectangle with max sum (any other 
>> rectangle taken would have lesser sum)
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Algorithm Geeks" group.
>> To post to this group, send email to algo...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> algogeeks+...@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 view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/4jFUDHYfBqUJ.
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] Command Line arguments

2012-10-08 Thread rahul sharma
@dharmendradoes every uninitialized memory has NULL or there can be
some garbage value also...plz comment???

On Mon, Oct 8, 2012 at 9:02 PM, rahul sharma wrote:

> If its NULL then y does it give segmentation fault as for NULL it should
> print an empty stringplz xomment
>
>
> On Sun, Oct 7, 2012 at 6:56 PM, DHARMENDRA KUMAR VERMA <
> dharmendrakumarverm...@gmail.com> wrote:
>
>> Bcoz u r trying to access an argument which doesnt even exist...
>> for exmple  ./a.out  --> argc=1
>>  (argv[0]="./a.out",argv[1]=NULL(not exist))
>>  ./a.out 1st_arg --> argc=2
>>  (argv[0]="./a.out",argv[1]="1st_arg",argv[2]=NULL(not exist));
>> resulting '0' as %d specifier is used the print NULL string .
>> instead if u use %s it'll give u sementation fault...
>>
>> --
>> 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] Command Line arguments

2012-10-08 Thread rahul sharma
If its NULL then y does it give segmentation fault as for NULL it should
print an empty stringplz xomment

On Sun, Oct 7, 2012 at 6:56 PM, DHARMENDRA KUMAR VERMA <
dharmendrakumarverm...@gmail.com> wrote:

> Bcoz u r trying to access an argument which doesnt even exist...
> for exmple  ./a.out  --> argc=1
>  (argv[0]="./a.out",argv[1]=NULL(not exist))
>  ./a.out 1st_arg --> argc=2
>  (argv[0]="./a.out",argv[1]="1st_arg",argv[2]=NULL(not exist));
> resulting '0' as %d specifier is used the print NULL string .
> instead if u use %s it'll give u sementation fault...
>
> --
> 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] Min Edges to be added to DAG to make it Strongly connected?

2012-10-08 Thread bharat b
@jaspreet: take an ex:
 B->A
B->C
B->D
Here the no.of zero-indegree is one . But its not the correct ans.

On Mon, Oct 8, 2012 at 1:19 AM, Jaspreet Singh wrote:

> count the no. of nodes having 0 in-degree.
>
>
> On Mon, Oct 8, 2012 at 12:44 AM, atul anand wrote:
>
>> yeah i read it wrongly .. i thought ques was asking to find total
>> strongly connected component in the graph
>>
>> On 10/7/12, bharat b  wrote:
>> > @atul : if there is no cut vertex, that doesn't mean that graph is
>> strongly
>> > connected ...
>> >
>> >
>> > On Sat, Oct 6, 2012 at 7:37 PM, atul anand 
>> wrote:
>> >
>> >> find no. of cut vertex in the DAGthat will be the ans.
>> >> On 6 Oct 2012 19:33, "KK"  wrote:
>> >>
>> >>> Given a DAG(Directed Acyclic Graph). How to find out the minimum
>> number
>> >>> of edges that needs to be added so that the given graph becomes
>> Strongly
>> >>> Connected?
>> >>>
>> >>> --
>> >>> You received this message because you are subscribed to the Google
>> >>> Groups
>> >>> "Algorithm Geeks" group.
>> >>> To view this discussion on the web visit
>> >>> https://groups.google.com/d/msg/algogeeks/-/PbR3j9S5OXUJ.
>> >>> 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.
>>
>>
>  --
> 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] finding element in array with minimum of comparing

2012-10-08 Thread atul anand
@ Mangal : well if see the soln carefully then before loop starts elem is
assigned to arr[0] and copy of arr[0] is saved to temp. This will make sure
that the elem exists in the arr[] ,so it will never reach arr[-1] . when
size become =0 then it will come out of the loop bcoz of the assignment
done before.So it acts like a delimiter for termination of loop.
But there could be possibility that *actual arr[]* contains elem at
position arr[0], dats why it is saved to temp and checking is done at the
end , after the while() loop if temp is elem or not .
i hope now you got the solution , *very poor analysis of the given solution
i will say *;) ;) ;)

On Mon, Oct 8, 2012 at 12:31 AM, Mangal Dev Gupta wrote:

> *@Dave  while( arr[--size] != elem );*
>
> *Exception will come when it will encounter a[-1]*
> *i dont know if this loop will ever end... very poor solution i will say
> *
>
> On Sat, Oct 6, 2012 at 10:00 PM, Umer Farooq  wrote:
>
>> Well actually, I've just gone through Dave's code thoroughly and I
>> believe that his code is most appropriate.
>>
>> Thanks viper11 for providing the explanation.
>>
>> As for my code, I'd like to replace
>>
>> while (i!=j)
>>
>> with
>>
>> while (i < j)
>>
>> because != won't work for middle element if the number of elements are
>> odd ... and it also won't work if the number of elements are even.
>>
>> Anyway, thanks Dave for providing us with such a great solution. Please
>> keep posting! :-)
>>
>> And others, thanks for pointing out the issue in my code.
>>
>> On Sat, Oct 6, 2012 at 9:03 PM, Kalidhakani J wrote:
>>
>>> @umer - what if the element to be searched is at the middle of the
>>> array? your code doesn't handles this. check out.
>>>
>>>
>>> On Sat, Oct 6, 2012 at 3:38 AM, icy`  wrote:
>>>
 nice solution, Dave!

 @Umer -- if the sought ele is first, then Dave's code has it sitting in
 the variable temp for a little while.   Loop will stop when size is 0,
 since arr[0]==elem.  Now he throws temp back into arr[0], which will return
 index 0 from the last compare line.

 On Wednesday, October 3, 2012 2:08:56 AM UTC-4, Umer Farooq wrote:
>
> @Dave Thanks for pointing that out.
>
> But I still can't get what if elem is on first element or it is not
> present in the array? How is your code going to handle that situation?
>
> @Atul, Well yes, In the given question, the number of iterations were
> 2n. Which I have reduced to n+n/2.
>
>
>
>
>
> On Tue, Oct 2, 2012 at 11:13 PM, atul anand wrote:
>
>> @umer : how no. of comparison are reduced to half by moving both
>> sidesyou have 2 if condition inside, so you are making 2
>> comparisons at each iteration + n/2 comparison for while loop so
>> number of comparisons are n+n/2
>>
>> On 10/2/12, Umer Farooq  wrote:
>> > why don't we try it from both ends ... something like this:
>> >
>> > int i = 0; j = size-1;
>> >
>> > while (i != j)
>> > {
>> > if (arr[i] == elem)
>> >   return arr[i];
>> > if (arr[j] == elem)
>> >return arr[j];
>> > }
>> >
>> > this way, we have eliminated half of the comparisons in for loop?
>> What do
>> > you guys say?
>> >
>> > On Tue, Oct 2, 2012 at 12:18 PM, rafi  wrote:
>> >
>> >> Vikas is right!
>> >> while (n) is equal to (while n!=0)
>> >> you have 2n compares!
>> >>
>> >> בתאריך יום שני, 1 באוקטובר 2012 12:12:21 UTC+2, מאת vikas:
>> >>
>> >>> still there is no improvement, compiler will generate the code to
>> >>> compare
>> >>> with zero here. what you have accomplished is , hide it from
>> human eyes
>> >>>
>> >>> On Monday, 1 October 2012 15:25:09 UTC+5:30, Navin Kumar wrote:
>> 
>>  @atul:
>>  still it won't compare 0 th element. Slight modification in your
>> code:
>> 
>>  n=*sizeof(arr)*;
>>  do
>>  {
>>   if(elem==arr[*--n*])
>>   print found;
>> 
>>  }while(n);
>> 
>>  On Mon, Oct 1, 2012 at 9:50 AM, atul anand 
>> wrote:
>> 
>> > yes, but there no need of checking outside the loop
>> >
>> > n=sizeof(arr)-1;
>> > do
>> > {
>> >  if(elem==arr[n])
>> >  print found;
>> > n--;
>> >
>> > }while(n);
>> >
>> >
>> >
>> > On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar
>> > wrote:
>> >
>> >> @atul: keep one more checking outside loop for element at 0 th
>> index.
>> >> Because when n = 0  the your loop come out from the loop
>> without
>> >> comparing
>> >> it.
>> >>
>> >>
>> >> On Mon, Oct 1, 2012 at 8:55 AM, atul anand
>> >> wrote:
>> >>
>> >>> n=sizeof(arr);
>> >>> n-

Re: [algogeeks] finding element in array with minimum of comparing

2012-10-08 Thread Arun Vishwanathan
@Dave: Nice solution. Can you clarify why you need to store the first
element in a temp variable and put 'elem' in the first position? If elem
was already first in array then it makes no difference. If elem was not
first but somewhere in between, the loop will break there when coming from
behind and size will have the index right? Why do we need to store elem in
first position according to your code?

On Sun, Oct 7, 2012 at 3:01 PM, Mangal Dev Gupta wrote:

> *@Dave  while( arr[--size] != elem );*
>
> *Exception will come when it will encounter a[-1]*
> *i dont know if this loop will ever end... very poor solution i will say
> *
>
> On Sat, Oct 6, 2012 at 10:00 PM, Umer Farooq  wrote:
>
>> Well actually, I've just gone through Dave's code thoroughly and I
>> believe that his code is most appropriate.
>>
>> Thanks viper11 for providing the explanation.
>>
>> As for my code, I'd like to replace
>>
>> while (i!=j)
>>
>> with
>>
>> while (i < j)
>>
>> because != won't work for middle element if the number of elements are
>> odd ... and it also won't work if the number of elements are even.
>>
>> Anyway, thanks Dave for providing us with such a great solution. Please
>> keep posting! :-)
>>
>> And others, thanks for pointing out the issue in my code.
>>
>> On Sat, Oct 6, 2012 at 9:03 PM, Kalidhakani J wrote:
>>
>>> @umer - what if the element to be searched is at the middle of the
>>> array? your code doesn't handles this. check out.
>>>
>>>
>>> On Sat, Oct 6, 2012 at 3:38 AM, icy`  wrote:
>>>
 nice solution, Dave!

 @Umer -- if the sought ele is first, then Dave's code has it sitting in
 the variable temp for a little while.   Loop will stop when size is 0,
 since arr[0]==elem.  Now he throws temp back into arr[0], which will return
 index 0 from the last compare line.

 On Wednesday, October 3, 2012 2:08:56 AM UTC-4, Umer Farooq wrote:
>
> @Dave Thanks for pointing that out.
>
> But I still can't get what if elem is on first element or it is not
> present in the array? How is your code going to handle that situation?
>
> @Atul, Well yes, In the given question, the number of iterations were
> 2n. Which I have reduced to n+n/2.
>
>
>
>
>
> On Tue, Oct 2, 2012 at 11:13 PM, atul anand wrote:
>
>> @umer : how no. of comparison are reduced to half by moving both
>> sidesyou have 2 if condition inside, so you are making 2
>> comparisons at each iteration + n/2 comparison for while loop so
>> number of comparisons are n+n/2
>>
>> On 10/2/12, Umer Farooq  wrote:
>> > why don't we try it from both ends ... something like this:
>> >
>> > int i = 0; j = size-1;
>> >
>> > while (i != j)
>> > {
>> > if (arr[i] == elem)
>> >   return arr[i];
>> > if (arr[j] == elem)
>> >return arr[j];
>> > }
>> >
>> > this way, we have eliminated half of the comparisons in for loop?
>> What do
>> > you guys say?
>> >
>> > On Tue, Oct 2, 2012 at 12:18 PM, rafi  wrote:
>> >
>> >> Vikas is right!
>> >> while (n) is equal to (while n!=0)
>> >> you have 2n compares!
>> >>
>> >> בתאריך יום שני, 1 באוקטובר 2012 12:12:21 UTC+2, מאת vikas:
>> >>
>> >>> still there is no improvement, compiler will generate the code to
>> >>> compare
>> >>> with zero here. what you have accomplished is , hide it from
>> human eyes
>> >>>
>> >>> On Monday, 1 October 2012 15:25:09 UTC+5:30, Navin Kumar wrote:
>> 
>>  @atul:
>>  still it won't compare 0 th element. Slight modification in your
>> code:
>> 
>>  n=*sizeof(arr)*;
>>  do
>>  {
>>   if(elem==arr[*--n*])
>>   print found;
>> 
>>  }while(n);
>> 
>>  On Mon, Oct 1, 2012 at 9:50 AM, atul anand 
>> wrote:
>> 
>> > yes, but there no need of checking outside the loop
>> >
>> > n=sizeof(arr)-1;
>> > do
>> > {
>> >  if(elem==arr[n])
>> >  print found;
>> > n--;
>> >
>> > }while(n);
>> >
>> >
>> >
>> > On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar
>> > wrote:
>> >
>> >> @atul: keep one more checking outside loop for element at 0 th
>> index.
>> >> Because when n = 0  the your loop come out from the loop
>> without
>> >> comparing
>> >> it.
>> >>
>> >>
>> >> On Mon, Oct 1, 2012 at 8:55 AM, atul anand
>> >> wrote:
>> >>
>> >>> n=sizeof(arr);
>> >>> n--;
>> >>>
>> >>> while(n)
>> >>> {
>> >>>  if(elem=arr[n])
>> >>>   print found;
>> >>>
>> >>> n--;
>> >>>
>> >>> }
>> >>>
>> >>> On Sun, Sep 30, 2012

Re: [algogeeks] Min Edges to be added to DAG to make it Strongly connected?

2012-10-08 Thread Jaspreet Singh
count the no. of nodes having 0 in-degree.

On Mon, Oct 8, 2012 at 12:44 AM, atul anand  wrote:

> yeah i read it wrongly .. i thought ques was asking to find total
> strongly connected component in the graph
>
> On 10/7/12, bharat b  wrote:
> > @atul : if there is no cut vertex, that doesn't mean that graph is
> strongly
> > connected ...
> >
> >
> > On Sat, Oct 6, 2012 at 7:37 PM, atul anand 
> wrote:
> >
> >> find no. of cut vertex in the DAGthat will be the ans.
> >> On 6 Oct 2012 19:33, "KK"  wrote:
> >>
> >>> Given a DAG(Directed Acyclic Graph). How to find out the minimum number
> >>> of edges that needs to be added so that the given graph becomes
> Strongly
> >>> Connected?
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google
> >>> Groups
> >>> "Algorithm Geeks" group.
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/d/msg/algogeeks/-/PbR3j9S5OXUJ.
> >>> 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.
>
>

-- 
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] Command Line arguments

2012-10-08 Thread Abhishek Patro
will it not give an erroneous result since, argc = number of elements in
argv starting from 0?

On Sun, Oct 7, 2012 at 6:33 PM, rahul sharma wrote:

> #include
> int main(int argc,char *argv[])
> {
>
>   printf("%d\n",argv[argc]);
>   getchar();
>   return 0;
>
> }
>
>
> what will it print n y??
> thnx
> rahul
>
> --
> 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.
>



-- 
Abhishek Patro

-- 
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 element in array with minimum of comparing

2012-10-08 Thread Mangal Dev Gupta
*@Dave  while( arr[--size] != elem );*

*Exception will come when it will encounter a[-1]*
*i dont know if this loop will ever end... very poor solution i will say
*
On Sat, Oct 6, 2012 at 10:00 PM, Umer Farooq  wrote:

> Well actually, I've just gone through Dave's code thoroughly and I believe
> that his code is most appropriate.
>
> Thanks viper11 for providing the explanation.
>
> As for my code, I'd like to replace
>
> while (i!=j)
>
> with
>
> while (i < j)
>
> because != won't work for middle element if the number of elements are odd
> ... and it also won't work if the number of elements are even.
>
> Anyway, thanks Dave for providing us with such a great solution. Please
> keep posting! :-)
>
> And others, thanks for pointing out the issue in my code.
>
> On Sat, Oct 6, 2012 at 9:03 PM, Kalidhakani J wrote:
>
>> @umer - what if the element to be searched is at the middle of the array?
>> your code doesn't handles this. check out.
>>
>>
>> On Sat, Oct 6, 2012 at 3:38 AM, icy`  wrote:
>>
>>> nice solution, Dave!
>>>
>>> @Umer -- if the sought ele is first, then Dave's code has it sitting in
>>> the variable temp for a little while.   Loop will stop when size is 0,
>>> since arr[0]==elem.  Now he throws temp back into arr[0], which will return
>>> index 0 from the last compare line.
>>>
>>> On Wednesday, October 3, 2012 2:08:56 AM UTC-4, Umer Farooq wrote:

 @Dave Thanks for pointing that out.

 But I still can't get what if elem is on first element or it is not
 present in the array? How is your code going to handle that situation?

 @Atul, Well yes, In the given question, the number of iterations were
 2n. Which I have reduced to n+n/2.





 On Tue, Oct 2, 2012 at 11:13 PM, atul anand wrote:

> @umer : how no. of comparison are reduced to half by moving both
> sidesyou have 2 if condition inside, so you are making 2
> comparisons at each iteration + n/2 comparison for while loop so
> number of comparisons are n+n/2
>
> On 10/2/12, Umer Farooq  wrote:
> > why don't we try it from both ends ... something like this:
> >
> > int i = 0; j = size-1;
> >
> > while (i != j)
> > {
> > if (arr[i] == elem)
> >   return arr[i];
> > if (arr[j] == elem)
> >return arr[j];
> > }
> >
> > this way, we have eliminated half of the comparisons in for loop?
> What do
> > you guys say?
> >
> > On Tue, Oct 2, 2012 at 12:18 PM, rafi  wrote:
> >
> >> Vikas is right!
> >> while (n) is equal to (while n!=0)
> >> you have 2n compares!
> >>
> >> בתאריך יום שני, 1 באוקטובר 2012 12:12:21 UTC+2, מאת vikas:
> >>
> >>> still there is no improvement, compiler will generate the code to
> >>> compare
> >>> with zero here. what you have accomplished is , hide it from human
> eyes
> >>>
> >>> On Monday, 1 October 2012 15:25:09 UTC+5:30, Navin Kumar wrote:
> 
>  @atul:
>  still it won't compare 0 th element. Slight modification in your
> code:
> 
>  n=*sizeof(arr)*;
>  do
>  {
>   if(elem==arr[*--n*])
>   print found;
> 
>  }while(n);
> 
>  On Mon, Oct 1, 2012 at 9:50 AM, atul anand 
> wrote:
> 
> > yes, but there no need of checking outside the loop
> >
> > n=sizeof(arr)-1;
> > do
> > {
> >  if(elem==arr[n])
> >  print found;
> > n--;
> >
> > }while(n);
> >
> >
> >
> > On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar
> > wrote:
> >
> >> @atul: keep one more checking outside loop for element at 0 th
> index.
> >> Because when n = 0  the your loop come out from the loop without
> >> comparing
> >> it.
> >>
> >>
> >> On Mon, Oct 1, 2012 at 8:55 AM, atul anand
> >> wrote:
> >>
> >>> n=sizeof(arr);
> >>> n--;
> >>>
> >>> while(n)
> >>> {
> >>>  if(elem=arr[n])
> >>>   print found;
> >>>
> >>> n--;
> >>>
> >>> }
> >>>
> >>> On Sun, Sep 30, 2012 at 2:56 PM, רפי וינר 
> >>> wrote:
> >>>
>  Hi
>  i was in an interview and was given a simple function
>  int arrExsits(int* arr,int size,int elem){
>  for (int i=0;i  if(elem==arr[i])
> return i;
>  return -1;
>  }
>  this function does 2n compares
>  n- the if statment
>  n-check that i is smaller then size
>  i was suppose to give an optimal (less compares) solution so
> i gave
> 
>  int arrExsits(int* arr,int size,in

Re: [algogeeks] Min Edges to be added to DAG to make it Strongly connected?

2012-10-08 Thread Kailash Bagaria
@atul: No,it's not the correct answer. Let's take an example of star like
DAG:-

A-->
B-->C

|

V

   D
This DAG contains only one cut vertex(B) but we need to add two edges to
make it strongly connected.




On Sat, Oct 6, 2012 at 7:37 PM, atul anand  wrote:

> find no. of cut vertex in the DAGthat will be the ans.
> On 6 Oct 2012 19:33, "KK"  wrote:
>
>> Given a DAG(Directed Acyclic Graph). How to find out the minimum number
>> of edges that needs to be added so that the given graph becomes Strongly
>> Connected?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/algogeeks/-/PbR3j9S5OXUJ.
>> 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.
>



-- 

--

‘Kailash Bagaria’
B-tech 4th year
Computer Science & Engineering
Indian Institute of Technology, Roorkee
Roorkee, India (247667)

-- 
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] Command Line arguments

2012-10-08 Thread DHARMENDRA KUMAR VERMA
Bcoz u r trying to access an argument which doesnt even exist...
for exmple  ./a.out  --> argc=1
 (argv[0]="./a.out",argv[1]=NULL(not exist))
 ./a.out 1st_arg --> argc=2
 (argv[0]="./a.out",argv[1]="1st_arg",argv[2]=NULL(not exist));
resulting '0' as %d specifier is used the print NULL string .
instead if u use %s it'll give u sementation fault...

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