Data Structures Chapter 9 Test 1 and 2
38 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

The advantage of a linear search is that

  • it can be used on unordered data.
  • it is simple.
  • both A and D (correct)
  • it is fast.
  • it is efficient.
  • A(n) ______ search is more efficient than a(n) ______ search.

  • string, double
  • integer, double
  • binary, linear (correct)
  • linear, binary
  • None of the above. All searches are equally efficient.
  • The linear search is adequate for searching through ______ arrays, but not through ______ ones.

  • any regular, vector
  • ascending, descending
  • char, string
  • int, double
  • small, large (correct)
  • Using a linear search, you are more likely to find an item than if you use a binary search.

    <p>False</p> Signup and view all the answers

    A binary search begins by examining the ______ element of an array.

    <p>middle</p> Signup and view all the answers

    If the item being searched for is not in the array, binary search stops looking for it and reports that it is not there when

    <p>array index first &gt; array index last.</p> Signup and view all the answers

    When searching for an item in an unordered set of data, binary search can find the item more quickly than linear search.

    <p>False</p> Signup and view all the answers

    A search can be performed on an array of

    <p>all of the above whether the data is in order or not.</p> Signup and view all the answers

    A sorting algorithm can be used to arrange a set of ______ in ______ order.

    <p>All of the above.</p> Signup and view all the answers

    The ______ sort usually performs fewer exchanges than the ______ sort.

    <p>selection bubble</p> Signup and view all the answers

    To find a value that is in an unordered array of 100 items, how many values must linear search examine on average?

    <p>50</p> Signup and view all the answers

    To determine that an item is not in an unordered array of 100 items, how many values must linear search examine on average?

    <p>100</p> Signup and view all the answers

    To find a value in an ordered array of 100 items, how many values must binary search examine at most?

    <p>7</p> Signup and view all the answers

    If a bubble sort is used to arrange the numbers 7 5 3 9 2 6 in ascending order, what order will the data be in after the first pass?

    <p>5 3 7 2 6 9</p> Signup and view all the answers

    If a selection sort is used to arrange the numbers 7 5 3 9 2 6 in ascending order, what order will the data be in after the first pass?

    <p>2 5 3 9 7 6</p> Signup and view all the answers

    When sorting an array of objects, if the values in the data member being sorted on are out of order for two objects, those two data values should be swapped.

    <p>False</p> Signup and view all the answers

    Any sorting algorithm, such as bubble sort or selection sort, that can be used on data stored in an array can also be used on data stored in a vector.

    <p>True</p> Signup and view all the answers

    If algorithm A requires 2n + 1 basic operations to process an input of size n, and Algorithm B requires 3n + 2 basic operations to process the same input, algorithms A and B are considered to be equally efficient.

    <p>True</p> Signup and view all the answers

    A ______ search uses a loop to sequentially step through an array.

    <p>linear</p> Signup and view all the answers

    A binary search requires that the elements be in order.

    <p>True</p> Signup and view all the answers

    The ______ search is adequate for searching through small arrays, but not through large ones.

    <p>linear</p> Signup and view all the answers

    Using a binary search, you are more likely to find an item than if you use a linear search.

    <p>False</p> Signup and view all the answers

    If a binary search is used to search for the number 4 in the 11-element array shown here int A[] = {1, 2, 3, 4, 6, 7, 8, 9, 10, 12, 17}; which value will the 4 be compared to first?

    <p>7</p> Signup and view all the answers

    To determine that a value is not present in an unordered array of 50 items, how many values must linear search examine on average?

    <p>50</p> Signup and view all the answers

    To find a value that is in an unordered array of 50 items, how many values must linear search examine on average?

    <p>25</p> Signup and view all the answers

    To find a value in an ordered array of 50 items, how many values must binary search examine at most?

    <p>6</p> Signup and view all the answers

    When searching for a particular object in an array of objects, it is necessary to compare the search key to the value in each examined object's key field.

    <p>True</p> Signup and view all the answers

    A(n) ______ algorithm arranges data into some order.

    <p>sorting</p> Signup and view all the answers

    Sorted data can be ordered

    <p>in all of the above ways.</p> Signup and view all the answers

    When an array is sorted from highest to lowest, it is said to be in ascending order.

    <p>False</p> Signup and view all the answers

    If a bubble sort is used to arrange the numbers 8 6 4 9 3 7 in ascending order, what order will the data be in after the first pass of the sort is completed?

    <p>6 4 8 3 7 9</p> Signup and view all the answers

    If a selection sort is used to arrange the numbers 8 6 4 9 3 7 in ascending order, what order will the data be in after the first pass of the sort is completed?

    <p>3 6 4 9 8 7</p> Signup and view all the answers

    The ______ sort usually performs more exchanges than the ______ sort.

    <p>bubble, selection</p> Signup and view all the answers

    Selection sort requires _____ passes to put n data items in order.

    <p>n - 1</p> Signup and view all the answers

    When sorting an array of objects, if the values in the data member being sorted on are out of order for two objects, those two data values should be swapped.

    <p>False</p> Signup and view all the answers

    Any sorting algorithm, such as bubble sort or selection sort, that can be used on data stored in an array can also be used on data stored in a vector.

    <p>True</p> Signup and view all the answers

    We can estimate the ______ of an algorithm by counting the number of basic steps it requires to solve a problem.

    <p>efficiency</p> Signup and view all the answers

    If algorithm A requires 2n + 1 basic operations to process an input of size n, and Algorithm B requires 3n + 2 basic operations to process the same input, algorithms A and B are considered to be equally efficient.

    <p>True</p> Signup and view all the answers

    Study Notes

    Chapter 9 Test 1 and 2

    • Linear Search Advantage: Simple, usable on unordered data.
    • Binary Search Advantage: More efficient than linear search for ordered data.
    • Linear Search Use Cases: Arrays of ints, doubles, chars and strings. Not ideal for large ordered arrays.
    • Linear Search Limitations: Not efficient on large or ordered data.
    • Binary Search Use Cases: Ordered arrays to find a specific item quickly.
    • Binary Search for Missing Item: Array index first is greater than array last, or boolean variable found equals false.
    • Binary Search Starting Point: Examines the middle element of the array.
    • Binary Search Efficiency: More efficient for searching ordered data.
    • Sorting Algorithm Use Cases: Arranging data (numbers, strings, etc.) in ascending or descending order.
    • Bubble Sort: A sorting algorithm that progressively moves values to their correct positions.
    • Bubble Sort Pass Order: Values are swapped on each pass to move larger values towards the end
    • Selection Sort Pass Order: Finds the smallest element in each pass and places it in the beginning.
    • Sorting Algorithms and STL Vectors: Possible to use bubble and selection sort with STL vectors.
    • Algorithm Complexity: Measured by the number of basic steps for a given input size.
    • Object Comparison in Arrays of Objects: Compare search key with a certain field in each object.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Chapter 9 Test 1 PDF

    Description

    This quiz covers key concepts from Chapter 9 related to linear and binary search algorithms, including their advantages, use cases, and limitations. Additionally, it discusses sorting algorithms, focusing on bubble sort and its operational mechanics. Test your understanding of these fundamental data structures and algorithms.

    More Like This

    Use Quizgecko on...
    Browser
    Browser