- Game Theory 2person Zero-Sum Game
- April 13th, 2010 - Sioux Falls, SD city election sample
- 2010 League of Women Voters Primary Election Guide
- Election System
- Applied Mathematics Mam1044H sunflower and fractal project
- Ch_6_Part_1
- Election Day 2010 Public Advocate Voting Complaints
- SMS System
- 1948_reith5
- scimakelatex.10184.pepe+garz.loquillo
- GATE 2010 MN Aptitude Final
- Ar Thematic
- Decoupling SCSI Disks from I/O Automata in Consistent Hashing
- A Case for Telephony
- Green Party Responses to the Expats
- Dela Cruz vs. Comelec
- Scimakelatex.16428.Wag
- Synthesizing IPv6 and Internet QoS
- 26185
- 25755

You are on page 1of 20

Communication & Computing Group

Department of CSE, NIT Rourkela

Email: bdsahu@nitrkl.ac.in, 9937324437, 2462358

Moodle server : http://moodle.nitrkl.ac.in

The MinMax Problem

Given a sequence of integers, find the minimum and the

maximum values.

The straightforward solution to this problem is to scan

the elements searching for the minimum, which would

require n−1 comparisons, then scan the elements one more

time to search for the maximum.

Thus in total, there will be 2n−2 comparisons.

Algorithm Straightforward maximum and minimum

Algorithm Straightforward maximum and minimum

minimum, which would require n−1 comparisons, then scan the

elements one more time to search for the maximum.

Thus in total, there will be 2n−2 comparisons [best, average and

worst case].

4 Maximum and Minimum

An immediate improvement

Count of comparisons performed by the algorithm

increasing order. The number of element comparisons is

n-1.

The worst case occurs when the elements are in

decreasing order. In this case the number of element

comparisons is 2(n-1).

The average number of element comparison is less than

2(n - 1).

On the average, a[i] is greater than max half the time,

and so the average number of comparisons is 3n/2 - 1

A divide-and-conquer algorithm for the MinMax problem

8 Maximum and Minimum

The tree of recursive calls for computing MinMax(A,1,16).

Analysis

T ( 2) 1 (assume N 2 ) k

T ( N ) 2T ( N / 2) 2

T ( N ) 2[ 2T ( N / 4) 2] 2

T ( N ) 2 T ( N / 2 ) ( 2 2)

2 2 2

r 1

T (N ) 2 T (N / 2 ) 2

r r i

i 1

Analysis…

k 2

T (N ) 2 k 1

T (N / 2 k 1

) 2 2 i

i 0

T ( N ) 2 k 1 2( 2 k 1 1)

N N

T (N ) 2( 1) N

2 2 Note : 2

i 0

i

2 N 1

1

3N

T (N ) 2

2

Note, although this is still O(N), it is better than the

T(N)=2N found earlier.

Thanks for Your Attention!

APPENDIX

C Program to find maximum/minimum element in array

C Program to find maximum/minimum element in array

#include <stdio.h>

int main()

{

int arr[100];

int i, max, min, size;

/* Reads size array and elements in the array */

printf("Enter size of the array: ");

scanf("%d", &size);

printf("Enter elements in the array: ");

for(i=0; i<size; i++)

{ scanf("%d", &arr[i]); }

C Program to find maximum/minimum element in array

max = arr[0];

min = arr[0];

/*

* Finds maximum and minimum in all array elements.

*/

for(i=1; i<size; i++)

{

/* If current element of array is greater than max */

if(arr[i]>max)

{

max = arr[i];

}

C Program to find maximum/minimum element in array

/* If current element of array is smaller than min */

if(arr[i]<min)

{

min = arr[i];

}

}

/*

* Prints the maximum and minimum element

*/

printf("Maximum element = %d\n", max);

printf("Minimum element = %d", min);

return 0;

}

Exercises

Exercises

How do I find the max and min value of an array in 3n/2−2

comparisons?

Consider a divide and conquer approach for finding minimum and

maximum elements in an array. Calculate the number of

operations in a divide and conquer approach when the input is not

an exact power of 2.

Write an algorithm to find minimum and maximum value using

divide and conquer and also drive its complexity.

Finding the Majority Element

In an election involving n voters and k candidates, each voter casts his

vote to one of the k candidates. Thus, the outcome from voting can be

represented as an n-element sequence where an element is an integer in

[1,k]. There are then various criteria to determine the winner. One

criterion could be to declare the candidate who scores more than

50% of the votes as the winner. Such element is known as the

majority element. Since the majority element is not always assured, an

alternative criterion is that the winner be the candidate that scores

most votes. Such element is known as the mode element. Still

another possibility is to have a rerun election limited to the

candidates who score above certain threshold.

Finding the Majority Element

Problem: Given a sequence of n elements where each

element is an integer in [1,k], return the majority element

(an element that appears more than n/2 times) or zero if

no majority element is found. A sequence of size 2 has a

majority only if both elements are equal. For an input of

size n=8 (and n=9), the majority element must appear at

least 5 times. For example, for the sequence

1,2,1,3,1,1,4,1 the majority element is 1.

- Game Theory 2person Zero-Sum GameUploaded byLimKokSiong
- April 13th, 2010 - Sioux Falls, SD city election sampleUploaded byjohnwynnejr
- 2010 League of Women Voters Primary Election GuideUploaded bymgrisafi
- Election SystemUploaded byFidel Duna Banzon
- Applied Mathematics Mam1044H sunflower and fractal projectUploaded byChloe Sole
- Ch_6_Part_1Uploaded byFreesyria Campaign
- Election Day 2010 Public Advocate Voting ComplaintsUploaded byCeleste Katz
- SMS SystemUploaded bydc_mark
- 1948_reith5Uploaded byLume Spento
- scimakelatex.10184.pepe+garz.loquilloUploaded byLK
- GATE 2010 MN Aptitude FinalUploaded bySudip Choudhury
- Ar ThematicUploaded byprasannalaxmi825
- Decoupling SCSI Disks from I/O Automata in Consistent HashingUploaded byppjim
- A Case for TelephonyUploaded bylerikzzz
- Green Party Responses to the ExpatsUploaded byThe Expats
- Dela Cruz vs. ComelecUploaded bybillietot
- Scimakelatex.16428.WagUploaded byOne TWo
- Synthesizing IPv6 and Internet QoSUploaded byTom Hanks
- 26185Uploaded byAdamo Ghirardelli
- 25755Uploaded byAdamo Ghirardelli
- Intro to Programming1Uploaded byradebp
- The Impact of Relational Modalities on TheoryUploaded byGath
- wUploaded byLuck
- Epistemologies for APsUploaded byJohn
- VA-HD-94 Shelly Simonds' Memorandum in Support of Motion for Reconsideration (Dec. 2017)Uploaded bydailykos
- SAMPLE TOS 2017.xlsxUploaded byBhickoy Delos Reyes
- best lesson planUploaded byapi-398545121
- unit-IUploaded byshailajapede
- UCO Reporter, August 2018 Edition, July 27, 2018Uploaded byucopresident_2130533
- Qa Percentages AdwbUploaded byDeepika Neelapala

- DRYZECK - Deliberative Democracy in Divided SocietiesUploaded byJulián González
- S12. Maurice Duverger and the Study of Political Parties (Schlesinger 2006)Uploaded byAndrei Vîlcovan
- methodsspringunitplanUploaded byapi-130087742
- COMELEC Liquor Ban Resolution 9582Uploaded bytangubnet
- Laban v ComelecUploaded byLoisse Vitug
- The Bull's Eye - April 2012Uploaded bydbhsbullseye
- Hong Kong Tycoons Reluctant to Take Side Amid Occupy TurmoilUploaded byJeffrey Tse
- Diversity Committee LegislationUploaded byUofA_ASG
- Local Governance Mechanism in PakistanUploaded byAdnanYousuf
- Man, the Puppet: the art of controlling minds by Abram Lipsky (1925)Uploaded byDerrick Kardos
- The Hindu Diary of EventsUploaded bySachin Gaur
- Minalabac, Camarines SurUploaded bySun.Star Philippine news
- 260Uploaded bySimon Herteleer
- Absentee Ballot Request Form for Sarasota residentsUploaded bySarasotaObserver
- StarbucksUploaded byConstantin Emilian
- Blp Bye LawsUploaded byvenkatmurali99
- Sal F. Albanese, Tim Carl, Loretta Carl, Joseph Carolei, John Castelli, Stephen Clinton, Gregory Glover, Tinamarie Lambiasi, John O'donnell, Elaine Polenini, Rochelle Puglisi, Tobias Russo, Terry Silveira and Victor M. Suarez v. Federal Election Commission, Susan Molinari, Committee to Re-Elect Susan Molinari, 78 F.3d 66, 2d Cir. (1996)Uploaded byScribd Government Docs
- CCSCElectionsAmendment (1)Uploaded byColumbia Daily Spectator
- Spirit Lake v. JaegerUploaded byLaw&Crime
- Putnam Voice - 1/19/12Uploaded byThe Lima News
- Cotabato (North Cot.) - pUploaded byirene
- Kellstedt-Whitten 2013_26Oct (1)Uploaded byCarlos Esteban Carbajal Solano
- BylawUploaded byJayden K. Amolli
- November 14Uploaded byanna
- Clarity Idaho Voices for Change Now Poll Results July 2018Uploaded byIdaho Voices for Change Now
- Salvador, Lanao del NorteUploaded bySun.Star Philippine news
- SUP-REP-0153/2018Uploaded byRepositorio Ponencia FMP
- Sikh Manifesto 2015Uploaded bySikh Bee
- Some German counterstamps of the late seventeenth century and the standard of the Leipzig convention / [Herbert J. Erlanger]Uploaded byDigital Library Numis (DLN)
- Federal Court Notice of Application FORM 301_v3Uploaded byGlen McGregor

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.