Question: 5.5 and 5.7 only, please. 5.4 Consider this split) method where: pList is an ArrayList of Integers containing zero or more elements; pEvenList is an

5.5 and 5.7 only, please.

5.5 and 5.7 only, please. 5.4 Consider this split) method where: pList

5.4 Consider this split) method where: pList is an ArrayList of Integers containing zero or more elements; pEvenList is an empty ArrayList of Integers; and pOddList is an empty ArrayList of Integers. On return, pEvenList will contain the even Integers of pList and pOddList will contain the odd Integers. void split(ArrayList pList, ArrayList pEvenList, ArrayList pOddList) for (int n pList) if (n % 2" 0) pEvenList.add(n); else pOddList.add (n); To analyze the worst case time complexity of an algorithm we first identify the "key operation" and then derive a function which counts how many times the key operation is performed as a function of the size of the input. What is the key operation in this algorithm? Explain. 5.5 Continuing with the previous exercise, derive a function fn) which equates to the number of times the key operation is performed as a function of n, where n is the size of pList. State the worst case time complexity of split) in big O notation. 5.6 Would the time complexity of split) change if the elements of pList were sorted into ascending order? Explain. 5.7 Binary search is such an efficient searching algorithm because during each pass of the loop (in the iterative version) or in each method call (in the recursive version) the size of the list is essentially halved. If reducing the size of the list to be searched by one half is so effective, it may seem that reducing it by two thirds each time would be even more effective. To that end, consider this iterative ternary search method. Rewrite it is as a recursive ternary search method named int recTernarySearch (ArrayList pList, Integer pKey, int pLow, int pHigh) int ternarySearch (ArrayList pList, Integer pKey) f int low -0, high -pList.size 1; while (low high) [ int range high - low; int oneThirdIdx(int)Math.round (low range / 3.0); int twoThirdIdx(int)Math.round (low range / 1.33); if (pKey.equals (pList.get (oneThirdIdx))) else if (pKey.equals(pList.get (twoThirdIdx))) else if (pKey pList.get (twoThirdIdx)) else return oneThirdIdx; return twoThirdIdx; high oneThirdIdx - 1; low twoThird1dx + 1 ; -oneThirdIdx 1; high - twoThirdIdx 1; return -1; 5.4 Consider this split) method where: pList is an ArrayList of Integers containing zero or more elements; pEvenList is an empty ArrayList of Integers; and pOddList is an empty ArrayList of Integers. On return, pEvenList will contain the even Integers of pList and pOddList will contain the odd Integers. void split(ArrayList pList, ArrayList pEvenList, ArrayList pOddList) for (int n pList) if (n % 2" 0) pEvenList.add(n); else pOddList.add (n); To analyze the worst case time complexity of an algorithm we first identify the "key operation" and then derive a function which counts how many times the key operation is performed as a function of the size of the input. What is the key operation in this algorithm? Explain. 5.5 Continuing with the previous exercise, derive a function fn) which equates to the number of times the key operation is performed as a function of n, where n is the size of pList. State the worst case time complexity of split) in big O notation. 5.6 Would the time complexity of split) change if the elements of pList were sorted into ascending order? Explain. 5.7 Binary search is such an efficient searching algorithm because during each pass of the loop (in the iterative version) or in each method call (in the recursive version) the size of the list is essentially halved. If reducing the size of the list to be searched by one half is so effective, it may seem that reducing it by two thirds each time would be even more effective. To that end, consider this iterative ternary search method. Rewrite it is as a recursive ternary search method named int recTernarySearch (ArrayList pList, Integer pKey, int pLow, int pHigh) int ternarySearch (ArrayList pList, Integer pKey) f int low -0, high -pList.size 1; while (low high) [ int range high - low; int oneThirdIdx(int)Math.round (low range / 3.0); int twoThirdIdx(int)Math.round (low range / 1.33); if (pKey.equals (pList.get (oneThirdIdx))) else if (pKey.equals(pList.get (twoThirdIdx))) else if (pKey pList.get (twoThirdIdx)) else return oneThirdIdx; return twoThirdIdx; high oneThirdIdx - 1; low twoThird1dx + 1 ; -oneThirdIdx 1; high - twoThirdIdx 1; return -1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!