(Directory size) Listing 18.10, DirectorySize.java, gives a recursive method for finding a directory size. Rewrite this method without using recursion. Your
long getSize(File directory) {
long size = 0;
add directory to the queue;
while (queue is not empty) {
Remove an item from the queue into t;
if (t is a file)
size += t.1ength();
else
add all the files and subdirectories under t into the
queue ;
}
return size;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with Python (3rd Edition)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Database Concepts (7th Edition)
- (Generic binary search) Implement the following method using binary search. public static <E extends Comparable<E>> int binarySearch(E[] list, E key) Note:- Please type this java code fully running and also need an output for this given code.arrow_forwarddef removeMultiples(x, arr) - directly remove the multiples of prime numbers (instead of just marking them) by creating a helper function. This recursive function takes in a number, n, and a list and returns a list that doesn’t contain the multiples of n.def createList(n) - a recursive function, createList(), that takes in the user input n and returns an array of integers from 2 through n (i.e. [2, 3, 4, …, n]). def Sieve_of_Eratosthenes(list) - a recursive function that takes in a list and returns a list of prime numbers from the input list.Template below: def createList(n): #Base Case/s #ToDo: Add conditions here for base case/s #if <condition> : #return <value> #Recursive Case/s #ToDo: Add conditions here for your recursive case/s #else: #return <operation and recursive call> #remove the line after this once all ToDo is completed return [] def removeMultiples(x, arr): #Base Case/s #TODO: Add conditions here for your…arrow_forwardQ3arrow_forward
- #python codecoud you provide comments and little explanation it would really help me to understandthankyouarrow_forward- Do not add any imports, the ones that you need will be given to you.- Do not use recursion.- Do not use break/continue.- Do not use try-except statements, you should be able to anticipateor prevent any errors from happening at all!arrow_forwardplease code in python Forbidden concepts: arrays/lists (data structures), recursion, custom classes Create a program that takes a password string from the user and encrypts the letters to go up or down the alphabet using a triple-number key. The amount up or down for the encryption of the alphabetical characters will depend on the input from the user. Input for the encryption key integers will be -25 ≤ key ≤ 25.For example, ‘CHICKEN’ with a 1, 2, -3 would be C up 1 to D, H up 2 to J, I down 3 to F,then C up 1 to D, K up 2 to M, E down 3 to B, and N up 1 to O. Thus the encryption becomes ‘DJFDMBO’.arrow_forward
- /** numUnique returns the number of unique values in an array of doubles. * The array may be empty and it may contain duplicate values. * Unlike the previous questions, you can assume the array is sorted. * * Your solution should contain at most one loop. You may not use recursion. * Your solution must not call any other functions. * Here are some examples (using "==" informally): * * * * * Ⓒ == numUnique (new double[] { }) 1 == numUnique (new double[] {11}) 1 == numUnique (new double[] { 11, 11, 11, 11 }) 8 == numUnique (new double[] { 11, 11, 11, 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88, 88 }) 8 == numUnique (new double[] { 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88 }) * */ public static int numUnique (double[] list) { return StdRandom.uniform (100); //TODO: fix thisarrow_forward(Sort ArrayList) Write the following method that sorts an ArrayList: public static <E extends Comparable<E>> void sort(ArrayList<E> list) Write a test program that prompts the user to enter 10 integers, invokes this method to sort the numbers, and displays the numbers in increasing order. Sample Run Enter 10 integers: 3 4 12 7 3 4 5 6 4 7 The sorted numbers are 3 3 4 4 4 5 6 7 7 12 Class Name: Exercise19_09arrow_forwardPlease convert Mutual Recursion to Java. See attached image. Thank you.arrow_forward
- Please fix the code and explain the steps (specially the recursive part). Also please test it and screenshot the code as well as the output. (using python)arrow_forwardNEED HELP WITH 2-D list. (PYTHON) For e.g., the following is another example of 2-D multidimensional list. Each row contains student name followed by their grades in 5 subjects: students = [ ['Anna', 98.5, 77.5, 89, 93.5, 85.5], ['Bob', 77, 66.5, 54, 90, 85.5], ['Sam', 98, 97, 89.5, 92.5, 96.5] ] To access, a specific row, you would use students[row_number][column_number]. students[0][0] would print 'Anna' students[0][1] would print 98.5 Create your own 2-D list with at-least 5 students and their grades in 5 subjects like the example above. Write a nested for/while loop that would use find the total of 5 subjects for each student and stores that into a sepearate list. Display the Total for each student.arrow_forwardInstructions: Implement a merge sort in Java, creating a class to hold the main method as well as the mergesort method (which should be a static method). The mergesort method should be able to use any Collection object and it should return a Collection that contains the contents of the original Collection, but in sorted order. The program must ask the user for the data to sort, using numeric data in this case, but your mergesort method must be capable of working with any Collection of Comparable objects. Use recursion.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education