Professional Documents
Culture Documents
Bhaskar - CSE-2 - DAA Experential Learning
Bhaskar - CSE-2 - DAA Experential Learning
About Assignment:
I have attempted the first question of the assignment which can be divided into
three parts:
1. The first part include the pattern searching algorithm followed by the
usage of hash maps. Time complexity of the first part is O(nlogn)+c, where
c is some constant work done. Space Complexity for the same is O(n).
In 2nd part I have used Array Data Structure which was very useful in
creating the 2-D matrix for the LCS matrix.
2-D LCS matrix schematic diagram
In 3rd part there is main usage of Tree Data structure,Priority Queue and
hash maps.
Algorithms/Pseudocode
3.Huffman Coding:
CODES:
st nd
Since 1 and 2 question were done in the same class I am attaching one code for it.
There are commented explanation as well in some places.
Programming Language used: Java, IDE: Eclipse.
import java.util.*;
public class hg {
public static List<String> Pattern_Search(String first,String second)
{
List<String> arr_second = Arrays.asList(second.split(" "));
List<String> list = new ArrayList<String>();
for (String word : first.split(" ")) {
if(arr_second.contains(word))
{
list.add(word);
}
}
if (list == null || list.size() == 0) {
return new ArrayList<String>();
}
return cand.subList(0, 3);//returns the 3 words that are most frequent in the
two strings.
}
public static String LCS(List<String> str1,List<String> str2)
{
String s1=str1.toString();
String s2=str2.toString();
int l1 = s1.length();
int l2 = s2.length();
int dp[][]=new int[l1 + 1][l2 + 1];
// Storing LCS
String lcs="";
int i = l1, j = l2;
while (i > 0 && j > 0)
{
// If current character in both the strings are same, then current
character is part of LCS
if (s1.charAt(i - 1) == s2.charAt(j - 1))
{
lcs=lcs+s1.charAt(i-1);
i--;
j--;
}
The first List<string> is the output of 2nd ques and 2nd is the output of 1st.
The most common three words occurring are thef fox and red here,and the lcs of
these strings taken pair wise is ef.
This [ef] is returned to the Huffman class and we get the following code for Huffman.
CODE:
class Huffman {
return;
}
// main function
public static void xyz() throws NullPointerException
{
// number of characters.
hn.c =x.charAt(0);
hn.data =Chars.get(x);
hn.left = null;
hn.right = null;
int data;
char c;
HuffmanNode left;
HuffmanNode right;
}
OUTPUT: