Re: [algogeeks] c++ this pointer

2013-06-09 Thread Shiva Kumar
Its undefined behavior. In c++ once you delete the pointer(in you case
this) and trying  to access it may lead to undefined behavior you may or
may not get correct value. Its not possible to come to conclusion as result
is not fixed. Delete of pointer will return memory to pool. if it is not
used for allocation the values will be same.


On Wed, Jun 5, 2013 at 9:35 PM, Nitish Raj raj.n...@gmail.com wrote:

 @saini  oops... i answered very fast...Let me think...Destruction of this
 pointer. Delete operator works only for heap allocated data. If you object
 is created using new, then you can apply delete this, otherwise behavior is
 undefined
 delete this will not normally affect the this pointer itself, so it can
 still be used to call the function. This behaviour is undefined though - it
 might work, it might not. In general, delete this is a bad idea in C++.
 The only justification for using it is in some reference counted classes,
 and there are beter approaches to reference counting which do not require
 its use.


 On Wed, Jun 5, 2013 at 9:21 PM, Nitish Raj raj.n...@gmail.com wrote:

 When destroy called it will print garbage then it will print desired one.
 Coz this pointer is self link but with different address of this pointer.
 So after deletion of pointer this ...
  On 5 Jun 2013 14:37, shubham saini shubhamsain...@gmail.com wrote:

 #includeiostream
 using namespace std;

 class Test
 {
 private:
   int x;
   int y;
 public:
   Test(int x = 0, int y = 0) { this-x = x; this-y = y; }
   void setX(int a) { x = a; }
   void setY(int b) { y = b; }
   void destroy()  { delete this;
 coutx=this-x,y= this-y;
   }
   void print() { cout  x =   x   y =   y  endl; }
 };

 int main()
 {
   Test *obj=new Test();
  (*obj).setX(10);
  (*obj).setY(20);
  (*obj).destroy();
   (*obj).print();
   return 0;
 }

 i created object dynamically yet how it is still able to print values of
 x  y even after deletion of object through 'this' .

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to algogeeks+unsubscr...@googlegroups.com.




  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Is a point inside a polygon?

2012-12-07 Thread shiva@Algo
draw any ray through the point.
the ray cuts the polygon at several places on both sides of the point.
if the no off cuts @ both side is odd
 point lie inside the polygon
else outside the polygon.
Plz see the example in the attached PDF.



On Thu, Dec 6, 2012 at 9:48 AM, shivendra singh vivac...@gmail.com wrote:

 Point-In-Polygon Algorithm


 On Thu, Dec 6, 2012 at 3:54 AM, Don dondod...@gmail.com wrote:

 Given a simple polygon (specified by a list of the vertices) and a
 point, how do you determine if the point is inside the polygon?

 --



  --




-- 




polygon.pdf
Description: Adobe PDF document


[algogeeks] Binomial Coefficients

2012-07-30 Thread shiva@Algo
Hey Guys,
how to solve this problem where the input size is 500 digit Integer??
https://www.interviewstreet.com/challenges/dashboard/#problem/4fe19c4f35a0e

-- 
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] Binomial Coefficients

2012-07-30 Thread shiva@Algo
Cant we do in c++??Any smart algo

On Mon, Jul 30, 2012 at 9:14 PM, Kishore kkishoreya...@gmail.com wrote:

 Python has no int limits

 On Mon, Jul 30, 2012 at 11:27 AM, shiva@Algo shiv.jays...@gmail.comwrote:


 Hey Guys,
 how to solve this problem where the input size is 500 digit Integer??

 https://www.interviewstreet.com/challenges/dashboard/#problem/4fe19c4f35a0e

  --
 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] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread shiva@Algo
A simple Divide and Conquer strategy can work Well

Seg_pos_neg(A,beg,end) //A is the array
-
mid=beg+end/2
if(begend)
 Seg_pos_neg(A,beg,mid)
 Seg_pos_neg(A,mid+1,end)
 //if leftsubarray contains +ve no and right subarray -ve array,we
swap them
 if(A[mid+1]0)
  j=mid+1
 i=beg
 while(A[i]0i=mid)
 i++
 while(A[j]0i=mid)
 swap(A[j],A[i])
-
  Running Time O(nlogn)
  O(1) space
   Correct me if I'm Wrong.


On Mon, Jul 2, 2012 at 7:53 AM, Bhaskar Kushwaha 
bhaskar.kushwaha2...@gmail.com wrote:

 @amol u have used O(n) extra space!
 I think it's not possible without using extra space.

 On 7/2/12, Darpan Baweja darpan.bav...@gmail.com wrote:
  @amol :- i don't think this algo would work here
  after sorting how would you replace back the original no.s(as no.s are
 not
  0 and 1 in this case)
 
  On Sun, Jul 1, 2012 at 11:08 PM, Amol Sharma amolsharm...@gmail.com
  wrote:
 
  i think it has been discussed beforenevertheless here is the
 required
  linear time solution.
 
  first, count the total number 0's and 1's in the array.
 
  let say, total elements are n and there are x zero's.
 
  take count1=0 and count2=x;
 
  traverse through the array :
  for(i=0;in;i++)
  if(arr[i]==0)
arr[i]=count1++;
  else
arr[i]=count2++;
 
  let's say array is {1,0,0,0,1,1,1,0,0,1}  n=10,x=5
  count1=0;count2=5
 
  after the traversal it becomes a[]={5,0,1,2,6,7,8,3,4,9}
 
  now sort this array in O(n) like this :
 
  for(j=0;j=1;j++)
  {
  for(i=0;in;i++)
  {
if(arr[i]!=i)
 swap(arr[i],arr[arr[i]]);
  }
  }
 
  after the array is sorted again traverse the array and set the elements
  from index 0 to x-1 to '0' and rest '1'.
 
 
 
 
 
 
 
 
  --
 
 
  Amol Sharma
  Final Year Student
  Computer Science and Engineering
  MNNIT Allahabad
 
  http://gplus.to/amolsharma99
  http://twitter.com/amolsharma99
 http://in.linkedin.com/pub/amol-sharma/21/79b/507
 http://www.simplyamol.blogspot.com/http://facebook.com/amolsharma99
 
 
 
 
 
 
  On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha 
  bhaskar.kushwaha2...@gmail.com wrote:
 
  @Hassan I think your algo will take time O(n^2) in worst case which
  occurs when all elements are negative except the last one
  @everyone Can we solve this problem in linear time?
 
 
  On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared
  hmonfa...@gmail.comwrote:
 
  Hi,
  this can be done by simple modification in bubble sort :
  void inplace_pos_neg(int pdata[],int sz)
  {
  bool changed=false;
   do
  {
  changed=false;
   for(int i=1;isz;i++)
  if(pdata[i-1]0  pdata[i]0)
  {
   swap(pdata[i-1], pdata[i]);
  changed=true;
  }
   }while(changed);
  }
 
  void test_inplace_pos_neg()
  {
  int a[]={-1,-5,10,11,15,-500,200,-10};
 
 
 copy(a,a+sizeof(a)/sizeof(int),ostream_iteratorint(cout,,));coutendl;
  inplace_pos_neg(a,sizeof(a)/sizeof(int));
 
 
 copy(a,a+sizeof(a)/sizeof(int),ostream_iteratorint(cout,,));coutendl;
 
  }
 
 
  Regards
 
  On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma
  utsav.sharm...@gmail.comwrote:
 
  @bhaskar:- please explain stable sorting algorithm you would use(as
  mainly all of them require extra space)
  @sourabh:- that previous post discussion does't lead to any correct
  soln
 
  On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha 
  bhaskar.kushwaha2...@gmail.com wrote:
 
  @saurabh please provide the link to the post you are mentioning
 
  On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha 
  bhaskar.kushwaha2...@gmail.com wrote:
 
   If the order is important then I think we can use any stable
  sorting
  algorithm with the following comparison function
 
  int compare (int a ,int b)
  {
  if((a0b0)||(a0b0)) return 0;
  else return ab;
  }
  On Fri, Jun 29, 2012 at 3:37 PM, raghavan M 
  peacelover1987...@yahoo.co.in wrote:
 
  This is a variant of that one
 
--
  *From:* saurabh singh saurab...@gmail.com
  *To:* algogeeks@googlegroups.com
  *Sent:* Friday, 29 June 2012 3:05 PM
 
  *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
  negative nos in array without changing order
 
  duplicate of a previous post.Kindly refer to that post.
  Saurabh Singh
  B.Tech (Computer Science)
  MNNIT
  blog:geekinessthecoolway.blogspot.com
 
 
 
  On Fri, Jun 29, 2012 at 10:41 AM, raghavan M 
  peacelover1987...@yahoo.co.in wrote:
 
  Hi
  Question as in subject
 
  *No extra space (can use one extra space)-O(1) max
  *No order change allowed
  example:
 
  input : 1,-5,2,10,-100,-2
  output: -5,-10,-100,1,2
 
  input : -1,-5,10,11,15,-500,200,-10
  output : -1,-5,-10,-500,-10,10,11,15
 
 
  Thanks
  Raghavn
   --
  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 

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread shiva@Algo
*
while(A[j]0i=mid)
 swap(A[j],A[i])
  i++
  j++

On Mon, Jul 2, 2012 at 8:34 AM, shiva@Algo shiv.jays...@gmail.com wrote:

 A simple Divide and Conquer strategy can work Well

 Seg_pos_neg(A,beg,end) //A is the array
 -
 mid=beg+end/2
 if(begend)
  Seg_pos_neg(A,beg,mid)
  Seg_pos_neg(A,mid+1,end)
  //if leftsubarray contains +ve no and right subarray -ve array,we
 swap them
  if(A[mid+1]0)
   j=mid+1
  i=beg
  while(A[i]0i=mid)
  i++
  while(A[j]0i=mid)
  swap(A[j],A[i])
 -
   Running Time O(nlogn)
   O(1) space
Correct me if I'm Wrong.



 On Mon, Jul 2, 2012 at 7:53 AM, Bhaskar Kushwaha 
 bhaskar.kushwaha2...@gmail.com wrote:

 @amol u have used O(n) extra space!
 I think it's not possible without using extra space.

 On 7/2/12, Darpan Baweja darpan.bav...@gmail.com wrote:
  @amol :- i don't think this algo would work here
  after sorting how would you replace back the original no.s(as no.s are
 not
  0 and 1 in this case)
 
  On Sun, Jul 1, 2012 at 11:08 PM, Amol Sharma amolsharm...@gmail.com
  wrote:
 
  i think it has been discussed beforenevertheless here is the
 required
  linear time solution.
 
  first, count the total number 0's and 1's in the array.
 
  let say, total elements are n and there are x zero's.
 
  take count1=0 and count2=x;
 
  traverse through the array :
  for(i=0;in;i++)
  if(arr[i]==0)
arr[i]=count1++;
  else
arr[i]=count2++;
 
  let's say array is {1,0,0,0,1,1,1,0,0,1}  n=10,x=5
  count1=0;count2=5
 
  after the traversal it becomes a[]={5,0,1,2,6,7,8,3,4,9}
 
  now sort this array in O(n) like this :
 
  for(j=0;j=1;j++)
  {
  for(i=0;in;i++)
  {
if(arr[i]!=i)
 swap(arr[i],arr[arr[i]]);
  }
  }
 
  after the array is sorted again traverse the array and set the elements
  from index 0 to x-1 to '0' and rest '1'.
 
 
 
 
 
 
 
 
  --
 
 
  Amol Sharma
  Final Year Student
  Computer Science and Engineering
  MNNIT Allahabad
 
  http://gplus.to/amolsharma99
  http://twitter.com/amolsharma99
 http://in.linkedin.com/pub/amol-sharma/21/79b/507
 http://www.simplyamol.blogspot.com/http://facebook.com/amolsharma99
 
 
 
 
 
 
  On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha 
  bhaskar.kushwaha2...@gmail.com wrote:
 
  @Hassan I think your algo will take time O(n^2) in worst case which
  occurs when all elements are negative except the last one
  @everyone Can we solve this problem in linear time?
 
 
  On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared
  hmonfa...@gmail.comwrote:
 
  Hi,
  this can be done by simple modification in bubble sort :
  void inplace_pos_neg(int pdata[],int sz)
  {
  bool changed=false;
   do
  {
  changed=false;
   for(int i=1;isz;i++)
  if(pdata[i-1]0  pdata[i]0)
  {
   swap(pdata[i-1], pdata[i]);
  changed=true;
  }
   }while(changed);
  }
 
  void test_inplace_pos_neg()
  {
  int a[]={-1,-5,10,11,15,-500,200,-10};
 
 
 copy(a,a+sizeof(a)/sizeof(int),ostream_iteratorint(cout,,));coutendl;
  inplace_pos_neg(a,sizeof(a)/sizeof(int));
 
 
 copy(a,a+sizeof(a)/sizeof(int),ostream_iteratorint(cout,,));coutendl;
 
  }
 
 
  Regards
 
  On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma
  utsav.sharm...@gmail.comwrote:
 
  @bhaskar:- please explain stable sorting algorithm you would use(as
  mainly all of them require extra space)
  @sourabh:- that previous post discussion does't lead to any correct
  soln
 
  On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha 
  bhaskar.kushwaha2...@gmail.com wrote:
 
  @saurabh please provide the link to the post you are mentioning
 
  On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha 
  bhaskar.kushwaha2...@gmail.com wrote:
 
   If the order is important then I think we can use any stable
  sorting
  algorithm with the following comparison function
 
  int compare (int a ,int b)
  {
  if((a0b0)||(a0b0)) return 0;
  else return ab;
  }
  On Fri, Jun 29, 2012 at 3:37 PM, raghavan M 
  peacelover1987...@yahoo.co.in wrote:
 
  This is a variant of that one
 
--
  *From:* saurabh singh saurab...@gmail.com
  *To:* algogeeks@googlegroups.com
  *Sent:* Friday, 29 June 2012 3:05 PM
 
  *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
  negative nos in array without changing order
 
  duplicate of a previous post.Kindly refer to that post.
  Saurabh Singh
  B.Tech (Computer Science)
  MNNIT
  blog:geekinessthecoolway.blogspot.com
 
 
 
  On Fri, Jun 29, 2012 at 10:41 AM, raghavan M 
  peacelover1987...@yahoo.co.in wrote:
 
  Hi
  Question as in subject
 
  *No extra space (can use one extra space)-O(1) max
  *No order change allowed
  example:
 
  input : 1,-5,2,10,-100,-2
  output: -5,-10,-100,1,2
 
  input : -1,-5,10,11,15,-500,200,-10
  output : -1,-5,-10,-500,-10,10,11,15
 
 
  Thanks
  Raghavn
   --
  You

Re: [algogeeks] String comparison

2012-04-18 Thread Shiva Kumar
Hi Abhishek,

You can use following string comparison function strcmplogicalw
you can refer
http://msdn.microsoft.com/en-us/library/windows/desktop/bb759947%28v=vs.85%29.aspx

Regards,
Shivakumar



On Wed, Apr 18, 2012 at 9:16 AM, abhishek zeal.gosw...@gmail.com wrote:

  Hi,

 I need to compare string into following way. Can anyone provide me some
 insight or algorithm in c++.

   For example:

  a5  a11- because 5 is less than 11
  6xxx  007asdf- because 6  7
  00042Q  42s  - because Q  s alphabetically
  6   8  006 9   - because 8  9

 ** **

 Thx in advance

 --
 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] Dp solution for this problem?

2011-10-30 Thread shiva@Algo
Min Cost Path:
http://www.geeksforgeeks.org/archives/14943

On Mon, Oct 31, 2011 at 12:52 AM, mohit verma mohit89m...@gmail.com wrote:

 Given a matrix you have to find the shortest path from one point to
 another within the matrix. The cost of path is all the matrix entries on
 the way. You can move in any direction (up, down, left, right, diagonally)

 e.g.

 5 9 10 1
 3 7 4 4
 8 2 1 9

 So shortest path from (0,0) to (2,2) is (0,0)--(1,1)---(2,2). Path cost -
 5+3+2+1=11

 I dont think some DP solution exist for this problem.Can it be?


 --
 Mohit

 --
 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: Exchanging bit values in a number

2011-10-29 Thread shiva@Algo
How abt this?
we need to swap only if both the bits are not same

if((n^(1i)n)!=(n^(1j)n))
n^=(1i)+(1j);

On 10/29/11, praveen raj praveen0...@gmail.com wrote:
 int func(int x)
 {
 int  y=(1i)+(1j);
  int z=xy;// if after bitwise and  ..we get power of 2 then ...
 we have to flip the bits..
 if((z(z-1))==0)
return(x^y);
 else
   return x;
 }

 With regards,

 Praveen Raj
 DCE-IT
 735993
 praveen0...@gmail.com




 --
 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: Exchanging bit values in a number

2011-10-29 Thread shiva@Algo
we need to swap only if both the bits are not same

if((n^(1i)n)!=(n^(1j)n))
n^=(1i)+(1j);

On 10/29/11, praveen raj praveen0...@gmail.com wrote:
 int func(int x)
 {
 int  y=(1i)+(1j);
  int z=xy;// if after bitwise and  ..we get power of 2 then ...
 we have to flip the bits..
 if((z(z-1))==0)
return(x^y);
 else
   return x;
 }

 With regards,

 Praveen Raj
 DCE-IT
 735993
 praveen0...@gmail.com




 --
 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] Searching In a large file

2011-10-27 Thread shiva@Algo
Given a file containing roughly 300 million social security
numbers(9-digit numbers), find a 9-digit number that is not in the file.
You have unlimited drive space but only 2megabytes of RAM at your
disposal.

-- 
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: Inplace Array Convertion

2011-10-14 Thread shiva@Algo
@Utkarsh As efficient as possible..

On Fri, Oct 14, 2011 at 6:25 AM, UTKARSH SRIVASTAV
usrivastav...@gmail.comwrote:



 @siddharth what is the complexity?

 --
 *UTKARSH SRIVASTAV
 CSE-3
 B-Tech 3rd Year
 @MNNIT ALLAHABAD*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to 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: Inplace Array Convertion

2011-10-14 Thread shiva@Algo
@Gaurav how will u do for
a1a2a3a4a5b1b2b3b4b5c1c2c3c4c5

On Fri, Oct 14, 2011 at 6:49 AM, gaurav yadav gauravyadav1...@gmail.comwrote:

 consider following example...
 suppose initailly we have   a1a2a3b1b2b3c1c2c3

 then do the following-
  a1a2a3 b1b2b3 c1c2c3   (look for b1 in the remaining array and swap with
 a2  ,  so in this case   swap(a2,b1)   )
  a1b1a3 a2b2b3 c1c2c3   (similarly swap(a3,c1) )
  a1b1c1 a2b2b3 a3c2c3swap(b3,c2)
  a1b1c1 a2b2c2 a3b2c3


 this in inplace

 (plz correct if im 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.


-- 
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] Inplace Array Convertion

2011-10-13 Thread shiva@Algo
Convert an array a1 a2 a3...an b1 b2 b3...bn c1 c2 c3...cn to a1b1c1
a2b2c2...anbncn, inplace

-- 
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: Algo for Search in a 2D Matrix

2011-10-10 Thread shiva@Algo
id we see the pattern then we can easily find that the kth smallest element
lie on the upper half of the k*k submatrix(on the upperleft corner )
we can do search on  (k*k)/2 elements to find that

On Mon, Oct 10, 2011 at 10:36 AM, Dave dave_and_da...@juno.com wrote:

 @Shubham: So if the matrix is
 1 2
 3 4
 and you want the 2nd smallest, are you saying that it is 4?

 Dave

 On Oct 9, 7:40 pm, shubham goyal shubhamgoyal.n...@gmail.com wrote:
  im assuming it be a square matrix
  then kth smallest element will be in a first k*k sub matrix.
  jst look for smallest element in the diagonal of this matrix.
  it will give the kth smallest element .
 
 
 
  On Mon, Oct 10, 2011 at 4:45 AM, Ankur Garg ankurga...@gmail.com
 wrote:
   Given a 2D matrix which is both row wise and column wise sorted.
 Propose an
   algorithm for finding the kth smallest element in it in least time
   complexity
 
   A General Max Heap can be used with k space and n+klogk complexity
 
   Any other solution  or even a way by which we dont scan the whole
 matrix to
   find the solution ?
 
   I
 
   --
   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] Give Algo to do this in O(n)

2011-10-09 Thread shiva@Algo
I think Min heap will do that..

On Mon, Oct 10, 2011 at 12:37 AM, Ankur Garg ankurga...@gmail.com wrote:

 Given an unsorted array of Integers

 Find 2 nos whose diff is minimum

 Say Array is  4 2 18 19 11 8 5

 Nos are 18 and 19

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


-- 
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: Basic Algorithm

2011-10-08 Thread shiva@Algo
:)

On Sat, Oct 8, 2011 at 6:41 AM, Navneet navneetn...@gmail.com wrote:

 I wonder why my name is there in the example string used :)

 On Oct 8, 3:11 pm, ManishMCS manishdaw...@gmail.com wrote:
  A string of characters are given. Find the highest occurrence of a
  character and display that character.
 
  E.g Input: AEGBCNAVNEETGUPTAEDAGPE
  Output: E.
 
  Please give the efficient algorithm w.r.t both space and time..

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

2011-10-08 Thread shiva@Algo
as expected value 100 goes to a,since %*d is variable field width specifier
 so the input 200 goes for that,and the remaining input 300 goes to b
value of c is not change
so the output will be:
100 300 3

On Sun, Oct 9, 2011 at 12:22 AM, Raghav Garg rock.ragha...@gmail.comwrote:

 *explain the o/p...if i/p are 100 200 300
 int main()
   {
int a=1,b=2,c=3;
scanf(%d %*d %d,a,b,c);
printf(%d %d %d,a,b,c);
return(0);
   }
 *Thanking you

 *With regards-
 Raghav garg
 Contact no. 9013201944
 www.facebook.com/rock.raghavag
 B. tech (IT), 5th sem
 University School Of Information Technology
 Guru Govind Singh Indraprastha University
 Delhi*

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

2011-10-08 Thread shiva@Algo
This is what you use if you want *scanf()* to eat some data but you don't
want to store it anywhere; you don't give *scanf()* an argument for this
conversion

On Sun, Oct 9, 2011 at 1:32 AM, shiva@Algo shiv.jays...@gmail.com wrote:

 as expected value 100 goes to a,since %*d is variable field width specifier
  so the input 200 goes for that,and the remaining input 300 goes to b
 value of c is not change
 so the output will be:
 100 300 3


 On Sun, Oct 9, 2011 at 12:22 AM, Raghav Garg rock.ragha...@gmail.comwrote:

 *explain the o/p...if i/p are 100 200 300
 int main()
   {
int a=1,b=2,c=3;
scanf(%d %*d %d,a,b,c);
printf(%d %d %d,a,b,c);
return(0);
   }
 *Thanking you

 *With regards-
 Raghav garg
 Contact no. 9013201944
 www.facebook.com/rock.raghavag
 B. tech (IT), 5th sem
 University School Of Information Technology
 Guru Govind Singh Indraprastha University
 Delhi*

  --
 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] print all numbers in a given range without using any loop statements, jump statements and recursion

2011-10-07 Thread shiva@Algo
Thanx ,owesome soln...

On Fri, Oct 7, 2011 at 11:44 AM, tanuj chawla houndhun...@gmail.com wrote:

 #includeiostream
 int i;
 class A
 {
 public:
 A(){couti++endl;}
 ~A(){cout--iendl;}
 }
 int main()
 {
 A a[100];
 return 0;
 }



 On Thu, Oct 6, 2011 at 10:42 PM, shiva@Algo shiv.jays...@gmail.comwrote:

 cant find in archives plz someone


 On Sun, Oct 2, 2011 at 6:03 PM, Sahil Garg garg.sahi...@gmail.comwrote:

 plz post the soln.. i cant find it..

 Sahil Garg
 Computer Engineering
 Delhi College of Engineering



 On Tue, Sep 27, 2011 at 3:41 PM, shady sinv...@gmail.com wrote:

 discussed, kindly look at archives


 On Tue, Sep 27, 2011 at 3:13 PM, surender sanke surend...@gmail.comwrote:

 print all numbers in a given range *without* using any loop
 statements, jump statements and recursion

 surender

 --
 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] can somebody kindly explain what would be the output for the following program

2011-10-06 Thread shiva@Algo
here

*char *p = ayqm;
p points to constant character string
so ++*(p++) is an attempt to modify the string so its an error
*


On Thu, Oct 6, 2011 at 8:35 AM, praneethn praneeth...@gmail.com wrote:

 *int main()

   {   

   char *p = ayqm;

   printf(%c,++*(p++));
   return 0;

  }*

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


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



Re: [algogeeks] can somebody kindly explain what would be the output for the following program

2011-10-06 Thread shiva@Algo
check this :
https://www.securecoding.cert.org/confluence/display/seccode/STR30-C.+Do+not+attempt+to+modify+string+literals

On Thu, Oct 6, 2011 at 9:40 PM, Neha Gupta nehagup...@gmail.com wrote:

 its not an error
 infact pre-increment operator doesnt hv an impact in changing the value of
 const stringdats y the o/p is a

 --
 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] print all numbers in a given range without using any loop statements, jump statements and recursion

2011-10-06 Thread shiva@Algo
cant find in archives plz someone

On Sun, Oct 2, 2011 at 6:03 PM, Sahil Garg garg.sahi...@gmail.com wrote:

 plz post the soln.. i cant find it..

 Sahil Garg
 Computer Engineering
 Delhi College of Engineering



 On Tue, Sep 27, 2011 at 3:41 PM, shady sinv...@gmail.com wrote:

 discussed, kindly look at archives


 On Tue, Sep 27, 2011 at 3:13 PM, surender sanke surend...@gmail.comwrote:

 print all numbers in a given range *without* using any loop statements,
 jump statements and recursion

 surender

 --
 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] Tree Question

2011-10-04 Thread shiva@Algo
check this(considering valid input)
http://www.ideone.com/Nuhil

On Tue, Oct 4, 2011 at 3:36 PM, Dheeraj Sharma
dheerajsharma1...@gmail.comwrote:

 yeah..but am looking for code..that takes the input...as string of 
 (A(B(E(K,L),F),D(H(M,I),J)))
 and returns head of tree..


 On Tue, Oct 4, 2011 at 2:11 PM, Raghav Garg rock.ragha...@gmail.comwrote:

 *you have to check for the braces where they have been used..in comman
 brace that means they are on same level..i am providing answer to your
 problem in attached file..
 check that out..

 *Raghav garg



 On Tue, Oct 4, 2011 at 1:53 PM, Dheeraj Sharma 
 dheerajsharma1...@gmail.com wrote:

 1.How to construct a tree from the list representation
  for ex.- construct tree from (A(B(E(K,L),F),D(H(M,I),J)))
 the tree would be binary
 the structure of the node would be

 struct node{
 int data;
 struct node *left,*right;
 };

 2.Given a binary tree..give its list representaion..(reverse of above
 question)

 --
 *Dheeraj Sharma*


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




 --
 *Dheeraj Sharma*


  --
 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] structure padding

2011-10-02 Thread shiva@Algo
http://www.geeksforgeeks.org/archives/9705


On Sat, Oct 1, 2011 at 9:54 PM, rahul sharma rahul23111...@gmail.comwrote:

 in structure we want adress to be multiple of the max size variable of
 structure.
 mean i have
 struct
 {
 int
 float
  char}
 then multiple of 4


 struct
 {
 short int
 int
 }
 then multiple of 2.
 m i ryt

  --
 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: Amazon Interns

2011-10-01 Thread shiva@Algo
Thanx,,NIT Durgapur,Do i need to study OS and RDBMS

On Sat, Oct 1, 2011 at 10:41 AM, .itoa nitm...@gmail.com wrote:

 BST ,very Large Input data problems, graphs (dfs bfs ,etc).  which college
 ?

 --
 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/-/xqxjYxJ3cP8J.
 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: Amazon Interns

2011-10-01 Thread shiva@Algo
Thanx :)

On Sat, Oct 1, 2011 at 12:39 PM, SAMMM somnath.nit...@gmail.com wrote:

 Focus on Algorithm , Data Structure and your coding skills , as they
 can ask for proper working code at tht moment .

 --
 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: amazon ques

2011-10-01 Thread shiva@Algo
Dont know how to delete (how adress will be known of the node?

On Sat, Oct 1, 2011 at 12:27 PM, SAMMM somnath.nit...@gmail.com wrote:

 The hash table would be used by separate chaining method not open
 addressing because it may not find the correct entry efficiently in
 the hash table . In case of open addresssing the value gets entered in
 the first available entry after collision.

 In case of insertion :- (I have considered only simple insertion as It
 is not been mentioned )
 U can insert the element in the linked list at the end .

 In case of deletion :-
 you need to find the address of the node from the hashed table which
 is to be deleted .
 you can delete it  Hope u know the logic to delete the node of the
 whose address is only known . For that case we also need to Invalidate
 the entry in the hash table and update the entry of the next node in
 the hash table . I hope I am clear

 In case of searching .
 Hashing table will serve the purpose .

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

2011-09-30 Thread shiva@Algo
Amazon is Coming in our college ,Plz sugeest which subjects and what topic
to focus for that ...

-- 
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: use of ^ in char[]

2011-08-31 Thread shiva
ya i got it...
thanks...

On Aug 25, 9:43 pm, sukran dhawan sukrandha...@gmail.com wrote:
 i got stack smashing run time erroer







 On Wed, Aug 24, 2011 at 11:24 AM, Md.Khalid Ahmad hack...@gmail.com wrote:
  Since you are accessing array out of bound.
  there will be runtime error of stack corruption.

  On Aug 23, 7:40 pm, shiva shiva8ve...@gmail.com wrote:
   #includestdio.h
   int main(){
       char str[]=abcd;
       int i;

       for(i=0;i6;i++){
               str[i]^=str[6-i];
               }
               printf(\n%s,str);
               getch();
               return 0;

   }

   i don understand how it works... can u explain if u guys understand..?

  --
  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] stack interview question

2011-08-31 Thread shiva
Suppose that a client performs an intermixed sequence of (stack) push
and pop operations. The push operations put the integers 0 through 9
in order on to the stack; the pop operations print out the return
value. Which of the following sequences could not occur?
(a) 4 3 2 1 0 9 8 7 6 5
(b) 4 6 8 7 5 3 2 9 0 1
(c) 2 5 6 7 4 8 9 3 1 0
(d) 4 3 2 1 0 5 6 7 8 9
(e) 1 2 3 4 5 6 9 8 7 0
(f) 0 4 6 5 3 8 1 7 2 9
(g) 1 4 7 9 8 6 5 3 0 2
(h) 2 1 4 3 6 5 8 7 9 0

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



[algogeeks] use of ^ in char[]

2011-08-23 Thread shiva
#includestdio.h
int main(){
char str[]=abcd;
int i;

for(i=0;i6;i++){
str[i]^=str[6-i];
}
printf(\n%s,str);
getch();
return 0;
}

i don understand how it works... can u explain if u guys understand..?

-- 
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: use of ^ in char[]

2011-08-23 Thread shiva
ya tat's 4 nos. but tat doesn't seem 2 b workin for char... chk it out
with an example...

On Aug 23, 10:28 pm, nagarajan naga4...@gmail.com wrote:
 You are doing Bitwise XOR 

 and getting values corresponding symbols of XOR -ed result..









 On Tue, Aug 23, 2011 at 8:10 PM, shiva shiva8ve...@gmail.com wrote:
  #includestdio.h
  int main(){
     char str[]=abcd;
     int i;

     for(i=0;i6;i++){
             str[i]^=str[6-i];
             }
             printf(\n%s,str);
             getch();
             return 0;
  }

  i don understand how it works... can u explain if u guys understand..?

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

 --

 Nagarajan S

-- 
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] How to identify what is stored in union in c language

2011-02-21 Thread shiva
I have an union with following members

union data
{
int age;
char grade;
}var;

now after some operation which assign value to var(it can assign it
either age or grade), is there any way i can identify whether var
contain age or grade now.

Thanks for the comments..

-- 
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: for loop performace in terms of speed makes any difference when we run from max to min and min to max

2010-11-24 Thread shiva
After googling i came to know that comparison with 0 takes less time
than comparing with some other number.So decremental loop is
fast(difference is very very low)

On Nov 22, 5:42 pm, rahul patil rahul.deshmukhpa...@gmail.com wrote:
 Might be its is due to the comparison operation which takes many cycles

 i  max takes more cycles of cpu than just simply checking i

 On Sun, Nov 21, 2010 at 6:50 PM, shiva shivanand.kadwad...@gmail.comwrote:



  I want to know is there any difference between following two loop in
  terms of speed.

  1.
  for(i=0;imax;i++)
  {

  //Some operation
  }
  2.
  for(i=max; i; i--)
  {

  /Some operation

  }

  I heard second one is faster but don't have any proof

  Please comment.

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

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



[algogeeks] Re: Mathematics Puzzle

2010-11-22 Thread shiva

Any explanation of how it works and how you got log(69) as answer.

Thanks in advance.


On Nov 22, 2:27 pm, Salil Joshi joshi.sali...@gmail.com wrote:
 Hi,
 The puzzle needs to be rephrased as:
 If the rank of the student who comes out of the classroom is better
 than ranks of all students who came out before him/her, then he/she
 gets a lollipop.
 Rephrased this way, this is a famous puzzle, and the answer is
 log(69).

 On Nov 22, 12:44 pm, shiva shivanand.kadwad...@gmail.com wrote:

  If all the person got his rank increased except the first(he is last
  know)  then

  1. if the previous first ranked person stand front in queue then  69
  lollipop need to be distributed.
  2. other case 68 lollipop need to be distributed.

  On Nov 21, 9:46 pm, Shiv Shankar Prajapati mca.shivshan...@gmail.com
  wrote:

   Its total no. of Student i.e. 69.
      If all the students ranking is increased then all the student will get
   the lollipop. But there is one student left who was at top n now on the
   least ranking and as the condition is given that student may appear first
   and get the lollipop. So professor need will give 69 lollipop. in this
   (worst) case.

   On Sun, Nov 21, 2010 at 8:42 PM, Ashim Kapoor ashimkap...@gmail.com 
   wrote:
Do you mean if the rank of a student is better than the rank of the prev
student then he/she gets a lollipop?

Thank you,
Ashim

On Sun, Nov 21, 2010 at 6:57 PM, vamsee marpu 
marpu.vam...@gmail.comwrote:

Does anybody know the solution for the following problem :

*A headmaster of a primary school performs an activity with the 
students
of a class to encourage them to perform better in academics. He asks 
them to
stand in queue, starts calling the students out one by one and asks 
them
their rank in class. Each one has a unique rank in class. If the rank 
of a
student is better than his/her previous best rank, then he awards him/ 
her a
lollipop (students love lollipops). Note that the first one in the 
queue
will always get a lollipop and the students arrange themselves in 
random
order in the queue. What is the expected number of lollipops the 
headmaster
will have to distribute among students if the total number of students 
in
the class is 69? Note that the answer can be a fractional number.*

Thanks and Regards,
M. Vamsee

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

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

   --
   With Regards,

   Shiv Shankar,

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



[algogeeks] switch vs if -- which is faster

2010-11-21 Thread shiva
As per my understanding it is compiler depending thing..

what i feel is switch need to evaluate the expression only once but if
else if need to evaluate the expression more than once(what if
expression stored in variable and then compare...)

Does any one please comment difference in speed of switch and if
depending on how it is implemented...

I heard switch uses jump table for its operation.

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



[algogeeks] for loop performace in terms of speed makes any difference when we run from max to min and min to max

2010-11-21 Thread shiva
I want to know is there any difference between following two loop in
terms of speed.

1.
for(i=0;imax;i++)
{

//Some operation
}
2.
for(i=max; i; i--)
{

/Some operation

}

I heard second one is faster but don't have any proof

Please comment.

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



[algogeeks] Re: Mathematics Puzzle

2010-11-21 Thread shiva
If all the person got his rank increased except the first(he is last
know)  then

1. if the previous first ranked person stand front in queue then  69
lollipop need to be distributed.
2. other case 68 lollipop need to be distributed.

On Nov 21, 9:46 pm, Shiv Shankar Prajapati mca.shivshan...@gmail.com
wrote:
 Its total no. of Student i.e. 69.
    If all the students ranking is increased then all the student will get
 the lollipop. But there is one student left who was at top n now on the
 least ranking and as the condition is given that student may appear first
 and get the lollipop. So professor need will give 69 lollipop. in this
 (worst) case.



 On Sun, Nov 21, 2010 at 8:42 PM, Ashim Kapoor ashimkap...@gmail.com wrote:
  Do you mean if the rank of a student is better than the rank of the prev
  student then he/she gets a lollipop?

  Thank you,
  Ashim

  On Sun, Nov 21, 2010 at 6:57 PM, vamsee marpu marpu.vam...@gmail.comwrote:

  Does anybody know the solution for the following problem :

  *A headmaster of a primary school performs an activity with the students
  of a class to encourage them to perform better in academics. He asks them 
  to
  stand in queue, starts calling the students out one by one and asks them
  their rank in class. Each one has a unique rank in class. If the rank of a
  student is better than his/her previous best rank, then he awards him/ her 
  a
  lollipop (students love lollipops). Note that the first one in the queue
  will always get a lollipop and the students arrange themselves in random
  order in the queue. What is the expected number of lollipops the headmaster
  will have to distribute among students if the total number of students in
  the class is 69? Note that the answer can be a fractional number.*

  Thanks and Regards,
  M. Vamsee

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

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

 --
 With Regards,

 Shiv Shankar,

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