


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: DATA STRUC/ALGORITHMS; Subject: COMPUTER PROGRAMMING; University: University of Florida; Term: Unknown 1989;
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



public void compress() { int numberToRemove = size / 2; ChainNode currentNode = lastNode.next; // remove the nodes for (int i = 0; i < numberToRemove; i++) {// remove node next to currentNode currentNode.next = currentNode.next.next; currentNode = currentNode.next; } // new size size -= numberToRemove; } (b) The for loop iterates n/2 times, where n is the initial size of the chain. Each iteration of this loop takes O(1) time. Therefore, the complexity of this loop is O(n). The remainder of the code takes O(1) time. Therefore, the overall complexity is O(n). 3 (a) A sample 5 x 5 F-matrix is given below. 1 2 3 4 5 6 0 0 0 0 7 8 9 10 11 12 0 0 0 0 13 0 0 0 0 The compact representation is [1,2,3,4,5,6,7,8,9,10,11,12,13]. (b) The code is given below. public Object get(int i, int j) {// return F(i,j) if ( i < 1 || j < 1 || i > n || j > n) throw new IllegalArgumentException("index out of range"); if (i == 1)
{// return F(i,j) if ( i < 1 || j < 1 || i > n || j > n) throw new IllegalArgumentException("index out of range"); if (i == 1) // first row return element[j - 1]; if (i == (n + 1) / 2) // middle row return element[n – 1 + j]; if (j == 1) // first column if (i < n / 2) // top part return element[2 * n + i - 2]; else // bottom part return element[2 * n + i - 3]; // not part of F return zero; }