Implement the following functions in your class: getTotalWords, getUniqueWords, getMostUsedWord, getMaxOccurrence. Name them as indicated here. The last function returns how many times the most common word occurred. The code to add the functions to: import edu.princeton.cs.algs4.*; import edu.princeton.cs.algs4.LinearProbingHashST; import edu.princeton.cs.algs4.SeparateChainingHashST; import edu.princeton.cs.algs4.ST; import edu.princeton.cs.algs4.SequentialSearchST; import edu.princeton.cs.algs4.In; import edu.princeton.cs.algs4.StdOut; public class TestPerf {     public static long LinearProbingHashST(String x[])

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

Implement the following functions in your class: getTotalWords, getUniqueWords, getMostUsedWord, getMaxOccurrence. Name them as indicated here. The last function returns how many times the most common word occurred.

The code to add the functions to:

import edu.princeton.cs.algs4.*;
import edu.princeton.cs.algs4.LinearProbingHashST;
import edu.princeton.cs.algs4.SeparateChainingHashST;
import edu.princeton.cs.algs4.ST;
import edu.princeton.cs.algs4.SequentialSearchST;
import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.StdOut;


public class TestPerf {

    public static long LinearProbingHashST(String x[]) {
        
        LinearProbingHashST<String, Integer> st = new LinearProbingHashST<String, Integer>();
            long start = System.currentTimeMillis();
            for(int i = 0; i < x.length; i++){
                String key = x[i];
                if (!st.contains(key))  st.put(key, 1); 
            else                    st.put(key, st.get(key) + 1); 
            }
        long finish = System.currentTimeMillis();
            return (finish - start);
    }
    
    
    public static long SeparateChainingHashST(String x[]) {
        SeparateChainingHashST<String, Integer> st = new SeparateChainingHashST<String, Integer>();
        long start = System.currentTimeMillis();
            for(int i = 0; i < x.length; i++){
                String key = x[i];
                if (!st.contains(key))  st.put(key, 1); 
            else                    st.put(key, st.get(key) + 1); 
            }
        long finish = System.currentTimeMillis();
        return (finish - start);
    }
    
    
    public static long ST(String x[]) {
        ST<String, Integer> st = new ST<String, Integer>();
            long start = System.currentTimeMillis();
            for(int i = 0; i < x.length; i++){
                String key = x[i];
                if (!st.contains(key))  st.put(key, 1); 
            else                    st.put(key, st.get(key) + 1); 
            }
        long finish = System.currentTimeMillis();
        return (finish - start);
    }
    
    public static long SequentialSearchST(String x[]) {
        SequentialSearchST<String, Integer> st = new SequentialSearchST<String, Integer>();
            long start = System.currentTimeMillis();
            for(int i = 0; i < x.length; i++){
                String key = x[i];
                if (!st.contains(key))  st.put(key, 1); 
            else                    st.put(key, st.get(key) + 1); 
            }
        long finish = System.currentTimeMillis();
        return (finish - start);
    }
    
    public static void main(String[] args) {
        
        In in = new In(args[0]);
        String[] tale = in.readAllStrings(); 
   
        StdOut.println();
        StdOut.println("LinearProbingHashST time: " + LinearProbingHashST(tale) + " ms");
        StdOut.println("SeparateChainingHashST time: " + SeparateChainingHashST(tale) + " ms");
        StdOut.println("ST time: "+ ST(tale) + " ms");
        StdOut.println("SequentialSearchST time: " + SequentialSearchST(tale) + " ms");

        
    }
}

Expert Solution
trending now

Trending now

This is a popular 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