Page 1 of 1

Problem 7. New York has many tall buildings, but only some of them have a clear view of Hudson River. Suppose we are giv

Posted: Fri May 20, 2022 5:05 pm
by answerhappygod
Problem 7 New York Has Many Tall Buildings But Only Some Of Them Have A Clear View Of Hudson River Suppose We Are Giv 1
Problem 7 New York Has Many Tall Buildings But Only Some Of Them Have A Clear View Of Hudson River Suppose We Are Giv 1 (42.51 KiB) Viewed 40 times
Problem 7. New York has many tall buildings, but only some of them have a clear view of Hudson River. Suppose we are given an array A1,..., n] that stores the height of n buildings on a city block, indexed from east to west. Building i has a good view of Hudson River if and only if every building to the west of i is shorter than i. Here is an algorithm that computes which buildings have a good view of Hudson River. Analyze the correctness and running time of the algorithm. Algorithm: GoodView (A[1,..., n]) 1: Initialize a stack S 2: for i = 1,...,n do 3: while S is not empty and A > Aſtop(S)] do 4: Pop(S) 5: end while 6: Push(S,) 7: end for 8: return s