QuestionQuestion

Write a O(n) function, deleteRanked(list, item), to delete an item from a frequency
ranked list. For example,
deleteRanked([6, 6, 6, 6, 3, 3, 3, 1, 1, 1, 2, 2, 2, 8, 8, 9, 9], 1)
should produce
[6, 6, 6, 6, 3, 3, 3, 2, 2, 2, 1, 1, 8, 8, 9, 9].
Note: If you think this cannot be done in O(n), justify clearly.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.*;

/*
* DeleteRanked Class
* - contains one static method: deleteRanked
*/
public class DeleteRanked {

    // Methold to delete an item into a frequency united list
    // This is very similar to insertRanked, except we insert 1 fewer than currently exist in the list
    public static <T extends Comparable<T>> List<T> deleteRanked(List<T> list, T item) {
       // Check if item does not exist in list;
       if (!list.contains(item))
            return list;
       // Count number of items in list
       int count = -1; // CHANGE from insertRanked -- insert 1 fewer values rather than 1 greater
       while (list.contains(item)) {
            list.remove(item);
            count++;
       }
       // Calculate index bounds to perform insertion
       int lindex = 0;
       int hindex = list.size();
       int frequency...

By purchasing this solution you'll be able to access the following files:
Solution.java.

$13.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats