Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
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 <= 105
1 <= Value of nodes <= 104
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
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 the following function:int enigma(NodeInt32* node){if(node == NULL)return 0; elsereturn 1 + enigma(node->next);}(a)The enigma function is recursive.A. True B. Falsearrow_forwardGiven a singly linked list L, where x and y are two data elements that occupy the nodes NODEX and NODEY with PREVIOUSX as the node, which is the previous node of NODEX, write a pseudo-code to swap the date x and y in list L by manipulating the links only (data swapping is not allowed). Assume that x and y are available in the list and are neither neighbors nor the end nodes of list L. For example, given the list L shown in Figure P6.10(a), with L, NODEX, NODEY and PREVIOUSX marked on it, the swapping should yield the list shown in Figure P6.10(b). NODEX and NODEY are neither immediate neighbors nor the end nodes of list L. Th PREVIOUS X NODE X ‘oddada g c PREVIOUS X (a) Before swapping g and x NODE Y с NODE Y X NODE X addgħa W (b) After swapping g and x Figure P6.10. Swapping of elements in a singly linked list by manipulating links iarrow_forwardImplement a function to insert a node at the end of a doubly linked list. Explain the steps involved and analyze the time complexity of your implementation.arrow_forward
- 2. You have a family tree diagram like the following, very smallI, sample tree and file. It is stored as a file with the following format (parent: , one line for all people in the tree). Your task is to be able to find the descendants of any person in a family tree, e.g. the descendants of p1 are p4.p5,p7,p8 in O(|P|) time, where P is the set of people in the graph. "Sketching" the approach is fine but you may give full pseudocode, just reuse an algorithm from class, perform some obvious conversion (Adjacency Matrix to/from Array List, etc.) or some combination of these. You may not use depth first search or breadth first search. You may preprocess the input with any polynomial approach and may assume the |P| people in the tree are labelled po, p1, .p. p0: p4, p5 p1: p4, p5 p2: p6 p3: p6 p4: p4 p5: p7, p8 p6: p7, p8 p7: p8: p7 p8 Preprocess File By: How to retrieve descendants (O(|P|) time, max): getDescendants(Person ):arrow_forwardWrite a program that maintains a personal phone book in C. The program allows to:▪ Add and Delete entries from the phone book,▪ Search the phone book for a specific entry by last name or by phone number, and▪ Print out the entire entries in the phone book.The data in the phone book is maintained by storing in memory with the use of a singly linked list, withone list node per entry. Each node contains members for storing a person’s family name, first name, address,and the phone number. Use strings to store this information. The linked list must be kept in increasingalphabetical order, sorted by family name. There are no duplicate entries with the same family nameallowed in the phone book. This program should be menu driven, with the user being offered a choice of the following commandsdescribed below:▪ Insert a new entry into the phone book.The program should prompt the user for a new family name and first name, an address and a phonenumber. This information should be placed in a new…arrow_forward
arrow_back_ios
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