• retagged by
1,612 views
1 1 vote
Suppose that the votes of n people for different candidates (where there can be more than two candidates) for a particular office are the elements of a sequence. A person wins the election if this person receives a majority of the votes. What is the time complexity to find a candidate who receives majority of the votes using divide and conquer approach?

1 Answer

2 2 votes
A B B B B C C C D........

1 2 3 4 5 6 7 8 9 10 .......n

here i took the contestants as the A,B,C,D...each person(1...n) can vote to A,B,C,D...it will be in a sequence as the above...

so the sequence can be in traversed and number of votes for A,B,C,D can be stored in array,this is a O(N) method

Divide and Conquer method

now the sequence of array can be divided into n pieces and they are traversed to update the votes of A,B,C,D in arrray

so T(N)=2NT(N/N)+O(1)---which also takes the same complexity O(N)
• edited by
Position:
Show:

Related questions

2 2 votes
1 1 answer
2.0k
2.0k views
3 3 votes
1 1 answer
159
159 views
GO Classes asked Aug 24
159 views
Consider three recursive algorithms.Algorithm $\mathbf{1}$Divides a problem of size $N$ into two subproblems of size $N/2$ and performs constant additional work.$T_1(N)=2...
1 1 vote
1 answers 1 answer
1.1k
1.1k views
Emankashyap asked Apr 30, 2024
1,055 views
In quick sort, n numbers the (n/10)th element is selected as pivot using n^2 sortimng time complexity what will be the time complexity of quick sort is.....a)O(nlogn)b)O(...
3 3 votes
1 1 answer
2.4k
2.4k views
aashish1406 asked Aug 9, 2023
2,420 views
Which of the following statement(s) is/are true?(a) Quicksort and merge sort are both examples of divide and conquer algorithms.(b) If we randomly choose a pivot element ...