Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Data Structures -- String -- Arrange Based On Repetition, String data structure
varalu
post Nov 13 2007, 10:40 AM
Post #1


Super Member
*********

Group: [HOSTED]
Posts: 346
Joined: 1-October 07
From: India
Member No.: 50,968
myCENT:55.24



Consider a string with any number of elements occurring any number of time.

Rearrange the string in such a way that the alphabet with most occurrence occurs in the followed by the next most occurring alphabet and so on... It should also be seen that the alphabets should occur frequency number of times.

Example:

Input : abcdaeghzabcdbhb
Output : bbbbaaaccddhhegz
Go to the top of the page
 
+Quote Post
fffanatics
post Nov 14 2007, 05:50 PM
Post #2


Privileged Member
*********

Group: [HOSTED]
Posts: 936
Joined: 14-April 05
From: West Chester, PA
Member No.: 5,636



First of all, why are you posting a problem and not a solution or tutorial on how to find the solution? Your current post is just stupid since it is hard to respond to and it just looks like you are trying to get credits in any possible way.

However, to solve this (since you did not say) is really easy. You can do it in O(n) and there are multiple ways to achieve this. The easiest method is O(n^2) or O(nlogn) depending on the sort method used. Since you know the size of the alphabet so you can initilize counts to zero. Then go through the string incrementing the letter's value by 1. Then just sort the list and print out the corresponding letter's and their counts.

To do this in O(n), you would have to be kinda of tricky with how you store and sort. What you would do is obtain a letter's value and concatenate that number of them to the correct part of the out string (which you would keep track of with another string of values or an array).
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Limiting Returned Data To Last X Fields With Sql(2)
  2. Data Structure Questions(4)
  3. Data Structures -- Binary Tree -- Mirror Image(0)
  4. Data Structures -- Linked List(13)
  5. Data Structures -- Binary Tree -- Structurally Same(4)
  6. Data Structures -- Linked List -- Reverse(5)
  7. Data Structures -- String -- Palindrome(5)
  8. Data Structures -- Linked List -- Point Of Merging(2)
  9. Data Structure -- Arrays -- Odd Number Of Elements(0)
  10. Data Structures -- Expression Trees(0)
  11. Data Structure -- Trees -- Threaded Binary Tree(0)
  12. Data Structure -- Queue -- Implement Using Stack(1)
  13. Data Structure -- Permutations(1)


 



- Lo-Fi Version Time is now: 1st December 2008 - 06:00 PM