You are a visitor at a political convention with delegates; each delegate is a member of exactly one political party. It is impossible to tell which political party any delegate belongs to; in particular, you will be summarily ejected from the convention if you ask. However, you can determine whether any pair of delegates belong to the same party or not simply by introducing them to each other. Members of the same party always greet each other with smiles and friendly handshakes; members of different parties always greet each other with angry stares and insults.

Required:
Suppose more than half of the delegates belong to the same political party. Design a divide and conquer algorithm that identifies all member of this majority party and analyze the running time of your algorithm.

Answers

Answer 1

Answer:

The algorithm is as follows:

Step 1: Start

Step 2: Parties = [All delegates in the party]

Step 3: Lent = Count(Parties)

Step 4: Individual = 0

Step 5: Index = 1

Step 6: For I in Lent:

Step 6.1: If Parties[Individual] == Parties[I]:

Step 6.1.1: Index = Index + 1

Step 6.2: Else:

Step 6.2.1 If Index == 0:

Step 6.2.2: Individual = I

Step 6.2.3: Index = 1

Step 7: Else

Step 7.1: Index = Index - 1

Step 8: Print(Party[Individual])

Step 9: Stop

Explanation:

The algorithm begins here

Step 1: Start

This gets the political parties as a list

Step 2: Parties = [All delegates in the party]

This counts the number of delegates i.e. the length of the list

Step 3: Lent = Count(Parties)

This initializes the first individual you come in contact with, to delegate 0 [list index begins from 0]

Step 4: Individual = 0

The next person on the list is set to index 1

Step 5: Index = 1

This begins an iteration

Step 6: For I in Lent:

If Parties[Individual] greets, shakes or smile to Party[i]

Step 6.1: If Parties[Individual] == Parties[I]:

Then they belong to the same party. Increment count by 1

Step 6.1.1: Index = Index + 1

If otherwise

Step 6.2: Else:

This checks if the first person is still in check

Step 6.2.1 If Index == 0:

If yes, the iteration is shifted up

Step 6.2.2: Individual = I

Step 6.2.3: Index = 1

If the first person is not being checked

Step 7: Else

The index is reduced by 1

Step 7.1: Index = Index - 1

This prints the highest occurrence party

Step 8: Print(Party[Individual])

This ends the algorithm

Step 9: Stop

The algorithm, implemented in Python is added as an attachment

Because there is an iteration which performs repetitive operation, the algorithm running time is: O(n)


Related Questions

Rupesh wants to try programming with Eclipse. What is the first step he should take to make that happen?


download the Eclipse IDE

download the current Java Development Kit

create a restore point

disable his security program

Answers

Answer:

create a restore point

Explanation:

PLEASE SOMEONE ANSWER THIS
If the old code to a passcode was 1147, and someone changed it, what would the new code be?

(I already tried 4117)



[I forgot my screen time passcode please someone help I literally can’t do anything on my phone.]

Answers

Answer:

Any of these?

Explanation:

1147. 4117. 7411

1471. 4171

1714. 4711

1741. 7114

1417. 7141

Answer:

1417

Explanation:

Which of the following characterizes how an enabled security program might react to a new program installation on a computer system?


It might alert you to space requirement excesses.

It might report an error or tell you that the file is corrupted.

It might protect the new installation from getting viruses.

It might automatically set a restore point for the computer system.

Answers

Answer:

It might automatically set a restore point for the computer system

Answer:

It might report an error or tell you that the file is corrupted.

Explanation:

Write a function charInWord that takes in two parameters, a char (character) and a word (string). The program will return true if the character is in the word and false if it is not. If word is not a string type, or if char is not a string type, or if the length of char is greater than 1, the function should return None. Your main program should call the function and print char is in word if the function returns true, or char is not in word if the function returns false, using the user-supplied values instead of char and word. The program should print incorrect input provided if the function returns None. Ex: If the input is: a cat the output is: a is in cat Ex: If the input is: a club the output is: a is not in club Ex: If the input is: ab horse the output is:

Answers

Answer:

The program in Python, is as follows:

def charInWord(chr,word):

   if len(chr)>1:

       print("None")

   elif not(chr.isalpha() and word.isalpha()):

       print("None")

   else:

       if word.find(chr) == -1:

           print(chr+" is not in "+word)

       else:

           print(chr+" is in "+word)

chr = input("Character: ")

word = input("Word: ")

print(charInWord(chr,word))

Explanation:

This defines the function

def charInWord(chr,word):

This checks if the length of character is greater than 1

   if len(chr)>1:

If yes, it prints None

       print("None")

This checks if the character or the word contains invalid character

   elif not(chr.isalpha() and word.isalpha()):

If yes, it prints None

       print("None")

This is executed for valid parameters

   else:

If the character is not present, this is executed

       if word.find(chr) == -1:

           print(chr+" is not in "+word)

If the character is present, this is executed

       else:

           print(chr+" is in "+word)

The main begins here

This gets the character

chr = input("Character: ")

This gets the word

word = input("Word: ")

This calls the method and prints the required output

print(charInWord(chr,word))

Other Questions
10) Which of the following is TRUE about low self-concept?A) Athletes found with low self-concept should consider getting help.B) Athletes with low self-concept tend to have a relationship with injuries.C) Athletes with low self-concept are less able to deal effectively with the high stress of competition & pressure tosucceed.D) All of the above are true about low self-concept. What geologic process could have formed the channel on Mars? When we multiply the second equation by two, what is the resulting equation?2(5x2y=8) Traits that are determined by more than one gene are called what? 3. What two rights wereAfrican-Americansgranted? I have a triangle with two equal sides and need to find x the angle they give me is 74, and my answer needs to be 53 or 56 but all i get is 32 can someone help me. Please help, will give brainliest!Which economic development occurred in Louisiana during World War II?A) Garbage removal businesses scaled back their operationsB) Total bank deposits within the state topped the $1 billion markC) A surplus of workers reduced the usage of farm machinesD) Planters decreased their output in an effort to raise crop prices In IJK, k = 64 inches, j = 17 inches and J=68. Find all possible values of K, to the nearest 10th of a degree. A store sells a package of 3 notebooks for $2. The point on the graph represents this ratio relationship. Which ordered pairs represent equivalent ratios that would also be on the graph? Choose all the correct answers. A (4, 6) B (6, 4) C (9, 6) D (12, 8) E (15, 9) F (16, 12) Which sentence best summarizes the central idea of this story? Most people turn to newspapers for information about what?A. Classified adsB. Local informationC. TV listingsD. Sports scores The intercepts of the line Y=-2x-21 Which of the following is an accurate description of relations between European states and the Ottoman Empire in the period 1815 to 1914?a. Russian, English and French expansion came at the expense of the Ottomansb. The Ottomans and French cooperated to colonize North Africac. The Ottomans supported nationalism in the Balkans to destabilize Europed. The Ottomans alliance with the Russians, English and French sought to impede German unification Solve |3x + 9| + 6 = 6 Question 4 options: A) x = 3 B) x = 3 or x = 3 C) No solutions D) x = 3 Which is a unicellular fungus? A Slime mold B Mushroom C Yeast D none of these A recipe calls for 2 cups of butter for every 5 cups of flour. Question 1 Part A What is the ratio of flour to butter? Write the ratio in three different ways. Do not simplify the ratios. Enter the correct answers in the boxes. Please help! Will give Brainliest. (Photo below) Which system of equations is best represented by the graph? If my pay rate is $9 an hour and I worked 7 hours and 45 minutes. How much money did I make? What is the Vertex?y = x - 8x-1