1. Home
  2. Explore
  3. Computer Science
  4. Sorting Partially Sorted Data

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Sorting Partially Sorted Data

  • 54Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Problem Modeling

Which aspect of the textbook-merging problem can be generalized without relying on the data being email addresses?

54 questions

  1. 1

    Which aspect of the textbook-merging problem can be generalized without relying on the data being email addresses?

    1. A

      Merging one sorted collection and one unsorted collection into sorted output

    2. B

      Sorting email addresses by their domain names

    3. C

      Identifying duplicate domains in the input files

    4. D

      Determining which email addresses belong to textbook buyers

    Correct answer
    A

    Merging one sorted collection and one unsorted collection into sorted output

    Explanation

    The central operation is merging sorted and unsorted data into sorted output. It can be described generically unless the sorting criterion itself depends on email-specific properties such as domain names.

  2. 2

    Why does sorting by domain name make the email-specific nature of the data more important?

    1. A

      A domain-sorted list cannot be represented as an array

    2. B

      The sorting criterion then depends on a property specific to email addresses

    3. C

      Email addresses cannot be compared using any sorting algorithm

    4. D

      Domain sorting guarantees that the two input lists have no duplicates

    Correct answer
    B

    The sorting criterion then depends on a property specific to email addresses

    Explanation

    Sorting by domain requires using a feature of email addresses, whereas sorting by a generic value criterion can be framed as a more general data-merging problem.

  3. 3

    In the example, how are the two input lists ordered before they are merged?

    1. A

      Both lists are sorted by email address

    2. B

      The larger list is sorted by email address, and the smaller list is sorted by domain

    3. C

      Neither list is sorted

    4. D

      The larger list is sorted by domain, and the smaller list is sorted by email address

    Correct answer
    B

    The larger list is sorted by email address, and the smaller list is sorted by domain

    Explanation

    TextBooksAreUs has the larger list sorted by email address, while LittleTexts has the smaller list sorted by domain.

  4. 4

    Why should the possibility of duplicate email addresses be considered before choosing a merging strategy?

    1. A

      The file format automatically removes repeated addresses

    2. B

      Customers may buy multiple items online, so the lists are likely to overlap

    3. C

      A sorted list cannot contain repeated values

    4. D

      Duplicates make it impossible to compare email addresses

    Correct answer
    B

    Customers may buy multiple items online, so the lists are likely to overlap

    Explanation

    The same person may buy multiple items online, making repeated addresses across the lists very likely and requiring an explicit duplicate-handling policy.

  5. 5

    What is one proposed way to avoid duplicates before sorting the merged data?

    1. A

      Write both files unchanged and rely on the file system to remove repeats

    2. B

      Sort the sorted list by domain and compare only the first values

    3. C

      Delete every value from the unsorted list before reading it

    4. D

      Search the sorted list for each value in the unsorted list and remove matches

    Correct answer
    D

    Search the sorted list for each value in the unsorted list and remove matches

    Explanation

    One option is to perform a binary search on the sorted data for each unsorted value and exclude any value already present.

  6. 6

    Why might checking every unsorted value against a very large sorted list be an unattractive duplicate-removal strategy?

    1. A

      Searching changes the order of the sorted list

    2. B

      Even binary searches take time, and repeating them for many values can be costly

    3. C

      The sorted list must be copied before each search

    4. D

      Binary search works only on unsorted data

    Correct answer
    B

    Even binary searches take time, and repeating them for many values can be costly

    Explanation

    Binary search is cheaper than linear search, but it still requires work for each searched value. Repeated searches can be expensive when the sorted data set is large.

  7. 7

    Why can removing duplicates while writing the output be a poor choice if there are very many duplicates?

    1. A

      The output file cannot contain fewer values than the input arrays

    2. B

      The file-writing method cannot compare strings

    3. C

      Writing duplicates makes the sorted array lose its order

    4. D

      The program may do substantial sorting work on values that the output later discards

    Correct answer
    D

    The program may do substantial sorting work on values that the output later discards

    Explanation

    If many values are duplicates, sorting all of them and removing repeats only at output time may waste substantial work. The best choice depends partly on how common duplicates are.

  8. 8

    If a test case includes the same value in both input arrays, what should it verify when duplicates are removed only from the output file?

    1. A

      The merged array contains one copy, but the output file contains both copies

    2. B

      The merged array contains both copies, but the output file contains one copy

    3. C

      Both the merged array and the output file contain no copies

    4. D

      Both the merged array and the output file contain exactly two copies

    Correct answer
    B

    The merged array contains both copies, but the output file contains one copy

    Explanation

    The example deliberately places a shared value in both inputs. The merged array should retain both occurrences, while duplicate removal during file writing should emit that value only once.

  9. 9

    Why can a file begin with the number of data items followed by one item per line?

    1. A

      The count makes it possible to omit all line breaks from the file

    2. B

      The count allows an unsorted list to be treated as already sorted

    3. C

      The count guarantees that every value in the file is unique

    4. D

      Knowing the item count lets the program allocate the array before reading its values

    Correct answer
    D

    Knowing the item count lets the program allocate the array before reading its values

    Explanation

    Reading the count first lets the program construct an appropriately sized array and then read the values once, instead of first scanning the file to discover its size.

  10. 10

    Under the described file format, how should a file with no data values be represented?

    1. A

      As an empty file

    2. B

      With a repeated copy of the previous file's count

    3. C

      With one blank line in place of the count

    4. D

      With a count of zero

    Correct answer
    D

    With a count of zero

    Explanation

    A valid file must follow the specified format, so a file with no data contains the count zero rather than being empty.

  11. 11

    Which set of cases is especially useful for testing this merge program's boundaries?

    1. A

      Only files whose values are already in reverse order

    2. B

      Only two large files with no shared values

    3. C

      Only files containing alphabetically late email addresses

    4. D

      No data in either input, no data in one input, and inputs containing only one item

    Correct answer
    D

    No data in either input, no data in one input, and inputs containing only one item

    Explanation

    Boundary testing should include empty and singleton cases, including no sorted data, no unsorted data, and cases where one or both inputs have only one element.

  12. 12

    What is the main drawback of placing all values into one array and calling the general array-sorting utility?

    1. A

      It automatically removes every duplicate

    2. B

      It requires the output to preserve the original order

    3. C

      It cannot sort strings

    4. D

      It ignores the fact that one input is already sorted and may do unnecessary work

    Correct answer
    D

    It ignores the fact that one input is already sorted and may do unnecessary work

    Explanation

    A general sort is simple, but it does not take advantage of the existing sorted order. For enormous data sets, exploiting that order may improve efficiency.

  13. 13

    When might sorting the combined array with a general sorting utility still be a reasonable choice?

    1. A

      When the input arrays are too large to fit in memory

    2. B

      When the program must avoid using any array

    3. C

      When minimizing the time needed to write the program matters most

    4. D

      When duplicate values must remain in the output file

    Correct answer
    C

    When minimizing the time needed to write the program matters most

    Explanation

    Combining the data and calling a sort is the shortest implementation. It can be appropriate when development time, rather than runtime efficiency, is the main constraint.

  14. 14

    How does adapting selection sort find the next value to place in the result order?

    1. A

      It searches for the minimum among the remaining unsorted values and the relevant sorted-data value

    2. B

      It repeatedly swaps each value with the value immediately after it

    3. C

      It inserts every value at the beginning of the array

    4. D

      It selects the maximum value from the entire array on every pass

    Correct answer
    A

    It searches for the minimum among the remaining unsorted values and the relevant sorted-data value

    Explanation

    Selection sort places the next minimum value. In this adaptation, that value may come from the remaining part of the sorted input or from the unsorted input.

  15. 15

    What happens to the original sorted region during the adapted selection-sort process?

    1. A

      Swaps can mix its values with unsorted values, though the remaining ordering information can still be useful

    2. B

      It is discarded as soon as the first swap occurs

    3. C

      It remains completely unchanged throughout the entire algorithm

    4. D

      It must be sorted again by domain before each comparison

    Correct answer
    A

    Swaps can mix its values with unsorted values, though the remaining ordering information can still be useful

    Explanation

    After the first swap, values from the sorted region can move into other positions. The sorted data is mixed with the unsorted data, but the process can still exploit the ordering information.

  16. 16

    Why can adapted selection sort be harder to implement than a small modification to insertion sort?

    1. A

      It cannot use loops

    2. B

      It must use two result arrays

    3. C

      It has distinct search behavior depending on whether the current position is in the original sorted region

    4. D

      It requires comparing email domains rather than values

    Correct answer
    C

    It has distinct search behavior depending on whether the current position is in the original sorted region

    Explanation

    The selection-sort adaptation must handle two phases: searching the remaining unsorted input while positions are in the sorted region, and searching later positions once in the unsorted region.

  17. 17

    How does insertion sort naturally incorporate the unsorted values in this problem?

    1. A

      It first discards the sorted input and sorts only the unsorted input

    2. B

      It alternates between reversing the two input lists

    3. C

      It starts with a sorted group and inserts unsorted values into their appropriate positions one at a time

    4. D

      It compares each value only with the value at the end of the array

    Correct answer
    C

    It starts with a sorted group and inserts unsorted values into their appropriate positions one at a time

    Explanation

    Insertion sort maintains a sorted group and adds unsorted elements to it one at a time, which fits the structure of the problem.

  18. 18

    What is a key implementation advantage of adapting insertion sort for this task?

    1. A

      It removes the need to compare data values

    2. B

      It guarantees that no elements will be moved

    3. C

      It eliminates the need to know the sorted input's size

    4. D

      It may require only a change to the loop's starting condition

    Correct answer
    D

    It may require only a change to the loop's starting condition

    Explanation

    The adaptation can be viewed as starting insertion sort partway through its usual process, so relatively little existing code may need to change.

  19. 19

    What is the basic two-finger merge strategy after the smaller input has been sorted?

    1. A

      Alternate values from the two inputs without comparing them

    2. B

      Compare the current values at the fronts of the inputs and copy the smaller one into a result array

    3. C

      Copy the larger current value into the sorted input and discard the smaller one

    4. D

      Compare every value in one input against every value in the other

    Correct answer
    B

    Compare the current values at the fronts of the inputs and copy the smaller one into a result array

    Explanation

    Two-finger merge advances through the sorted inputs by comparing their current smallest remaining values and placing the smaller one in the result.

  20. 20

    Why does two-finger merge not need to compare the larger remaining values in one input after finding that input's current smallest value?

    1. A

      Because the input is sorted, its current smallest remaining value is no larger than its later values

    2. B

      Because the algorithm copies all remaining values without checking them

    3. C

      Because the larger values are always duplicates

    4. D

      Because all values in the two inputs are guaranteed to be equal

    Correct answer
    A

    Because the input is sorted, its current smallest remaining value is no larger than its later values

    Explanation

    Once the smaller input has been sorted, its current value is the smallest remaining value there. Its later values cannot precede that value, so the merge need not inspect them yet.

  21. 21

    What makes the two-finger merge approach potentially unacceptable for enormous arrays in this example?

    1. A

      It requires the input files to contain identical values

    2. B

      It needs a separate result array, which can double the storage requirement

    3. C

      It writes the result in reverse order

    4. D

      It cannot handle a sorted input

    Correct answer
    B

    It needs a separate result array, which can double the storage requirement

    Explanation

    The merge creates a second array to hold the result. For enormous inputs, doubling the required storage may prevent the program from working at all.

  22. 22

    Why was selection sort favored over insertion sort in the final algorithm choice described?

    1. A

      Insertion sort always requires two arrays

    2. B

      Selection sort was guaranteed to require no comparisons

    3. C

      Efficiency was the priority, and selection sort appeared potentially more efficient despite being harder to implement

    4. D

      The general sorting utility could not sort the input types

    Correct answer
    C

    Efficiency was the priority, and selection sort appeared potentially more efficient despite being harder to implement

    Explanation

    The decision was a tradeoff: insertion sort appeared easier to adapt, but selection sort might be more efficient. Since efficiency motivated avoiding a general sort, selection sort was chosen.

  23. 23

    Why would reading each input file into a separate array and then combining them be inefficient here?

    1. A

      It would require storing the input data twice before or during combination

    2. B

      It would cause all string comparisons to fail

    3. C

      It would make the sorted input lose its file count

    4. D

      It would prevent either file from being read line by line

    Correct answer
    A

    It would require storing the input data twice before or during combination

    Explanation

    Using a separate array for each file and then combining them would duplicate the data in memory, conflicting with the goal of minimizing storage.

  24. 24

    What information does the method that reads both files need in addition to the two file readers?

    1. A

      The number of values in each file

    2. B

      The final sorted position of every value

    3. C

      The number of duplicate values in the output

    4. D

      The domain of every email address

    Correct answer
    A

    The number of values in each file

    Explanation

    The method needs each file's size to allocate the combined array and to know where the sorted and unsorted sections of the input are.

  25. 25

    Why was it considered awkward for the read method to return only the combined array?

    1. A

      The caller also needs the size of the first file to know the boundary between the two sections

    2. B

      The array would not contain the values from the unsorted file

    3. C

      A method cannot return an array of strings

    4. D

      Returning an array closes both input files automatically

    Correct answer
    A

    The caller also needs the size of the first file to know the boundary between the two sections

    Explanation

    The combined array alone does not identify where the sorted input ends and the unsorted input begins. The program also needs the first file's size, and finding that afterward could require extra work.

  26. 26

    How does reading file sizes in the main method help the overall design?

    1. A

      It eliminates the need for a combined array

    2. B

      It guarantees that the files are not corrupted

    3. C

      It removes the need to read the file contents

    4. D

      It makes the sizes available when other methods are called without needing an extra search

    Correct answer
    D

    It makes the sizes available when other methods are called without needing an extra search

    Explanation

    The main method reads the counts first and passes them to the method that reads the data, avoiding an additional operation to determine the boundary later.

  27. 27

    How should the read method place the two files' values into one combined array?

    1. A

      Read the unsorted file first and overwrite its values with the sorted file

    2. B

      Read both files into the same array starting again at index zero

    3. C

      Alternate one line from each file regardless of their sizes

    4. D

      Read the sorted file first, then continue from the same index while reading the unsorted file

    Correct answer
    D

    Read the sorted file first, then continue from the same index while reading the unsorted file

    Explanation

    A shared index advances through the combined array: the first loop fills it with sorted-file values, and the second continues from that index with unsorted-file values.

  28. 28

    Why can the same index variable be declared before both file-reading loops?

    1. A

      The second loop must continue at the position immediately after the first loop's data

    2. B

      Java requires every loop in a method to share one index

    3. C

      The two loops must always execute the same number of times

    4. D

      The index records the number of duplicate values

    Correct answer
    A

    The second loop must continue at the position immediately after the first loop's data

    Explanation

    Keeping one index allows the second loop to continue filling the array where the first loop stopped, rather than restarting at zero.

  29. 29

    What should the program do if a file has fewer lines than its declared count?

    1. A

      Continue as if the declared count were always correct

    2. B

      Silently fill the missing array slots with duplicate values

    3. C

      Detect the mismatch and warn the user that the file may be corrupted

    4. D

      Treat the missing lines as a valid empty file

    Correct answer
    C

    Detect the mismatch and warn the user that the file may be corrupted

    Explanation

    The file may be corrupted if its contents do not match its declared size. The program should detect the mismatch and notify the user because the result may otherwise be incorrect.

  30. 30

    Why should the input files be closed after the reading method finishes?

    1. A

      Closing files removes duplicates from memory

    2. B

      Closing files is an important part of managing file resources correctly

    3. C

      The output file cannot be opened until all input files are closed

    4. D

      Closing files sorts the values in the arrays

    Correct answer
    B

    Closing files is an important part of managing file resources correctly

    Explanation

    The program explicitly closes both input files after reading them. Closing files is an important resource-management practice.

  31. 31

    What kind of object should a method use to write the output file?

    1. A

      A scanner

    2. B

      A string comparison object

    3. C

      A print writer

    4. D

      A binary-search result

    Correct answer
    C

    A print writer

    Explanation

    A scanner is used for input, while a print writer is appropriate for writing the output file.

  32. 32

    In the adapted selection-sort loop, what should the minimum index initially be for each pass?

    1. A

      The first position of the unsorted file

    2. B

      The last position in the array

    3. C

      The current position being filled

    4. D

      The position after the current minimum

    Correct answer
    C

    The current position being filled

    Explanation

    Selection sort begins each pass by treating the current position as the minimum. The search then checks the relevant remaining values for a smaller one.

  33. 33

    When the current position is still within the original sorted region, where does the adapted selection-sort search begin?

    1. A

      At the start of the unsorted region

    2. B

      At the final position of the array

    3. C

      At the current position itself

    4. D

      At the beginning of the array

    Correct answer
    A

    At the start of the unsorted region

    Explanation

    While processing positions in the original sorted region, the search examines the unsorted region, which begins at the sorted input's size.

  34. 34

    When the current position is already in the unsorted region, where does the adapted selection-sort search begin?

    1. A

      At the next position after the current one

    2. B

      At the first position of the sorted region

    3. C

      At the current position itself

    4. D

      At the end of the sorted region

    Correct answer
    A

    At the next position after the current one

    Explanation

    Once the algorithm is in the unsorted region, it searches the remaining positions beginning just after the current position.

  35. 35

    Why should the adapted selection-sort search not compare the current position with itself?

    1. A

      Self-comparisons would change the array's length

    2. B

      The current position is always the largest value

    3. C

      A string cannot be compared with itself

    4. D

      The current position is already the initial candidate for the minimum

    Correct answer
    D

    The current position is already the initial candidate for the minimum

    Explanation

    The minimum index starts at the current position, so the search only needs to compare later candidates against it.

  36. 36

    How should the program determine whether one string is less than another in Java?

    1. A

      Use equals and check whether the result is false

    2. B

      Use compareTo and check whether the result is negative

    3. C

      Use array length and compare the two lengths

    4. D

      Use the less-than operator directly on the strings

    Correct answer
    B

    Use compareTo and check whether the result is negative

    Explanation

    Strings are compared with compareTo rather than the less-than operator. A negative result means the receiver string is less than the compared string.

  37. 37

    When should the selection-sort adaptation swap two values?

    1. A

      Only when the two values are equal

    2. B

      After every search pass, even if the minimum is already in place

    3. C

      Whenever the current value is a string

    4. D

      When the minimum index differs from the current position

    Correct answer
    D

    When the minimum index differs from the current position

    Explanation

    If the minimum is already at the current position, no swap is needed. Otherwise, the two values are exchanged.

  38. 38

    What is the purpose of a temporary variable during the selection-sort swap?

    1. A

      To store the number of values in the unsorted file

    2. B

      To remember whether two strings are duplicates

    3. C

      To preserve one value while the two array positions are overwritten

    4. D

      To convert the strings into sortable numbers

    Correct answer
    C

    To preserve one value while the two array positions are overwritten

    Explanation

    A temporary variable holds one value during the exchange so it is not lost when the other position is assigned.

  39. 39

    Why were comments considered especially useful in the adapted selection-sort code?

    1. A

      Comments prevent the algorithm from swapping values

    2. B

      Its different search starting points can make correct logic look mistaken to a reader

    3. C

      Comments are required for string comparisons to work

    4. D

      The loops cannot run unless they contain comments

    Correct answer
    B

    Its different search starting points can make correct logic look mistaken to a reader

    Explanation

    The algorithm has more involved control flow than a basic sort, and its behavior can look incorrect without explanation. Comments make the reasoning easier to follow.

  40. 40

    Why can a sorted array be checked for duplicates by comparing each value with its previous value?

    1. A

      Equal values are adjacent in a sorted array

    2. B

      A sorted array contains no values other than duplicates

    3. C

      Every pair of duplicate values has the same index

    4. D

      Sorting moves all duplicate values to the beginning only

    Correct answer
    A

    Equal values are adjacent in a sorted array

    Explanation

    In sorted order, repeated values occur next to one another, so comparing neighboring values is sufficient to identify repeated entries.

  41. 41

    Why must the output-writing loop handle the first array value separately?

    1. A

      The first value is always a duplicate

    2. B

      The file format does not permit the first value to be written in a loop

    3. C

      There is no previous array value to compare with at index zero

    4. D

      The first value has not been sorted yet

    Correct answer
    C

    There is no previous array value to compare with at index zero

    Explanation

    A comparison with the previous element would refer to index negative one for the first value. The program therefore writes the first value separately when the array is nonempty.

  42. 42

    What does the program need to check before writing the first array value separately?

    1. A

      That the output file already contains one line

    2. B

      That the first value is equal to the last value

    3. C

      That the data array is not empty

    4. D

      That the array contains an even number of elements

    Correct answer
    C

    That the data array is not empty

    Explanation

    If the array has length zero, there is no first value to write. A nonempty check prevents an invalid access.

  43. 43

    Why can the duplicate-checking loop start at index one after handling the first value?

    1. A

      Each later value can be compared with the preceding value without an index-zero special check

    2. B

      Index zero is never part of the sorted array

    3. C

      The first value is always removed from the output

    4. D

      The array becomes shorter after every comparison

    Correct answer
    A

    Each later value can be compared with the preceding value without an index-zero special check

    Explanation

    Starting at index one ensures every value examined by the loop has a valid previous neighbor, simplifying the duplicate test.

  44. 44

    Which string operation should be used to test whether adjacent values are equal?

    1. A

      The less-than operator

    2. B

      The array length property

    3. C

      The equals method

    4. D

      The file's has-next-line method

    Correct answer
    C

    The equals method

    Explanation

    String values should be compared for equality with equals. The program uses that comparison to identify adjacent duplicates.

  45. 45

    If the output file should contain each value only once, how should its declared item count be calculated?

    1. A

      The number of lines in the unsorted input file

    2. B

      The sorted input size alone

    3. C

      The array length minus the number of duplicate occurrences omitted

    4. D

      The array length plus the number of duplicate occurrences

    Correct answer
    C

    The array length minus the number of duplicate occurrences omitted

    Explanation

    Because duplicate values are omitted from the output, the declared count must equal the array length minus the number of duplicate occurrences that will not be written.

  46. 46

    When should the duplicate counter be incremented in the output process?

    1. A

      When the current sorted value equals the preceding value

    2. B

      Only when the combined array has length zero

    3. C

      Whenever the current value differs from the preceding value

    4. D

      Once for every value read from the sorted file

    Correct answer
    A

    When the current sorted value equals the preceding value

    Explanation

    The duplicate counter should increase when adjacent sorted strings are equal, because that identifies a value that will not be written again.

  47. 47

    What did the incorrect output count reveal when the file declared thirteen values but contained twelve?

    1. A

      The input files had been read in the wrong order

    2. B

      The output file had included an extra blank line

    3. C

      The sorted array contained too few values

    4. D

      The count had not been adjusted to account for a duplicate omitted from the data lines

    Correct answer
    D

    The count had not been adjusted to account for a duplicate omitted from the data lines

    Explanation

    The file's declared count must agree with the number of data lines. The mismatch showed that duplicate values had been omitted from the lines but not subtracted from the count.

  48. 48

    Why did changing the duplicate test from inequality to equality correct the duplicate count?

    1. A

      The file format requires every unequal pair to be removed

    2. B

      Unequal neighboring strings are always omitted from the output

    3. C

      Equality checks determine the length of the array

    4. D

      Equal neighboring strings are the duplicates that need to be counted

    Correct answer
    D

    Equal neighboring strings are the duplicates that need to be counted

    Explanation

    The counter must increase for repeated neighboring values, which are equal. Counting unequal values instead would count ordinary distinct entries.

  49. 49

    Why is it useful to test the file-reading method by writing its unsorted result to a file before implementing sorting?

    1. A

      It removes the need to test boundary cases

    2. B

      It verifies that the input files contain no duplicates

    3. C

      It isolates whether the values were read and combined correctly

    4. D

      It proves that the final sorting algorithm is correct

    Correct answer
    C

    It isolates whether the values were read and combined correctly

    Explanation

    Saving the combined data before sorting provides a way to check that file reading and array construction work independently of the sorting logic.

  50. 50

    If a program runs without an error message but its output has not been inspected, what can be concluded?

    1. A

      The program handled every duplicate correctly

    2. B

      The program's output is definitely sorted

    3. C

      The program did not visibly fail, but correctness has not yet been confirmed

    4. D

      The input files were certainly uncorrupted

    Correct answer
    C

    The program did not visibly fail, but correctness has not yet been confirmed

    Explanation

    A run that does not fail is encouraging but does not establish correctness. The output still needs to be inspected or checked against expected results.

  51. 51

    Why should a programmer understand sorting algorithms even when a library provides sorting methods?

    1. A

      Library methods never work on real data

    2. B

      Algorithm knowledge helps select and adapt efficient building blocks for a problem

    3. C

      A programmer must rewrite every library method before using it

    4. D

      Understanding algorithms removes the need to test programs

    Correct answer
    B

    Algorithm knowledge helps select and adapt efficient building blocks for a problem

    Explanation

    Knowing how algorithms work helps programmers adapt them to a problem's constraints. Without that knowledge, they might rely on a general sort even when a more efficient approach is available.

  52. 52

    Why might an algorithm that is more complex to implement be a poor practical choice even if it is efficient?

    1. A

      Complex algorithms are harder to write correctly and maintain

    2. B

      Efficiency and implementation complexity are always identical

    3. C

      Complex algorithms cannot process large arrays

    4. D

      A complex algorithm necessarily uses no comparisons

    Correct answer
    A

    Complex algorithms are harder to write correctly and maintain

    Explanation

    More complicated algorithms are harder to implement correctly. Algorithm selection must balance efficiency with implementation difficulty.

  53. 53

    What does the example with a sorted array and a duplicate in both inputs illustrate about testing?

    1. A

      Testing is useful only after every method has been completed

    2. B

      Test data should avoid all repeated values

    3. C

      A single successful run proves that boundary cases work

    4. D

      Test data should include cases that expose known requirements, such as duplicate handling

    Correct answer
    D

    Test data should include cases that expose known requirements, such as duplicate handling

    Explanation

    Once duplicates were recognized as likely, a duplicate was added to the test data so the expected behavior could be checked directly.

  54. 54

    Why should the program warn users about corrupted input files rather than treating the resulting error as necessarily a sorting bug?

    1. A

      The user is responsible for sorting the output manually

    2. B

      Incorrect file contents can make a correct program produce an incorrect result

    3. C

      Corrupted files always contain duplicate values

    4. D

      Sorting algorithms automatically repair missing file lines

    Correct answer
    B

    Incorrect file contents can make a correct program produce an incorrect result

    Explanation

    If files are missing or contain extra data, the program may fail or produce incorrect results even when its sorting logic is correct. The user should be informed about the input problem.

Question 1 of 54
Question 1 of 54

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent