Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please implement this in Java. please implement this in java! Problem 2 (40 points): A Walk on the Hypercube: The unit hypercube in the n-dimensional

Please implement this in Java.

image text in transcribed

please implement this in java!

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 111 A Walk: 000 100 110 7X2 010 110 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 iterativeWalk() 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 iterativeWalk for at least the dimensions n = 3,4,5. Report the I/O results in a2sol.pdf. 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 111 A Walk: 000 100 110 7X2 010 110 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 iterativeWalk() 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 iterativeWalk for at least the dimensions n = 3,4,5. Report the I/O results in a2sol.pdf

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

=+and non-compete agreements in three to five different countries.

Answered: 1 week ago