[algogeeks] Re: Sort string based upon the count of characters

2011-01-13 Thread Davin
How we can preserve order of the string. When you sort the array, How you can track the specific count of character after the sort? On Jan 13, 12:46 pm, Bhavesh agrawal agr.bhav...@gmail.com wrote: we can also the concept of HASHING to count the frequency of each character . On

[algogeeks] Re: Sort string based upon the count of characters

2011-01-13 Thread juver++
@Davin. Please provide an example of output for this - cabbaacc -- 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] Re: Sort string based upon the count of characters

2011-01-13 Thread Davin
cab As 'c' and 'a' have same count but 'c' was before 'a' in the input string. On Jan 13, 1:39 pm, juver++ avpostni...@gmail.com wrote: @Davin. Please provide an example of output for this - cabbaacc -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Re: Sort string based upon the count of characters

2011-01-13 Thread juver++
@above, in order of the first occurence of the character -- 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] Re: Sort string based upon the count of characters

2011-01-13 Thread juver++
@Davin maintain count of each character, along with the first occurence of it in the string. then write your own comparator and run sort using it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-13 Thread Peyman
Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations. How about a circular doubly linked list for the push and pop, and then a priority queue for the min? -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-13 Thread juver++
@above What is the complexity of the pop_front() operation? -- 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] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-13 Thread Peyman
@above What is the complexity of the pop_front() operation? O(1) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-13 Thread juver++
@above Really? When one removes head then, min element should be updated. -- 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] Symmetric matrix

2011-01-13 Thread Azhar Hussain
I am wondering what data structure would best suit for this? - Azhar. On Wed, Jan 12, 2011 at 11:11 AM, Abdul Rahman Shariff ears7...@gmail.comwrote: i can tell 1 thing tht only (((n*n)-n)/2) +n elements are unique and the (((n*n)-n)/2) term is the one shoes the no of repeated elements and n

Re: [algogeeks] Symmetric matrix

2011-01-13 Thread juver++
One-dimensional array. 1 2 4 2 3 5 4 5 6 = [1, 2, 3, 4, 5, 6] Is your matrix summetric on a diagonal? -- 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

[algogeeks] Re: Sort string based upon the count of characters

2011-01-13 Thread Davin
@juver++ Thanks for hint. Problem solved. On Jan 13, 1:48 pm, juver++ avpostni...@gmail.com wrote: @Davin maintain count of each character, along with the first occurence of it in the string. then write your own comparator and run sort using it -- You received this message because you are

[algogeeks] [amazon] data transfer

2011-01-13 Thread snehal jain
there are two systems and transfer a data of 1TB. The hardware is best possible available. Tell the conditions which will optimize the data transfer. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] [amazon] data transfer

2011-01-13 Thread 周翔
can you explain more? are you mean ec2? 2011/1/13 snehal jain learner@gmail.com there are two systems and transfer a data of 1TB. The hardware is best possible available. Tell the conditions which will optimize the data transfer. -- You received this message because you are subscribed

Re: [algogeeks] Symmetric matrix

2011-01-13 Thread Azhar Hussain
Thanks for the help. It may not be symmetric on a diagonal. I have to consider both situations - Azhar. On Thu, Jan 13, 2011 at 3:37 PM, juver++ avpostni...@gmail.com wrote: One-dimensional array. 1 2 4 2 3 5 4 5 6 = [1, 2, 3, 4, 5, 6] Is your matrix summetric on a diagonal? -- You

[algogeeks] Re: Find The Looping Node

2011-01-13 Thread bittu
@snehal ..although ur approach ir good but u make d problem little complex,also missed out little checking, it can be done by using 2 pointers single while loop--Now Instruction(CPU) Matters. Rather then presenting different-2 algorithm i will present very famous algorithm Floyd’s Cycle-Finding

[algogeeks] Re: Amazon Analytical Puzzle

2011-01-13 Thread bittu
@dave how about this.. There are only 2 possible combinations when all labels are tagged incorrectly. All you need to do is pick one fruit from the one marked Apples + Oranges. If it's Apple, then change Apple + Orange to Apple The Apple one change to Orange The Orange one change to Apple +

Re: [algogeeks] Re: Find The Looping Node

2011-01-13 Thread snehal jain
@ above your code is only detecting loop.. my code is detecting loop and then removing loop as well On Thu, Jan 13, 2011 at 5:04 PM, bittu shashank7andr...@gmail.com wrote: @snehal ..although ur approach ir good but u make d problem little complex,also missed out little checking, it can be

[algogeeks] Adobe Question

2011-01-13 Thread bittu
1. 10 test cases for entering 3 values representing sides of a triangle and the program giving output as scalene, isosceles or equilateral--Means At Least 10 2 .Question on a program that calculates P=R/I where R, I are integer inputs and P a floating point output. Write 10 test

[algogeeks] Re: Sort string based upon the count of characters

2011-01-13 Thread ligerdave
use linked list. to improve the look up performance, use a binary tree to map the objects in the linked list On Jan 13, 1:23 am, Davin dkthar...@googlemail.com wrote: Smaple Data : input : abcdacdc Output : cadb If the count is same for  characters. maintain the original order of the

[algogeeks] Re: google paper/...plz help..its urgent

2011-01-13 Thread Lakhan Arya
Answer for question 6 maybe b) also for question 7 maybe b) On Jan 12, 2:14 pm, snehal jain learner@gmail.com wrote: 1. Quick-sort is run on two inputs shown below to sort in ascending order (i) 1,2,3, ….,n (ii) n, n - 1, n - 2, …., 2, 1 Let C1 and C2 be the number of comparisons made

[algogeeks] Re: amazon questions

2011-01-13 Thread Jammy
@snehal 1. Both are valid. 2. see taocp's sol. The probability of selecting AB to shoot is 1/3, so is BC,AC If AB were selected, the probability of hitting the target is (1- probability of both of them missed) = (1-(1-P(A)(1-P(B)), similar with case BC and AC. On Jan 11, 11:58 am, snehal jain

[algogeeks] Re: Sort string based upon the count of characters

2011-01-13 Thread Jammy
sort on two keys, primary key is frequency, secondary key is occurrence. using namespace std; struct Item{ int freq; int occur; char chr; Item(){ freq = 0; occur = -1; chr = -1;}; }; bool sortItem(const Item a, const Item b){ if(a.freq != 0 b.freq != 0){

[algogeeks] Coupon collector problem(Randomized algorithm problem)

2011-01-13 Thread suganya c
Hi all, Can someone help me to solve this randomized algorithm related puzzle? Let p(t) = Probability (atmost k copies of coupon1 are collected at time t) If p(t)= (1/2n), then prove that the expected time to get k+1 copies of all n coupons =2t. With regards, Sugi -- You received this

[algogeeks] Coupon collector problem(Randomized algorithm problem)

2011-01-13 Thread sugi
Hi all, Can someone help me to solve this randomized algorithm related puzzle? Let p(t) = Probability (atmost k copies of coupon1 are collected at time t) If p(t)= (1/2n), then prove that the expected time to get k+1 copies of all n coupons =2t. -- You received this message because you are

[algogeeks] Re: Symmetric matrix

2011-01-13 Thread Dan
You haven't provided enough information for anyone to give you any kind of reasonable answer. What language will you use to store manipulate the matrix? WHY do you wish to store the matrix? How BIG is the matrix that you anticipate storing? Do you need to store just one of them or several? What

Re: [algogeeks] Re: amazon c questn

2011-01-13 Thread Algoose chase
Apart from that , In Unicode application each char would be 2 bytes in length and its always advisable to use malloc(sizeof(char) * 25) which seamlessly works fine in ASCII application as well. On Wed, Jan 12, 2011 at 7:20 AM, Kiran K kira...@gmail.com wrote: p= (char*)malloc(25); KK: p

Re: [algogeeks] Re: [Athena 2011]

2011-01-13 Thread Terence
No need for calculating individual magic(x), just count the number of ordered list L with max(L)=11. Partition those ordered list by its gcd, and check each part, then you can see the trick. On 2011-1-13 11:06, Pratik Bhadkoliya wrote: For example, for 1: divisor is only 1

Re: [algogeeks] Modular Arithmetic

2011-01-13 Thread Nikhil Jindal
(a/b)mod m = (amodm)*(Bmodm) where B is the multiplicative inverse of b i.e (b*B)modM = 1 or B = 1/b Look into the wiki page of Multiplicative inverse for more. Hope this helps Cheers Nikhil Jindal On Wed, Jan 12, 2011 at 7:06 AM, mittal mohitm.1...@gmail.com wrote: Somehelp with (a/b)modm

[algogeeks] Randomized Algorithm puzzle(coupon collector problem)

2011-01-13 Thread suganya c
*Hi all,* *Can someone help me to solve this randomized algorithm related puzzle?* * * *Let p(t) = Probability (atmost k copies of coupon1 are collected at **time t)* *If p(t)= (1/2n), then prove that the expected time to get k+1 copies **of all n coupons =2t.* -- You received this message

Re: [algogeeks] Symmetric matrix

2011-01-13 Thread Sathaiah Dontula
1 + 2 + + n ( max diagonal) = n ( n + 1) / 2. Max elements you can store is n ( n + 1) / 2 . You can take an array of size n (n + 1) / 2 and store them. Thanks, Sathaiah On Wed, Jan 12, 2011 at 9:50 AM, Azhar Hussain azhar...@gmail.com wrote: I have a symmetric matrix. I am wondering what

Re: [algogeeks] Symmetric matrix

2011-01-13 Thread Umer Farooq
Well, u can use List of Lists. The List would contain head nodes of all the lists and each list would contain a row. The length of every list will be 1 greater than the next of it's next list. In this way: The tail of list would contain a diagonal element which L L1 1 L2 4 2 L3 4 3

Re: [algogeeks] Re: Modular Arithmetic

2011-01-13 Thread Nikhil Jindal
On Thu, Jan 13, 2011 at 12:06 AM, Aviral Gupta aviral@gmail.com wrote: we can do it when hcf(b,m)=1 , in that case find inverse of b by extended euclidean mod m and then multiply it by a Yes. And when m is prime, B(mulitplicative inverse of b) = b^(m-2) As b^(m-1)mod m = 1 if m is prime.

Re: [algogeeks] Re: Amazon Analytical Puzzle

2011-01-13 Thread Nikhil Jindal
Cut each slice into 8 equal pieces. Total 24 pieces. One part consists of 3 pieces. Total 8 parts. On Wed, Jan 12, 2011 at 6:14 PM, bittu shashank7andr...@gmail.com wrote: 2nd puzzle You have a birthday cake and have exactly 3 slices to cut it into 8 equal pieces. How do you do it? Thanks

Re: [algogeeks] SPOJ PROBLEM-pour1

2011-01-13 Thread Terence
No BFS, only mathematics. Get the better one out of the 2 choices. (Maybe simulating each of the 2 choices also fits into the time limit, given the input range in the problem page.). On 2011-1-12 9:28, Bharath 2009503507 CSE wrote: i tried solving this prob...

Re: [algogeeks] Re: Amazon Analytical Puzzle

2011-01-13 Thread rahul rai
A similar question http://ocw.mit.edu/courses/mathematics/18-s34-problem-solving-seminar-fall-2007/18.s34-problem-solving-seminar-fall-2007-home-page-answer/ On 1/12/11, vaibhav shukla vaibhav200...@gmail.com wrote: @Dave: gud one :) On Wed, Jan 12, 2011 at 7:48 PM, Dave

[algogeeks] Re: palindrome

2011-01-13 Thread Jammy
if you meant starting the leftmost 1, to check if its palindrome: unsigned int o = v; unsigned int r; for (r = 0; v; v = 1) { r = 1; r |= v 1; } if (o == r) printf(palindrome\n); else

Re: [algogeeks] Re: amazon c questn

2011-01-13 Thread 周翔
what is the wrong in the program? main() { char *p,*q; p=(char *)malloc(25); // check p==null q=(char *)malloc(25);//check q == null strcpy(p,amazon); strcpy(q,hyd); strcat(p,q); printf(%sp); } -- You received this message because you are subscribed to the Google

[algogeeks] Re: No. of ways to Merge 2 arrays

2011-01-13 Thread Gene
The number of ways that n things can be positioned within 2n things is 2n choose n. This is equal to (2n!) / (n!)^2. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To

[algogeeks] Re: No. of ways to Merge 2 arrays

2011-01-13 Thread Gene
Sorry I just noticed that Dave got it, too. -- 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.

[algogeeks] Building A Special Tree

2011-01-13 Thread Decipher
A special type of tree is given, where all leaf are marked with L and others are marked with N. every node can have 0 or at most 2 nodes. Trees preorder traversal is given give a algorithm to build tree from this traversal. -- You received this message because you are subscribed to the

Re: [algogeeks] Re: amazon c questn

2011-01-13 Thread juver++
@Harish You are wrong. It doesn't matter when it is Unicode or ASCII application. Size of the char type is ALWAYS 1 byte. To use unicode characters introduce wchar_t or something related. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] probability

2011-01-13 Thread snehal jain
An unbalanced dice (with 6 faces, numbered from 1 to 6) is thrown. The probability that the face value is odd is 90% of the probability that the face value is even. The probability of getting any even numbered face is the same. If the probability that the face is even given that it is greater than