美文网首页
4.2 「Stanford Algorithms」Optiona

4.2 「Stanford Algorithms」Optiona

作者: 墨小匠 | 来源:发表于2020-09-26 21:33 被阅读0次

Optional Theory Problems

1. You are given as input an unsorted array of n distinct numbers, where n is a power of 2. Give an algorithm that identifies the second-largest number in the array, and that uses at most 𝑛+log2𝑛−2 comparisons.

2. You are a given a unimodal array of n distinct elements, meaning that its entries are in increasing order up until its maximum element, after which its elements are in decreasing order. Give an algorithm to compute the maximum element that runs in O(log n) time.

3. You are given a sorted (from smallest to largest) array A of n distinct integers which can be positive, negative, or zero. You want to decide whether or not there is an index i such that A[i] = i. Design the fastest algorithm that you can for solving this problem.

相关文章

网友评论

      本文标题:4.2 「Stanford Algorithms」Optiona

      本文链接:https://www.haomeiwen.com/subject/xyixuktx.html