C++ How to Program, An Objects-
Natural Approach, 11th Edition by
Paul J. Deitel
Complete Chapter Test Bank
are included (Ch 1 to 21)
** Immediate Download
** Swift Response
** All Chapters included
,Table of Contents are given below
1.Intro: Test-Driving Popular, Free C++ Software
2.Intro to C++ 20 Programming
3.Control Statements: Part 1
4.Control Statements: Part 2
5.Functions and an Intro to Function Templates
6.arrays, vectors, Ranges and Functional-Style Programming
7.(Downplaying) Pointers in Modern C++
8.strings, string_views, Text files, CSV Files and Regex
9.Custom Classes
10.OOP: Inheritance and Runtime Polymorphism
11.Operator Overloading, Copy/Move Semantics, Smart Pointers and RAII
12.Exceptions and a Look Forward to Contracts
13.Standard Library Containers and Iterators
14.Standard Library Algorithms and C++ 20 Ranges and Views
15.Templates, C++ 20 Concepts and Metaprogramming
16.C++ 20 Modules: Large-Scale Development
17.Parallel Algorithms and Concurrency: A High-Level View
18.C++ 20 Coroutines
19.Stream I/O and C++ 20 Text Formatting
20.Other Topics and a Look Toward C++ 23 and C++ 26
21.Computer Science Thinking: Searching, Sorting and Big O
,The test bank is organized in reverse order, with the last chapter displayed first, to ensure that all
chapters are included in this document. (Complete Chapters included Ch21-1)
C++ How to Program: An Objects-Natural Approach, 11e (Deitel)
Chapter 21 Computer Science Thinking: Searching, Sorting and Big O
21.1 Introduction
1) Which of the following statements is false?
A) Big O notation characterizes how much work algorithms may need to do to solve problems, enabling
you to compare algorithm efficiency.
B) Two common search algorithms are the simple linear search and the faster but more complex binary
search. Three common sorting algorithms are insertion sort, selection sort and the more efficient but more
complex recursive merge sort.
C) When sorting arrays, the result is the same regardless of the algorithm, so your algorithm choice
affects only the program's run time and memory use.
D) Algorithms that are easy to program (such as linear search, insertion sort and selection sort) are
typically more efficient than algorithms that are harder to program such as binary search and recursive
merge sort.
Answer: D
Topic: 21.1 Introduction
21.2 Efficiency of Algorithms: Big O
1) Which of the following statements A, B or C is false?
A) Suppose an algorithm tests whether an array's first element is equal to its second. If the array has 10
elements, this algorithm requires one comparison. If the array has 1,000 elements, the algorithm still
requires one comparison. The algorithm is completely independent of the array's number of elements and
is said to have constant run time–represented in Big O notation as O(1) and pronounced "order 1."
B) An O(1) algorithm does not necessarily require only one comparison. O(1) means that the number of
comparisons is constant–it does not grow as the array size increases.
C) An algorithm that tests whether the first array element is equal to any of the next three elements is
O(3).
D) All of the above statements are true.
Answer: C
Topic: 21.2 Efficiency of Algorithms: Big O
2) Which of the following statements A, B or C is false?
A) An algorithm that tests whether an array's first element is equal to any of the array's other elements
requires at most n—1 comparisons, where n is the array's number of elements. If the array has 10
elements, this algorithm requires up to nine comparisons. If the array has 1,000 elements, this algorithm
still requires up to 9 comparisons.
B) As n grows larger, the n in the expression n—1 "dominates," so subtracting 1 becomes inconsequential.
Big O highlights the dominant terms and ignores those that become unimportant as n grows. An
algorithm that requires n—1 comparisons is said to be O(n).
C) An O(n) algorithm is referred to as having a linear run time. O(n) is often pronounced "on the order of
n" or simply "order n."
D) All of the above statements are true.
Answer: A
Topic: 21.2 Efficiency of Algorithms: Big O
1
, 3) Suppose an algorithm tests whether any array element is duplicated elsewhere in the array. Which of
the following statements A, B or C is false?
A) First, the algorithm compares the first element with all of the array's other elements.
B) Then, the algorithm then compares the second element with all of the array's other elements except the
first–the second was already compared to the first. Then, the algorithm compares the third element with
all the other elements except the first two.
C) In the end, this algorithm makes a total of (n—1) + (n—2) + … + 2 + 1 or n2/2—n/2 comparisons.
D) All of the above statements are true.
Answer: D
Topic: 21.2 Efficiency of Algorithms: Big O
4) Which of the following statements A, B or C is false?
A) O(n2) is referred to as quadratic run time and pronounced "on the order of n-squared" or simply
"order n-squared."
B) When n is small, O(n2) algorithms on today's computers will not noticeably affect performance. But as
n grows, performance degrades rapidly.
C) More efficient algorithms often require clever coding and more work to create. Their superior
performance can be worth the extra effort, especially as n gets large.
D) All of the above statements are true.
Answer: D
Topic: 21.2 Efficiency of Algorithms: Big O
21.3 Linear Search
1) Which of the following statements A, B or C about linear search is false?
A) A linear search compares each element of an array with a search key.
B) Because the array is not in any particular order, it's just as likely that the search key will be found in
the first element as the last. On average, therefore, the algorithm must compare the search key with half
of the array's elements. Also on average, the algorithm must compare the search key to half of the
array's elements to determine that a value is not in the array.
C) Linear search works well for small or unsorted arrays but is inefficient for large arrays. For a large
sorted array, use a high-speed binary search.
D) All of the above statements are true.
Answer: B
Topic: 21.3 Linear Search
2) Which of the following statements about linear search is false?
A) The linear search algorithm runs in O(n) time.
B) Linear search's worst case is checking every element to determine whether a non-existent search key is
in the array.
C) If the array's size doubles, so does the number of comparisons.
D) Linear search can provide outstanding performance if the element matching the search key happens to
be at or near the back of the array.
Answer: D
Topic: 21.3 Linear Search
2