PROGRAMMING:Insertion order
A friend of yours is currently taking a class on algorithms and data structures. Just last week he learned about binary search trees and the importance of using self-balancing trees in order to
keep the tree height low and guarantee fast access to every node.
A friend of yours is taking a course on Algorithms and data structures. Just last week, he learned the importance of binary search trees and using self balancing trees to keep the height of the trees low and ensure fast access to each node.
Recall that a binary search tree is a binary tree with each node storing a key, and the property that the key of each node is greater than all keys in the left subtree of that node and less than all keys in the right subtree. A new key is inserted into the tree by adding a new leaf node with that key in the only position such that the property is maintained, as seen in the figure below.
Recall that a binary search tree is a binary tree. Each node stores a key and an attribute. The key value of each node is greater than all the key values in the left subtree of the node and less than all the key values in the right subtree. By adding a new leaf node, insert a new key into the tree and type it in the unique position to keep the attribute, as shown in the figure below.
![ QQ picture 20200801230141. PNG] (~ / 4bb6f03e-9c5f-4775-9107-a8168283504a. PNG)
To illustrate to him just how bad things can get without self-balancing, you want to show him that it is possible to build trees of nearly any height by carefully choosing an insertion order.
To show him how bad things can get without self balance, you have to show him that by carefully choosing the insertion order, you can build trees of almost any height.
You are given two integers n and k and want to construct a binary search tree with n nodes of height k (the height of a tree is the maximal number of nodes on a path from the root to a leaf).
To do so, you need to find a permutation of the integers from 1 to n such that, when they are inserted into an empty binary search tree in that order (without self-balancing), the resulting tree has height k.
Given two integers n and K, we want to construct a binary search tree with n nodes and its height K (the height of the tree is the maximum number of nodes on the path from root to leaf). To do this, you need to find an arrangement of integers from 1 to N. when they are inserted into an empty binary search tree in this order (without self balancing), the resulting tree has a height of K.
### **Input:**
The input consists of two integers n and k (1 ≤ k ≤ n ≤ 2 · 105), where n is the number of nodes in the tree and k is the exact height the tree should have.
The input consists of two integers n and K (1 ≤ K ≤ n ≤ 2.105), where n is the number of nodes and K is the exact height of the tree.
### **Output:**
If there is no solution, output impossible. Otherwise, output one line with n integers, the requested permutation. If there is more than one solution, any one of them will be accepted.
If there is no solution, output "impossible". Otherwise, the output line of N integers requires permutation. If there is more than one solution, any one of them will be accepted.
### **Sample Input 1:**
```in
7 4
```
### **Sample Output 1:**
```out
4 7 6 5 3 2 1
```
### **Sample Input 2:**
```in
8 3
```
### **Sample Output 2:**
```out
impossible
```
answer:If there is no answer, please comment
keep the tree height low and guarantee fast access to every node.
A friend of yours is taking a course on Algorithms and data structures. Just last week, he learned the importance of binary search trees and using self balancing trees to keep the height of the trees low and ensure fast access to each node.
Recall that a binary search tree is a binary tree with each node storing a key, and the property that the key of each node is greater than all keys in the left subtree of that node and less than all keys in the right subtree. A new key is inserted into the tree by adding a new leaf node with that key in the only position such that the property is maintained, as seen in the figure below.
Recall that a binary search tree is a binary tree. Each node stores a key and an attribute. The key value of each node is greater than all the key values in the left subtree of the node and less than all the key values in the right subtree. By adding a new leaf node, insert a new key into the tree and type it in the unique position to keep the attribute, as shown in the figure below.
![ QQ picture 20200801230141. PNG] (~ / 4bb6f03e-9c5f-4775-9107-a8168283504a. PNG)
To illustrate to him just how bad things can get without self-balancing, you want to show him that it is possible to build trees of nearly any height by carefully choosing an insertion order.
To show him how bad things can get without self balance, you have to show him that by carefully choosing the insertion order, you can build trees of almost any height.
You are given two integers n and k and want to construct a binary search tree with n nodes of height k (the height of a tree is the maximal number of nodes on a path from the root to a leaf).
To do so, you need to find a permutation of the integers from 1 to n such that, when they are inserted into an empty binary search tree in that order (without self-balancing), the resulting tree has height k.
Given two integers n and K, we want to construct a binary search tree with n nodes and its height K (the height of the tree is the maximum number of nodes on the path from root to leaf). To do this, you need to find an arrangement of integers from 1 to N. when they are inserted into an empty binary search tree in this order (without self balancing), the resulting tree has a height of K.
### **Input:**
The input consists of two integers n and k (1 ≤ k ≤ n ≤ 2 · 105), where n is the number of nodes in the tree and k is the exact height the tree should have.
The input consists of two integers n and K (1 ≤ K ≤ n ≤ 2.105), where n is the number of nodes and K is the exact height of the tree.
### **Output:**
If there is no solution, output impossible. Otherwise, output one line with n integers, the requested permutation. If there is more than one solution, any one of them will be accepted.
If there is no solution, output "impossible". Otherwise, the output line of N integers requires permutation. If there is more than one solution, any one of them will be accepted.
### **Sample Input 1:**
```in
7 4
```
### **Sample Output 1:**
```out
4 7 6 5 3 2 1
```
### **Sample Input 2:**
```in
8 3
```
### **Sample Output 2:**
```out
impossible
```
answer:If there is no answer, please comment