1. Second Largest Problem Write a function second_largest() that takes a B Binary Search Tree (BST) as input and finds the second largest value in the given BST. You may assume that the BST has at...


use python to solve this question


1. Second Largest<br>Problem<br>Write a function second_largest() that takes a B<br>Binary Search Tree (BST) as input and finds the second<br>largest value in the given BST. You may assume that<br>the BST has at least two nodes, and that all of the<br>node values are distinct.<br>Sample<br>>>> nodes = [68, 88, 61, 89, 94, 50, 4,<br>76, 66, 82]<br>>>> second_largest(bst)<br>'2nd largest element is 89'<br>

Extracted text: 1. Second Largest Problem Write a function second_largest() that takes a B Binary Search Tree (BST) as input and finds the second largest value in the given BST. You may assume that the BST has at least two nodes, and that all of the node values are distinct. Sample >>> nodes = [68, 88, 61, 89, 94, 50, 4, 76, 66, 82] >>> second_largest(bst) '2nd largest element is 89'
def insert(bst , key):<br>if bst == {}:<br>bst['value'] = key<br>= {}<br>bst['left']<br>bst['right']= {}<br>elif bst['value'] < key:<br>insert(bst['right'],key)<br>elif bst['value'] > key:<br>insert(bst['left'],key)<br>v nodes = eval(input())<br>bst = {}<br>for n in nodes:<br>insert(bst , n)<br>second largest (bst)<br>

Extracted text: def insert(bst , key): if bst == {}: bst['value'] = key = {} bst['left'] bst['right']= {} elif bst['value'] < key:="" insert(bst['right'],key)="" elif="" bst['value']=""> key: insert(bst['left'],key) v nodes = eval(input()) bst = {} for n in nodes: insert(bst , n) second largest (bst)

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here