-
Couldn't load subscription status.
- Fork 162
Suffix Array #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Suffix Array #243
Changes from all commits
1eb6038
dd3b439
5c4fe0d
b8f7184
d96682d
e376f12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include<bits/stdc++.h> | ||
| using namespace std; | ||
|
|
||
| void Suff_Arr(string s) | ||
| { | ||
| map<string,int> m; | ||
|
|
||
| vector<string> v; | ||
| for(int i = 0; i < s.size();i++) | ||
| { | ||
| m[s.substr(i,s.size()-i)] = i; | ||
| v.push_back(s.substr(i,s.size()-i)); | ||
| } | ||
| sort(v.begin(),v.end()); | ||
| for(int i = 0; i < v.size();i++) | ||
| { | ||
| cout << m[v[i]] <<" "; | ||
| } | ||
| cout<<"\n"; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| string s; | ||
| cin >> s; | ||
| Suff_Arr(s); | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| This is the code to build suffix array for any given string input. | ||
|
|
||
| Suffix Array:- | ||
| A suffix array for a given string is basically a sorted array of all suffixes of a string. | ||
|
|
||
| For example:- | ||
|
|
||
| Given the string is "banana" | ||
|
|
||
| The suffixes are:- | ||
|
|
||
| 0 banana 5 a | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this part more look good. Like codify this part to make it look good. Otherwise this part looks odd |
||
| 1 anana sorted 3 ana | ||
| 2 nana --------------> 1 anana | ||
| 3 ana alpabetically 0 banana | ||
| 4 na 4 na | ||
| 5 a 2 nana | ||
|
|
||
| So, the suffix array for the string "banana" will be [5,3,1,0,4,2] | ||
|
|
||
| Application of suffix array:- | ||
|
|
||
| Suffix array is an extremely useful data structure, it can be used for a wide range of problems. Following are some famous problems where Suffix array can be used. | ||
| 1) Pattern Searching | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use * instead of numbering |
||
| 2) Finding the longest repeated substring | ||
| 3) Finding the longest common substring | ||
| 4) Finding the longest palindrome in a string | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments here will make it better