retagged by
991 views
1 votes
1 votes
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?
retagged by

1 Answer

2 votes
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

Related questions

2 votes
2 votes
1 answer
1
1 votes
1 votes
1 answer
4
lalitver10 asked Jan 4, 2022
612 views
T(n)=T(n/5)+T(7n/10)+ana: constantwhat will be the time complexity of the above recurrence relation??Please share the approach for this kind of recurrence relation