NodeTransitionFunction(int exp, int KVal){
this.exp = exp;
this.KVal = KVal;
}
//idea is if the exp is even we square the val and make exp = exp / 2
// otherwise we decrease exp by 1 and multiply the val with ans
int apply(int val){
int ans = 1;
int e = exp;
while(e != 0){
if(e % 2 ==
0){
val = (val * val) % KVal;
e = e / 2;
}
else{
ans = (ans * val) % KVal;
e--;
}
}
return ans;
}
Q3)
Node(int n, int e, int d, int k, boolean encrypt,
boolean useBI, Map<Integer, Node> m, MessageTrackCheck
t){
this.n = n;
this.e = e;
this.d = d;
this.k = k;
this.encrypt = encrypt;
this.useBI = useBI;
this.m = m;
this.t = t;
}
2. Write the following methods for the NodeTransitionFunction class. public NodeTransitionFunction (Integer exp, Intege...
***Code to solve***
package functions;
import java.math.*; // for BigInteger
public class NodeTransitionFunction {
public NodeTransitionFunction(Integer exp, Integer
KVal) {
// CONSTUCTOR: Sets the class to
calculate f(x) = (x ^ exp) mod KVal
// TODO
}
public Integer apply(Integer val) {
// PRE: -
// POST: Implements f(val)
return null;
}
public BigInteger apply(BigInteger val) {
// PRE:...
5. There are several getter methods for class Node: public Integer getIDO //PRE:- // POST: Returns node ID public Integer getEO /7PRE //POST: Returns value of e in this node's function f) public Integer getkO /PRE: //POST: Returns value of K in this node's function f) public Boolean transmittedMessage) 7PRE:- /POST: Returns true if this node has transmitted a message, false otherwise public String getMsg) /PRE: // POST: Returns the current received (non-augmented) message, null if no received message
5....
The code is in JAVA
public class CheckBST {
//method to implement
public static boolean isValidBST(TreeNode root) {
}
public static void main(String[] args) {
TreeNode a = new TreeNode(1);
TreeNode b = new TreeNode(2);
TreeNode c = new TreeNode(3);
a.left = b;
a.right = c;
System.out.println(isValidBST(a));
TreeNode d = new TreeNode(2);
TreeNode e = new TreeNode(1);
TreeNode f = new TreeNode(3);
d.left = e;
d.right = f;
System.out.println(isValidBST(d));
}
}
TreeNode.java
class TreeNode {
int val;
TreeNode left;
TreeNode...
java problem
here is the combination class
class Combination
{
int first,second,third, fourth;
public Combination(int first, int second, int
third,int fourth)
{
this.first=first;
this.second=second;
this.third=third;
this.fourth=fourth;
}
public boolean equals(Combination other)
{
if ((this.first==other.first)
&& (this.second==other.second) &&
(this.third==other.third) &&
(this.fourth==other.fourth))
return
true;
else
return
false;
}
public String toString()
{
...
Create a complete LinkedList class which implements all of the methods listed below using dynamic memory allocation. You will need a Node class to represent each node in the list. The list should store String values. Include a main method which tests all the methods of your list. Also answer these questions: What is the time complexity (using big-O notation) of these operations in your linked list? add(String val) add(int index, String val) get(int index) remove(String val) Submit three files:...
if we have following List classes: public class LinkedList<T> { class ListNode { protected T value; protected ListNode next; public ListNode(T val, ListNode nxt) { value = val; next = nxt; } public ListNode(T val) { this(val, null); } public ListNode() { this(null, null); } } can you write the folowing methods in java: 1.Write a method for the LinkedList class called int indexOf(T val) which returns the integer index indicating the location of val in the list, or -1...
Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA { private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...
create a class named IntegerQueue given a singlylinkedqueue of integers, write the following methods: max(SinglyLinkedQueue<Integer> s) to return the max element in the queu. min(SinglyLinkedQueue<Integer> s) to return the min element in the queue. sum(SinglyLInkedQueue<Integer> s) to return the sum of elements in the queu. median(SinglyLinkedQueue<Integer> s) to return the median of elements in the queue. split(SinglyLinkedQueue<Integer> s) to separate the SinglyLinkedQueue into two ArrayQueues based on whether the element values are even or odd. package Stack_and_Queue; import java.util.Iterator; import...
Please help!!!!!!
import java.util.Random;
public class CSE205_Assignment04 {
private static Random rnd = new Random();
public static void main(String[] args) {
Tree_ctor_test();
Tree_insert1_test();
Tree_insert3_test();
Tree_insertMany1_test();
Tree_insertMany2_test();
Tree_insertMany3_test();
Tree_insertMany4_test();
}
public static void Tree_ctor_test()
{
Tree<Integer> t = new BSTree<Integer>();
assertEqual("", t.toString(), "Tree_ctor_test: toString", false);
assertEqual(false, t.contains(0), "Tree_ctor_test: contains", false);
}
public static void Tree_insert1_test()
{
Tree<Integer> t = new BSTree<Integer>();
t.insert(1);
assertEqual("1 ", t.toString(), "Tree_insert1_test: toString", false);
assertEqual(false, t.contains(0), "Tree_insert1_test: contains", false);
assertEqual(true, t.contains(1), "Tree_insert1_test: contains", false);
}
public static...
Java help: Please help complete the locate method that is in bold.. public class LinkedDoubleEndedList implements DoubleEndedList { private Node front; // first node in list private Node rear; // last node in list private int size; // number of elements in list ////////////////////////////////////////////////// // YOU MUST IMPLEMENT THE LOCATE METHOD BELOW // ////////////////////////////////////////////////// /** * Returns the position of the node containing the given value, where * the front node is at position zero and the rear node is...