This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSE 100 Midterm Examination
W.A. Burkhard May 1, 1997 1. This is a closed book examination; one study sheet is allowed. 2. Please check the entire examination immediately to ensure that your copy has all six pages.
3. Put your name on all pages of the examination. 4. All questions have equal mark value. 5. Neatness counts. r 6. You must clearly show your work; take time to prepare a legible answer. 7. Good luck and have fun!’ SOLLATloNS name oce or c5100 login 1 6.
2 7.
3 8.
4 9.
5 10. total Table Data Type: Hashing name
For the hashing problem, use the hashing functions h1(x)=x'/.11 and h2(x)=(x'/.10)+1
for a table of size eleven. 1. Insert the following sequence of key values into an empty table using Ordered hashing: 11, 69*, 81, 36, 55, 40, 15, 60 Show your work here . hi hi
i H: o 7—
6"): 3
81; 4
35: 3 7
55'. O bmmps \\
'40: “7
\5; ‘1! e
503 5 lamps \5‘ MC; ’3. S3“ : ﬁlwlﬂ <6
M: A 0
u WA Table Data Type: Hashing name 3. What is the average unsuccessful search length for the following double hashing table? The key space is the
set of non—negative integers. Show your work here
\ Z 3 ‘i ﬁrst: sec
0: 1 1 \1 j. prom. la ”04$ 4—. ““043 TOTAL, : 94HO+Lt+H+1l 4.A If good unsuccessful search lengths are required, should pass bits or ordered hashing be used? The following
graph may be of use. 6 ”The. Gown1% clean/was. 0n Unsuccessful Search Lengths : _._._——_ — FAW’ rm. Swu“ i99~di©7¥hdﬁm 4 X
P935 bi‘l’s Q‘we, inc+4?» {3%‘Pvﬁ—unhbé‘. $41.. {VA’QL lOméiwo “FM/17"“ >/ K
OWN/ma, hashing L: lea/“Hm.  expected passb'ﬂ
— expected ordered hashing (— search lengths O.“ 0 2 0.1 “.6 01 L0
loadan factor 4.B Can ordered hashing and pass bits be used together obtaining unsuccessful search lengths better than either
by itself? Answer yes or no and argue why your answer is correct. Eyes or D110 The pass \o\+ ﬁes4w; doe/c my?” omilfm‘
{QM/k orcLMed “hiking ‘mgpAﬁ‘q‘m W (hangs, We 5U?“ PM ‘57": p»; inst/tack. Miscellaneous name 5. The following tree arises within the Floyd—Williams heap algorithm. Position the tree nodes within the array 23456789 suitable for the FloydWilliams algorithm. 6.A Within a two—dimensional triangular array, where is index (3,6) located? 1 (3:43): 5.51 3. : is t 6.B Which index is associated with location 48 within a twodimensional array? 0 4 Z" 4 2.
‘ 7. (21} 4. (LI) : ‘1‘% 3 wzvﬁ +\~e V'ﬁmk ‘tncw'
i:  2 (”WWW l7?) s W
l L L ‘ '9 ' (3) \o) C_______.._.———— 7. Derive the expression for the expected number of items visited while doing a successful search within a linear list of n items. h 1 l+L+3+ lvvir l/l __ n+1 a», i wwmynnia Q
2‘75: h “=2 N,
N (More) Run—Time Performance name __ 8. How many times is the x assignment statement executed? for(inti=1;i<=n;i++)
for(intj i;j<=n;j++) inJEj] 35;
TV X assign NM szM }s Mégwﬁvaé
m V\ V“
I ‘ .1
E, 1 : : ,(h‘L+j—) : HQ?) +tv~nag,
‘151 Jz‘i 2,: 9. What is the O runtime for this fragment? for(inti=1;i<=n;i++)
for(intj=n/i;j>=1;j—)
X[i1[j1=35; 11“ . Y'}
13L ‘ “/2.
1:2 \ 0/3 C++ Programming name 10. We are to implement the “update” method for a double table implementation of our expanded Table class
which is listed below. template <class DATA> class Table { DATA at +kb\b a public: ‘ 3
" Table ( ) ; mE Y\ 3 H $32, ()4 +ab\€
bool insert ( const DATA 8: ) ' x j
’ l 4. m r In my» 4: ‘
bool fetch ( DATA 2; ) const ; m 5 I] M \ ° “ﬁn“ bool update (rconst DATA & ) ;
bool remove ( DATA & ) ;
l The update method provides a mechanism to change data that has already been inserted in the table
without having ﬁrst to remove the previous version of the data and then inserting the new version. Your
implementation must not use these two functions either! The update method locates the proper record within
' the table using the data “key;” it then stores its DATA parameter within the same slot that contained the
previous version of the data. If no such record is found in the table, update operates just as the insert method would; The update return value is true if it can store its “new version” DATA parameter within
the table; otherwise it returns false. template <c1ass DATA> bool DoubleTab1e<DATA> :: update ( const DATA & data ) { . . \
lh‘t start = index : (““5‘ j“¢¢\ &W 070 ﬂ ‘9
‘mt $+ep :: (Mosxcsneéh $aﬁ’k G7; (n~1\ 'i‘ 1 :3 While ( l “talolel: ‘mdmcjds EMFtam ﬁg +a‘oltt‘molex] l: cicc‘i”:\\) 5L Male/x = (Mela/>4 + S'drep') '79 YX 3 ii ( saw»: =2 ‘maw‘x (‘v‘rw‘n am 3 // Cam we: it ( +o~b\tl.\ndw1.isE~pmH \ TmH 3 // mamMm comm ‘i‘ nblal: lnéqu] ; $°J§ a 3 Y{.+wrn true 3, C++ Programming name 10. We are to implement the “update” method for a double table implementation of our expanded Table class
which is listed below. template <class DATA> class Table { DATA *¥ +o.\o\e, ‘ publlc: 3
' Table () ; ‘m—t n  u 939' or +56%
bool insert ( const DATA 8: ) ; '
bool fetch ( DATA 85 ) const ;
bool update ( const DATA Kc ) ;
bool remove ( DATA & ) ; 1va m 3 // hum‘eex 0'? meme. } The update method provides a mechanism to change data that has already been inserted in the table
without having ﬁrst to remove the previous version of the data and then inserting the new version. Your
" implementation must not use these two functions either! The update method locates the proper record within
the table using the data “key;” it then stores its DATA parameter within the same slot that contained the
previous version of the data. If no such record is found in the table, update operates just as the insert method would. The update return value is true if it can store its “new version” DATA parameter within
the table; otherwise it returns false. template <c1ass DATA> bool DoubleTable<DATA> :: update ( const DATA & data ) { .
‘uﬂ, start = index :: (““3‘3“¢é\&m 070 Y“ 69
in": sup : (Msxgnees exec—rot "‘2a (na\ + 1' 93 Wh‘xle ( E ‘lmHQ C 'mdtﬂj . '\ S EMptg‘W 932i +o.\o\t [Melba] }: Acctth index = (Mela/7L + seep) '79 n 3 it ( S‘iort =: ‘lhabfx‘\ fc‘rw'n ¥Q\5¢ w: // can‘t» updati ‘3 ll hm Fa“
if? ( +¢~\Q\ti \ndQ/‘t 1 r ‘l'a EMF*‘3(\ \ YYxtt‘ 3 // Mﬁ‘in'ﬁ‘hin (‘Comﬂ'l
“t ablet )némj : Cleg‘c c\ 3 ‘(t‘thrn true, ‘, ...
View
Full Document
 Winter '08
 staff

Click to edit the document details