Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you write the pseodocode and make sure to comment each line. 2 . Create pseudocode for the following algorithm. To get credit for this
Can you write the pseodocode and make sure to comment each line. Create pseudocode for the following algorithm. To get credit for this problem, your pseudocode needs to be organized in functions which must be understood by people with both; technical and nontechnical background. Note that your pseudocode should work for files of any size, not only for the example algorithm given in the problem. Given a file F that contains integers separated by commas, and a machine with limited memory, sort the contents of this file in ascending order without missing a single bit. Assumptions for this problem: The original file F is given as the input for the problem and the size of the file is x KiB, where x in N You are running this algorithm in a machine with limited memory. Your machine has KiB of memory only, where you have an additional bytes reserved to a pointer that may perform reading or writing operations. In memory, you are only allowed to have buffers or arrays one input buffer, and two output buffers. The size of each of the buffers is KiB. Buffers in memory only support integers. You are allowed to store data into temporal files in your hard drive while performing the algorithm. However, these temporal files must be deleted as soon as they are emptied. When placed in a file, every digit of an integer is a char byte On the other hand, when placed in buffers in memmory, an integer is always bytes. This problem allows duplicated integers Commas in files are always chars kb The output file must be the same size and contains the same data as the original file, but sorted in ascending order. You cant miss a bit. At least one of your functions in your pseudocode to solve this problem must be recursive
Example algorithm given for a file F of size KIB: a Open the original file located in a specific folder in the machines hard drive b Create a pointer to reads every char in the file until the maximum input buffer capacity is reached c Sort the elements in the input buffer in place, move the sorted elements to the output buffer, and flush the elements in the output buffer to a new temporal file in disk d Repeat steps b and c until the pointer reach the end of the original file. e At this point, we should have a set of temporal files F fi fi fn saved in the hard drive of the machine f Use input buffer to read KIB of data from temporal file fi g Use input buffer to read KIB of data from temporal file fih Merge data from input buffer and into the output buffer youll need to do this X times until the input buffers are empty
i Delete temporal files fi and fi and increase i i j Flush the data from the output buffer into a new or existing tmp file. Note that merging the data of two files ie KIB each file will result in a new temporal file of KIB. k Repeat steps fghi and j until you end up with only one file of size KIB same as original file but with all the elements already sorted in ascending order separated by a comma. The final sorted file needs to be exactly KIB as the original file. Write your pseudocode for this problem here. Note that your pseudocode needs to work for all the instances of this problem. In other words, for input files of any size not only for files of size KIB:
Step 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