[algogeeks] Re: Doubt in C++

2012-01-03 Thread Lucifer
@above..

This is what i assume is happening ( apart from inherent compiler
optimization is any)...Let me know if i m wrong..

when s2=name; is done it should call the overloaded equal to
operator..

But, 'name' is not a string object, its basically a char pointer to a
const string test..
Now, for simplicity lets assume that name is char array..

Now, given a binary operator, for the operation to take place both the
operands ideally should be of the same type...

For ex:
int a;
a = 10.0;
Here, 10.0 is double and a is int, for the assignment to work first
10.0 will be converted to int data type and then assigned to a..

In case, the right hand side of a = operator cannot be converted to
the left hand side type, then ideally an incompatible assignment shall
be thrown..

Going back to the above example... conversion of 10.0 to 10 is
basically performed as part of implicit conversion or type propagation
as part of basic data types (supported by the compiler)...

Now class is a custom data type and hence, we don't expect the
compiler to randomly convert from any data type to the class type for
the '=' operator to work..
Then how is it done..
Basically constructors of a class act as implicit type converters as
well...
Hence, for statement similar to s2 = name;
If 'name' is not of the type of s2 i.e.'string' type then it will try
to look for implicit conversions..
Now, a constructor of a class acts as an implicit converter as well..
and a 'string' class has a constructor 'string(char *)', it will use
'string(char*)' constructor to construct a temporary intermediate
string object which will hold the value 'test' and then assign to
s2...
Once, assignment operation is over, the temporary string object
containing the value 'test' will be destroyed..

On Jan 3, 12:05 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote:
 I just have a basic doubt..does the string s1,s2 statement call any default
 constructor?or is it that it is not performed since parameterised
 constructor is present?

 On Wed, Sep 21, 2011 at 1:31 AM, vijay singh vijaysinghb...@gmail.comwrote:









  It is because of the presence of the single parameterised constructor in
  the class definition.
  So, if we are writing the following statement...
  string s1;
  s1=test;

  It'll call the single parameterised constructor.

  But this only true in the case of single value assignment as in the above
  statement..

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

 --
  People often say that motivation doesn't last. Well, neither does bathing
 - that's why we recommend it daily.

-- 
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: Longest sequence of numbers with atmost diff K

2012-01-03 Thread atul anand
when i made changes to the inner loop - from for (j = N; j  0; --j) to
for (j = *N-1*; j  0; --j)
and endind = j-1; to endind = j;
i am getting same output:-

but for input : - 6,7,1,10,3,7,2,5,9
K=8
output : start = 0 , end = 8

below code is fine after fixing??

for(i=0;i=N;i++)
X[i]=0;

for (i = 0; i  N; ++i)
{
  for (j = N-1; j  0; --j)
  {
   X[j] =  ( abs(arr[i] - arr[j])  K ) ? 0 : 1 + min(X[j],X[j-1]);
   if ( X[j]  max)
   {
max = X[j];
strtind = i - max + 1;
endind = j;
}
  }

}

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



Re: [algogeeks] Re: Longest sequence of numbers with atmost diff K

2012-01-03 Thread atul anand
correction :-

when i made changes to the inner loop - from for (j = N; j  0; --j) to
for (j = *N-1*; j  0; --j)
and endind = j-1; to endind = j;
i am getting *right* output:-

-- 
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] learning android

2012-01-03 Thread atul anand
develop application like SIRI ... can be used by blink people bcoz
touchscreen application will be useless from them.

-- 
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: Longest sequence of numbers with atmost diff K

2012-01-03 Thread atul anand
@Lucifier : for your heap approach here is my concerns :-


input :- 6,10,8,5,9,7,1,5,4
K=8;

min heap=1,5,6,7,8,9,10
max heap=10,9,8,6,7,5,1

 A[Top(MaxH)] - A[Top(MinH)]  K i.e 10-1  8

A[j] = A[Top(MinH)];

currentStrInd = Top(MaxH) +1;  // currentStrInd=2

pop(Top(MaxH));

(now , max heap= 9,8,6,7,5,1   min heap=1,5,6,7,8,9,10 )

while(MaxH is not empty)
{
  if (Top(MaxH)  currentStrInd)// 9  2 -move to else if
condition
pop(Top(MaxH)) ;

 else if (A[Top(MaxH)] - A[Top(MinH)] = K)  -- 9-2 = 8 TRUE
.break this loop.
break;


}

min heap=1,5,6,7,8,9,10
max heap=9,8,6,7,5,1

where i am getting it wrong??

-- 
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: Longest sequence of numbers with atmost diff K

2012-01-03 Thread atul anand
@above : correction...

while(MaxH is not empty)
{
  if (Top(MaxH)  currentStrInd)// *4(index of 9)  2 *-move
to else if condition
pop(Top(MaxH)) ;

 else if (A[Top(MaxH)] - A[Top(MinH)] = K)  -- *9-1 = 8* TRUE
.break this loop.
break;


}

-- 
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] PERFECT HASHING

2012-01-03 Thread Karthikeyan V.B
Hi,

I have learnt insertion using perfect hashing.

Can anyone pls provide me the pseudo code for delete and search operations
using perfect hashing?

Since it involves randomization , i don know how retrieval and delete can
take place?

Pls help me asap.

Thanks in advance

Regards,
Karthikeyan.V.B

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



[algogeeks] finding all combination

2012-01-03 Thread atul anand
There is integer array like {1,2,4,5,6,1,2,4,3,5,7,2,1}. I want to find the
possible combination which will sum to 4.
input : {1,2,4,5,6,1,2,4,3,5,7,2,1}
output : {1,1,2}, {2,2}, {3,1}, {1,2,1}{4}...etc which make the sum as 4

any approach better than O(n^2) ???

-- 
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 all combination

2012-01-03 Thread saurabh singh
Most probably noThis is the subset sum problem which is proven NP
complete...Even if a better solution than n^2 exists it won't work for all
cases
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD




On Tue, Jan 3, 2012 at 4:56 PM, atul anand atul.87fri...@gmail.com wrote:

 }
 output : {1,1,2}, {2,2}, {3,1}, {1,2,1}{4}...etc which make the sum as 4


-- 
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 all combination

2012-01-03 Thread Prakash D
0-1 knapsack!

On Tue, Jan 3, 2012 at 5:14 PM, saurabh singh saurab...@gmail.com wrote:

 Most probably noThis is the subset sum problem which is proven NP
 complete...Even if a better solution than n^2 exists it won't work for all
 cases
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD





 On Tue, Jan 3, 2012 at 4:56 PM, atul anand atul.87fri...@gmail.comwrote:

 }
 output : {1,1,2}, {2,2}, {3,1}, {1,2,1}{4}...etc which make the sum as 4


  --
 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 all combination

2012-01-03 Thread shady
ya range is less, so 0-1 knapsack will work

On Tue, Jan 3, 2012 at 5:21 PM, Prakash D cegprak...@gmail.com wrote:

 0-1 knapsack!


 On Tue, Jan 3, 2012 at 5:14 PM, saurabh singh saurab...@gmail.com wrote:

 Most probably noThis is the subset sum problem which is proven NP
 complete...Even if a better solution than n^2 exists it won't work for all
 cases
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT ALLAHABAD





 On Tue, Jan 3, 2012 at 4:56 PM, atul anand atul.87fri...@gmail.comwrote:

 }
 output : {1,1,2}, {2,2}, {3,1}, {1,2,1}{4}...etc which make the sum as 4


  --
 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: learning android

2012-01-03 Thread rafi
http://thenewboston.org/list.php?cat=6 have lots of android tutorials

On Jan 3, 11:41 am, atul anand atul.87fri...@gmail.com wrote:
 develop application like SIRI ... can be used by blink people bcoz
 touchscreen application will be useless from them.

-- 
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: DP problems in SPOJ

2012-01-03 Thread saurabh singh
@atul in case you are considering indexing from 1 then your for loop shud
be *for(i=1 *.
Its more obvious this way that you are indexing from 1.(Although
doesn;t makes any difference to the overall objective)


Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Sat, Dec 31, 2011 at 8:25 PM, atul anand atul.87fri...@gmail.com wrote:

 @Lucifier :

 i wrote  for (int i=0; i = 9; ++i) because i was considering index from
 1 to n
 not 0 to n-1;

 you are considering from 0 to n-1. so both are correct.

 --
 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] Amazon Onsite

2012-01-03 Thread gaurav arora
@ankur : I also think u r right

@everyone : Plz check if my code is right

p[] : array of petrol
d[]:  array of distance

int FirstPetrolPump(int p[],int d[],int n)
{
int c=0,ThisPetrol=0,FirstPump=0,i;
 for(i=0;in  cn; i++)
{
ThisPetrol+=p[i];
 if(ThisPetrold[i])
{
ThisPetrol=0;
FirstPump=i+1;
c=0;
}
else
c++;
}
 while(cn)
{
ThisPetrol+=p[i%n];
 if(ThisPetrold[i%n])
return -1;
 i++;
c++;
}
return FirstPump;
}

-- 
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: Doubt in C++

2012-01-03 Thread Arun Vishwanathan
@lucifer: ok so you are saying that the constructor implicitly creates a
temporary 'string' object to hold this char string which is then assigned
to s2. Does this mean that if a constructor function was not specified
(unlike here where we have a parameterized constructor) this would not work
or does this sort of assingment require a single paramterized constructor?

On Tue, Jan 3, 2012 at 12:31 AM, Lucifer sourabhd2...@gmail.com wrote:

 @above..

 This is what i assume is happening ( apart from inherent compiler
 optimization is any)...Let me know if i m wrong..

 when s2=name; is done it should call the overloaded equal to
 operator..

 But, 'name' is not a string object, its basically a char pointer to a
 const string test..
 Now, for simplicity lets assume that name is char array..

 Now, given a binary operator, for the operation to take place both the
 operands ideally should be of the same type...

 For ex:
 int a;
 a = 10.0;
 Here, 10.0 is double and a is int, for the assignment to work first
 10.0 will be converted to int data type and then assigned to a..

 In case, the right hand side of a = operator cannot be converted to
 the left hand side type, then ideally an incompatible assignment shall
 be thrown..

 Going back to the above example... conversion of 10.0 to 10 is
 basically performed as part of implicit conversion or type propagation
 as part of basic data types (supported by the compiler)...

 Now class is a custom data type and hence, we don't expect the
 compiler to randomly convert from any data type to the class type for
 the '=' operator to work..
 Then how is it done..
 Basically constructors of a class act as implicit type converters as
 well...
 Hence, for statement similar to s2 = name;
 If 'name' is not of the type of s2 i.e.'string' type then it will try
 to look for implicit conversions..
 Now, a constructor of a class acts as an implicit converter as well..
 and a 'string' class has a constructor 'string(char *)', it will use
 'string(char*)' constructor to construct a temporary intermediate
 string object which will hold the value 'test' and then assign to
 s2...
 Once, assignment operation is over, the temporary string object
 containing the value 'test' will be destroyed..

 On Jan 3, 12:05 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote:
  I just have a basic doubt..does the string s1,s2 statement call any
 default
  constructor?or is it that it is not performed since parameterised
  constructor is present?
 
  On Wed, Sep 21, 2011 at 1:31 AM, vijay singh vijaysinghb...@gmail.com
 wrote:
 
 
 
 
 
 
 
 
 
   It is because of the presence of the single parameterised constructor
 in
   the class definition.
   So, if we are writing the following statement...
   string s1;
   s1=test;
 
   It'll call the single parameterised constructor.
 
   But this only true in the case of single value assignment as in the
 above
   statement..
 
--
   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.
 
  --
   People often say that motivation doesn't last. Well, neither does
 bathing
  - that's why we recommend it daily.

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




-- 
 People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily.

-- 
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: DP problems in SPOJ

2012-01-03 Thread atul anand
@saurabh: dats wat i said in my prev post...
*both are correct*
On 3 Jan 2012 19:16, saurabh singh saurab...@gmail.com wrote:

 @atul in case you are considering indexing from 1 then your for loop shud
 be *for(i=1 *.
 Its more obvious this way that you are indexing from 1.(Although
 doesn;t makes any difference to the overall objective)


 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT
 blog:geekinessthecoolway.blogspot.com



 On Sat, Dec 31, 2011 at 8:25 PM, atul anand atul.87fri...@gmail.comwrote:

 @Lucifier :

 i wrote  for (int i=0; i = 9; ++i) because i was considering index from
 1 to n
 not 0 to n-1;

 you are considering from 0 to n-1. so both are correct.

 --
 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] Invitation - Abacus'12 Online Programming Contest

2012-01-03 Thread Kashyap Krishnakumar
Hi,
 I invite you to take part in *CODE MODULE*http://www.spoj.pl/ABACUS12/,
the *Online Programming Contest of *Abacus'12 http://www.abacus.org.in/,
organised by the Department of Computer Science and Engineering, College of
Engineering Guindy, Anna University, Chennai. Details about the contest can
be found here http://abacus.org.in/online-programming-contest/. *Register
here http://abacus.org.in/opc/* to participate as well as to get updates
and reminders about it. The contest will take place on *Jan 15, 2012 at 9
PM IST*. To find out the time and date in your time zone, check out this
linkhttp://www.timeanddate.com/worldclock/fixedtime.html?msg=CODE+MODULE+-+Online+Programming+Contest+of+Abacus+12iso=20120115T21p1=1648
.

*Prize Money*
First Place - $200
Second Place - $100

Regards,
Kashyap.K,
III year, B.E CSE,
College of Engineering Guindy,
Anna University,
Chennai.

--
If you've never failed, you've never lived!

-- 
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: Find even length palindrome.

2012-01-03 Thread sravanreddy001
This is still N^2 solution.. If i'm not mistaken?

-- 
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/-/zbJxeO-T4sMJ.
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: Doubt in C++

2012-01-03 Thread Lucifer
@Arun...

Basically what u have asked boils down to 2 questions...

1. First, this sort of assignment requires single parameterized
constructor ?

Yes ( and No as well in special cases.).
But its not a mandate that the class defines...

There is something called as implicit and explicit construction...

Class X
{
 public:
   X(){} // default constructor...
   X(int a) // single param constr
   X( int a, double b) // const with 2 parameters...
};

Now there are 2 ways of creating an object of class X which takes only
one parameter..

a)  X obj(10); // this is the most common way of doing it...
  // also here we are explicitly asking the compiler to use a
particular constr whose prototype should match X(int );

b) X obj = 10; // this is more uncommon way of doing it..
  // here , an implicit conversion happens and it goes as follows:
/*
   i)  X temp = X(10); // creating temp object..
   ii) X obj = temp; // overloaded '=' operator called
   iii)  temp.~temp(); // destruct temp...

Though, theoritically this is how it should create obj..
But, due to compiler optimization a temporary object is not created
and destroyed...

But, to verify that there is a difference b/w implicit and explicit
creation, u can look at generated assembly code and see that a
reduntant copy operation is present in the assembly level code..
This redundant copy code is to mimic the usage of default '='
overloaded operator...i.e something similar to * mov bx, bx *

*/
Given the above explanation we can say that we want to implicitly
create an object which takes 2 parameters... Now, given the fact that
'=' is a binary operator, there is no way we can use more than 2
parameters in the expression..

Say, i want to create:
 X obj(10, 2.0), implicitly... then ' X obj = 10 20 ' needs to be a
valid expression.. Basically for this is happen there needs to be a
way where the rhs can take more than 2 expression values.. which is
not possible...

Hence, implicit creation of objects only work with single
parameterized constructors...

Now, you must have seen that i have used the following statement
above:
*But its not a mandate that the class defines...* - the above
explanation should justify this statement..

*Yes ( and No as well in special cases.* - *Yes* is obvious as per the
above explanation...
Now, to show what *No* meant, say class X has the following
constructor instead of the single parameterized constructor...
///
X( int a, char *b = NULL, bool b = true);
///
Now, by looking at it we can say that its not a single parameterized
constr..hence it can't be used in implicit construction..
But thats not true as the constructor as got default parameters except
the first one which is int type...

Hence, given the above constructor.. X obj = 10, is still valid...


2. Does this mean that if a constructor function was not specified
(unlike here where we have a parameterized constructor) this would not
work ?

Yes, should be self explanatory..



Though its obvious but a conversion only works when RHS of '='
operator can itself be assigned to the formal argument parameter of a
constructor...
Basically what i mean from the above statement is,
apart from the basic types... it can also work for related(different
not same) class types... say, the formal parameter of constrcutor has
a base class type and the RHS of '=' has a derieved class type...



On Jan 3, 7:52 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote:
 @lucifer: ok so you are saying that the constructor implicitly creates a
 temporary 'string' object to hold this char string which is then assigned
 to s2. Does this mean that if a constructor function was not specified
 (unlike here where we have a parameterized constructor) this would not work
 or does this sort of assingment require a single paramterized constructor?









 On Tue, Jan 3, 2012 at 12:31 AM, Lucifer sourabhd2...@gmail.com wrote:
  @above..

  This is what i assume is happening ( apart from inherent compiler
  optimization is any)...Let me know if i m wrong..

  when s2=name; is done it should call the overloaded equal to
  operator..

  But, 'name' is not a string object, its basically a char pointer to a
  const string test..
  Now, for simplicity lets assume that name is char array..

  Now, given a binary operator, for the operation to take place both the
  operands ideally should be of the same type...

  For ex:
  int a;
  a = 10.0;
  Here, 10.0 is double and a is int, for the assignment to work first
  10.0 will be converted to int data type and then assigned to a..

  In case, the right hand side of a = operator cannot be converted to
  the left hand side type, then ideally an incompatible assignment shall
  be thrown..

  Going back to the above example... conversion of 10.0 to 10 is
  basically performed as part of implicit conversion or type propagation
  as part of basic data types (supported by the 

Re: [algogeeks] Invitation - Abacus'12 Online Programming Contest

2012-01-03 Thread saurabh singh
Kindly mail any further queries to the author of this mail directly
@kashyap Thanx for sharing the info...


*THREAD CLOSED-*

Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Tue, Jan 3, 2012 at 9:33 PM, cibe hariharan k.cibehariha...@gmail.comwrote:

 well what is the last date for registration dude


 On Tue, Jan 3, 2012 at 9:08 PM, Kashyap Krishnakumar kashyap...@gmail.com
  wrote:

 Hi,
  I invite you to take part in *CODE 
 MODULE*http://www.spoj.pl/ABACUS12/,
 the *Online Programming Contest of *Abacus'12 http://www.abacus.org.in/,
 organised by the Department of Computer Science and Engineering, College of
 Engineering Guindy, Anna University, Chennai. Details about the contest can
 be found here http://abacus.org.in/online-programming-contest/. *
 Register here http://abacus.org.in/opc/* to participate as well as to
 get updates and reminders about it. The contest will take place on *Jan
 15, 2012 at 9 PM IST*. To find out the time and date in your time zone,
 check out this 
 linkhttp://www.timeanddate.com/worldclock/fixedtime.html?msg=CODE+MODULE+-+Online+Programming+Contest+of+Abacus+12iso=20120115T21p1=1648
 .

 *Prize Money*
 First Place - $200
 Second Place - $100

 Regards,
 Kashyap.K,
 III year, B.E CSE,
 College of Engineering Guindy,
 Anna University,
 Chennai.

 --
 If you've never failed, you've never lived!

  --
 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] check Similar array

2012-01-03 Thread atul anand
There are two arrays.
int arr1[5] = { 3, 5, 2, 5, 2}
int arr2[5] = { 2, 3, 5, 5, 2}
The arrays will be called similar if they contain same number of elements
equally.
Write the pseudo code to check this ?
not allowed to use sorting and hashtable.

naive approach O(n^2)

NOTE: Xoring , sum wont work.

we can use O(n) space , using index as elements in the array. but if it has
negative number then it will fail for eg arr1 has -1,...  and arr2 has
1,.

-- 
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] Best way to rank sentences based on similarity from a set of Documents

2012-01-03 Thread Anantha Krishnan
Dear Geeks,
I want to know the best way to rank sentences based on similarity from a
set of documents.
For e.g lets say,
1. There are 5 documents.
2. Each document contains many sentences.
3. Lets take Document 1 as primary, i.e output will contain sentences from
this document.
4. Output should be list of sentences ranked in such a way that sentence
with FIRST rank is the most similar sentence in all 5 documents, then 2nd
then 3rd...

Thanks in advance.

Regards,
Anantha Krishnan

-- 
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: Find the path in two nodes of a binary search tree

2012-01-03 Thread atul anand
@Lucifier : nice solution for problem 2.

-- 
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: Longest sequence of numbers with atmost diff K

2012-01-03 Thread Lucifer
@atul...

For the O(n^2) approach, here's the working code..It should work for
all ur examples.. I have fixed it..

int max = 0;
int strtind = -1;
int endind =  -1;

int X[2][N];

for(int i=0;i=N;i++)
   X[0][i]=X[1][i] = 0;

int *prev, *curr;
for (int i = 0; i  N; ++i)
{
  prev = X[i%2];
  curr = X[(i+1)%2];

  for (int j = 0; j  N; ++j)
  {
   curr[j+1] =  ( abs(A[i] - A[j])  K ) ? 0 : 1 + min(curr[j],
min(prev[j+1], prev[j]));
   if ( curr[j+1]  max)
   {
max = curr[j+1];
strtind = j - max + 1;
endind = j;
}
  }
}
printf(%d , %d, %d, max, strtind, endind);


Let me know if u hit an issue...
---

For the heap approach it seems that it worked for u..as i see that in
the last post u have corrected the storage of values to indices..
Am i ryt? Did it work for u?
In case u have a doubt, plz let me know...

---


On Jan 3, 4:01 pm, atul anand atul.87fri...@gmail.com wrote:
 @above : correction...

 while(MaxH is not empty)
 {
       if (Top(MaxH)  currentStrInd)    // *4(index of 9)  2 *    -move
 to else if condition
         pop(Top(MaxH)) ;

      else if (A[Top(MaxH)] - A[Top(MinH)] = K)  -- *9-1 = 8* TRUE
 .break this loop.
         break;







 }

-- 
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: sqrt function...

2012-01-03 Thread Arun Vishwanathan
@gene:
I checked the wiki link given..In that it is mentioned that initial root is
chosen as 2.10^n or 6.10^n based on the number of digits being even or odd
in the number.
The concept of choosing 2 or 6 in this formula is based on some geometric
mean concept mentioned. Can you please clarify what they mean to say? I
wasnt able to follow that...

On Sun, Sep 25, 2011 at 3:06 AM, Gene gene.ress...@gmail.com wrote:

 Binary search isn't the right term.  Rather you want bisection.  But
 for each iteration it adds only one bit to the precision of the
 answer.

 You should also look at Newton's method. It doubles the number of bits
 of precision in each iteration.

 Algorithm: float sqrt(float x)
 root = intial guess
 while root^2 is not close enough to x do
  root = (x / root + root) / 2;
 return root;

 Wikipedia has a nice article with more details and in particular how
 to get a good initial guess.


 http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Taylor_series

 On Sep 25, 8:29 am, Vikram Singh singhvikram...@gmail.com wrote:
  ok.. thanks guys...
  one doubt now... if this ques is asked in an interview(its already been
  asked in ms interview)... then u cant just write the code... u hv to
 explain
  the whole approach like why u r choosing that way to narrowing dowm the
  range...
 
  so pls explain how this sol is derived...
 
  On Sun, Sep 25, 2011 at 10:15 AM, keyan karthi 
 keyankarthi1...@gmail.comwrote:
 
 
 
   binary search!!! :)
 
   On Sat, Sep 24, 2011 at 11:38 PM, sunny agrawal 
 sunny816.i...@gmail.comwrote:
 
   let x be the number
   initialize ans to some value like x or x/2
 
   now repeatedly do the following
   ans  = (ans + x/ans)/2
   each time you perform this operation you will move closer to the sqrt
   value and depending upon the precision required stop
 
   On Sat, Sep 24, 2011 at 11:17 PM, siddharth srivastava 
   akssps...@gmail.com wrote:
 
   On 24 September 2011 13:45, shady sinv...@gmail.com wrote:
 
   one of the simplest way is to do binary search... :)
 
   +1
 
   On Sat, Sep 24, 2011 at 8:42 PM, teja bala 
 pawanjalsa.t...@gmail.comwrote:
 
  http://www.geeksforgeeks.org/archives/3187
 
   check dis one.
 
   --
   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.
 
   --
   Regards
   Siddharth Srivastava
 
--
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
   --
   Sunny Aggrawal
   B.Tech. V year,CSI
   Indian Institute Of Technology,Roorkee
 
--
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algogeeks@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
--
   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.- Hide quoted text -
 
  - Show quoted text -

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




-- 
 People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily.

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

Re: [algogeeks] Re: Doubt in C++

2012-01-03 Thread Arun Vishwanathan
@lucifer: thanks !

On Tue, Jan 3, 2012 at 9:02 AM, Lucifer sourabhd2...@gmail.com wrote:

 @Arun...

 Basically what u have asked boils down to 2 questions...

 1. First, this sort of assignment requires single parameterized
 constructor ?

 Yes ( and No as well in special cases.).
 But its not a mandate that the class defines...

 There is something called as implicit and explicit construction...

 Class X
 {
  public:
   X(){} // default constructor...
   X(int a) // single param constr
   X( int a, double b) // const with 2 parameters...
 };

 Now there are 2 ways of creating an object of class X which takes only
 one parameter..

 a)  X obj(10); // this is the most common way of doing it...
  // also here we are explicitly asking the compiler to use a
 particular constr whose prototype should match X(int );

 b) X obj = 10; // this is more uncommon way of doing it..
  // here , an implicit conversion happens and it goes as follows:
 /*
   i)  X temp = X(10); // creating temp object..
   ii) X obj = temp; // overloaded '=' operator called
   iii)  temp.~temp(); // destruct temp...

 Though, theoritically this is how it should create obj..
 But, due to compiler optimization a temporary object is not created
 and destroyed...

 But, to verify that there is a difference b/w implicit and explicit
 creation, u can look at generated assembly code and see that a
 reduntant copy operation is present in the assembly level code..
 This redundant copy code is to mimic the usage of default '='
 overloaded operator...i.e something similar to * mov bx, bx *

 */
 Given the above explanation we can say that we want to implicitly
 create an object which takes 2 parameters... Now, given the fact that
 '=' is a binary operator, there is no way we can use more than 2
 parameters in the expression..

 Say, i want to create:
  X obj(10, 2.0), implicitly... then ' X obj = 10 20 ' needs to be a
 valid expression.. Basically for this is happen there needs to be a
 way where the rhs can take more than 2 expression values.. which is
 not possible...

 Hence, implicit creation of objects only work with single
 parameterized constructors...

 Now, you must have seen that i have used the following statement
 above:
 *But its not a mandate that the class defines...* - the above
 explanation should justify this statement..

 *Yes ( and No as well in special cases.* - *Yes* is obvious as per the
 above explanation...
 Now, to show what *No* meant, say class X has the following
 constructor instead of the single parameterized constructor...
 ///
 X( int a, char *b = NULL, bool b = true);
 ///
 Now, by looking at it we can say that its not a single parameterized
 constr..hence it can't be used in implicit construction..
 But thats not true as the constructor as got default parameters except
 the first one which is int type...

 Hence, given the above constructor.. X obj = 10, is still valid...


 2. Does this mean that if a constructor function was not specified
 (unlike here where we have a parameterized constructor) this would not
 work ?

 Yes, should be self explanatory..


 

 Though its obvious but a conversion only works when RHS of '='
 operator can itself be assigned to the formal argument parameter of a
 constructor...
 Basically what i mean from the above statement is,
 apart from the basic types... it can also work for related(different
 not same) class types... say, the formal parameter of constrcutor has
 a base class type and the RHS of '=' has a derieved class type...



 On Jan 3, 7:52 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote:
  @lucifer: ok so you are saying that the constructor implicitly creates a
  temporary 'string' object to hold this char string which is then assigned
  to s2. Does this mean that if a constructor function was not specified
  (unlike here where we have a parameterized constructor) this would not
 work
  or does this sort of assingment require a single paramterized
 constructor?
 
 
 
 
 
 
 
 
 
  On Tue, Jan 3, 2012 at 12:31 AM, Lucifer sourabhd2...@gmail.com wrote:
   @above..
 
   This is what i assume is happening ( apart from inherent compiler
   optimization is any)...Let me know if i m wrong..
 
   when s2=name; is done it should call the overloaded equal to
   operator..
 
   But, 'name' is not a string object, its basically a char pointer to a
   const string test..
   Now, for simplicity lets assume that name is char array..
 
   Now, given a binary operator, for the operation to take place both the
   operands ideally should be of the same type...
 
   For ex:
   int a;
   a = 10.0;
   Here, 10.0 is double and a is int, for the assignment to work first
   10.0 will be converted to int data type and then assigned to a..
 
   In case, the right hand side of a = operator cannot be converted to
   the left hand side type, then ideally an incompatible assignment shall
   be 

Re: [algogeeks] check Similar array

2012-01-03 Thread SAMM
I think this may works . needs verification.

For the given array (3 5 2 5 2)
For +ve number (N) take the sum from 1 to N .
For -ve number (N) take the sum from -1 to N .
And take take the cumulative sum ... For this array it comes 42 .
Similarly check the sum for the second array . If it is same then we r done .

On 1/3/12, atul anand atul.87fri...@gmail.com wrote:
 There are two arrays.
 int arr1[5] = { 3, 5, 2, 5, 2}
 int arr2[5] = { 2, 3, 5, 5, 2}
 The arrays will be called similar if they contain same number of elements
 equally.
 Write the pseudo code to check this ?
 not allowed to use sorting and hashtable.

 naive approach O(n^2)

 NOTE: Xoring , sum wont work.

 we can use O(n) space , using index as elements in the array. but if it has
 negative number then it will fail for eg arr1 has -1,...  and arr2 has
 1,.

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




-- 
Somnath Singh

-- 
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] check Similar array

2012-01-03 Thread saurabh singh
Why would xoring fail?
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Wed, Jan 4, 2012 at 9:56 AM, SAMM somnath.nit...@gmail.com wrote:

 I think this may works . needs verification.

 For the given array (3 5 2 5 2)
 For +ve number (N) take the sum from 1 to N .
 For -ve number (N) take the sum from -1 to N .
 And take take the cumulative sum ... For this array it comes 42 .
 Similarly check the sum for the second array . If it is same then we r
 done .

 On 1/3/12, atul anand atul.87fri...@gmail.com wrote:
  There are two arrays.
  int arr1[5] = { 3, 5, 2, 5, 2}
  int arr2[5] = { 2, 3, 5, 5, 2}
  The arrays will be called similar if they contain same number of elements
  equally.
  Write the pseudo code to check this ?
  not allowed to use sorting and hashtable.
 
  naive approach O(n^2)
 
  NOTE: Xoring , sum wont work.
 
  we can use O(n) space , using index as elements in the array. but if it
 has
  negative number then it will fail for eg arr1 has -1,...  and arr2 has
  1,.
 
  --
  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.
 
 


 --
 Somnath Singh

 --
 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] check Similar array

2012-01-03 Thread atul anand
how its 42??..didnt get it :(

-- 
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] check Similar array

2012-01-03 Thread saurabh singh
Ok got itwill fail for the cases where the xor in the arrays
individually come to 0..
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Wed, Jan 4, 2012 at 10:13 AM, atul anand atul.87fri...@gmail.com wrote:

 how its 42??..didnt get it :(

  --
 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] check Similar array

2012-01-03 Thread SAMM
@Atul

For array (3 2 5 2 5)
Sum+= (sum of number from 1 to n) , n is each array element.

Sum=(1+2+3)+(1+2)+(1+2+3+4+5)+(1+2)+(1+2+3+4+5) =42

On 1/4/12, SAMM somnath.nit...@gmail.com wrote:
 This may not work for the array having both +ve  -ve numbers becoz
 this logic is based on frequency distribution of elements from 1 to
 max(array elements) and if -ve num comes in here will disturb the
 frequency distribution.

 So this logic may work for only +ve and -ve elements array.

 On 1/4/12, SAMM somnath.nit...@gmail.com wrote:
 I think this may works . needs verification.

 For the given array (3 5 2 5 2)
 For +ve number (N) take the sum from 1 to N .
 For -ve number (N) take the sum from -1 to N .
 And take take the cumulative sum ... For this array it comes 42 .
 Similarly check the sum for the second array . If it is same then we r
 done
 .

 On 1/3/12, atul anand atul.87fri...@gmail.com wrote:
 There are two arrays.
 int arr1[5] = { 3, 5, 2, 5, 2}
 int arr2[5] = { 2, 3, 5, 5, 2}
 The arrays will be called similar if they contain same number of
 elements
 equally.
 Write the pseudo code to check this ?
 not allowed to use sorting and hashtable.

 naive approach O(n^2)

 NOTE: Xoring , sum wont work.

 we can use O(n) space , using index as elements in the array. but if it
 has
 negative number then it will fail for eg arr1 has -1,...  and arr2 has
 1,.

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




 --
 Somnath Singh



 --
 Somnath Singh



-- 
Somnath Singh

-- 
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: Longest sequence of numbers with atmost diff K

2012-01-03 Thread atul anand
@Lucifier : it didnt work as you can see

input :- 6,10,8,5,9,7,1,5,4
K=8;

min heap=1,5,6,7,8,9,10
max heap=10,9,8,6,7,5,1

 A[Top(MaxH)] - A[Top(MinH)]  K i.e 10-1  8

//we are in else part of your logic

A[j] = A[Top(MinH)];

currentStrInd = Top(MaxH) +1;  // currentStrInd=2

pop(Top(MaxH));

(now , max heap= 9,8,6,7,5,1   min heap=1,5,6,7,8,9,10 )

while(MaxH is not empty)
{
  if (Top(MaxH)  currentStrInd)// 4  2 -move to else if
condition
pop(Top(MaxH)) ;

 else if (A[Top(MaxH)] - A[Top(MinH)] = K)  -- 9-1 = 8 TRUE
.break this loop.
break;


}

even after coming out of the loop..
as you can see that element 6 is still in max heap array , along with this
i can see there is code to remove elements from the min heap...
this will cause problem for certain seq of input.

min heap=1,5,6,7,8,9,10
max heap=9,8,6,7,5,1

hope you get it what i am trying to say , correct me if i am wrong

-- 
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] check Similar array

2012-01-03 Thread atul anand
@Samm : dat woud be O(n^2) approach 

-- 
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: check Similar array

2012-01-03 Thread SAMMM
No it's not if u use the AP series mathematical formula n(n+1)/2..
Then it will be of O(n).

-- 
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: check Similar array

2012-01-03 Thread rahul patil
@samm: Ur solution is great. It could be used to tell that arrays are not
similar, in linear time. But cant tell that they are 100% similar
ur solution fails for the simple case.
arr1: 3,4
arr2: 5,1

On Wed, Jan 4, 2012 at 10:49 AM, SAMMM somnath.nit...@gmail.com wrote:

 No it's not if u use the AP series mathematical formula n(n+1)/2..
 Then it will be of O(n).

 --
 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,
Rahul Patil

-- 
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: check Similar array

2012-01-03 Thread rahul patil
@samm: Rather than adding numbers could we add squares(or cube) of numbers
which could also be done in linear time?

On Wed, Jan 4, 2012 at 10:56 AM, rahul patil
rahul.deshmukhpa...@gmail.comwrote:

 @samm: Ur solution is great. It could be used to tell that arrays are not
 similar, in linear time. But cant tell that they are 100% similar
 ur solution fails for the simple case.
 arr1: 3,4
 arr2: 5,1

 On Wed, Jan 4, 2012 at 10:49 AM, SAMMM somnath.nit...@gmail.com wrote:

 No it's not if u use the AP series mathematical formula n(n+1)/2..
 Then it will be of O(n).

 --
 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,
 Rahul Patil




-- 
Regards,
Rahul Patil

-- 
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: check Similar array

2012-01-03 Thread sharad dixit
Can we use concept of prime number as fundamental theorem of arithmetic i.e
every number has a unique factorization into primes (
http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic) and then
multiply them together.

e.g
 A1[3] = { 2,3,4}   =  secondprime*thirdprime*forthprime = 2 * 3 * 5 = 30
 A2[3] = { 3,2,4}   =  3rdprime * 2ndprime* 4thprime = 3 * 2 * 5 =30

On Wed, Jan 4, 2012 at 11:00 AM, rahul patil
rahul.deshmukhpa...@gmail.comwrote:


 @samm: Rather than adding numbers could we add squares(or cube) of numbers
 which could also be done in linear time?


 On Wed, Jan 4, 2012 at 10:56 AM, rahul patil 
 rahul.deshmukhpa...@gmail.com wrote:

 @samm: Ur solution is great. It could be used to tell that arrays are not
 similar, in linear time. But cant tell that they are 100% similar
 ur solution fails for the simple case.
 arr1: 3,4
 arr2: 5,1

 On Wed, Jan 4, 2012 at 10:49 AM, SAMMM somnath.nit...@gmail.com wrote:

 No it's not if u use the AP series mathematical formula n(n+1)/2..
 Then it will be of O(n).

 --
 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,
 Rahul Patil




 --
 Regards,
 Rahul Patil

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




-- 
-Sharad Dixit
 B.Tech(IT)
 Indian Institute of Information Technology Allahabad
-
We aim above the mark to hit the mark.
~ Ralph Waldo Emerson

-- 
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: check Similar array

2012-01-03 Thread saurabh singh
@sharad Your approach limits the size of array to be very small(as well as
the elements of the array to be small).Else the product will become too big
to be held in an array.Same applies with samm's solution too though in his
case we can be more liberal with element's value..


Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Wed, Jan 4, 2012 at 11:11 AM, sharad dixit sharad.emine...@gmail.comwrote:

 Can we use concept of prime number as fundamental theorem of arithmetic
 i.e every number has a unique factorization into primes (
 http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic) and then
 multiply them together.

 e.g
  A1[3] = { 2,3,4}   =  secondprime*thirdprime*forthprime = 2 * 3 * 5 = 30
  A2[3] = { 3,2,4}   =  3rdprime * 2ndprime* 4thprime = 3 * 2 * 5 =30

 On Wed, Jan 4, 2012 at 11:00 AM, rahul patil 
 rahul.deshmukhpa...@gmail.com wrote:


 @samm: Rather than adding numbers could we add squares(or cube) of
 numbers which could also be done in linear time?


 On Wed, Jan 4, 2012 at 10:56 AM, rahul patil 
 rahul.deshmukhpa...@gmail.com wrote:

 @samm: Ur solution is great. It could be used to tell that arrays are
 not similar, in linear time. But cant tell that they are 100% similar
 ur solution fails for the simple case.
 arr1: 3,4
 arr2: 5,1

 On Wed, Jan 4, 2012 at 10:49 AM, SAMMM somnath.nit...@gmail.com wrote:

 No it's not if u use the AP series mathematical formula n(n+1)/2..
 Then it will be of O(n).

 --
 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,
 Rahul Patil




 --
 Regards,
 Rahul Patil

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




 --
 -Sharad Dixit
  B.Tech(IT)
  Indian Institute of Information Technology Allahabad

 -
 We aim above the mark to hit the mark.
 ~ Ralph Waldo Emerson

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

2012-01-03 Thread Arun Vishwanathan
actually is there any reason as to why same address is returned to the
pointer when both pointers(p and q) are initialised to persons unlike
when p[] and q[] =persons?

On Tue, Sep 6, 2011 at 9:08 AM, Sandy sandy.wad...@gmail.com wrote:

 String constants (literals) are saved into the .data section of the
 program,  Here is the sample program to show that.  if() is essentially
 comparing the addresses of two pointers which is same.

 int main()
 {
 char *p=persons;
 char *q=persons;
  char *r=persons;
 char *s=persons;
  printf(%x %x %x %x\n,p,q,r,s);
 if(p==persons)
 printf(technical %s,p);
  else
 printf(true %s,p);
 return 0;
 }
 -
 Output:
 403021 403021 403021 403021
 technical persons

 On Tue, Sep 6, 2011 at 9:04 PM, sivaviknesh s sivavikne...@gmail.comwrote:


 main()
 {
 char *p=persons;
 clrscr();
 if(p==persons)
 printf(technical %s,p);
 else
 printf(true %s,p);
 return 0;
 }

 ..op : technical persons ..plz explain .. how come it works like an
 strcmp operation???
 --
 Regards,
 $iva

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




 --

 *Sandeep Kumar,*
  ( Mobile +91-9866507368

 *“I believe in smart work, Believe Me”*


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




-- 
 People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily.

-- 
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: check Similar array

2012-01-03 Thread atul anand
Btw an array can have both positive and negative number.
On 4 Jan 2012 11:00, rahul patil rahul.deshmukhpa...@gmail.com wrote:


 @samm: Rather than adding numbers could we add squares(or cube) of numbers
 which could also be done in linear time?

 On Wed, Jan 4, 2012 at 10:56 AM, rahul patil 
 rahul.deshmukhpa...@gmail.com wrote:

 @samm: Ur solution is great. It could be used to tell that arrays are not
 similar, in linear time. But cant tell that they are 100% similar
 ur solution fails for the simple case.
 arr1: 3,4
 arr2: 5,1

 On Wed, Jan 4, 2012 at 10:49 AM, SAMMM somnath.nit...@gmail.com wrote:

 No it's not if u use the AP series mathematical formula n(n+1)/2..
 Then it will be of O(n).

 --
 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,
 Rahul Patil




 --
 Regards,
 Rahul Patil

 --
 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: check Similar array

2012-01-03 Thread atul anand
@sharad : after checking the link provided by u...it seem like complexity
will be O(n^2) { not sure } + saurabh point is also valid.

-- 
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-01-03 Thread Rahul
it's near to a common mis conception that string liberals are in data
sections of THE PROGRAM


PLEASE READ THE FILE
a.out.h

and find the difference between initialized data and non initialized data

On 9/6/11, Sandy sandy.wad...@gmail.com wrote:
 String constants (literals) are saved into the .data section of the program,
  Here is the sample program to show that.  if() is essentially comparing the
 addresses of two pointers which is same.

 int main()
 {
 char *p=persons;
 char *q=persons;
 char *r=persons;
 char *s=persons;
  printf(%x %x %x %x\n,p,q,r,s);
 if(p==persons)
 printf(technical %s,p);
 else
 printf(true %s,p);
 return 0;
 }
 -
 Output:
 403021 403021 403021 403021
 technical persons

 On Tue, Sep 6, 2011 at 9:04 PM, sivaviknesh s sivavikne...@gmail.comwrote:


 main()
 {
 char *p=persons;
 clrscr();
 if(p==persons)
 printf(technical %s,p);
 else
 printf(true %s,p);
 return 0;
 }

 ..op : technical persons ..plz explain .. how come it works like an strcmp
 operation???
 --
 Regards,
 $iva

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




 --

 *Sandeep Kumar,*
  ( Mobile +91-9866507368

 *“I believe in smart work, Believe Me”*

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

2012-01-03 Thread saurabh singh
@all.Your explanations work because probably all of you are using a
compiler that's behaving in the same way.Don't conclude from what you
see...The compiler is free to store the constant strings the way it
wants.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Wed, Jan 4, 2012 at 12:13 PM, Rahul raikra...@gmail.com wrote:

 it's near to a common mis conception that string liberals are in data
 sections of THE PROGRAM


 PLEASE READ THE FILE
 a.out.h

 and find the difference between initialized data and non initialized data

 On 9/6/11, Sandy sandy.wad...@gmail.com wrote:
  String constants (literals) are saved into the .data section of the
 program,
   Here is the sample program to show that.  if() is essentially comparing
 the
  addresses of two pointers which is same.
 
  int main()
  {
  char *p=persons;
  char *q=persons;
  char *r=persons;
  char *s=persons;
   printf(%x %x %x %x\n,p,q,r,s);
  if(p==persons)
  printf(technical %s,p);
  else
  printf(true %s,p);
  return 0;
  }
  -
  Output:
  403021 403021 403021 403021
  technical persons
 
  On Tue, Sep 6, 2011 at 9:04 PM, sivaviknesh s sivavikne...@gmail.com
 wrote:
 
 
  main()
  {
  char *p=persons;
  clrscr();
  if(p==persons)
  printf(technical %s,p);
  else
  printf(true %s,p);
  return 0;
  }
 
  ..op : technical persons ..plz explain .. how come it works like an
 strcmp
  operation???
  --
  Regards,
  $iva
 
   --
  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.
 
 
 
 
  --
 
  *Sandeep Kumar,*
   ( Mobile +91-9866507368
 
  *“I believe in smart work, Believe Me”*
 
  --
  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: Longest sequence of numbers with atmost diff K

2012-01-03 Thread atul anand
@Lucifier : great :) :) ... your new fixed code it working perfectly .
but it would be great if you give little explanation of this updated code


On Tue, Jan 3, 2012 at 2:56 PM, atul anand atul.87fri...@gmail.com wrote:

 when i made changes to the inner loop - from for (j = N; j  0; --j) to
 for (j = *N-1*; j  0; --j)
 and endind = j-1; to endind = j;
 i am getting same output:-

 but for input : - 6,7,1,10,3,7,2,5,9
 K=8
 output : start = 0 , end = 8

 below code is fine after fixing??
 
 for(i=0;i=N;i++)
 X[i]=0;

 for (i = 0; i  N; ++i)
 {
   for (j = N-1; j  0; --j)
   {
X[j] =  ( abs(arr[i] - arr[j])  K ) ? 0 : 1 + min(X[j],X[j-1]);

if ( X[j]  max)
{
 max = X[j];
 strtind = i - max + 1;
 endind = j;
 }
   }

 }



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



Re: [algogeeks] Explanation

2012-01-03 Thread Arun Vishwanathan
@Vrashabh: yea the explanation is kinda difficult to follow since f(1,2) is
once done first and once is not though the expressions look similarcan
u pls explain what decides the order of evaluation here

On Mon, Aug 29, 2011 at 6:23 AM, kartik sachan kartik.sac...@gmail.comwrote:

 see the out put will the help of gcc -E.u will get ur ans

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




-- 
 People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily.

-- 
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: String passing

2012-01-03 Thread Arun Vishwanathan
if instead of passing hello directly to function if we passed char array
p then this would not show as an error right? and why is this so? is it due
to the fact tat p array was not possibly allocated in the read only segment
of memory and hence when passed it can be modified by function? so if const
string is passed directly what causes the error?

On Sat, Aug 27, 2011 at 11:28 AM, sagar pareek sagarpar...@gmail.comwrote:

 @raj

 u already mentioned that if we write :-
 char *p=hello;
 p[0]='k'; // gives runtime error


 so if we are passing arguments as

 modify(char a[],char *b)
 {
 .
 .
 }

 main()
 {
 .
 .
 modify(hello,hi);
 .
 .
 }


 then its actually
 char arr[]=hello;
 char *b=hi;

 so ofcourse now
 b[0]='a'; // give u runtime error

 now u may be confuse about
 arr[0]='a'; //gives runtime error

 here i would like to tell you that arr is char pointer not char array
 you can check by yourself in :-   http://www.ideone.com/EQrjj

 On Sat, Aug 27, 2011 at 10:39 PM, raj kumar megamonste...@gmail.comwrote:


 monsters are monsters



 -- Forwarded message --
 From: raj kumar megamonste...@gmail.com
 Date: Sat, Aug 27, 2011 at 10:30 PM
 Subject: Re: [algogeeks] Re: String passing
 To: algogeeks@googlegroups.com


 can't understand what are you trying to say

 source

  --
 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
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 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.




-- 
 People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily.

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