[algogeeks] Re: Finding total number of inversions in an array in O(nlogn) complexity .

2011-06-14 Thread KK
This code is not getting AC on spoj.. m not able to point out the error plzzz help. Here is the link to this problem at spoj : http://www.spoj.pl/problems/INVCNT/ #include #include #include #include using namespace std; void MergeSort(vector &v, int p, int r); void Merge(vector &v, int p, in

Re: [algogeeks] Re: MS Question

2011-06-14 Thread sunny agrawal
Nice Confusion... :) Consider the following case A[M] = {1,1,3,12}; B[N] = {1,2,12} here again i think answer should be {1,1,12} , why are u binding one occurrence of 1 in array A with one in B. Question is which elements of first array is present in second array. so for this case A[0], A[1], A[

Re: [algogeeks] output

2011-06-14 Thread Vishal Thanki
@ Harshal, you are absolutely right. Again, this kind of code is highly discouraged when used in real life projects. And there is no need to go into details of how to evaluate such expressions, which are not complying to standards. On Wed, Jun 15, 2011 at 10:49 AM, Harshal wrote: > Google sequenc

Re: [algogeeks] Java Developer Needed in PA -- F2F required -- Rate: $45/hr on C2C

2011-06-14 Thread Harshal
moderators, please ban leon.pan...@gmail.com On Wed, Jun 15, 2011 at 1:00 AM, Leon Parker wrote: > Hello Associate, > > Please go through the below requirement and let me know if you have any > consultants for the below position. > > Job Title: Java Developer > Location: Pittsburgh, PA > Duratio

Re: [algogeeks] output

2011-06-14 Thread Harshal
Google sequence points. The C Standard states that between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. So, expressions like i++ + ++i can produces different results on different compilers. Its not a standard ex

Re: [algogeeks] Re: FOR ALL INDIANS PLZ READ IT

2011-06-14 Thread Naveen Kumar
Hi Sharad, Just see the active members in the recent past and those who have done the maximum post recently. And add that to the moderator list. We don't want many moderators here 2 active ones will do it. I think one of them can be dave don't know his id. On Wed, Jun 15, 2011 at 10:28 AM, Akshay

[algogeeks] Re: HASHIT

2011-06-14 Thread rahul
You can check the modified code at http://ideone.com/7NFTd and got AC at spoj Thanks Rahul Singal Computer Science Department BITS PILANI -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegr

Re: [algogeeks] Re: FOR ALL INDIANS PLZ READ IT

2011-06-14 Thread Akshay Rastogi
Vas happening forum ?? On Mon, Jun 13, 2011 at 5:59 PM, Umer Farooq wrote: > +1 > > I really like this group ... but sometimes people get rude and > show prejudice attitude towards me. I hope the admin takes notice of one of > the comment posted above :) > > > On Mon, Jun 13, 2011 at 12:30 AM, D

Re: [algogeeks] Re: Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread Akshay Rastogi
@t3rminal: k On Wed, Jun 15, 2011 at 7:05 AM, Terence wrote: > Traversal the suffix tree is enough. > All substrings from root to leaf (including at least 1 character of leaf > node) occur only once. > Choose the shortest among them. > > > > On 2011-6-15 5:28, T3rminal wrote: > >> @bittu >> How

[algogeeks] output

2011-06-14 Thread Bhavesh agrawal
int a,c=5; a=c++ + ++c + c++ + ++c; printf("%d\n",a); c=5; a=c++ + ++c + c++; printf("%d\n",a); c=5; a=++c + ++c; printf("%d\n",a); c=5; a=++c + ++c + ++c; printf("%d\n",a); compiled with gcc and the outputs are 25 18 14 22 can anyone plz explain these outputs -- You received this message becau

RE: [algogeeks] Swapping two variables without using a temporary variable

2011-06-14 Thread umesh kewat
Adding two huge no will cross the integer or what's its range will fall under overflow categories same case goes to negative which fall under underflow .. In both the case numbers will change.. For example no range is -10 to 10 so if x =5 and y=7 then addition will produce the result -9 so u can

[algogeeks] Re: a doubt..

2011-06-14 Thread Dan
On Jun 13, 11:43 am, snehi jain wrote: > hi, > we try to implement many programs using Recursion > and its said that this is better than iterative procedure. > > if i am right then > i cant understand why is it so? >  can anybody explain ... > and are there situations when iterative procedure is

Re: [algogeeks] Re: Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread Terence
Traversal the suffix tree is enough. All substrings from root to leaf (including at least 1 character of leaf node) occur only once. Choose the shortest among them. On 2011-6-15 5:28, T3rminal wrote: @bittu How can u find the shortest substring from the tree in 0(n). Can u please elaborate a

Re: [algogeeks] Re: remove duplicate chars in a string without using extra memory

2011-06-14 Thread Kamakshii Aggarwal
@akash:can u please explain your code...? On Mon, Jun 13, 2011 at 2:27 AM, Divye Kapoor wrote: > No extra memory except input buffer: O(n log n) time O(n) space (can't do > better than this). > > https://github.com/swagatata/ds_and_algos/blob/master/cpp/trivia/remove_duplicates_without_extra_mem

Re: [algogeeks] Puzzles....NOT Spam

2011-06-14 Thread Kamakshii Aggarwal
I am not able to logincan u help me... On Mon, Jun 13, 2011 at 12:17 AM, ADITYA KUMAR wrote: > http://www.freepuzzles.com > > This is the best site for quality puzzles, > But solutions are not given... > so i request members ,try to solve these puzzles and post their solutions > to this thre

Re: [algogeeks] Re: FOR ALL INDIANS PLZ READ IT

2011-06-14 Thread Umer Farooq
+1 I really like this group ... but sometimes people get rude and show prejudice attitude towards me. I hope the admin takes notice of one of the comment posted above :) On Mon, Jun 13, 2011 at 12:30 AM, Divye Kapoor wrote: > While you're on this - could we have a policy that the first time > so

Re: [algogeeks] Re: FOR ALL INDIANS PLZ READ IT

2011-06-14 Thread Umer Farooq
Hi buddy, nominate me as a group member my id is: the.um...@gmail.com On Mon, Jun 13, 2011 at 12:03 AM, shady wrote: > Vishwakarma deok...@gmail.com > Arpit Sood soodfi...@gmail.com > > @kartik could have given your name had you read the post carefully. > > > Shady. > > > On Mon, Jun 13, 2011

Re: [algogeeks] Swapping two variables without using a temporary variable

2011-06-14 Thread Lego Haryanto
Have you tested your claim regarding overflow/underflow and proved it is indeed a problem, or you just thought that it won't work? Using two's complement, it should still work. On Friday, June 10, 2011, Wladimir Tavares wrote: > Swapping two variables without using a temporary variable using the

[algogeeks] Re: Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread T3rminal
@bittu How can u find the shortest substring from the tree in 0(n). Can u please elaborate a bit ? On Jun 14, 6:03 pm, bittu wrote: > I found one interesting question > > Given a string s , return the shortest substring that is > only occurring once. > Examples: > s="aabbabbaab" gives either "bab

[algogeeks] Re: Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread T3rminal
@Akshay Suffix tree construction is O(n) On Jun 14, 8:58 pm, Akshay Rastogi wrote: > But generating a suffix tree itself is O(n2) . > > On Tue, Jun 14, 2011 at 7:54 PM, sunny agrawal wrote: > > > > > > > > > > > it must be any general string > > Suffix tree approach seems best both in time and spa

Re: [algogeeks] [brain teaser ] Probability Riddle Loaded Revolver 13 june

2011-06-14 Thread Anika Jain
henry will give the answer that will favour to save him.. so if rotated then probab. of getting safe is 2/3=0.666 and if not rotated then probab. of getting safe is 3/4=0.75 so its better to not to rotate.. On Tue, Jun 14, 2011 at 12:36 AM, Arpit Sood wrote: > +1 to Kunal's post > > i think if y

Re: [algogeeks] Re: MS Question

2011-06-14 Thread Arpit Sood
i meant if N = { 1, 1, 1, 2, 12} and M = { 1, 1, 3, 12} then answer should be = {1, 1, 12} On Mon, Jun 13, 2011 at 8:06 PM, sunny agrawal wrote: > no we can take care of duplicates without any extra memory > modify 2nd step of my previous solution as follows > > if T[a[i]] is set then this eleme

[algogeeks] Java Developer Needed in PA -- F2F required -- Rate: $45/hr on C2C

2011-06-14 Thread Leon Parker
Hello Associate, Please go through the below requirement and let me know if you have any consultants for the below position. Job Title: Java Developer Location: Pittsburgh, PA Duration: 2-3 Months Rate: $45/hour C2C Description: The candidate should be well versed with the following technologie

[algogeeks] Re: MS Question

2011-06-14 Thread Dumanshu
@Sunny: what if the number is repeated multiple times? u seem to consider only the duplicates(2 times). On Jun 13, 7:36 pm, sunny agrawal wrote: > no we can take care of duplicates without any extra memory > modify 2nd step of my previous solution as follows > > if T[a[i]] is set then this elemen

Re: [algogeeks] Swapping two variables without using a temporary variable

2011-06-14 Thread tech rascal
@sunny... yeah sorry, m stupid..:) thanx On Tue, Jun 14, 2011 at 10:52 AM, sunny agrawal wrote: > @tech rascal > > 10 = 01010 > 20 = 10100 > -- > xor = 0 > = 30 > why r u getting 1 ?? > > > On Tue, Jun 14, 2011 at 2:28 AM, Supraja Jayakumar < > suprajasank...@gmail.com> wrote:

[algogeeks] Re: spoj NKTM

2011-06-14 Thread kartik sachan
case like 5 1 2 3 45 got worng 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 mor

[algogeeks] Re: spoj NKTM

2011-06-14 Thread kartik sachan
got AC silliy mistake i am sorting array only one 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+uns

Re: [algogeeks] help

2011-06-14 Thread snehi jain
first it checks Q if that is NOT true then it computes R else it doesn't. this is the correct line . On Tue, Jun 14, 2011 at 10:21 PM, snehi jain wrote: > that is what is happening here > m = ++i || (++j && ++k); > > in C if P = Q || R; > > first it checks Q if that is NOT true then it com

Re: [algogeeks] help

2011-06-14 Thread snehi jain
that is what is happening here m = ++i || (++j && ++k); in C if P = Q || R; first it checks Q if that is NOT true then it computes C else it doesn't. ++ is a unary operator so before the || and && operations can happen increment will take place. This justifies the higher precedence of ++ o

[algogeeks] spoj NKTM

2011-06-14 Thread kartik sachan
https://www.spoj.pl/problems/NTKM/ my code is : # include # include # include using namespace std; int main() { long long int n; while(1) { long long int a[1]={0},i; if(scanf("%lld",&n)==EOF) break; for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] help

2011-06-14 Thread nicks
hmm...someone explain...me too confused :( On Tue, Jun 14, 2011 at 9:14 AM, rahul dixit wrote: > > bt increment operator has the higher precedence than || and && > so all the variables should be incremented first then && and then || > should be evaluated > then how it is happening.plz explain >

Re: [algogeeks] help

2011-06-14 Thread rahul dixit
bt increment operator has the higher precedence than || and && so all the variables should be incremented first then && and then || should be evaluated then how it is happening.plz explain rahul dixit Du-Mca -- You received this message because you are subscribed to the Google Groups "Algori

Re: [algogeeks] help

2011-06-14 Thread snehi jain
according to precedence m= ++i || ++j && ++k will become m = ++i || (++j && ++k);NOT this m = (++i || ++j) && ++k; first i gets incremented and since that gives a non-zero value the rest of the statement is not executed. On Tue, Jun 14, 2011 at 8:41 PM, nicks wrote: > anybody

Re: [algogeeks] Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread Akshay Rastogi
But generating a suffix tree itself is O(n2) . On Tue, Jun 14, 2011 at 7:54 PM, sunny agrawal wrote: > it must be any general string > Suffix tree approach seems best both in time and space complexity > > > > > On Tue, Jun 14, 2011 at 7:36 PM, Navneet Gupta wrote: > >> This looks like a good pro

Re: [algogeeks] Re: is it correct??

2011-06-14 Thread • » νιρυℓ « •
Its not a standard, it is one of the gcc extension i.e variable length arrays. Memory allocation is done dynamically from stack in such case. On Tue, Jun 14, 2011 at 8:27 PM, kartik sachan wrote: > it is correct ...in c++ 4.3.2 compiler > > -- > You received this message because you are subs

[algogeeks] Re: Intuitive Understanding of XOR Operation

2011-06-14 Thread Don
It is important to remember that xor is a bitwise operator, so x ^= y affects the individual bits of x based on the bits in y. Think of xor as a bitwise not-equal operator. The expression a = x ^ y Will set the bits of "a" to true if the corresponding bits of "x" and "y" are not equal. Thus the

Re: [algogeeks] help

2011-06-14 Thread nicks
anybody having idea about preference order ?? On Tue, Jun 14, 2011 at 4:20 AM, nicks wrote: > What about precedence order then. > http://www.difranco.net/cop2220/op-prec.htm i mean acc. to precedence > order && should be evaluated before || in the second exampleresult > should be k=1,j=3

Re: [algogeeks] Re: is it correct??

2011-06-14 Thread kartik sachan
it is correct ...in c++ 4.3.2 compiler -- 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] Re: is it correct??

2011-06-14 Thread amit kumar
but such a declaration is working correctly in g++ On Tue, Jun 14, 2011 at 8:22 PM, Don wrote: > One line or the other is not correct. The size of an array must be a > constant, and you can't read into a const. > If you want to do something like this, use malloc: > > cin >> x; > int *a = (int *)

[algogeeks] Re: is it correct??

2011-06-14 Thread Don
One line or the other is not correct. The size of an array must be a constant, and you can't read into a const. If you want to do something like this, use malloc: cin >> x; int *a = (int *)malloc(x*sizeof(int)); You can now use "a" as if it is an array of size x. Be sure to free the memory before

Re: [algogeeks] is it correct??

2011-06-14 Thread prateek gupta
no the no of elements in an array should be known to compiler before execution of the program. On Tue, Jun 14, 2011 at 8:09 PM, amit wrote: > is such a declaration correct: > cin>>x; > int a[x]; > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geek

[algogeeks] is it correct??

2011-06-14 Thread amit
is such a declaration correct: cin>>x; int a[x]; -- 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...@googlegroup

Re: [algogeeks] Interview Question: Puzzle: Probability

2011-06-14 Thread Navneet Gupta
Put one red ball in one jar and rest 99 balls in other jar. Probability in that case is 1/2*1 + 1/2*49//99 On Tue, Jun 14, 2011 at 7:45 PM, Vishal Jain wrote: > Folks, > > This question was asked during a screening process of a product based > company. Please answer. > > http://exploreriddles.b

Re: [algogeeks] Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread sunny agrawal
it must be any general string Suffix tree approach seems best both in time and space complexity On Tue, Jun 14, 2011 at 7:36 PM, Navneet Gupta wrote: > This looks like a good problem. Could you confirm if string contains only > two characters as you mentioned in both examples or it is a general

Re: [algogeeks] Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread Navneet Gupta
This looks like a good problem. Could you confirm if string contains only two characters as you mentioned in both examples or it is a general string with any characters. On Tue, Jun 14, 2011 at 6:33 PM, bittu wrote: > I found one interesting question > > Given a string s , return the shortest su

[algogeeks] Interview Question: Puzzle: Probability

2011-06-14 Thread Vishal Jain
Folks, This question was asked during a screening process of a product based company. Please answer. http://exploreriddles.blogspot.com/2011/06/interview-questions-puzzle.html Thanks & Regards Vishal Jain Success taste better when target achieved is bigger. P *We have a responsibility to the en

Re: [algogeeks] Re: MS Question

2011-06-14 Thread Divye Kapoor
Good one! That halved the memory requirement. :) -- 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/-/N6mbMaJHO64J. To post to this group, send email to algogeek

[algogeeks] Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread bittu
I found one interesting question Given a string s , return the shortest substring that is only occurring once. Examples: s="aabbabbaab" gives either "bab" or "baa" s="" gives "" My Approaches Generate All Possible SubStrings O(N^2) puts all substrings into hashtable & keep incrementing c

Re: [algogeeks] Finding shortest path in 4-ary tree

2011-06-14 Thread Raghavan
Ok lemme add some more details to it. See it is a kind of n-ary tree having n=4 and each pointer is represented as left, right,top and bottom compare it to the four directions. So the shortest path starting from the root node to the leaf node where the val = 1000, taken into consideration there

[algogeeks] Re: Finding shortest path in 4-ary tree

2011-06-14 Thread L
Any graph algorithm would work. If val is positive then use Dijkstra's algorithm, otherwise use Bellman Ford. On Jun 14, 5:07 pm, Raghavan wrote: > Hi, >    How to find the shortest path in a 4-ary tree in an optimal way? > > Node tree{ > Node *left,*right,*top,*bottom; > int val; > > }; > > Let

Re: [algogeeks] Finding shortest path in 4-ary tree

2011-06-14 Thread vaibhav agarwal
What actually is meant by bottom pointer On Tue, Jun 14, 2011 at 5:57 PM, sunny agrawal wrote: > Did you mean Shortest path from one node to another > Use BFS i think we can find the shortest path > > > > On Tue, Jun 14, 2011 at 5:37 PM, Raghavan wrote: > >> Hi, >>How to find the shortest pa

Re: [algogeeks] Finding shortest path in 4-ary tree

2011-06-14 Thread sunny agrawal
same as left right or top u can consider as each node as a cell of grid type of thing for easy understanding On Tue, Jun 14, 2011 at 5:59 PM, vaibhav agarwal wrote: > What actually is meant by bottom pointer > > > On Tue, Jun 14, 2011 at 5:57 PM, sunny agrawal wrote: > >> Did you mean Shortest p

[algogeeks] Re: Finding shortest path in 4-ary tree

2011-06-14 Thread L
Sorry, i confused val with weight of the edge. BFS would be a better option. On Jun 14, 5:31 pm, L wrote: > Any graph algorithm would work. > If val is positive then use Dijkstra's algorithm, otherwise use > Bellman Ford. > > On Jun 14, 5:07 pm, Raghavan wrote: > > > > > > > > > Hi, > >    How t

Re: [algogeeks] Finding shortest path in 4-ary tree

2011-06-14 Thread sunny agrawal
Did you mean Shortest path from one node to another Use BFS i think we can find the shortest path On Tue, Jun 14, 2011 at 5:37 PM, Raghavan wrote: > Hi, >How to find the shortest path in a 4-ary tree in an optimal way? > > Node tree{ > Node *left,*right,*top,*bottom; > int val; > }; > > Let

[algogeeks] Finding shortest path in 4-ary tree

2011-06-14 Thread Raghavan
Hi, How to find the shortest path in a 4-ary tree in an optimal way? Node tree{ Node *left,*right,*top,*bottom; int val; }; Let the above given be the tree structure. -- Thanks and regards, Raghavan.K.L -- You received this message because you are sub

Re: [algogeeks] [brain teaser ] Sign Puzzle

2011-06-14 Thread shady
it means that time has come for you to get banned. Very bad puzzle. Oh, sorry, it was a joke. On Tue, Jun 14, 2011 at 12:39 PM, Lavesh Rawat wrote: > *Sign Puzzle - 14 june > * > * > * > *As the school year was progressing, a teacher was distressed that more > and more of her students were begi

[algogeeks] Suffix Trees Discussion

2011-06-14 Thread Divye Kapoor
Hey Supraja, Just a request, since this is a high volume mailing list, you should make your subject very informative. "Hi" isn't very descriptive you know. :) I'm changing the subject to "Suffix Trees Discussion" and reposting your question. Hope people are more interested in following the thr

[algogeeks] Hi

2011-06-14 Thread Supraja Jayakumar
Hi All I tried going through the code here for constructing suffix tires - http://marknelson.us/1996/08/01/suffix-trees/ But I am not sure I get it well. If its ok, can we discuss this implementation. Thanks Supraja J -- U -- You received this message because you are subscribed to the Google

Re: [algogeeks] help

2011-06-14 Thread nicks
What about precedence order then. http://www.difranco.net/cop2220/op-prec.htm i mean acc. to precedence order && should be evaluated before || in the second exampleresult should be k=1,j=3 and i= -2 On Mon, Jun 13, 2011 at 11:41 AM, udit sharma wrote: > hmm. Sry yr... Got it.. Thanx.. :)

Re: [algogeeks] [brain teaser ] Sign Puzzle

2011-06-14 Thread nicks
I LIKE YOU LIKE YOU ARE On Tue, Jun 14, 2011 at 12:09 AM, Lavesh Rawat wrote: > *Sign Puzzle - 14 june > * > * > * > *As the school year was progressing, a teacher was distressed that more > and more of her students were beginning to tease and make fun of one > another. She decided to do someth

[algogeeks] MS

2011-06-14 Thread Akshata Sharma
Design an elevator system for a 100 story building. Address all issues, like number of elevators, speed of each (Not numerically), waiting times etc. There would be 100-200 people living/working on each floor. (You don't need to discuss the traffic patterns.) -- You received this message because

[algogeeks] [brain teaser ] Sign Puzzle

2011-06-14 Thread Lavesh Rawat
*Sign Puzzle - 14 june * * * *As the school year was progressing, a teacher was distressed that more and more of her students were beginning to tease and make fun of one another. She decided to do something about it. When they returned to the classroom after Spring Break, they saw a mirror on the