Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Recursions { /** * Complete the following method. The method is to return the number of possible * ways to fill a sequence

public class Recursions { /** * Complete the following method. The method is to return the number of possible * ways to fill a sequence of (linear) slots with sticks of length 1 and length * 2. For example, if there are 3 slots, the number will be 3 (A represents the * stick of length 1 and B of length 2. * * ABB AAB AAA * * You can assume that the number of sticks is infinite. * * @param numSlots * @return */ public static int fillLine1_2(int numSlots) { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } /** * Given an array of ints, write a method that checks if there is a subset of * ints, such that the subset sum is equal to the target value. Consider the * following constraints: (1) All multiples of 7 in the array must be added to * the subset sum, (2) if 7 follows 3, 3 cannot be added. If needed, write * additional helper method(s). * * @param start * initial value passed to subsetSum7. * @param nums * @param target * @return */ public static boolean subsetSum7(int start, int[] nums, int target) { throw new UnsupportedOperationException("Remove this line and replace with your implementation."); } }

__________________________________________________________Test cases

@Test public void testFillLine3() { assertEquals(3, Recursions.fillLine1_2(3)); }

@Test public void testFillLine4() { assertEquals(5, Recursions.fillLine1_2(4)); }

@Test public void testFillLine5() { assertEquals(8, Recursions.fillLine1_2(5)); }

@Test public void testGroupSumTrues() { assertTrue(Recursions.subsetSum7(0, new int[] { 3, 5, 7, 4 }, 14)); assertTrue(Recursions.subsetSum7(0, new int[] { 2, 5, 14, 4 }, 19)); assertTrue(Recursions.subsetSum7(0, new int[] { 3, 5, 1 }, 9)); }

@Test public void testGroupSumFalses() { assertFalse(Recursions.subsetSum7(0, new int[] { 4, 7, 2 }, 10)); assertFalse(Recursions.subsetSum7(0, new int[] { 9 }, 1)); }

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions