c17f01t2 - CSc 17 Test 2 Wednesday 28 November 2001...

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

View Full Document Right Arrow Icon
CSc 17 Test 2 Wednesday 28 November 2001 >>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<< 1. (10 pts) Using the algorithms discussed in class for building a balanced binary tree for sorting integers, draw a picture of the tree after each of the numbers listed in (a) are added to the tree in the order given. Repeat the exercise for the numbers in (b). (a) 16 -4 28 35 20 40 16 --> 16 --> 16 --> 16 --> 16 --> 16 / / \ / \ / \ / \ -4 -4 28 -4 28 -4 28 -4 28 \ / \ / \ 35 20 35 20 35 \ 40 ==> 28 / \ 16 35 / \ \ -4 20 40 (b) 16 -4 28 -2 8 12 16 --> 16 --> 16 --> 16 --> 16 --> -2 / / \ / \ / \ / \ -4 -4 28 -4 28 -4 28 -4 16 \ \ / \ -2 -2 8 28 \ 8 ==> -2 --> -2 ==> 8 / \ / \ / \ -4 16 -4 16 -2 16 / \ / \ / / \ 8 28 8 28 -4 12 28 \ 12 2. (25 pts) Write a function inList(). If we have the declarations int n,y,x[20]; then the call inList(y,x,n) should return the index of the first entry among the first n entries in x[] which equals y. If none of the first n entries in x[] equals y, then inList(y,x,n) should return -1. int inList(int y, int x[],int n)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2008 for the course CSE 17 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 2

c17f01t2 - CSc 17 Test 2 Wednesday 28 November 2001...

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

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