a.
To find whether a list is a collection of elements of the same type or not.
a.
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.
To find whether the sequential search of the elements in a list assumes that the elements are sorted or not.
b.
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.
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.
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:
where n is the number of elements in the list.
Here,
Number of key comparisons
Conclusion:
Therefore, as per the above calculation, the given number of comparisons are not correct. Hence, the given statement is false.
d.
To find whether the binary search of the elements in a list assumes that the elements are sorted or not.
d.
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.
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.
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.
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.
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.
To find whether a
g.
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.
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.
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?
Chapter 16 Solutions
Mindtap Computing, 1 Term (6 Months) Printed Access Card For Malik's C++ Programming: From Problem Analysis To Program Design, 8th (mindtap Course List)
- Single Linked Linear List (S.L.L.L.) 1-Write a steps to search for a node contain a given value in a S.L.L.L. its head is given by pointer variable ( First ) 2-Write Recursive function to count number of nodes in a given S.L.L.L. 3-Write a steps to count number of nodes contain odd number in a given S.L.L.L. its head is given by pointer variable ( First ). 4-Write a steps to test values stored in S.L.L.L. if it is in ascending order or not .arrow_forwardOld MathJax webview Old MathJax webview In Java Some methods of the singly linked list listed below can be implemented efficiently (in different respects) (as opposed to an array or a doubly linked list), others not necessarily which are they and why? b. Implement a function to add an element before the first element. c. Implement a function to add an item after the last one element. d. Implement a function to output an element of the list. e. Implement a function to output the entire list. f. Implement a function to output the number of elements. G. Implement a function to delete an item. H. Implement a function to clear the entire list. I. Implement functionality to search for one or more students by first name, last name, matriculation number or course of study. J. Implement functionality to sort the records of the student, matriculation number and course according to two self-selected sorting methods.arrow_forwardTROUBLESHOOT 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…arrow_forward
- Indicate true or false for the following statements:(a) Every element in a list must have the same type.(b) A list’s size is fixed after it is created.(c) A list can have duplicate elements.(d) The elements in a list can be accessed via an index operator.arrow_forwardQuestion 2 A doubly linked list may be referred to as a complex type of linked list in which a node contains a pointer to the previous node (previous pointer) as well as the next node (next pointer) in the sequence. You have been given the following fruits: Apple, Lemon, Orange, Grape, Strawberry, Mango, Banana, Peach. Write a Python program that will insert these fruits into a sorted doubly linked list.arrow_forwardPlease answer the above question in python programming languagearrow_forward
- Exercise 6 Write a quicksort function of type int list -> int list. Here's a review of the quicksort algorithm. First pick an element and call it the pivot. (The head of the list is an easy choice for the pivot.) Partition the rest of the list into two sublists, one with all the elements less than the pivot and another with all the elements not less than the pivot. Recursively sort the sublists. Combine the two sublists (and the pivot) into a final sorted list.arrow_forward1a. Distinguish between singly-linked lists and doubly-linked lists. Give examples to illustrate your answer. 1b. You are preparing for your mid-semester examinations in an empty lecture hall at school. You left your laptop unattended for 15 minutes and returned to find that it was missing/stolen. Describe an algorithm to search for, and find, your missing/stolen laptop.arrow_forwardA list is given an = {6,2,-4,13,7} Answer the following questions. a. What is n in an? b. List all the steps of sorting this list using insertion sort. c. What is the output of this search? And what does it indicate?arrow_forward
- #python codecoud you provide comments and little explanation it would really help me to understandthankyouarrow_forwardWrite proceedures for the following: 1) Given a 9x9 grid of numbers (lists of lists, so [[1,2,3,4,5,6,7,8,9],[3,4,5,1,2,6,7,8,9],....]), a column number, and a fixed number between 1 and 9, determine if the fixed number appears in the column. (Unimportant here, but missing numbers for an incomplete grid will be zeros). The program should return a true or false.arrow_forwardsolve with python language pleasearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning