C++ Programming: From Problem Analysis To Program Design, Loose-leaf Version
C++ Programming: From Problem Analysis To Program Design, Loose-leaf Version
8th Edition
ISBN: 9781337684392
Author: Malik, D. S.
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
Answer the given question with a proper explanation and step-by-step solution. Write in Java:   Write a menu-driven program to illustrate the use of a linked list. The entries will only consist of integer number keys (values). The program should implement the following options in order: • Insert- insert a key into a list- not allowing duplicate integers. • Delete- delete a key from the list. • Search- finds or does not find a particular key in the list. • Print- prints the list graphically in horizontal form. If the list is empty output- "Nothing to print". • Size- count of all the keys in the list. • Sort- sorts the keys in the list in ascending order. • Reverse- reverses the order of the keys in the list • Rotate- moves the key at the front of the list to the end of the list. If the list has 0 or 1 elements it should have no effect on the list. • Shift- rearranges the keys of a list by moving to the end of the list all values that are in odd number positions (indexes) and otherwise…
A fibonacci series is defined as a series where the number at the current index, is the value of the summation of the index preceding it (index -1) and (index-2). Essentially, for a list fibonacci_numbers which is the fibonacci numbers series, fibonacci_numbers[i] = fibonacci_numbers[i-1] + fibonacci_numbers[i-2] The fibonacci series always begins with 0, and then a 1 follows. So an example for fibonacci series up to the first 7 values would be - 0, 1, 1, 2, 3, 5, 8, 13 Complete the fibonacci(n) function, which takes in an index, n, and returns the nth value in the sequence. Any negative index values should return -1. Ex: If the input is: 7 the output is: fibonacci(7) is 13 Important Note Use recursion and DO NOT use any loops. Review the Week 9 class recording to see a variation of this solution. def fibonacci(n):    if (n < 0 ):        return -1    else:        return n        fibonacci_numbers = (fibonacci[n - 1] + fibonacci[n - 2])    return fibonacci_numbers(n)   # TODO: Write…
For this exercise, a list of non-negative numbers will be given, for which the following operation can be done: subtract 1 from two contiguous elements from the list. It must say whether after any number of operations the list can be converted to a list of zeros.   EntryThe input will be a list of non-negative integers x_i such that 0 <= x_i <= 2000000000. ". DepartureIf the given list can be converted to a list of zeros with the operation defined above, print "YES", otherwise, print "NO". Examples Input Example 1 1 2Output Example 1 NOT Input Example 2 2 4 2Output Example 2 YES
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
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning