Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you write a psedocode and make sure to comment each line of the psedocode do it in easier way? 2 . Create pseudocode for

Can you write a psedocode and make sure to comment each line of the psedocode do it in easier way? 2.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 non-technical 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 2x KiB, where x in N You are running this algorithm in a machine with limited memory. Your machine has 12 KiB of memory only, where you have an additional 4 bytes reserved to a pointer that may perform reading or writing operations. In memory, you are only allowed to have 3 buffers (or arrays), one input buffer, and two output buffers. The size of each of the buffers is 4 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 (1 byte). On the other hand, when placed in buffers in memmory, an integer is always 4 bytes. This problem allows duplicated integers Commas in files are always chars (1 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 32 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+1,..., fn} saved in the hard drive of the machine (f) Use input buffer 1 to read 4 KIB of data from temporal file fi (g) Use input buffer 2 to read 4 KIB of data from temporal file fi+1(h) Merge data from input buffer 1 and 2 into the output buffer (youll need to do this X times until the input buffers are empty)
(i) Delete temporal files fi and fi+1 and increase i = i +1(j) Flush the data from the output buffer into a new (or existing) tmp file. Note that merging the data of two files (i.e 4 KIB each file) will result in a new temporal file of 8 KIB. (k) Repeat steps (f),(g),(h),(i) and (j) until you end up with only one file of size 32 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 32 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 32 KIB):

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

What are the values and risks of self-disclosing communication?

Answered: 1 week ago