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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 38 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply