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!
Students have asked these similar questions
Mark the following statements as true or false. A sequential search of a list assumes that the list elements are sorted in ascending order. A binary search of a list assumes that the list is sorted.
1. a function that takes in a list (L), and creates a copy of L. note: The function should return a pointer to the first element in the new L. [iteration and recursion].   2. a function that takes in 2 sorted linked lists, and merges them into a single sorted list. note: This must be done in-place, and it must run in O(n+m).
Select which of the following statements about searching for items in a list is incorrect. Group of answer choices   1. In an unsorted list, if the item is not present in the list, we will need to check every single item. In a sorted list, if we start the search at the smallest item, at most we would only need to check all items smaller than the target. If we get to an item larger than the target we can end our search early. This would make searching faster in the sorted list.   2. Sorting a list only makes sense for primitive types (ints, doubles) and Strings but not objects. For this reason we cannot sort a list of objects, and will always have to check each object in a list when we search for a target object.   3. In an unsorted list you need to check each item, to see if it is the item you want. If the list is sorted you can look at the middle item and then you can direct your search to the relevant portion of the list (higher or lower). This is called binary search. This will…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning