Question: Suppose that each row of an nn array A consists of 1s and 0s such that, in any row of A, all the 1s come
Suppose that each row of an n×n array A consists of 1’s and 0’s such that, in any row of A, all the 1’s come before any 0’s in that row. Assuming A is already in memory, describe a method running in O(nlogn) time (not O(n2) time) for counting the number of 1’s in A.
Step by Step Solution
3.44 Rating (154 Votes )
There are 3 Steps involved in it
To count the number of 1s in A we can do a binary search on ea... View full answer
Get step-by-step solutions from verified subject matter experts
