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
Vaselesa [24]
3 years ago
9

Suppose that a list contains integers that are in order of largest to smallest and an integer can appear repeatedly in this list

.
1) Devise an algorithm that locates all occurrences of an integer x in the list.
2) Estimate the number of comparisons used.
You must show/explain your work.
Computers and Technology
1 answer:
salantis [7]3 years ago
6 0

Answer:

(a) The algorithm is as follows:

count = 0

for i = 1 to n:

  if x = xi:

       count++

print(count)

(b) n comparisons

Explanation:

Solving (a):

Assume the integer to locate is x and the elements of the list are: x_1, x_2, x_3, x_4..... x_n

Such that: x_1 \ge x_2 \ge x_3 ...... \ge x_n

The algorithm is as follows:

<em>count = 0</em>

<em>for i = 1 to n:</em>

<em>   if x = xi:</em>

<em>        count++</em>

<em>print(count)</em>

<em />

The above iterates through the count of the list (i.e. n) and makes comparison with each element of the list (i.e. element 1 to element n).

When a match is found, the count variable is incremented by 1 and printed at the end of the loop

Furthermore:

If there are 3 elements in the list, the algorithm makes 3 comparisons.

It makes 10 comparisons if there are 10 elements in the list.

<em>So: it makes n elements if there are n elements in the list</em>

You might be interested in
__________ is a collection of formatting options—such as a frame, a rounded shape, and a shadow—that changes a picture’s overall
LenaWriter [7]

Answer:

Picture Style

Explanation:

According to my research on the Microsoft Word Software, I can say that based on the information provided within the question the term being mentioned in the question is called a Picture Style. This is a feature in Microsoft Word that allows you to apply a style or effect to a picture in order to enhance the way it looks or presents, such as a frame, shadow, or shape.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

6 0
3 years ago
What is the name of the place where students access all of their course information? Student handbook. Learning management syste
ehidna [41]
The syllabus is where students can find their course information.
3 0
3 years ago
Which is one of the modes of game advertising?
-BARSIC- [3]

Answer:

I'm pretty sure its A

Explanation:

The Media it the biggest platform rn

7 0
3 years ago
Read 2 more answers
Software that enables you to display and interact with text and other media on the web is a web ________.
a_sh-v [17]
It's a web site or web page
5 0
4 years ago
How much do you think it would cost to develop an app?
netineya [11]

It really depends on the type of app. There are lots of free pieces of software but distribution is expensive.

Android - $20 one  time fee

IOS - $99 per year

5 0
3 years ago
Read 2 more answers
Other questions:
  • Simon wants to use an invoice template created by Office.com. The first step after selecting the File tab is to select
    14·1 answer
  • What is a alt key and how does it work
    14·2 answers
  • Which of the following refers to rules written by an organization or entity to guide behavior in a particular setting or situati
    7·2 answers
  • What aspect of web design is Gloria following when she uses the same color
    5·2 answers
  • Inthe old days, databases did NOT support ____________.
    10·1 answer
  • 1. You have just upgraded memory on a computer from 4 GB to 8 GB by adding one DIMM. When you first turn on the PC, the memory c
    13·2 answers
  • What are three attributes of the input tag
    5·1 answer
  • Once you have a listing of every unique combination of salesperson, product and location, what Excel function would you use to c
    14·1 answer
  • Consider the following code: String word [] = {"algorithm", "boolean", "char", "double"}; for ( int i =0; i &lt; word.length/2;
    11·2 answers
  • Write a program in Cto define a structure Patient that has the following members
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!