Re: [algogeeks] arrays in c

2011-09-03 Thread UTKARSH SRIVASTAV
an array variable is an *unmodified* lvalue variable


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



Re: [algogeeks] arrays in c

2011-09-03 Thread Anup Ghatage
In other words, The original array identifer, and hence the pointer, is a
constant pointer.

-- 
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] arrays in c

2011-09-03 Thread teja bala
arr means the base address of the entire character array if u increase it
i.e arr++ array reference that means arr no longer referring to the
respective character array, it 'll be lost that's y C won't allow to modify
the arr's address.

-- 
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] arrays in c

2011-09-03 Thread siddharam suresh
you cant predect the o/p because u are assigning the memory address(16/32
bit) to the charecter variable(8bit).

Thank you,
Sid.



On Sat, Sep 3, 2011 at 7:36 PM, teja bala pawanjalsa.t...@gmail.com wrote:

 arr means the base address of the entire character array if u increase it
 i.e arr++ array reference that means arr no longer referring to the
 respective character array, it 'll be lost that's y C won't allow to modify
 the arr's address.

 --
 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] arrays in c

2011-09-03 Thread Siddhartha Banerjee
how does compiler internally store the fact that a points to an unmodifiable
lvalue, and also it's size???
where are the normal pointer variables stored??? (stack region, heap region,
data segment???)
and the array pointer variable and it's range???

-- 
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] arrays in c

2011-09-03 Thread siddharam suresh
@Siddhartha:
as per my knowledge,
strings are stored in code segment(its read only place) please correct me if
i m wrong.
normal variable/pointer variable stored in stack.
i dont know about array.
Thank you,
Sid.



On Sat, Sep 3, 2011 at 8:30 PM, Siddhartha Banerjee thefourrup...@gmail.com
 wrote:

 how does compiler internally store the fact that a points to an
 unmodifiable lvalue, and also it's size???
 where are the normal pointer variables stored??? (stack region, heap
 region, data segment???)
 and the array pointer variable and it's range???

  --
 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] arrays in c

2011-09-03 Thread sukran dhawan
array shud be char * nt just char.here ur declaring a char variable
yes array is a const pointer

On Sat, Sep 3, 2011 at 6:25 PM, priya ramesh love.for.programm...@gmail.com
 wrote:

 main(){
 char arr=algogeeks\0;
 arr++;
 }

 y does the compiler complain l value required in line 3.??
 arr is a pointer holding address. This address is an lvalue. Why is it
 complaining??

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

2011-05-25 Thread Piyush Sinha
Write a function

int triangle( int A [ ] )

that given a zero-indexed array A consisting of N integers returns 1
if there exists a triple (P, Q, R) such that 0 = P  Q  R  N and
A[P] + A[Q]  A[R],
A[Q] + A[R]  A[P],
A[R] + A[P]  A[Q].
The function should return 0 if such triple does not exist.

For example, given array A such that

A[0]=10, A[1]=2, A[2]=5, A[3]=1, A[4]=8, A[5]=20

the function should return 1, because the triple (0, 2, 4) fulfills
all of the required conditions.

For array A such that

A[0]=10, A[1]=50, A[2]=5, A[3]=1

the function should return 0

-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

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

2011-05-25 Thread immanuel kingston
Brute force Approach would be


int checkForTriangle(int a, int b, int c) {
 return (a + b  c)  (b + c  a)  (a + c  b);
}

int triangle (int a[], int n) {
 if (a == null || n = 0) return 0;

 for (int i=0 ; i  n ; i++) {
 for (int j=i + 1; j  n; j++ ) {
 for (int k=j + 1; k  n; k++ ) {
 if (checkForTriangle(a[i], a[j], a[k])) return 1;
  }
 }
}
 return 0;
}

Thanks,
Immanuel

On Wed, May 25, 2011 at 11:23 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 Write a function

 int triangle( int A [ ] )

 that given a zero-indexed array A consisting of N integers returns 1
 if there exists a triple (P, Q, R) such that 0 = P  Q  R  N and
 A[P] + A[Q]  A[R],
 A[Q] + A[R]  A[P],
 A[R] + A[P]  A[Q].
 The function should return 0 if such triple does not exist.

 For example, given array A such that

 A[0]=10, A[1]=2, A[2]=5, A[3]=1, A[4]=8, A[5]=20

 the function should return 1, because the triple (0, 2, 4) fulfills
 all of the required conditions.

 For array A such that

 A[0]=10, A[1]=50, A[2]=5, A[3]=1

 the function should return 0

 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

2011-05-25 Thread Aakash Johari
Sort array and then apply binary search.

On Wed, May 25, 2011 at 11:31 AM, immanuel kingston 
kingston.imman...@gmail.com wrote:

 Brute force Approach would be


 int checkForTriangle(int a, int b, int c) {
  return (a + b  c)  (b + c  a)  (a + c  b);
 }

 int triangle (int a[], int n) {
  if (a == null || n = 0) return 0;

  for (int i=0 ; i  n ; i++) {
  for (int j=i + 1; j  n; j++ ) {
  for (int k=j + 1; k  n; k++ ) {
  if (checkForTriangle(a[i], a[j], a[k])) return 1;
   }
  }
 }
  return 0;
 }

 Thanks,
 Immanuel


 On Wed, May 25, 2011 at 11:23 PM, Piyush Sinha 
 ecstasy.piy...@gmail.comwrote:

 Write a function

 int triangle( int A [ ] )

 that given a zero-indexed array A consisting of N integers returns 1
 if there exists a triple (P, Q, R) such that 0 = P  Q  R  N and
 A[P] + A[Q]  A[R],
 A[Q] + A[R]  A[P],
 A[R] + A[P]  A[Q].
 The function should return 0 if such triple does not exist.

 For example, given array A such that

 A[0]=10, A[1]=2, A[2]=5, A[3]=1, A[4]=8, A[5]=20

 the function should return 1, because the triple (0, 2, 4) fulfills
 all of the required conditions.

 For array A such that

 A[0]=10, A[1]=50, A[2]=5, A[3]=1

 the function should return 0

 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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




-- 
-Aakash Johari
(IIIT 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.



Re: [algogeeks] arrays

2011-01-01 Thread Soumya Prasad Ukil
Is the second array really required, assuming intersection of both A  B is
equal to either A or B?

How about X[a[i]] = i?

On 27 December 2010 21:24, Anand anandut2...@gmail.com wrote:

 I have a two arrays

 One is

 2 5 1 6 4 3

 other is

 1 2 3 4 5 6.

 I want to make an array X which gives the index of its element on other
 arrays.

 Meaning X[1] = 3  1 is element of the second array and 3 is the index of
 element 1 in first array.

 How shall we get array X in O(nlogn).

  --
 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,
soumya prasad ukil

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



Re: [algogeeks] arrays

2011-01-01 Thread coolfrog$
yes O(n) solution posible..
1. traverse the first array..
2. for(i=1;i=n;i++)
 {  X[a[i]] = i ;
 }
3. print array X[];
On Sat, Jan 1, 2011 at 10:42 PM, Soumya Prasad Ukil
ukil.sou...@gmail.comwrote:

 Is the second array really required, assuming intersection of both A  B is
 equal to either A or B?

 How about X[a[i]] = i?


 On 27 December 2010 21:24, Anand anandut2...@gmail.com wrote:

 I have a two arrays

 One is

 2 5 1 6 4 3

 other is

 1 2 3 4 5 6.

 I want to make an array X which gives the index of its element on other
 arrays.

 Meaning X[1] = 3  1 is element of the second array and 3 is the index of
 element 1 in first array.

 How shall we get array X in O(nlogn).

  --
 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,
 soumya prasad ukil

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




-- 
*Divesh*
(¨`·.·´¨) Always
  `·.¸(¨`·.·´¨ ) Keep
  (¨`·.·´¨)¸.·´Smiling!
   `·.¸.·´ Life can give u 100's of reason 2cry,but u can give life 1000's
of reasons 2Smile

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

2010-12-27 Thread Anand
I have a two arrays

One is

2 5 1 6 4 3

other is

1 2 3 4 5 6.

I want to make an array X which gives the index of its element on other
arrays.

Meaning X[1] = 3  1 is element of the second array and 3 is the index of
element 1 in first array.

How shall we get array X in O(nlogn).

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

2010-09-20 Thread Anand
Two unsorted arrays are given A[n] and B[n+1]. Array A contains n integers
and B contains n+1 integers of which n are same as in array B but in
different order and one extra element x. Write an optimized algorithm to
find the value of element x. Use only one pass of both arrays A and B.

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



Re: [algogeeks] Arrays

2010-09-20 Thread vishal raja
add up all the elements in array A  say sumA and array B say sumB ,substract
the sumA from sumB... You'll get the element.

On Tue, Sep 21, 2010 at 5:36 AM, Anand anandut2...@gmail.com wrote:

 Two unsorted arrays are given A[n] and B[n+1]. Array A contains n integers
 and B contains n+1 integers of which n are same as in array B but in
 different order and one extra element x. Write an optimized algorithm to
 find the value of element x. Use only one pass of both arrays A and B.

 --
 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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Arrays

2010-09-20 Thread Baljeet Kumar
There can be overflow in case of adding up all the elements. Use Xor
instead.

int result = 0;
for (int i = 0; i  n ;i++){
  result ^= A[i]^B[i];
}

result ^= B[i];
result is the number we need.
On Tue, Sep 21, 2010 at 9:48 AM, vishal raja vishal.ge...@gmail.com wrote:

 add up all the elements in array A  say sumA and array B say sumB
 ,substract the sumA from sumB... You'll get the element.


 On Tue, Sep 21, 2010 at 5:36 AM, Anand anandut2...@gmail.com wrote:

 Two unsorted arrays are given A[n] and B[n+1]. Array A contains n integers
 and B contains n+1 integers of which n are same as in array B but in
 different order and one extra element x. Write an optimized algorithm to
 find the value of element x. Use only one pass of both arrays A and B.

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




-- 
Baljeet Kumar

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



Re: [algogeeks] Arrays

2010-09-20 Thread Baljeet Kumar
There can be overflow in case of adding up all the elements. Use Xor
instead.


 int result = 0;
 for (int i = 0; i  n ;i++){
   result ^= A[i]^B[i];
 }

 result ^= B[n]; === (correction)
 result is the number we need.

 On Tue, Sep 21, 2010 at 9:48 AM, vishal raja vishal.ge...@gmail.comwrote:

 add up all the elements in array A  say sumA and array B say sumB
 ,substract the sumA from sumB... You'll get the element.


 On Tue, Sep 21, 2010 at 5:36 AM, Anand anandut2...@gmail.com wrote:

 Two unsorted arrays are given A[n] and B[n+1]. Array A contains n
 integers and B contains n+1 integers of which n are same as in array B but
 in different order and one extra element x. Write an optimized algorithm to
 find the value of element x. Use only one pass of both arrays A and B.

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




 --
 Baljeet Kumar





-- 
Baljeet Kumar

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

2010-06-26 Thread sharad kumar
Give an unsorted array find count of pairs of numbers[a,b] where a  b and b
comes after a in the array.

Eg. {8,3,6,10,5}

the count of such numbers is 5. i.e. (8,3), (8,6), (8,5), (6,5) and (10,5)

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