CS 32 Solution Homework 5

# CS 32 Solution Homework 5 - parent field is set to par....

This preview shows pages 1–3. Sign up to view the full content.

Winter 2009 CS 32 Homework 5 Solution Problem 1 Problem 3 Problem 2 Problem 4 Problem 1: 50 20 60 10 40 70 30 45 65 80 25 35 75 One possibility is O 50 25 60 10 40 70 35 45 65 80 75 Other possibilities have the left subtree of 50 being O 10 40 35 45 25 or o 10 40 25 45

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
35 In-order: 10 20 25 30 35 40 45 50 60 65 70 75 80 Pre-order: 50 20 10 40 30 25 35 45 60 70 65 80 75 Post-order: 10 25 35 30 45 40 20 65 75 80 70 60 50 Problem 2: 6 3 5 1 2 4 6 3 5 1 2 4 5 3 4 1 2 Problem 3: struct Node { int data; Node* left; Node* right; Node* parent; }; { if (n == NULL) set n to point to a new Node whose data field is set to value, whose left and right children are NULL, and whose
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: parent field is set to par. else if (value &lt; n-&gt;data) insertAuxiliary(n-&gt;left, value, n); else insertAuxiliary(n-&gt;right, value, n); } void insert(Node*&amp; n, int value) { insertAuxiliary(n, value, NULL); // pass NULL as parent of root } Problem 4: Adjacency matrix (entries shown as blank are 0; row is source, col is destination): d A B C D E F G H I +-----------------A | 1 1 B | 1 C | 1 1 D | 1 1 E | 1 F | 1 1 G | 1 1 H | 1 I | 1 I Adjacency list: A A -&gt; B C B -&gt; H C -&gt; D E D -&gt; B H E -&gt; G F -&gt; G I G -&gt; C H H -&gt; G I -&gt; C I E G C D B H E G C D H B E G H C D B...
View Full Document

## This note was uploaded on 11/07/2009 for the course CS 32 taught by Professor Davidsmallberg during the Winter '08 term at UCLA.

### Page1 / 3

CS 32 Solution Homework 5 - parent field is set to par....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online