CSC148H1 Study Guide - Midterm Guide: Docstring, Binary Tree, Binary Search Tree

104 views6 pages
25 Oct 2018
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

Read over the declaration of class btnode as well as the header and docstring for function has branch. Then complete the implementation of has branch. class btnode: """initialize this node. self. item, self. left, self. right = item, left, right def has_branch(t: btnode, item1: object, item2: object) -> bool: """return true if tree rooted at t has some node with node. item == item1 that has a child with child. item == item2. >>> t = btnode(1, btnode(2, btnode(3)), btnode(4, btnode(5), \ False if t is none: return false else: return ((t. item == item1 and ((t. left and t. left. item == item2) or (t. right and t. right. item == item2))) or has_branch(t. left, item1, item2) or has_branch(t. right, item1, item2)) Marking notes: 1 mark for none base case, 2 marks for checking whether t has a branch with appropriate values, 2 marks for checking t. left and t. right for branches. B, b1: check existence of children (lines 5, 6) -1. D: check further than current parent/child if they don"t match -1.