Which of the following functions f : {0, 1, 2, 3} → {0, 1, . . . , 7} are one-to-one?
A heap is a data structure that is used to represent a collection of items, each of which has an associated priority. (See p. 529.) A heap can be represented as a complete binary tree—a binary tree with no “holes” as you read in left-to-right, top-to-bottom order—but a heap can also be stored more efficiently as an array, in which the elements are stored in that same left-to-right and top-to-bottom order. (See Figure 2.60.) To do so, we define three functions that allow us to compute the index of the parent of a node; the index of the left child of a node; and the index of the right child of a node. (For example, the parent of the node labeled 8 in Figure 2.60 is labeled 9, the left child of the node labeled 8 is labeled 3, and the right child is labeled 5.) Here are the functions: given an index i into the array, we define
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here