Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Quearn

Quearn Logo Quearn Logo

Quearn Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Quearn Academy
  • About Us
  • Blog
  • Contact Us
Home/Questions/Q 803880
Next
In Process
codemania
  • 0
codemania
Asked: May 27, 20232023-05-27T09:24:55+00:00 2023-05-27T09:24:55+00:00In: Education

Java Program to Implement Suffix Array

  • 0
Java Program to Implement Suffix Array
codejava
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    1. codemania
      2023-05-27T09:25:05+00:00Added an answer on May 27, 2023 at 9:25 am
      This Java program is to Implement Suffix arrayIn computer science, a suffix array is a sorted array of all suffixes of a string. It is a simple, yet powerful data structure which is used, among others, in full text indices, data compression algorithms and within the field of bioinformatics. 

      Here is the source code of the Java program to implement suffix array. The Java program is successfully compiled and run on a Linux system. The program output is also shown below.

      1. import java.io.BufferedReader;
      2. import java.io.IOException;
      3. import java.io.InputStreamReader;
      4. public class SuffixArray
      5. {
      6.     private String[] text;
      7.     private int length;
      8.     private int[] index;
      9.     private String[] suffix;
      10.     public SuffixArray(String text)
      11.     {
      12.         this.text = new String[text.length()];
      13.         for (int i = 0; i < text.length(); i++)
      14.         {
      15.             this.text[i] = text.substring(i, i+1);
      16.         }
      17.         this.length = text.length();
      18.         this.index = new int[length];
      19.         for (int i = 0; i < length; i++)
      20.         {
      21.             index[i] = i;
      22.         }
      23.         suffix = new String[length];
      24.     }
      25.     public void createSuffixArray()
      26.     {
      27.         for(int index = 0; index < length; index++)
      28.         {
      29.             String text = "";
      30.             for (int text_index = index; text_index < length; text_index++)
      31.             {
      32.                 text+=this.text[text_index];
      33.             }
      34.             suffix[index] = text;
      35.         }
      36.         int back;
      37.         for (int iteration = 1; iteration < length; iteration++)
      38.         {
      39.             String key = suffix[iteration];
      40.             int keyindex = index[iteration];
      41.             for (back = iteration - 1; back >= 0; back--)
      42.             {
      43.                 if (suffix[back].compareTo(key) > 0)
      44.                 {
      45.                     suffix[back + 1] = suffix[back];
      46.                     index[back + 1] = index[back];
      47.                 }
      48.                 else
      49.                 {
      50.                     break;
      51.                 }
      52.             }
      53.             suffix[ back + 1 ] = key;
      54.             index[back + 1 ] = keyindex;
      55.         }
      56.         System.out.println("SUFFIX \t INDEX");
      57.         for (int iterate = 0; iterate < length; iterate++)
      58.         {
      59.             System.out.println(suffix[iterate] + "\t" + index[iterate]);
      60.         }
      61.     }
      62.     public static void main(String...arg)throws IOException
      63.     {
      64.         String text = "";
      65.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      66.         System.out.println("Enter the Text String ");
      67.         text = reader.readLine();
      68.         SuffixArray suffixarray = new SuffixArray(text);
      69.         suffixarray.createSuffixArray();
      70.     }
      71. }

       

      $javac SuffixArray.java
      $java SuffixArray
      Enter the Text String 
      banana
       
      SUFFIX 	 INDEX
      a         5
      ana	  3
      anana	  1
      banana	  0
      na	  4
      nana	  2
      • 0
      • Share
        Share
        • Share onFacebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Related Questions

    • Codility Passing Car Problem in Java
    • Dutch National Flag Problem in Java
    • Java Program to Check if an Array is Decreasing
    • Java Program to Check if an Array is Increasing
    • Smallest Sum Contiguous Subarray in Java

    Sidebar

    Ask A Question
    • Popular
    • Answers
    • imran

      Point out the wrong statement. A. The standard instances are ...

      • 272 Answers
    • imran

      Point out the correct statement. A. A volume is mounted ...

      • 250 Answers
    • VARISHA PARVEZ

      Which type of e‐commerce focuses on consumers dealing with ...

      • 181 Answers
    • Shivangi Panthi
      Shivangi Panthi added an answer B.die, dye June 6, 2023 at 8:52 pm
    • Shivangi Panthi
      Shivangi Panthi added an answer rate June 6, 2023 at 8:52 pm
    • Shivangi Panthi
      Shivangi Panthi added an answer B.Homophones June 6, 2023 at 8:51 pm

    Related Questions

    • 30. A noun that dandies neither a male or a ...

      • 1 Answer
    • What does grade 33 cement indicate?

      • 1 Answer
    • . In Unix, which system call creates the new process? ...

      • 1 Answer
    • What are the types of distributed operating systems? a) Zone ...

      • 1 Answer
    • Network operating system runs on ___________ a) every system in ...

      • 7 Answers

    Top Members

    jafri

    jafri

    • 0 Questions
    • 0 Answers
    Namita

    Namita

    • 0 Questions
    • 0 Answers
    Sohail hossain

    Sohail hossain

    • 0 Questions
    • 0 Answers

    Trending Tags

    account algorithm analytics answer c computer computer science python cs e commerce electric electronics it language mcq mechanical physics poll programming python question

    Explore

    • Home
    • Quearn Academy
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help

    Footer

    Quearn

    Quearn is a social questions & Answers Engine which will help you establish your community and connect with other people, Also you Can Earn Money.

    About Us

    • Meet The Team
    • Blog
    • About Us
    • Contact Us

    Legal Stuff

    • Terms of Use
    • Privacy Policy
    • Cookie Policy

    Help

    • Knowledge Base
    • Support

    Follow

    © 2018-2023 Quearn®. All Rights Reserved | Developed by ASHAS Industries Proudly 🇮🇳