0 views

Uploaded by shower

AAD

- debatecommissionspeech
- Ruling in Ohio Provisional Ballots Case
- 1896 El Paso CO Vote for President
- MAMANLEYdiv and Conquer
- The Frum Voters Guide for the New York City Primary Elections
- Capstone Project Format
- Common Cause Georgia v. Kemp - NOTICE OF FILING OF DECLARATION OF CHRIS HARVEY
- Spring 2018 Candidate App.
- blockchain-spec.pdf
- Fundamentals of Data Structures - Ellis Horowitz, Sartaj Sahni.pdf
- 20140602 - Statement - Parliamentary and LGE Results
- 1. Carlos v Angeles
- Bank Model Papers 1
- lessonplan sa 80
- Consul Dossier En
- g.r
- Barber Agreeing Mcsally Can Intervene
- YK Rebutle
- Cobol
- Towards the Simulation of Redundancy

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.

- debatecommissionspeechUploaded byapi-263289045
- Ruling in Ohio Provisional Ballots CaseUploaded byProgressOhio251
- 1896 El Paso CO Vote for PresidentUploaded byJohn M
- MAMANLEYdiv and ConquerUploaded byadetejubello
- The Frum Voters Guide for the New York City Primary ElectionsUploaded byGotham Gazette
- Capstone Project FormatUploaded byJerome Elioses
- Common Cause Georgia v. Kemp - NOTICE OF FILING OF DECLARATION OF CHRIS HARVEYUploaded byAnonymous LoJdpi
- Spring 2018 Candidate App.Uploaded byWebmaster HUCM
- blockchain-spec.pdfUploaded byblue
- Fundamentals of Data Structures - Ellis Horowitz, Sartaj Sahni.pdfUploaded byShambo Sen
- 20140602 - Statement - Parliamentary and LGE ResultsUploaded byJohn Richard Kasalika
- 1. Carlos v AngelesUploaded byGladys Bantilan
- Bank Model Papers 1Uploaded byRamakanth Ravirala
- lessonplan sa 80Uploaded byapi-303485077
- Consul Dossier EnUploaded byEnrique Muguerza Judez
- g.rUploaded byKristine Faye
- Barber Agreeing Mcsally Can InterveneUploaded byarizonaspolitics
- YK RebutleUploaded byanon-676188
- CobolUploaded byVK.marar
- Towards the Simulation of RedundancyUploaded byPamela Lindsey
- LinzUploaded byRaúl S Cedillo
- goboard3Uploaded bypostscript
- lesing_22Uploaded bymojtaba_2424
- Carter Center Election Witnessing MissionUploaded byAhmed Zaki Osman
- 2008 Register & Vote Poster - Chinese, OhioUploaded byAPIAVote
- Greer Citizen E-Edition 10.17.18Uploaded bygreercitizen
- 6.25.10 Bysiewicz Announces State and Federal Seats for 44 Primaries in 2010 ElectionsUploaded byAlfonso Robinson
- February 28 Labor Law 2 LectureUploaded byTetDillera
- AM GMUploaded bybharanivldv9
- CCP104Uploaded byapi-3849444

- Petroleum Engineering Principles and PracticeUploaded byNabilaCL
- 1g_dgdrspUploaded byhieunguyenbk
- CV - English_Juris BaldunciksUploaded byHeather Lawson
- A New Classification of Isotherms for Gibbs Adsorption of Gases OnUploaded byleizar_death64
- Silicone Keyboard 177436Uploaded byFritz Bukowsky
- Briggs and Stratton ManualUploaded byildiko1234
- Defects in Hot Dip GalvanisingUploaded byMathews Joseph
- jurnal pegasUploaded byFirda Ferry Sanjaya
- Exposure to current affairs Talk shows An Empirical opinion formation in Balochistan YouthUploaded byNaseer Baloch
- Scholarship Terms and ConditionsUploaded byAnand Jaiswal
- Performance Appraisal & ManagementUploaded byaabbcc_19102014
- Catalogue_IMT-PN_ENUploaded byWahyu Ramadhani Kustiabudi
- k-90-2140_FM-200_10-6-14Uploaded byFrancisco Borges
- ISTQB sample question papers-part 1Uploaded bychall
- Ch01 51 TotalUploaded byLinda Rosalina
- TWI Ultrasonic Inspection Coursework 5Uploaded byHassanSoboh
- Plant Tissue Culture iPad OptimisedUploaded bymadura prasanga
- IIT_2012_12_13_p1_p2_Phy_UN1_SAUploaded byjassyj33
- 781207MCQ's _Unit III_Synthetic Organic PolymersUploaded byHoài Nguyễn Tô
- Computers, Maths and Minds _ Plus.mathsUploaded byAM004
- chapter3 USPUploaded byChristine Chuah
- Canon T2i ManualUploaded byXu Jun
- Navtec_HydraulicAccessoriesUploaded byJim Haig
- jurnalUploaded byHafiez Ahmad
- ICSSG Spanish TermsUploaded byRina Von Pettersen
- Dynamic Internal Table CreationUploaded bysouban7-1
- 01_Computer Abstractions and TechUploaded byAbd Arrahman Mesk
- Job Procedure for Eriction of TankUploaded byAnonymous i3lI9M
- M.sc BioTechUploaded byDeepak
- Report Final (1)Uploaded byPrateek Jaiswal