janashilpa
BAN USERA..Z = 26
AA...ZZ= 26^2
AAA...ZZZ=26^3
So divide 2842 with 26 you get reminder 8. If 1 is A, 2 is B then 8 is H.
quotient is 109 divide it with 26 reminder is 5. Hence 5 is E
quotient is 4 from above. so divide it with 26 so reminder is 4. Hence 4 is D
so you get DEH.
I got this idea from our regular binary bit structure. Think in those lines then you will get what i did.
Why not to just write a simple AVL tree code which takes care of balancing with every node insertion. No extra space. No arrays. No length checking. No need of finding middle which becomes tricky when length of list is even.
- janashilpa October 01, 2010Cant we have ptr1 as 1st pointer and ptr2 as second. both char ptrs. then start a for loop from 0 to 2. see where ptr1 matches ptr2. i is the byte.
- janashilpa September 18, 2010I dont think its garbage collection coz we have defined empty and filled memory slots. Its more like how would you manage memory. There are two ways paging and segmentation. For implementation sake you can use array and write a code.
- janashilpa September 18, 2010
When you read each word put it in the list. The list will be in descending order coz higher freq means such words will be more. so to reduce searches of higher freq the linked list is in descending order of freq.
- janashilpa October 04, 2010case 1: word is not in list then you will go to the end of list. so add the word in the end with freq =1
case 2: word in the list. If the freq of the word is 2 then it will become 3 only ie 2+1. So keep a pointer at the last node with freq 4. Search through all words with freq 3. As the word is not there change to ptr to last word with freq 3. Then search words with freq 2. You get the word then delete it from there and add it at the end of ptr pointing to last of freq 3.
You have your O(n) solution :) Please comment.