Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a JAVA program as described in the question. Please be aware about some restrictions listed in the question.below: Problem 2 (40 points): A Walk
Write a JAVA program as described in the question. Please be aware about some restrictions listed in the question.below:
Problem 2 (40 points): A Walk on the Hypercube: The unit hypercube in the n-dimensional space is the set of all points (x1,x2,...,xn) in that space such that its coordinates are restricted to be 0 SX S1 for i = 1..n. This hypercube has 2"corners. Each coordinate of a corner is either 0 or 1. Each edge of the hypercube connects a pair of corners that differ in exactly one of their coordinates. A walk on the hypercube starts at some corner and walks along a sequence of edges of the hypercube so that it visits each corner exactly once. There are many such walks possible. The following figure shows an example for n=3. The edges of the (hyper)cube along the walk are thickened. 011 A Walk: 000 100 010 110 110 010 011 111 101 001 000 100 The problem: for any given n, output the sequence of corners visited along a walk of the n- dimensional hypercube. We want to study recursive and iterative solutions to this problem. In order to do that, design a Hypercube class that (among possibly other members) includes the following: a) A nested class named Corner. An instance of this type represents a corner of the hypercube and occupies O(n) memory cells. b) A recursive method named recursive Walk() to solve the above problem. The parameters and local variables of this method can only be primitives or Corner types. c) An iterative method named iterative Walk() to solve the above problem using a single queue. The elements of this queue, as well as the other local variables and method parameters, can only be primitives or Corner types. (Note: We know that any recursive algorithm can be converted to an equivalent iterative one by simulating a recursion stack. However, here you are forbidden to use a stack or any structure that may act as one such as an array or a list. Java has a Queue interface, not a class. But it has an ArrayDeque class that can do the job of a queue as well as other lists. You may either design your own Queue class or use the queue methods in ArrayDeque. You are not allowed to use the stack or other methods in ArrayDeque. In other words, use ArrayDeque only as a queue, i.e., a First-In-First-Out list.) d) Explain the running times of your solutions in parts (b) and (c) in a2sol.pdf. e) The main() method of Hypercube class should test recursive Walk and iterative Walk for at least the dimensions n = 3,4,5. Report the i/o results in a2sol.pdfStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started