Modify the sequential search function in Figure 5.6 to allow for lists that are not sorted.
def Search(List, TargetValue):
if (List is empty):
Declare search a failure.
else:
Select the first entry in List to be TestEntry.
while (TargetValue > TestEntry and
there remain entries to be considered):
Select the next entry in List as TestEntry.
if (TargetValue = TestEntry):
Declare search a success,
else:
Declare search a failure.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Degarmo's Materials And Processes In Manufacturing
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
SURVEY OF OPERATING SYSTEMS
Starting Out With Visual Basic (8th Edition)
Mechanics of Materials (10th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Write the following function that sorts and merges two lists into a new sorted list. The new list contains only even numbers. def myMergeEvenList(list1, list2): Enter list1: 10,5,6,7 Enter list2: 12,8,5,0,1 The merged list is: 0,6,8,10,12arrow_forwardThe mapped list pattern Our second pattern is the mapped list pattern, described in video 4 3 mapped list pattern. Often we need to write a function that takes a list as a parameter and returns a new list in which each item in the original list is "mapped" to a new item in the result list. For example, the following function takes a list of numbers as a parameter and returns a list of all the numbers squared, e.g. squares ( [1, 3, 7]) returns [1, 9, 49]. def squares (nums): "Returns the squares of the given numbers""" result = [] for num in nums: result.append (num * num) return result Although this is just a special case of the accumulator pattern, it is so common that we give it its own name: the mapped list pattern. Consider the following function: def squares(nums): ""Returns the squares of the given numbers""" result = [] for num in nums: result.append (num * num) return result If the main program calls print(squares ( [5, -3, 2, 7]) what is the state table for the function…arrow_forwardBy pythonarrow_forward
- Note : It is required to done this by oop in C++. Create a queue, size of queue will be dependent on the user. Insert the numbers in the queue till the queue reaches the size. Create a menu and perform the following function on that queue. Enqueue: Add an element to the end of the queue Dequeue: Remove an element from the front of the queue IsEmpty: Check if the queue is empty IsFull: Check if the queue is full Peek: Get the value of the front of the queue without removing itarrow_forwardUsing the ListNode structure introduced in this chapter, write a function void printFirst(ListNode *ptr)that prints the value stored in the first node of a list passed to it as parameter. The function should print an error message and terminate the program if the list passed to it is empty.arrow_forward3. A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements. PROCEDURE isIncreasing(numberList) Tue 61 Line 1: Line 2: { Line 3: count 2 Line 4: REPEAT UNTIL(count > LENGTH(numberList)) Line 5: } IF(numberList[count] =. a. b. Lines 10 and 11 should be interchanged. d. In line 3, 2 should be changed to 1. 3.arrow_forward
- Create a queue, size of queue will be dependent on the user. Insert the numbers in the queue till the queue reaches the size. Create a menu and perform the following function on that queue. This is all done by using oop in C++. Enqueue: Add an element to the end of the queue Dequeue: Remove an element from the front of the queue IsEmpty: Check if the queue is empty IsFull: Check if the queue is full Peek: Get the value of the front of the queue without removing itarrow_forwardQ1:Write a function that returns a new list by eliminating theduplicate values in the list. Use the following function header:def eliminateDuplicates(lst):Write a test program that reads in a list of integers, invokes the function,and displays the result. Here is the sample run of the program Enter ten numbers: 2 3 2 1 6 3 4 5 2The distinct numbers are: 1 2 3 6 4 5 Q2:Write a program that reads in your Q1 Pythonsource code file and counts the occurrence of each keyword in the file.Your program should prompt the user to enter the Python source code filename. This is the Q1: code: def eliminateDuplictes(lst):newlist = [] search = set() for i in lst: if i not in search: newlist.append(i) search.add(i) return newlist a=[] n= int(input("Enter the Size of the list:")) for x in range(n):item=input("\nEnter element " + str(x+1) + ":") a.append(item) result = eliminateDuplictes(a) print('\nThe distinct numbers are: ',"%s" % (' '.join(result)))arrow_forwardDouble trouble def double_trouble(items, n): Suppose, if just for the sake of argument, that the following operation is repeated n times for the given list of items: remove the first element, and append that same element twice to the end of items. Which one of the items would be removed and copied in the last operation performed? Sure, this problem could be finger-quotes “solved” by actually performing that operation n times, but the point of this exercise is to come up with an analytical solution to compute the result much faster than actually going through that whole rigmarole. To gently nudge you towards thinking in symbolic and analytical solutions, the automated tester is designed so that anybody trying to brute force their way through this problem by performing all n operations one by one for real will run out of time and memory long before receiving the answer, as will the entire universe. To come up with this analytical solution, tabulate some small cases (you can implement the…arrow_forward
- Double trouble def double_trouble(items, n): Suppose, if just for the sake of argument, that the following operation is repeated n times for the given list of items: remove the first element, and append that same element twice to the end of items. Which one of the items would be removed and copied in the last operation performed?Sure, this problem could be finger-quotes “solved” by actually performing that operation n times, but the point of this exercise is to come up with an analytical solution to compute the result much faster than actually going through that whole rigmarole. To gently nudge you towards thinking in symbolic and analytical solutions, the automated tester is designed so that anybody trying to brute force their way through this problem by performing all n operations one by one for real will run out of time and memory long before receiving the answer, as will the entire universe.To come up with this analytical solution, tabulate some small cases (you can implement the…arrow_forwardDomino cycledef domino_cycle(tiles):A single domino tile is represented as a two-tuple of its pip values, such as (2,5) or (6,6). This function should determine whether the given list of tiles forms a cycle so that each tile in the list ends with the exact same pip value that its successor tile starts with, the successor of the last tile being the first tile of the list since this is supposed to be a cycle instead of a chain. Return True if the given list of domino tiles form such a cycle, and False otherwise. tiles Expected result [(3, 5), (5, 2), (2, 3)] True [(4, 4)] True [] True [(2, 6)] False [(5, 2), (2, 3), (4, 5)] False [(4, 3), (3, 1)] Falsearrow_forwardSearch closet 711 Complete the following function according to its docstring using a for loop. String method startswith may come in handy here. The lists we test will not all be shown; instead, some will be described in English. If you fail any test cases, you will need to read the description and make your own test. 1 from typing import List 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 def search_closet (items: List[str], colour: str) -> List[str]: """items is a list containing descriptions of the contents of a closet where every description has the form 'colour item', where each colour is one word and each item is one or more word. For example: ['grey summer jacket', 'orange spring jacket', 'red shoes', green hat'] colour is a colour that is being searched for in items. Return a list containing only the items that match the colour. >>>search_closet (['red summer jacket', 'orange spring jacket', 'red shoes', 'green hat'], 'red') ['red summer jacket', 'red shoes'] >>> search_closet (…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education