1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yKpoI14uk [10]
3 years ago
13

Design an application that has an array of at least 20 integers. It should call a module that uses the sequential search algorit

hm to locate one of the values. The module should keep a count of the number of comparisons it makes until it finds the value. Then the program should call another module that uses the binary search algorithm to locate the same value. It should also keep a count of the number of comparisons it makes. Display these values on the screen.
Computers and Technology
1 answer:
PIT_PIT [208]3 years ago
4 0

Answer:

  1. def sequenceSearch(myList, target):
  2.    count = 0
  3.    for x in myList:
  4.        count += 1
  5.        if(x == target):
  6.            return count  
  7.    
  8.    return -1
  9. def binarySearch(myList, target):
  10.    minIndex = 0
  11.    maxIndex = len(myList) - 1
  12.    count = 0
  13.    while(maxIndex >= minIndex):
  14.        middleIndex = minIndex + (maxIndex - minIndex)//2
  15.        count += 1
  16.        if(target < myList[middleIndex]):
  17.            maxIndex = middleIndex - 1
  18.        elif(target > myList[middleIndex]):
  19.            minIndex = middleIndex + 1
  20.        else:
  21.            return count  
  22.    return -1
  23. myList = [4, 7, 9, 12, 15, 19, 21, 40, 57, 80, 91, 111, 123, 127, 145, 167, 178, 180, 210, 222]
  24. print(sequenceSearch(myList, 210))
  25. print(binarySearch(myList, 210))

Explanation:

Firstly, create a sequential search function that will take two parameter, list and target number (Line 1). In the function, create a counter variable, count and initialize it with zero (Line 2). Next create a for loop to start the sequential search from the first element of list and keep tracking of count (Line 4 -7). If target is found in the list, return the count (Line 7) otherwise return -1.

Next, create another function for binary search that will take the same input parameters as sequential search function (Line 11). In the binarySearch function, use the similar counter variable, count to track the number of searching (Line 14).  Next, use a while loop to implement the binary search algorithm that will keep comparing target against the list element in middle index (Line 20 - 25). If target is smaller than middle value adjust the maxIndex by having middleIndex -1. If target bigger than the middle value, set the minIndex to middleIndex - 1. Otherwise it will return the count. If the target is not found, return -1 (Line 27).

In the main program, create a sample list with 20 elements and then test the sequenceSearch and binarySearch function ny using the sample list and target = 210 as arguments. We shall get the output: 19 4

You might be interested in
Kamal plans to offer new, more favorable contracts to business customers who are now receiving a discount and use wireless servi
raketka [301]

Solution :

'AND" operation is a logical operation and is used in logical connective combining two statements and in truth tables.

Using AND operation verifies whether the outcome P and Q is true only when both the P as well as Q are true.  If one of the P or Q is not true, then outcome result will be false.

In the context, Kamal wishes to offer a new and more favorable contracts to the business customers who use a wireless services and receive a discount.

Therefore, using the AND operation of the customers as :

Customer     Wireless     Discount     Outcome

   A                   N                   N             FALSE

   B                   Y                   N             FALSE

  C                   N                   Y              FALSE

   D                   Y                   Y             TRUE

   

8 0
3 years ago
In a blockchain, each block has a unique hash value which is dependent on the hash value of the previous block in the chain. Wha
pantera1 [17]

Answer: hello your question lacks the required option, below are the missing options

A. The transaction data in the tampered block is deleted, and a copy is created with the same hash value.

B. The hash values of transaction data of subsequent blocks are validated, and the chain is broken.

C. The hash value for the entire block is nullified, creating a domino effect on all subsequent blocks.

D. The hash values of subsequent blocks are updated as soon as they are tampered with, and the chain continues.

answer : The hash values of subsequent blocks are updated as soon as they are tampered with, and the chain continues ( D )

Explanation:

What happens if a transaction data is changed in an earlier existing block in a Blockchain is that the Hash values of subsequent blocks will be updated as soon as they are tampered with and the chain will continue.

Blockchain is a specially design system for recording information, hence any change in data inputted in an earlier existing blocks that changes will automatically be updated as well in all preceding blocks.

4 0
3 years ago
HELLLP
mojhsa [17]

Explanation:

The output of this program is 5 7, because the first time bruce is printed, his value is 5, and the second time, his value is 7. The comma at the end of the first print statement suppresses the newline after the output, which is why both outputs appear on the same line.

Here is what multiple assignment looks like in a state diagram:



With multiple assignment it is especially important to distinguish between an assignment operation and a statement of equality. Because Python uses the equal sign (=) for assignment, it is tempting to interpret a statement like a = b as a statement of equality. It is not!

First, equality is symmetric and assignment is not. For example, in mathematics, if a = 7 then 7 = a. But in Python, the statement a = 7 is legal and 7 = a is not.

Furthermore, in mathematics, a statement of equality is always true. If a = b now, then a will always equal b. In Python, an assignment statement can make two variables equal, but they don’t have to stay that way:

a = 5

4 0
3 years ago
Read 2 more answers
What is the difference between the paste and paste special options
Darina [25.2K]

Paste special allows the item being transferred to be formatted in several different ways. Paste is just going to be transferred the exact way you copied it.

7 0
3 years ago
What is the influence of new technology on society?
sweet [91]

Answer:

E. New technology is beneficial but can also be used in a detrimental way.

Explanation:

New technology such as cryptocurrency (powered by blockchain technology) can be regarded as a welcome development that has benefited the society in so many good ways. However, cryptocurrency as a new technology also has disadvantages it presents to the society. One of such negative influence cryptocurrency has is that it can be used for illicit activities such as money laundering, funding terrorism and so on.

So, in summary, we can conclude that:

"New technology is beneficial but can also be used in a detrimental way."

5 0
3 years ago
Other questions:
  • Write a class named Averager containing: An instance variable named sum of type integer, initialized to 0. An instance variable
    6·1 answer
  • What's is the contribution of technology to the country?
    15·1 answer
  • Implement a recursive method named power that takes 2 integer parameters named base and expo. The method will return the base ra
    6·1 answer
  • What color mode would you use when designing for web &amp; devices?
    9·1 answer
  • define the term computer hardware and its various types mentioning 5 examples of IP or devices with one diagram each​
    9·1 answer
  • You are a developer for a news, entertainment, lifestyle, and fashion website. User traffic has steadily increased month-over-mo
    11·1 answer
  • How is technology moving the business world forward?
    13·1 answer
  • Help PLEASE ILL MARK as brainlest
    11·1 answer
  • You have been asked to replace a cracked screen on a laptop. The replacement screen was delivered today, but it did not include
    7·1 answer
  • Which benefit does the Cloud provide to start-up companies without access to large funding?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!