Question: using recursion and recursive data structures. No loops please. Please help with return statements for isValid() and is ValidAdvanced() public class Block { public int

using recursion and recursive data structures. No loops please. 

Please help with return statements for isValid() and is ValidAdvanced()

public class Block { public int id; // Number public int rank; // position in the Chain public Block next;

// attributes to be added public int size;

public Block(int id, int rank) { this.id = id; this.rank = rank; this.next = null; // attributes to be added } public Block(int id, int rank, Block next) { this.id = id; this.rank = rank; this.next = next; // attributes to be added }

// Additional constructors may be added

// DO NOT MODIFY public String toString() { String str = "(" + id + ", " + rank + ")"; if (this.next == null) { return str; } return str + " -> " + next.toString(); } /** * * @return true if the chain starting at the current node is a valid Collatz * chain and false otherwise. For a chain to be valid, it needs to * follow the 3n+1 rule but not necessarily have a valid rank. The fast * collatz chain should be treated as invalid. */ public boolean isValid() { return false; /** * IMPORTANT: Even thought this method is in the Block class, it may be harder * than most in the Chain class. * * @return true if the chain starting at the current node is either a valid * Collatz chain or a fast Collatz chain. In this question, you also * need to ensure that the rank is valid. A valid rank starts at 1 and * increases with one. */ public boolean isValidAdvanced() { return false; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres how you can create the isValid and isValidAdvanced functions using recursion Ill include detailed explanations to help you understand the logic ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!