Homework Assignment 6 CS 340d Unique Number: 50960 Spring, 2019 Given: March 4, 2019 Due: March 13, 2019 1. Write a C-language predicate that recognizes well-formed binary trees: a. Trees are referenced by natural numbers, b. The tree reference 0 is a terminal node, c. The tree reference 1 is a terminal node, d. MaxPair is a natural number (less than 2^40), e. A tree reference n < MaxPair*2 is an index to a tree array ``pa'' declared by: unsigned int pa[ MaxPair * 2 ] f. To access binary (sub-)tree i two fields (left and right), the following code is used: unsigned int left = pa[ i * 2 ]; unsigned int right = pa[ (i * 2) + 1 ]; -------+ | MaxPair * 2 +--------------+ | | +--------------+ | | o o o | | +--------------+ | | 7 right entry for pair referenced by 3 +--------------+ | | 6 left entry for pair referenced by 3 +--------------+ | | 5 right entry for pair referenced by 2 +--------------+ | | 4 left entry for pair referenced by 2 +--------------+ | | 3 These four (0,1,2,3) locations are unused. +--------------+ Why? We use 0 and 1 as endpoints; that is, | | 2 all trees end by the 1 or 0 ``pointer''. +--------------+ Thus, these four array locations (or pairs | | 1 0 and 1) are unreachable. +--------------+ | | 0 +--------------+ unsigned int treep( unsigned idx ) { ... } // Fill in ``...'' 2. Describe what you have learned in the class thus far. Below are 5 topics. You should write at least 15 line per topic. Your entire submission should be at least 90 to 120 lines long of plain ASCII text. You may include small pieces of code in your answer to demonstrate your understanding, but it should primarily be English text. Formatting, composition, grammar and spelling count to satisfy the writing requirement for the course. Include some discussion of what you think is most or least interesting and useful. A. Memory layout and data types B. Representation of and operations on 1- and 2-dimensional sets. C. Character sets and word recognition D. Memory copy (single vs multiple bytes, aligned vs non-aligned) E. Invariants and loop termination