Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding lowest number with a run-time of O(1) - java
    primarykey
    data
    text
    <p>I'm in a need to create a data-structure based on Linked list, Array, And constant memory usage.</p> <p>As an input i get two numbers: N and M.</p> <p>N represents maximum capacity of a disk-on-key, M represents maximum capacity of a computer hard-drive, So that M>N.</p> <p>So i need to create a program that 'moves' information from the hard-drive to the disk-on-key, That program needs to implements the following methods:</p> <ol> <li>Insert(data) - Inserts the data into the disk-on-key, If its full it removes the data least important(*): worst case run-time O(1).</li> <li>delete(data) - deletes the given data from the disk-on-key - O(1)</li> </ol> <p>(*) the user can change the file importance.</p> <p>Maximum amount of memory usage is O(M)</p> <p>What i did so far:</p> <p>I've created an array [1...M] which will 'hold' the computer data, I've created a doubly linked list which will hold the disk-on-key data. [The idea is: each time a data is added to the disk-on-key it will be added to the linked list, and i can go directly to the data using the array as a index(/key) storage.]</p> <p>My computer data fields:</p> <pre><code>node firstNode; node currentNode; node[] dataCollection; // Will hold computer hard-drive data </code></pre> <p>So i wanted to create method replacing the least important data with data i want to add [so i'll be able to use in Insert], My code for replace:</p> <pre><code>public void replace(int leastImportantdata, int insertData){ node leastImportant = dataCollection[leastImportantdata]; if (leastImportant.prev!=null) leastImportant.prev.next=dataCollection[insertData-1]; if (leastImportant.next!=null) leastImportant.next.prev=dataCollection[insertData-1]; numOfReplacements++; </code></pre> <p>So, my main problem is finding the least important data given those two 'combined' data structures and still keeping a run-time of O(1), Especially when the user decides to change the files importance.</p> <ul> <li>Say that we start with {4,3,2,1} (numbers represents importance) the least important data would be 1.Suddenly, the user decided to change the last file importance to 5, we get {4,3,2,5} and least important data is 2.</li> </ul> <p>Any idea?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload