Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

logic - How to find Suffix array and prefix array of a given Array?

Given an array such as [4,1,3,2], I need to find the prefix array and suffix array of the given array.

For example prefix array of [4,1,3,2] is [4] and suffix array is [1,3,2]. and for array [10,20,30,40] prefix array is [] and suffix array is [10,20,30,40].

I tried a logic for prefix array which is like this:-

//given array is [4,1,3,2]
ArrayList<Integer> prefix=new ArrayList<>();
int i=0;

while(array[i]>array[i+1]){
prefix.add(array[i]);
}
//after making prefix the rest will be suffix array

and Rest which remain will be suffix array. This logic is corrected for above two arrays but not satisfied many others such as when array is [20,69,4,83,23,100,63,50,85,80,53,40,44,1] then prefix is whole given array and suffix array is empty array.

I am unable to get the logic for getting prefix and suffix array, any suggestions?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...