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
C++ Programming: From Problem Analysis To Program Design, Loose-leaf Version
- 1. Here is how the built-in sum function can be combined with Python’s comprehension syntax to compute the sum of all numbers in an n x n data set, represented as a list of lists: sum(sum(subset) for subset in data) Group of answer choices True False 2. Which of the following statements are correct? Group of answer choices a) A stack is a collection of objects that are inserted and removed according to the Last-in First-out principle; whereas, queue is based on the First-in First-out principle. b) A queue would be a logical choice for a data structure for a Web server responding to requests. c) Unlike arrays, linked list elements are not stored at a contiguous location; the elements are linked using pointers.arrow_forwardWRITE THE MAIN.CPP FOR THIS PROGRAM a. Write a version of the sequential search algorithm that can be used to search a sorted list. (1, 2) b. Consider the following list: 2, 20, 38, 41, 49, 56, 62, 70, 88, 95, 100, 135, 145 Using a sequential search on ordered lists, that you designed in (a), how many comparisons are required to determine whether the following items are in the list? (Recall that comparisons mean item comparisons, not index comparisons.) (1, 2) 2 57 88 70 135 Write a program to test the function you designed. Note: Have the function,seqOrdSearch, return -1 if the item is not found in the list. (return the index of the item if found).arrow_forward1. 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).arrow_forward
- Tukey's ninther def tukeys_ninthers(items): Back in the day when computers were far slower and had a lot less RAM for our programs to burrow into, special techniques were necessary to achieve many things that are trivial today with a couple of lines of code. In this spirit, "Tukey's ninther" is an approximation algorithm from the seventies to quickly find some value that should be “reasonably close” to the median element of the given unsorted list. For the purposes of this problem, the median element of the list is defined to be the element that would end up in the middle position if that list were sorted. This makes the median unambiguous, regardless of the elements and their multiplicities. This function is not tasked to find the true median, which would be a trivial one-liner by sorting items, but find and return the same element that Tukey's ninther algorithm would return for those items. Tukey's algorithm splits the list into triplets of three elements, and finds the median of…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_forward7) Implement counting sort over a list of keys that lie within the range (a, b),where a and b are small positive integers input by the user.8) Implement bucket sort with an array of lists data structure to sort i) a list ofstrings, ii) a list of floating point numbers and iii) a list of integers, which areuniformly distributed over a range, for an appropriate choice of the number ofbuckets.arrow_forward
- 1. Write a C program that will initially create a SORTED list containing the following and then run the program:DianeJackKatherineMitchRobbie Answer and explain the following questions below:a) If we check the memory location of each element in the list, what would it be? What index represent each element?b) What happens if we add Morrie in the list? What will be its index value? c) What does the new list looks like? Where do you think Morrie should be placed and why? With the same list above (with Morrie added), delete/remove Jack. Answer and explain the following questions below:a) What is the new list? Identify the elements of the list and its index.b) What happened to the former location occupied by Jack?arrow_forwarddiscrete mathematics (a) Apply the bubble sort to the following list and write the modified list in every cycle [6, 12, 8, 11, 15, 14, 17, 2, 18, 7] (you may stop after it is fully sorted). (b) Merge the following two sets and write the merging list in every iteration [3, 5, 6, 8, 10, 11, 15] and [4, 7, 9, 13, 17]arrow_forwardPlease code this in Java Or C or C++ Given two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and return the sum as linked list: Example : Input : (7-> 1 -> 6) + (5-> 9-> 2). That is 617 + 295 = 912 Output : 2-> 1 -> 9 Expected time complexity : O(m+n), where m and n are no. of nodes in first and second linked list respectively.arrow_forward
- You were tasked to do programs that will illustrate the use of lists implemented using an array. One uses a sorted list, the other an unsorted list. Run the programs separately and answer the following questions. Write a program that will initially create an UNSORTED list containing the following and then run the program: Mitch Diane Jack Robbie Katherine Answer and explain the following questions below: Ifwecheckthememorylocationofeachelementinthelist,whatwoulditbe?What index represent eachelement? What happens if we add Morrie in the list? What will be its indexvalue? Whatdoesthenewlistlooklike?WheredoyouthinkMorrieshouldbeplacedand why? With the same list above (with Morrie added), delete/remove Jack. Answer and explain the following questions below: What is the new list? Identify the elements of the list and itsindex. What happened to the former location occupied byJack? Write a program that will initially create a SORTED list containing the following and then run…arrow_forwardUse Java : Delete N Nodes After M Nodes of a Linked List You are given the head of a linked list and two integers m and n.Traverse the linked list and remove some nodes in the following way:- Start with the head as the current node.- Keep the first m nodes starting with the current node.- Remove the next n nodes- Keep repeating steps 2 and 3 until you reach the end of the list.Return the head of the modified list after removing the mentioned nodesarrow_forwardDo you know what the difference is between a single-linked list and a doubly-linked list? When is it better to use a singly-linked list rather than a doubly-linked list?When is it better to use a doubly-linked list rather than a singly-linked list? In a search for a node that is part of a linked list with N elements, how many nodes will be visited and how long will it take? Describe the best- and worst-case scenarios that may occur during a search operation.Explain why the RemoveAfter() function is present in a singly-linked list yet the Remove() function is present in a doubly-linked list.Could the RemoveAfter() function be extended to include a doubly-linked list as well as a simple list? Explain why you believe this is the case, or why you believe it is not the case.What are the chances of implementing a Remove() function for a singly-linked list? Explain why you believe this is the case, or why you believe it is not the case.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning