EBK C++ PROGRAMMING: FROM PROBLEM ANALY
EBK C++ PROGRAMMING: FROM PROBLEM ANALY
8th Edition
ISBN: 9781337514491
Author: Malik
Publisher: CENGAGE LEARNING - CONSIGNMENT
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
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).
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.
TROUBLESHOOT my PYTHON code, please :)   The code of a sequential search function is shown on textbook page 60. In fact, if the list is already sorted, the search can halt when the target is less than a given element in the list. For example, given my_list = [2, 5, 7, 9, 14, 27], if the search target is 6, the search can halt when it reaches 7 because it is impossible for 6 to exist after 7. Define a function linearSearchSorted, which is used to search a sorted list. This function displays the position of the target item if found, or 'Target not found' otherwise. It also displays the elements it has visited. To test your function, search for these targets in the list [2, 5, 7, 9, 14, 27]: 2, 6, 14, 27 and 28.   Expected output:   List: [2, 5, 7, 9, 14, 27] Search target: 2 Elements visited: 2 Target found at position 0 Search target: 6 Elements visited: 2 5 7 Target not found Search target: 14 Elements visited: 2 5 7 9 14 Target found at position 4 Search target: 27 Elements visited: 2…
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