Skip to main content
Tweeted twitter.com/StackCompSci/status/985999145356988422

So I have this algorithm that outputs the largest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: Largest value of an array

Maximum (A)

 
Maximum (A) m = A[1]  i = 1  while i < n   if A[i+1] > A[i]   m = A[i+1]   i = i+1   return m 

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

So I have this algorithm that outputs the largest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: Largest value of an array

Maximum (A)

m = A[1] i = 1 while i < n if A[i+1] > A[i] m = A[i+1]   i = i+1   return m 

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

So I have this algorithm that outputs the largest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: Largest value of an array
 
Maximum (A) m = A[1]  i = 1  while i < n   if A[i+1] > A[i]   m = A[i+1] i = i+1 return m 

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

Fix code styling markdown
Source Link

So I have this algorithm that outputs the highestlargest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: HighestLargest value of an array

Maximum (A)

m = A[1] i = 1 while i < n if A[i+1] > A[i] m = A[i+1] i = i+1 return m 

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

So I have this algorithm that outputs the highest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: Highest value of an array

Maximum (A)

m = A[1] i = 1 while i < n if A[i+1] > A[i] m = A[i+1] i = i+1 return m 

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

So I have this algorithm that outputs the largest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: Largest value of an array

Maximum (A)

m = A[1] i = 1 while i < n if A[i+1] > A[i] m = A[i+1] i = i+1 return m 

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

So I have this algorithm that outputs the highest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: Highest value of an array

Maximum (A)

  1. m = A[1]
  2. i = 1
  3. while i < n
  4. if A[i+1] > A[i]
  5.  m = A[i+1] 
  6. i = i+1
  7. return m
Maximum (A)

m = A[1] i = 1 while i < n if A[i+1] > A[i] m = A[i+1] i = i+1 return m 

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

So I have this algorithm that outputs the highest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: Highest value of an array

Maximum (A)

  1. m = A[1]
  2. i = 1
  3. while i < n
  4. if A[i+1] > A[i]
  5.  m = A[i+1] 
  6. i = i+1
  7. return m

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

So I have this algorithm that outputs the highest value of an array:

  • Input: $A[1,\dots,n]$, $n\geq 1$
  • Output: Highest value of an array

Maximum (A)

m = A[1] i = 1 while i < n if A[i+1] > A[i] m = A[i+1] i = i+1 return m 

I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.

edited tags
Link
Raphael
  • 73.4k
  • 31
  • 184
  • 406
Loading
added 20 characters in body
Source Link
Yuval Filmus
  • 280.9k
  • 27
  • 320
  • 518
Loading
Source Link
Loading