Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 14.1, Problem 4E
Program Plan Intro
To write a recursive procedure of OS-KEY-RANK( T,k ) that takes OS tree and a key k as input and return the rank of k in dynamic set representation by T.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Create a binary linked tree, and traverse the tree by using the recursive function.
The structure of the tree is as follow: //PICTURE//
You should input the nodes in pre-order sequence. If a child of a node is NULL, input a space.
Write the function of create binary tree, pre-order to print the nodes, in-order to print the nodes and post-order to print the nodes.
Count the height of the tree.
Create a binary linked tree, and traverse the tree by using the recursive function.
The structure of the tree is as follows:
//check pic//
You should input the nodes in pre-order sequence. If a child of a node is NULL, input a space.
Write the function of create binary tree, pre-order to print the nodes, in-order to print the nodes and post-order to print the nodes.
Count the height of the tree.
Hints:
Header file
typedef char ElemType;
typedef struct node//define the type of binary tree node
{
}BTnode;
Source file
#include <stdio.h>
#include <stdlib.h>
#include "tree.h"
BTnode * createTree()//create the binary tree,return the root
{
BTnode *tnode;// tnode is the root
char elem;
;//input the character
//if the input is a space,set the pointer as NULL
Else// if the input is not a space,generate the binary node and create its left…
Given a binary tree, let an H-node be defined as a non-leaf node in the tree whose value is greater than or equal to its children nodes (1 or 2 children). Write a function called countHNodes(TreeNode* p), that returns the number of H-nodes in a binary tree (pointed by p). Use recursion in the function.
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Consider a recursively defined set S such that 1 is an element of S (x-y) is an element of S if both x and y are elements of S. S is equal to the ----------------------------------.arrow_forward3. The following is a recursive algorithm for a preorder binary tree traversal. Determine the worst-case runtime of this algorithm where the proper binary tree t has n internal nodes (non null nodes). Do this by specify the recurrence equation for the runtime T(n) and then deriving the closed form. Count the comparison v != null as 1 primary operation and the call processNode(t,v) as c primary operations, where c is some constant. Algorithm preorder(Tree t, TreeNode v) Input: Binary tree t of size n and node v of t Output: None if v!= null then end end processNode(t.v) preorder(t,v.getLeft()) preorder(t,v.getRight())arrow_forwardAlgorithm Element as a Strong Generator ProductInput: a group G operating on f = 1,2,.....n; an element g of G; a base and strong generating set for G; Schreier vectors v I 1 I k, for the stabiliser chainOutput: a symbolic product, a word that expresses g in terms of the strong generators.arrow_forward
- Given two binary trees with head reference as T and S having at most N nodes. The task is to check if S is present as subtree in T.A subtree of a tree T1 is a tree T2 consisting of a node in T1 and all of its descendants in T1 You don't need to read input or print anything. Your task is to complete the function isSubtree() that takes root node of S and T as parameters and returns 1 if S is a subtree of T else 0. Expected Time Complexity: O(N).Expected Auxiliary Space: O(N). Constraints:1 <= Number of nodes <= 1051 <= Value of nodes <= 104arrow_forwardProvide an example of a recursive function in which the amount of work on each activation is constant. Provide the recurrence equation and the initial condition that counts the number of operations executed. Specify which operations you are counting and why they are the critical ones to count to assess its execution time. Draw the recursion tree for that function and determine the Big-Θ by determining a formula that counts the number of nodes in the tree as a function of n.arrow_forwardimplement this 2 functions in c using binary search tree: SetEquals Given two sets, returns true if the sets are equal, i.e., they contain exactly the same elements, and false otherwise.arrow_forward
- Your second function is called “isTree". Its input is a graph G, which is a dictionary whose keys are the vertices, and whose values are lists of vertices that are adjacent to the given vertex. Its output is True if G is a tree and False if G is not a tree. Hint: You may want to make use of your "connected" function from the last coding assignment.arrow_forwardWrite a recursive function treeToList(Node root) that takesan ordered binary tree and rearranges the internal pointers to make a circular doubly linked list outof the tree nodes. The "previous" pointers should be stored in the "small" field and the "next"pointers should be stored in the "large" field. The list should be arranged so that the nodes are inincreasing order. Return the head pointer to the new list. The operation can be done in O(n) time -- essentially operating on each node once. Try the problem directly, or see the hints below.Hint #1 The recursion is key. Trust that the recursive call on each sub-tree works and concentrate onassembling the outputs of the recursive calls to build the result. It's too complex to delve into howeach recursive call is going to work -- trust that it did work and assemble the answer from there.Hint #2The recursion will go down the tree, recursively changing the small and large sub-trees into lists,and then append those lists together with the…arrow_forwardThe BST remove algorithm traverses the tree from the root to find the node to remove. When the node being removed has 2 children, the node's successor is found and a recursive call is made. One node is visited per level, and in the worst-case scenario, the tree is traversed twice from the root to a leaf. A BST with N nodes has at least log2N levels and at most N levels. Therefore, the runtime complexity of removal is best case O(logN) and worst case O(N). Two pointers are used to traverse the tree during removal. When the node being removed has 2 children, a third pointer and a copy of one node's data are also used, and one recursive call is made. Thus, the space complexity of removal is always O(1)." I have to explain this clearly! and the advantages of the BST algorithimarrow_forward
- Given a binary tree, let an H-node be defined as a non-leaf node in the tree whose value is greater than or equal to its children nodes (1 or 2 children). Write a function, countHNodes(), that returns the number of H-nodes in a binary tree (pointed by p) using recursion.arrow_forwardGiven a reference to a binary tree t. I am trying to write a python function using recursion that will check if an integer called k is stored in a leaf node in the tree. if not stored it should return false but if it is I want it to return True. starting function: def in_leaf(t,k):arrow_forwardB. Recall your implementation of a binary search tree. Write a function int levelOf(int k) that computes and returns the level of the node with the key k. (Consider the root at level 1)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education