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
Musya8 [376]
2 years ago
14

You are a visitor at a political convention with delegates; each delegate is a member of exactly one political party. It is impo

ssible 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.
Computers and Technology
1 answer:
Fed [463]2 years ago
5 0

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

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

Download txt
You might be interested in
Hello! I am a new coder, so this is a simple question. But I am trying to create a code where you enter a number, then another n
slavikrds [6]

no longer returns an error but your math seems to have something wrong with it, always returns 0

Console.WriteLine("Enter a percentage here");

   int Percent = int.Parse(Console.ReadLine());

   Console.WriteLine("Enter your number here");

   int Number = int.Parse(Console.ReadLine());

   int result = Percent / 100 * Number;

6 0
2 years ago
After adding an image to her flyer, Danica played around to see which layout would look the best. At one point, her text was on
Norma-Jean [14]

Answer:

Position Feature

Wrap text feature

Picture tools

Explanation:

3 0
3 years ago
Read 2 more answers
Graphic characters used to identify items on an unordered list first line indent is called _______
Elodia [21]

Answer: they are calles BULLETS

Explanation:

4 0
3 years ago
What is the best definition for a relationship?
velikii [3]

Answer:

special instance of a dataset

7 0
3 years ago
The user location is usually a city
castortr0y [4]
What do you mean but I think yes the user location is usually a city
4 0
3 years ago
Other questions:
  • Research the disadvantages of the computer and explain them.​
    15·1 answer
  • How do I get more points?
    13·2 answers
  • HELP URGENT
    12·2 answers
  • Minerals that contain the elements silicon and oxygen are called ______.
    7·1 answer
  • A descriptive study represents the highest level on the knowledge-level continuum.
    11·1 answer
  • Many inventions have enabled us to use digital cameras. The biggest difference between traditional and digital cameras is that d
    10·1 answer
  • A program that will read each player’s name and golf score as keyboard input,
    9·1 answer
  • Help pweaseee!! Lloyd has created a validation script for a data entry form. What property should he use to test for a selected
    10·1 answer
  • Aurelia is designing a user interface for a new game app. Which of the following should she taken into consideration for the use
    7·1 answer
  • What does data warehousing allow organizations to achieve?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!