Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that implements the following size balancing (not height balanced) binary search tree where the node knows the number of left and

Write a C++ program that implements the following size balancing (not height balanced) binary search tree where the node knows the number of left and right nodes in each subtree in order to achieve runtime.

CODE BASE:

https://ybin.me/p/b8539a35dedd4d59#CCjscmXaEecNhSqbof6/EZPGSYEW1lUpJSboZNpmNc4=

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

In this part of the assignment you will implement what we will call the "size-balanced: strategy described below As we know, "vanilla" BSTs do not in general guarantee logarithmic height and as a result, basic operations like lookup, insertion and deletion are linear time in the worst case There are ways to fix this weakness - e.g., AVL trees and Red-Black trees. We will not be doing either of those; instead, you will implement the "size-balanced" strategy described below Big picture: size-balanced trees are not quite as "strong" as AVL or Red-Black trees in the sense that insert and delete will have amortized_logarithmic runtime instead of (instead of guaranteed logarithmic runtime for individual_inserts/deletes as with AVL and Red-Black trees). (The amortized property is formalized a bit below.) On the other hand, size-balanced trees are probably easier to implement than AVL or Red-Black trees. Furthermore, as far as I know, a simple google search will not find complete C++ implementations of size-balanced trees) The "size-balanced" property: Definition (size-balance property for a node) Consider a node v in a binary tree with n, nodes in its left subtree and n nodes in its right subtree; we say that v is size-balanced if and only if: max(ni, nR 2 x min(n, np) + 1 (so roughly, an imbalance of up to - is allowed) Definition: (size-balance property for a tree We say that a binary tree t is size-balanced if and only if all nodes v in t are size-balanced In this part of the assignment you will implement what we will call the "size-balanced: strategy described below As we know, "vanilla" BSTs do not in general guarantee logarithmic height and as a result, basic operations like lookup, insertion and deletion are linear time in the worst case There are ways to fix this weakness - e.g., AVL trees and Red-Black trees. We will not be doing either of those; instead, you will implement the "size-balanced" strategy described below Big picture: size-balanced trees are not quite as "strong" as AVL or Red-Black trees in the sense that insert and delete will have amortized_logarithmic runtime instead of (instead of guaranteed logarithmic runtime for individual_inserts/deletes as with AVL and Red-Black trees). (The amortized property is formalized a bit below.) On the other hand, size-balanced trees are probably easier to implement than AVL or Red-Black trees. Furthermore, as far as I know, a simple google search will not find complete C++ implementations of size-balanced trees) The "size-balanced" property: Definition (size-balance property for a node) Consider a node v in a binary tree with n, nodes in its left subtree and n nodes in its right subtree; we say that v is size-balanced if and only if: max(ni, nR 2 x min(n, np) + 1 (so roughly, an imbalance of up to - is allowed) Definition: (size-balance property for a tree We say that a binary tree t is size-balanced if and only if all nodes v in t are size-balanced

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_2

Step: 3

blur-text-image_3

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

Conduct the survey and review the results.

Answered: 1 week ago