[algogeeks] Inversion problem

2012-07-08 Thread Navin Kumar
Let A[n] be an array of n distinct number. If ij and A[i] A[j] then the pair (i , j) is called inversion of A. Give an algorithm that determines the total number of inversions in O(nlogn) time. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: Inversion problem

2012-07-08 Thread deepikaanand
http://www.geeksforgeeks.org/archives/3968 On Jul 8, 11:01 am, Navin Kumar algorithm.i...@gmail.com wrote: Let A[n] be an array of n distinct number. If ij and A[i] A[j] then the pair (i , j) is called inversion of A. Give an algorithm that determines the total number of inversions in

Re: [algogeeks] Re: Inversion problem

2012-07-08 Thread Navin Kumar
Thanx Deepika :) On Sun, Jul 8, 2012 at 11:48 AM, deepikaanand swinyanand...@gmail.comwrote: http://www.geeksforgeeks.org/archives/3968 On Jul 8, 11:01 am, Navin Kumar algorithm.i...@gmail.com wrote: Let A[n] be an array of n distinct number. If ij and A[i] A[j] then the pair (i , j)

Re: [algogeeks] Inversion problem

2012-07-08 Thread Prakhar Jain
You can use either Merge sort or BIT(refer TopCoder tutorial). -- Prakhar Jain IIIT Allahabad B.Tech IT 3rd Year Mob no: +91 9454992196 E-mail: rit2009...@iiita.ac.in jprakha...@gmail.com On Sun, Jul 8, 2012 at 11:31 AM, Navin Kumar algorithm.i...@gmail.comwrote: Let A[n] be an

Re: [algogeeks] Inversion problem

2012-07-08 Thread Krishnan
Try like merge sort. http://www.geeksforgeeks.org/archives/3968 -- 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

Re: [algogeeks] Re: Write a C program to reconstruct a BST from a given array of preorder traversal.

2012-07-08 Thread atul anand
+1 Akshat On 7/7/12, Akshat Sapra sapraaks...@gmail.com wrote: There is no need to use any other data structure or sort the array one can directly construct the BST from a given array by taking one element at a time from the beginning and inserting into a BST. -- Akshat Sapra Under

[algogeeks] candies - interviewstreet -- how to go about solving this problem

2012-07-08 Thread g4ur4v
Alice is a teacher of kindergarten. She wants to give some candies to the children in her class. All the children sit in a line and each of them has a rating score according to his or her usual performance. Alice wants to give at least 1 candy for each children. Because children are somehow

Re: [algogeeks] Amazon Interview Question

2012-07-08 Thread Decipher
@ashgoel - Could you please explain what exactly are you doing here ? On Wednesday, 4 July 2012 16:16:38 UTC+5:30, ashgoel wrote: Q4 vectorString prefix; prefix[0]=NULL; prefixCount =1; for (int i=0;in;i++) for (int j=0;jn;j++) for (int k=0; kprefixCount;k++) { if

[algogeeks] C o/p

2012-07-08 Thread rahul sharma
int i=5; i=++i/i++; print i; i=1 how? -- 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.

Re: [algogeeks] C o/p

2012-07-08 Thread adarsh kumar
Firstly, this is ambiguous and expressions with multiple increment/decrement operators will get executed according to the compiler. Even if you consider the normal way, as we(humans) percieve it, it will be evaluated as (++i)/(i++), which is 6/5, which is 1. Simple! On Sun, Jul 8, 2012 at

Re: [algogeeks] C o/p

2012-07-08 Thread adarsh kumar
Sorry, its 6/6 and not 6/5, regds. On Sun, Jul 8, 2012 at 10:39 PM, adarsh kumar algog...@gmail.com wrote: Firstly, this is ambiguous and expressions with multiple increment/decrement operators will get executed according to the compiler. Even if you consider the normal way, as we(humans)

Re: [algogeeks] C o/p

2012-07-08 Thread md shaukat ali
agree with adarsh On Sun, Jul 8, 2012 at 10:39 PM, adarsh kumar algog...@gmail.com wrote: Sorry, its 6/6 and not 6/5, regds. On Sun, Jul 8, 2012 at 10:39 PM, adarsh kumar algog...@gmail.com wrote: Firstly, this is ambiguous and expressions with multiple increment/decrement operators

Re: [algogeeks] C o/p

2012-07-08 Thread md shaukat ali
but i am confused in this problem... int a=10; int b; b=--a--; printf(%d %d,a,b);..what will output? On Sun, Jul 8, 2012 at 11:39 PM, md shaukat ali ali.mdshau...@gmail.comwrote: agree with adarsh On Sun, Jul 8, 2012 at 10:39 PM, adarsh kumar algog...@gmail.com wrote: Sorry, its 6/6 and

Re: [algogeeks] C o/p

2012-07-08 Thread ashish jain
I think it should output: 9 9 On Sun, Jul 8, 2012 at 11:42 PM, md shaukat ali ali.mdshau...@gmail.comwrote: but i am confused in this problem... int a=10; int b; b=--a--; printf(%d %d,a,b);..what will output? On Sun, Jul 8, 2012 at 11:39 PM, md shaukat ali ali.mdshau...@gmail.comwrote:

Re: [algogeeks] C o/p

2012-07-08 Thread vindhya chhabra
.i think there will be an error in this -l value required, as post increment has more precedence than pre increment On Sun, Jul 8, 2012 at 11:44 PM, ashish jain ashishjainco...@gmail.comwrote: I think it should output: 9 9 On Sun, Jul 8, 2012 at 11:42 PM, md shaukat ali

Re: [algogeeks] C o/p

2012-07-08 Thread vindhya chhabra
int a=10; int b; b=--a--; printf(%d %d,a,b);. l value error in this ques.. On Sun, Jul 8, 2012 at 11:48 PM, vindhya chhabra vindhyachha...@gmail.comwrote: .i think there will be an error in this -l value required, as post increment has more precedence than pre increment On Sun, Jul 8, 2012

Re: [algogeeks] C o/p

2012-07-08 Thread atul anand
b=--a--; this will result into compiler error because 1st the post decrement will occur and value will be saved in a temp variable . but you cannot apply pre decrement on temp variable. On 7/8/12, vindhya chhabra vindhyachha...@gmail.com wrote: int a=10; int b; b=--a--; printf(%d %d,a,b);. l

Re: [algogeeks] C o/p

2012-07-08 Thread md shaukat ali
then atul what would be the output of this prob... int a=10; int b=a++*a--; prinf (%d,b); On Sun, Jul 8, 2012 at 11:52 PM, atul anand atul.87fri...@gmail.com wrote: b=--a--; this will result into compiler error because 1st the post decrement will occur and value will be saved in a temp variable

Re: [algogeeks] C o/p

2012-07-08 Thread atul anand
it violates sequence pt. rule..so output is compiler dependent , but as there is Lvalue error it would compile fine. but in prev case pre decrement expects Lvalue but has r-value instead bcoz of the post increment. On 7/9/12, md shaukat ali ali.mdshau...@gmail.com wrote: then atul what would

[algogeeks] Help woth LISP

2012-07-08 Thread Victor Manuel Grijalva Altamirano
The next solve the problem of eight Queeen... but i don't undestand it!!! can you explain me? (defun n-queens (n m) ( if (= n 1) (loop for x from 1 to m collect (list x)) (loop for sol in (n-queens (1- n) m) nconc (loop for col from 1 to m when (loop for row

Re: [algogeeks] C o/p

2012-07-08 Thread mitaksh gupta
the o/p will be 2 not 1 because of the post-increment operator. On Sun, Jul 8, 2012 at 10:23 PM, rahul sharma rahul23111...@gmail.comwrote: int i=5; i=++i/i++; print i; i=1 how? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Re: candies - interviewstreet -- how to go about solving this problem

2012-07-08 Thread sravanreddy001
Requires review and comments: My solution: find the continuous increasing sequences from the input followed by continues decreasing array. let there are k such array (continuous increase followed by continuous decrease) Now we have the trivial components. find sum for each such array.. and sum