CS 32 Solution Homework 5

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Background image of page 3
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 < n->data) insertAuxiliary(n->left, value, n); else insertAuxiliary(n->right, value, n); } void insert(Node*& 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 -> B C B -> H C -> D E D -> B H E -> G F -> G I G -> C H H -> G I -> C I E G C D B H E G C D H B E G H C D B...
View Full Document

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 Right Arrow Icon
Ask a homework question - tutors are online