Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

l. Traversing the tree level by level For the following question, assume binary trees consist of nodes from the following class: class node{ public: int

image text in transcribed
l. Traversing the tree level by level For the following question, assume binary trees consist of nodes from the following class: class node{ public: int data; node * left; node * right; }; Write a method 'void IevelOrderTraversal(node * r)' which prints the items of a binary tree in a \"level order\". That is, the first item printed is the root, the next items printed are the children of the root, the next items printed are the grandchildren of the root, etc. Your algorithm must run in O(n} time. Hint: use a queue. You may use the STL queue in your solution. For example, the following tree would be printed in the order: A B C D E F IZIIZIIE 2. Find the medium Suppose you are given 2 sorted arrays A and B with n and m items respectively, n>=m. Design an O(log n) time algorithm to nd the median of all n+m items. 0 Provide pseudo code for your solution along with analysis. 0 Implement your algorithm in c++ with the function ' double medium (vector &A, vector &B)' 3. A heap for getting the median quickly Design a data structure that supports the following 2 operations: 0 Insert(x) : Add x to the data structure. Must run in O(log n) time 0 extractMedianO : Remove and return the median value om the data structure. If n is even, remove the oor(nf2) smallest item (the lower median). Must run in O(log n) time. In your solution, be sure to describe what your data structure consists of in clear, concise, we ll-written sentences, including describing your insertion and extraction algorithm. Then explainfanalyze why your data structure works properly (i.e. is guaranteed to nd and remove the median value), and analyze the run time of each operation

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

What are the major sources of competitor intelligence?

Answered: 1 week ago