Consider below sequences. [code] array=60 90 10 100 40 150 90 reverse 2 to 3 array=60 10 90 100 40 150 90 reverse 3 to

Đạt Michio

New member
Consider below sequences.
Code:
    array=60 90 10 100 40 150 90
    reverse 2 to 3
    array=60 10 90 100 40 150 90
    reverse 3 to 6
    array= 60 100 150 40 100 90 90
      now printout from 1 to 6 :-- 60 100 150 40 100 90
How to achieve the above operation efficiently?
A. use linked lists
B. use avl trees
C. use red-black trees
D. use treaps (cartesian trees)
 
Answer: D
Explanation: This can be solved efficiently using treap which is a modification of cartesian tree. an attribute like “boolean reverse” can be maintained with every node representing whether to reverse or not.
 

Tìm kiếm

Back
Top