C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Question
100%
Book Icon
Chapter 16, Problem 1TF

a.

Program Plan Intro

To find whether a list is a collection of elements of the same type or not.

a.

Expert Solution
Check Mark
Program Description Answer

True.

Explanation of Solution

Explanation:

A list is a collection of elements that are of the same type. The elements of the list can be stored in a one-dimensional array. The size of the list can be described with the help of the number of elements that it can store.

Conclusion:

Therefore, the given statement is true.

b.

Program Plan Intro

To find whether the sequential search of the elements in a list assumes that the elements are sorted or not.

b.

Expert Solution
Check Mark
Program Description Answer

False.

Explanation of Solution

Explanation:

In a sequential search, the desired element is searched sequentially. The element is compared from the first element in the list to the last element in the list until the desired element is found in the list. The sequential search does not assume that the list is sorted in any order.

Conclusion:

Therefore, the given statement is false.

c.

Program Plan Intro

To find whether the given statement is true or not.

For a list of 100 elements, whether the number of key comparisons is 5050 or not.

c.

Expert Solution
Check Mark
Program Description Answer

False.

Explanation of Solution

Explanation:

The bubble sort is a sorting technique that sorts the list of elements by comparing them to each other. The first element is compared to the next element and sorted if required. Then, it is compared to the next element and so on until it is placed in its proper place. This process is repeated until the entire list is sorted.

The key comparisons in bubble sort are calculated using the formula:

  nn1/2

where n is the number of elements in the list.

Here, n =100

Number of key comparisons =100 1001/2 

  = 9900/2 = 4950

Conclusion:

Therefore, as per the above calculation, the given number of comparisons are not correct. Hence, the given statement is false.

d.

Program Plan Intro

To find whether the binary search of the elements in a list assumes that the elements are sorted or not.

d.

Expert Solution
Check Mark
Program Description Answer

True.

Explanation of Solution

Explanation:

The binary search technique is a searching technique in which the middle element of the list is calculated. Then the middle element is compared with the element that needs to be searched from the list. If it matches then the search is successful otherwise another list is chosen and again the middle element is calculated. This process is repeated until the desired element is not found in the list.

The elements in binary search are sorted in a certain order. The order may be ascending or descending. The binary search on a list assumes that the list of elements is sorted.

Conclusion:

Therefore, the given statement is true.

e.

Program Plan Intro

To find whether the binary search is faster on the ordered list and slower on the unordered list of elements is true or not.

e.

Expert Solution
Check Mark
Program Description Answer

False.

Explanation of Solution

Explanation:

The elements in binary search are sorted in a certain order. The order may be ascending or descending. The only necessary condition to search an element in the given list using the binary search technique is that the list must be sorted.

The binary search applies to an ordered list of elements. The search operation is performed using the binary search technique if the list is ordered. It cannot be applied to the unordered list of elements.

Conclusion:

Therefore, the given statement is false.

f.

Program Plan Intro

To find whether the given statement “a binary search is faster on larger lists and a sequential search is faster on smaller lists” is correct or not.

f.

Expert Solution
Check Mark
Program Description Answer

True.

Explanation of Solution

Explanation:

The binary search is performed on a sorted list of elements. Whenever the medium of the list is calculated half of the list is rejected based on the elements that need to be searched in the list. It shortens the list in every step. So, it is faster on larger lists.

While the sequential search is performed on unsorted lists. The element is searched till the end of the list. It increases the execution time of the sequential search. So, it is more suitable for the smaller lists.

Conclusion:

Therefore, the given statement is true.

g.

Program Plan Intro

To find whether a vector object declared with 10 elements can store 10 elements or not.

g.

Expert Solution
Check Mark
Program Description Answer

False.

Explanation of Solution

Explanation:

A list is implemented using the vector type. It is implemented in the same as the array is implemented. The only difference is that the size of the vector can increase during the time of execution. If the vector object of size 10 is declared, it can shrink or expand to store more or fewer elements than 10.

Conclusion:

Therefore, the given statement is false.

h.

Program Plan Intro

To find whether the given statement “the expression vecList.capacity() returns the number of elements that can be added to the vecList” is correct or not.

h.

Expert Solution
Check Mark
Program Description Answer

True.

Explanation of Solution

Explanation:

The vector class contains many operations that can be performed on the vector object. The vecList.capacity() is the operation that returns the number of elements that can be added to the vecList.

Conclusion:

Therefore, the given statement is true.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education