Skip to content
Jinho D. Choi edited this page Aug 24, 2016 · 7 revisions

Select Abstract Class

Dumb Select

  • Create a class DumbSelect under select.
  • Extend AbstractSelect.
  • Make a generic type T extends[Comparable<T>]
  • Override the select method in the class.
  • Make a copy of the input list.
  • Find and remove the maximum key from the copied list.
  • Repeat this procedure k times, and return the last maximum key.

Smart Select

  • Create a class SmartSelect under select.
  • Extend AbstractSelect.
  • Make a generic type T extends[Comparable<T>]
  • Override the select method in the class.
  • Create a new empty list, maxK.
  • For each key in the input list,
    • Add the key to maxK.
    • If the size of maxK is greater than k, remove the minimum key in maxK.
  • Return the minimum key in maxK.

Evaluation

Exercise

  • Imagine that the following condition didn't exist in BinarySearch (lines 45-46).
if (beginIndex > endIndex)
  return -1;
  • Give a list of integers containing more than one key, sorted in ascending order, that would make BinarySearch throw a different kind of exception or error. Explain why this would be thrown.

CS323: Data Structures and Algorithms

Instructor


Emory University

Clone this wiki locally