codez
BAN USER 0of 0 votes
AnswerHi all,
 codez in United States
can anyone tell some methods & related brief for sorting the strings lexicographically ,
i just have implemented using quick sort.....
i want to learn abt hashing nd TRIE......bt still nt able to get.....how to sort using these methods Report Duplicate  Flag  PURGE
Algorithm  0of 0 votes
AnswersIs there any alternative in c++/c to pass array to a function by value apart from cloning so that no change is reflected?
 codez in United States Report Duplicate  Flag  PURGE
Arrays
take an array a[26][26]=0;
taking the eg:
abbababcd
tring len=n;
size[0n]=0;
for(int i=1;i<strlen();i++)
{ if(s[i1]+1=s[i])
{
size[i]=size[i1]+1;
a[s[i]size[i]'a'][size[i]]++;
}}
for(i=0;i<26;i++)
{ for(j=0;j<26;j++)
{ if(a[i][j]!=0)
{
cout<<"sequence from start= "<<i+'0'<<" to end= "<<i+j+'0'<<" no. of times= "<<a[i][j]<<"\n";
}
}
}

codez
July 04, 2012 for both stack s1,s2
pop elements of s1 first
maintain a separate negativesum and a positivesum(sum of negative & positive no.s respectively);
lets say they r ns1 & ps1
similarly for s2
find ns2,ps2
now
if(ns1==ns2) { if(ps2>ps1) missingno=ps2ps1;
else missingno=ps1ps2;
}
else if(ps1==ps2) { if(ns2>ns1) missingno=ns2ns1;
else missingno=ns1ns2;
}

codez
July 04, 2012 queue s1;
s1.push(root);
while(!s1.empty())
{
node q=s1.front();
if(q is a leaf) print q; pop s1;
else if(left child of q explored && q>right!=NULL)
{
print q; push(q>right);
pop s1;
}
else if( q>left is explored && !q>right)
{
print q; pop s1;
}
else
push(q>left);
}

codez
July 04, 2012 hey i used approach similar to this:
max_start=0; max_end =0; maxv = 0; sum 0;
for i in range(arr):
sum+= arr[i];
if sum<0:
sum=0; max_start =i;
if maxv<sum:
maxv=sum; max_end = i;
#seocnd pass
for i in range(max_start):
sum+= arr[i];
if sum<0:
break;
if maxv<sum:
maxv=sum;max_end = i;
but dint find it much efficient for a case like this
8 8 9 9 10 11 12 14
can u plz dry run on the above data set ur algo
Thnx!
@shondik
Are u sure u r correct?
if yes then plz point out my mistake.in case of fundamental data types the alignment remains the same as size while in case of user defined,alignment is on the basis of the largest element of the struct which here is int(4 byte) so 4+4=8 should be correct
I have implementd the code ,o/p is 8(for 64 bit sys).
using a stack,push each of the non leaf nodes at each level frst like
push(12)
push(4)
push(8)
push(22)
when no more of level 1 child left , repeating the process for the stack top and
in case a leaf encountered print elements from stack[0] to stack[top] then the leaf node
so print(18)
print(24)
now no more of child node(22) left so pop it
repeat the same process for node(8),then node(4)
yes it is a right way.Also we can have each node in the trie such that they contain the position last matched number from the sequence and the subsequent nodes can either contain the position in the parent node or a next position depending on whether at that node we dont find the matching number of the required sequence or we do find matching number
 codez June 30, 2012Open Chat in New Window
@^ bt my algo doesnt work for strings like "aaad"
 codez October 05, 2012