PE 2007 - PE 2007/08 Sem I 1 Date: 3 Nov 2007 Time: 9am...

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

View Full Document Right Arrow Icon
1 PE 2007/08 Sem I
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 • Date: 3 Nov 2007 • Time: 9am – 11.30am • Organisation: Similar to sit-in labs • First 30 minutes are for analysis and design • Lab allocation will be posted in IVLE workbin. • Scope: up to Hashing • There will be 2 questions. One is 30% and the other 70%.
Background image of page 2
3 Q1:Is it Complete? Background A complete binary tree is a binary tree in which all leaves are at depth d or d -1 for some d and all the nodes on the last level must be filled in from left to right without any gaps.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Is it Complete? Description In this problem, you are given the description of a binary tree and you need to check whether the given tree is a complete tree. The nodes of the tree contains a label which is the identifier for the node, a left child label and a right child label. The left/right child label may be -1 if the node has no left/right child.
Background image of page 4
5 Is it Complete? Input Format The first line of the input is a positive integer n (0 < n < 1000), which is the number of nodes in the tree. This is followed by n lines, each line contains 3 integers ID (label), L (label of left child) and R (label of right child). You may assume that each node has a unique label from 0 to n -1.
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Output Format You should output on a single line the word “true” if the given binary tree is a complete tree and “false” otherwise.
Background image of page 6
7 Sample Input 1 5 2 -1 -1 3 -1 -1 4 -1 -1 1 0 2 0 3 4 Sample Output 1 true 1 2 0 34 This diagram shows the tree given in sample input 1.
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Sample Input 2 2 0 -1 1 1 -1 -1 Sample Output 2 false This diagram shows the tree given in sample input 2. 0
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/02/2009 for the course ECE CS1102C taught by Professor Dr.tansuntuck during the Spring '07 term at National University of Singapore.

Page1 / 32

PE 2007 - PE 2007/08 Sem I 1 Date: 3 Nov 2007 Time: 9am...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online