Embercode
✕
Dynamic ProgrammingQuick quiz

LIS in n log n

7 questions. Covers LIS in n log n with patience piles.

Questions 1 to 5 of 7

  1. 1. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { vector<int> a = {3, 1, 2, 2, 4, 3, 5}; vector<int> tail; for (int x : a) { auto it = lower_bound(tail.begin(), tail.end(), x); if (it == tail.end()) tail.push_back(x); else *it = x; } cout << "LIS length = " << tail.size() << endl; for (int t : tail) cout << t << " "; cout << endl; } ``
  2. 2. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { vector<int> t1, t2; for (int x : {2, 6, 6, 3, 7}) { auto it1 = lower_bound(t1.begin(), t1.end(), x); if (it1 == t1.end()) t1.push_back(x); else *it1 = x; auto it2 = upper_bound(t2.begin(), t2.end(), x); if (it2 == t2.end()) t2.push_back(x); else *it2 = x; } cout << "strict length = " << t1.size() << endl; cout << "non-strict length = " << t2.size() << endl; } ``
  3. 3. What is the time complexity of the length-only program for n numbers?
  4. 4. The lesson says the link method takes roughly how many steps for n = 200,000 numbers?
  5. 5. For the input 1 2 0, what is the tail list after all three numbers are read?

5 question(s) left on this page.