@akshata.. The algorithm for which u have expected a runtime of O(n^2)
i think it still runs only for 26 * n.. and. for a large values of n.. its
O(n)
here's the logic.. but also look how it works.
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++){
{
}
}
this runs for n^2
for each character ch of 26 alphabet {
found = false;
for(i=0:i<n;i++)
if(str[i] == ch)
found = true;
if(found){
for each ch after found in str.. update it to 1;
}
}
finally.. while printing.. print every character in the str.. except the
'1''s
-- the inner for loop is expected to run for O(n) time.. and outer loop runs
for 26 times.. fixing each alphabet every time..
so.. O(n)..
any other inputs??
{i didn't find the other thread where it's posted.. if some one finds it..
please post it there...
--
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/-/P1rUR_Z8Bw8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.