0% found this document useful (0 votes)
25 views

Assignment 4

This document outlines 3 problems related to binary trees and Huffman coding for an advanced problem solving assignment. The first problem asks to determine if a given binary tree represented by an array is a binary search tree. The second problem involves reconstructing the preorder or postorder traversal of a binary tree given its inorder traversal and one other traversal. The third problem asks to construct a Huffman tree from a set of characters and their frequencies and output the Huffman code for each character.

Uploaded by

anil87t
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Assignment 4

This document outlines 3 problems related to binary trees and Huffman coding for an advanced problem solving assignment. The first problem asks to determine if a given binary tree represented by an array is a binary search tree. The second problem involves reconstructing the preorder or postorder traversal of a binary tree given its inorder traversal and one other traversal. The third problem asks to construct a Huffman tree from a set of characters and their frequencies and output the Huffman code for each character.

Uploaded by

anil87t
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Advanced Problem Solving (CS3600)

Assignment 4 Deadline: 02/09/2010

1.
You are given a binary tree in the form of its array representation. Decide if the tree is a binary
search tree or not. The first number in the input indicates the number of elements that follows,
and the blank spaces in the array are indicated by a -1.

Input: 14 17 12 25 9 15 21 29 -1 11 -1 -1 19 -1 27
Output: YES
Input: 14 17 12 25 9 18 21 29 -1 11 -1 -1 19 -1 27
Output: NO

2.
Given the in order and one of pre-order or post order traversals of a binary tree, output the
remaining of preorder or post order traversal of the tree. Your input will contain the number of
nodes, n, followed by 1 for the in-order and post-order, and 2 for in-order and pre-order
traversals, followed by 2n integers corresponding to the two traversals.

Input:
71
2351476
2537641
Output:
1325467

3.

You have a set of numbers and their frequency of use and want to create a huffman encoding for
them:

FREQ VALUE

5 1

7 2

10 3

15 4

1|Page
20 5

45 6

Create a huffman tree and output the encoding of every element.

N – number of data items (0<N<=100000),next line contains N integers as data- items, next line
contains the frequency of the corresponding data-item

Output must be in sorted order of data-items with there Huffman code.

Solve this question using trees only.

Input:

123456

5 7 10 15 20 45

Output:

1 0010

2 0011

3 000

4 010

5 011

61

2|Page

You might also like