Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is java Client. Write a client program Subset.java that takes a command-lin

ID: 3588347 • Letter: T

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 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.

Your program must implement the following API:

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.

Explanation / Answer

import java.util.Random; import java.util.Scanner; public class Gray_Code_Permutation { public static int[] grayCode(int N) { int[] grayCode = new int[(int) Math.pow(2, N)]; int[] binary = new int[(int) Math.pow(2, N)]; for (int i = 0; i > 1) ^ i; for (int i = 0; i 0) { binary[i] += (grayCode[i] % 2) * b; grayCode[i] /= 2; b = b * 10; } } return binary; } public static void main(String args[]) { Random random = new Random(); Scanner sc = new Scanner(System.in); System.out.println("Enter the number of elements in the set: "); int N = sc.nextInt(); int[] sequence = new int[N]; for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote