Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Winter 2020 Homework 2 CIS 350: Data Structures and Algorithm Analysis a node w in a general BST Opis. Consider the SUCCESSOR function Algorithm 4)

image text in transcribed

Winter 2020 Homework 2 CIS 350: Data Structures and Algorithm Analysis a node w in a general BST Opis. Consider the SUCCESSOR function Algorithm 4) for a general linked-structured BST implementation for a sorted map ADT. It takes as input a node win a general and outputs its successor node in the BST that is the node whose key immediately follows the key w.key of node w, if any; otherwise it outputs NULL. It uses two auxiliary functions, FIRSTLEFT ANCESTOR and FLOOR ENTRYNODE Algorithm 4 SUCCESSOR(L) 1: if w = NULL then return to 2: if w.right = NULL then return FIRSTLEFTANCESTOR(W) 3: return FLOOR ENTRYNODEw.right) (a) Write an algorithm, using pseudocode for the function FIRSTLEFT ANCESTOR, which takes as input a node w in the BST and outputs the first ancestor u of w in the BST such that w is the ceiling entry node of the left subtree w.left of u, that is, the key w.key of w is the largest in the left subtree of u, so that, w is the predecessor of u in the BST; it outputs NULL if no such ancestor exists, or if the subtree is empty. The algorithm should run in time that is linear in the depth of node w in the BST, and use a constant amount of space. (b) Write an algorithm, using pseudocode, for the function FLOOR ENTRYNODE, which takes as input a node w in the BST and outputs the node with the smallest key in the subtree rooted at w, that is, the last left ancestor of w (or said differently, the left-most node in the subtree rooted at w); it outputs NULL if no such node exists, or if the subtree is empty. The algorithm should run in time that is linear in the height of the subtree rooted at w, and use a constant amount of space. Homework 2 CIS 350: Data Structures and Algorithm Analysis Winter 2020 (c) Write down tight big-Oh characterizations of the worst-case running time and space complexity of the implementation of the SUCCESSOR function (Algorithm 4) as a function of the number of nodes n in the (general) BST. Time Space Winter 2020 Homework 2 CIS 350: Data Structures and Algorithm Analysis a node w in a general BST Opis. Consider the SUCCESSOR function Algorithm 4) for a general linked-structured BST implementation for a sorted map ADT. It takes as input a node win a general and outputs its successor node in the BST that is the node whose key immediately follows the key w.key of node w, if any; otherwise it outputs NULL. It uses two auxiliary functions, FIRSTLEFT ANCESTOR and FLOOR ENTRYNODE Algorithm 4 SUCCESSOR(L) 1: if w = NULL then return to 2: if w.right = NULL then return FIRSTLEFTANCESTOR(W) 3: return FLOOR ENTRYNODEw.right) (a) Write an algorithm, using pseudocode for the function FIRSTLEFT ANCESTOR, which takes as input a node w in the BST and outputs the first ancestor u of w in the BST such that w is the ceiling entry node of the left subtree w.left of u, that is, the key w.key of w is the largest in the left subtree of u, so that, w is the predecessor of u in the BST; it outputs NULL if no such ancestor exists, or if the subtree is empty. The algorithm should run in time that is linear in the depth of node w in the BST, and use a constant amount of space. (b) Write an algorithm, using pseudocode, for the function FLOOR ENTRYNODE, which takes as input a node w in the BST and outputs the node with the smallest key in the subtree rooted at w, that is, the last left ancestor of w (or said differently, the left-most node in the subtree rooted at w); it outputs NULL if no such node exists, or if the subtree is empty. The algorithm should run in time that is linear in the height of the subtree rooted at w, and use a constant amount of space. Homework 2 CIS 350: Data Structures and Algorithm Analysis Winter 2020 (c) Write down tight big-Oh characterizations of the worst-case running time and space complexity of the implementation of the SUCCESSOR function (Algorithm 4) as a function of the number of nodes n in the (general) BST. Time Space

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago