BST-Permutations

# BST-Permutations - values 1 2 and 3 have degenerate...

This preview shows page 1. Sign up to view the full content.

1 Binary Search Tree A binary search tree (BST), is a binary tree where for every node n in the tree: n 's value is greater than all the values in its left subtree. n 's value is less than all the values in its right subtree. both n 's left and right subtrees are binary search trees. 2 4 1 5 3 Binary Search Tree Problem : How many possible BSTs containing
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: values 1, 2, and 3 have degenerate structure (i.e., each node in the BST has at most one child)? • Solution : 3! ways to order 1, 2, and 3 for insertion 1, 2, 3 1, 3, 2 2, 1, 3 2, 3, 1 3, 1, 2 3, 2, 1 There are 4 degenerate BSTs possible. 2 3 1 2 3 1 1 2 3 1 3 2 3 1 2 3 2 1...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern