Starting from:
$30

$24

Homework 02: Peak Finding Problem Solution




Instruction




Submit your answer to this question via PC^2 under your account by the posted due time. No late submissions will be accepted. Note that homework is opened-book, but no outside assistance is permitted.




Problem







A peak element is an element that is




greater than its neighbors. There is an




integer matrix (see the figure) which has




the following features: the numbers in




adjacent positions are different; the




matrix has n rows and m columns; and a




is a 2D-peak iff a b, a d, a c, a e.




(hint: you only need to compare the




elements which has exactly four neighbors.)







Write a program to find a peak element which is an element a that is not smaller than its neighbors b, c, d. Return the element of the peak.




Sample input




1,2,3,6,5,16,41,23,22,6,15,17,20,21,7,14,18,19,20,10,13,14,11,10,9




2,2,4,6,8,21,27,30,31,6,16,20,24,28,9,14,18,19,20,13,5,14,7,10,1







Sample output




Find it! The peak elements is 41




Find it! The peak elements is 31

More products