Data Structures Chapter 9 Test 1 and 2

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

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 (B)</p> Signup and view all the answers

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

<p>middle (A)</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. (A)</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 (B)</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. (E)</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. (E)</p> Signup and view all the answers

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

<p>selection bubble (E)</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 (C)</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 (A)</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 (B)</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 (A)</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 (A)</p> Signup and view all the answers

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

<p>linear (C)</p> Signup and view all the answers

A binary search requires that the elements be in order.

<p>True (A)</p> Signup and view all the answers

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

<p>linear (D)</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 (B)</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 (A)</p> Signup and view all the answers

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

<p>sorting (B)</p> Signup and view all the answers

Sorted data can be ordered

<p>in all of the above ways. (E)</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 (B)</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 (C)</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 (B)</p> Signup and view all the answers

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

<p>bubble, selection (B)</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 (B)</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 (A)</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 (E)</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 (A)</p> Signup and view all the answers

Flashcards

Linear Search Advantage

Linear search is simple and can be used on unordered data.

Binary Search Efficiency

More efficient than linear search; works best on ordered datasets.

Linear Search Suitability

Suitable for small arrays, less efficient for large, unordered datasets.

Linear Search vs. Binary Search

Linear search is more likely to find an item in an unordered set, while binary search is faster on ordered sets.

Signup and view all the flashcards

Binary Search Starting Point

Binary search starts by examining the middle element of the ordered array.

Signup and view all the flashcards

Binary Search Termination?

Binary search ends when the target item is not found because array index first is greater than array index last.

Signup and view all the flashcards

Binary Search and Unordered Data

Binary search is not suitable for unordered data; linear search is faster for unordered datasets.

Signup and view all the flashcards

Searchable Data Types

Arrays can hold integers, strings, and objects, requiring data to be in order for binary search.

Signup and view all the flashcards

Sorting Data Ordering

Sorting algorithms arrange data into ascending or descending order.

Signup and view all the flashcards

Bubble Sort vs. Selection Sort

Selection sort usually performs fewer exchanges than bubble sort when sorting data.

Signup and view all the flashcards

Linear Search Average for 100 Items

On average, linear search needs to examine 50 values in an unordered array of 100 items to find the target.

Signup and view all the flashcards

Binary Search Maximum Examination

In a sorted array of 100 items, binary search will examine at most 7 elements.

Signup and view all the flashcards

First Pass Bubble Sort Example

Given the unsorted array 7, 5, 3, 9, 2, 6, the first pass will result in the order 5, 7, 3, 9, 2, 6.

Signup and view all the flashcards

First Pass Selection Sort Example

Given the unsorted array 7, 5, 3, 9, 2, 6, the first pass of selection sort will result in the order 2, 5, 3, 9, 7, 6.

Signup and view all the flashcards

Sorting Objects

When sorting objects or structures, you need to specify the data member on which to sort.

Signup and view all the flashcards

Sorting Objects - Data Swapping

When sorting objects, swap the entire objects versus just individual data members, if they're out of order during the sort process.

Signup and view all the flashcards

Algorithm Efficiency

Efficiency of an algorithm is determined by number of basic steps it requires to address a given input size (n).

Signup and view all the flashcards

Algorithm Comparison

To compare algorithms, determine and compare the number of basic operations for a given input size.

Signup and view all the flashcards

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

More Like This

Use Quizgecko on...
Browser
Browser