// function to generate all subsequences of given array function generate_subseq(arr):    // length of arr    n = len(arr)    // total subsequences for array of length n    m = 2**n    // to store all subsequences    seqs = []    // running a loop for m times    for i in range(1, m):        // creating an array of zeros of length n        a = [0]*n        num = i        // to use as an index for 'a'        j = n-1        // run this loop till num > 0        while num > 0:            if num is odd:                a[j] = 1            // divide num by 2            num = num/2            // subtract 1 from 'j'            j -= 1        // to store current subsequence        seq = []        // iterating for n times        for i in range(n):            // add ith index value to 'seq'            if a[i] == 1:                seq.append(arr[i])        // add 'seq' to 'seqs'        seqs.append(seq)    // return seqs    return seqs // given lists S1 = ['B','C','D','A','A','C','D'] S2 = ['A','C','D','B','A','C'] // all non-empty subsequences of S1 seqs1 = generate_subseq(S1) // all non-empty subsequences of S2 seqs2 = generate_subseq(S2) // to store longest common subsequence ans = "" // iterating each subsequence in seqs1 for seq1 in seqs1:    // iterating each subsequence in seqs2    for seq2 in seqs2:        // found match and length of current answer < length of seq1        if seq1 == seq2 and len(ans) < len(seq1):            // updating answer            ans = seq1 // printing longest common subsequence print("Longest Common Subsequence: ", ans)   Convert the above code to java code?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

// function to generate all subsequences of given array
function generate_subseq(arr):

   // length of arr
   n = len(arr)

   // total subsequences for array of length n
   m = 2**n

   // to store all subsequences
   seqs = []

   // running a loop for m times
   for i in range(1, m):

       // creating an array of zeros of length n
       a = [0]*n

       num = i
       // to use as an index for 'a'
       j = n-1

       // run this loop till num > 0
       while num > 0:

           if num is odd:
               a[j] = 1

           // divide num by 2
           num = num/2

           // subtract 1 from 'j'
           j -= 1

       // to store current subsequence
       seq = []

       // iterating for n times
       for i in range(n):

           // add ith index value to 'seq'
           if a[i] == 1:
               seq.append(arr[i])

       // add 'seq' to 'seqs'
       seqs.append(seq)

   // return seqs
   return seqs


// given lists
S1 = ['B','C','D','A','A','C','D']
S2 = ['A','C','D','B','A','C']

// all non-empty subsequences of S1
seqs1 = generate_subseq(S1)

// all non-empty subsequences of S2
seqs2 = generate_subseq(S2)

// to store longest common subsequence
ans = ""

// iterating each subsequence in seqs1
for seq1 in seqs1:

   // iterating each subsequence in seqs2
   for seq2 in seqs2:

       // found match and length of current answer < length of seq1
       if seq1 == seq2 and len(ans) < len(seq1):

           // updating answer
           ans = seq1

// printing longest common subsequence
print("Longest Common Subsequence: ", ans)

 

Convert the above code to java code?

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education