Question: This is java Client. Write a client program Subset.java that takes a command-line integer k ; reads in a sequence of strings from standard input
This is java
Client. Write a client program Subset.java that takes a command-line integer k ; reads in a sequence of strings from standard input using StdIn.readString(); and prints out exactly k of them, uniformly at random. Each item from the sequence can be printed out at most once.
% echo A B C D E F G H I | java-alg4 Subset 3 C G A % echo A B C D E F G H I | java-alg4 Subset 3 E D G % echo AA BB BB BB BB BB CC CC | java-alg4 Subset 8 BB AA BB CC BB BB CC BB
Your program must implement the following API:
public class Subset { public static void main(String[] args) } You may assume that 0 k N, where N is the number of strings on standard input.
Performance requirements: The running time of Subset must be linear in the size of the input. You may use only a constant amount of memory plus either one RandomizedBag or one Dequeue , of maximum size at most N.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
