Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Plz help me code with these three problems. Problem 1 Write a recursive function kth to the_last to find the kth to last element of

Plz help me code with these three problems.
image text in transcribed
image text in transcribed
Problem 1 Write a recursive function kth to the_last to find the kth to last element of a singly linked list (the definition given below) and print its data. You can return anything from the function (hint: retum an index) 1. class Node 2. IntList is one of None or Node. 3. Attributes: 4 5. next (Node): pointer to the next node of the IntList 6. 7. defnit (self, data, next None): 8. 9 10. # other boilerplate methods omitted. data (int): integer value self.data-value self.next- next Problem 2 Given the definition of a doubly-linked-ist based list IntList(Node), write a recursive function remove multiple, which takes an IntList (Node) object int list and a target int value target and returns an IntList (Node) object with all occurrences of the target value removed. Write the purpose statement and the signature of the function and leave some traces of step #4 (templating) ofthe design recipe by leaving inline comments in the function body 11.class Node 12. IntList is one of None or Node. 13. Attributes: 14. data (int): integer value 15. next (Node): pointer to the next node of the IntList 16. prev (Node): pointer to the previous node of the IntList 18. def nit (self, data, next-None, prev-None): 19. self.data data 20 21. pelf.prev prev 22. # other boilerplate methods omitted. self.next next Problem 3 Write a recursive function count_decendants, which takes a IntTree (TreeNode) object whose data definition is given below as an argument and updates the number of descendant nodes in the num_children (int) field of each tree node and returns the number of nodes in the entire subtree including the root of the subtree (the number of descendants 1). Write the purpose statement and the signature of the function and leave some traces of step #4 (templating) of the design recipe by leaving inline comments in the function body 1. class TreeNode 2.""class for a node of IntTree 3. IntTree is one of None or TreeNode Attributes: data (int) int value num children (int): the number of child nodes 7. eft (TreeNode) left subtree of IntTree right (TreeNode): right subtree of IntTree 10. def_init(self, data, left, right) self.data data self.leftleft self.right right 12 13. 14 15 16. self.num children 0 # other boilerplate methods omitted

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

2. Are my sources up to date?

Answered: 1 week ago