













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
CSE 310 Quizzes with correct answers
Typology: Exams
1 / 21
This page cannot be seen from the preview
Don't miss anything!
What |\is |\the |\height |\of |\any |\binary |\search |\tree |\with |\n |\nodes? |- |
CORRECT |\ANSWERS |\✔✔O(log |\n) Consider |\the |\hashing |\function |\h(k) |= |\k |\mod |\m. What |\is |\a |\good |\value |\for |\m? |- |\CORRECT |\ANSWERS |\✔✔A |\prime |
number. Which |\of |\the |\following |\statements |\are |\true |\regarding |\direct |\address |\tables? Statement |\1: |\If |\the |\universe |\U |\is |\large, |\storing |\a |\table |\of |\size ||U| |
may |\be |\impractical. Statement |\2: |\Often, |\most |\of |\the |\space |\allocated |\to |\table |\T |\is |
wasted |\as |\the |\set |\K |\of |\keys |\actually |\stored |\is |\small. |- |\CORRECT |
ANSWERS |\✔✔Both |\of |\the |\statements |\are |\true. |
Storing |\a |\large |\table |\is |\impractical |\because |\one |\will |\be |\allocating |\a |
large |\table, |\where |\here |\may |\be |\collisions |\or |\often |\times, |\unused |
space.
If |\for |\example, |\the |\set |\is |[1 |\ 8 |\ 10 |\ 12 |\20], |\one |\may |\allocate |\memory |
of |\size |\ 20 |\and |\store |\each |\at |\value |- |\1, |\there |\will |\be |\ 20 |\spaces |
allocated |\for |\only |\ 5 |\elements, |\leaving |\ 15 |\spaces |\unused. What |\is |\a |\hash |\table? |- |\CORRECT |\ANSWERS |\✔✔A |\generalization |\of |
an |\ordinary |\array |\where |\a |\function |\of |\key |\is |\used |\as |\the |\index |
instead |\of |\using |\key |\as |\index |\directly. Keys |\5, |\4, |\6, |\1, |\ 2 |\are |\mapped |\to |\a |\hash |\table |\of |\size |\ 3 |\with |\hash |
function |\h(k) |= |\k |\mod |\3. |\If |\collisions |\are |\resolved |\by |\separate |
chaining, |\what |\are |\the |\values |\of |\a, |\b, |\c, |\d, |\e |\respectively |\as |\shown |
below? T 0 |-> |\a |-> |/ 1 |-> |\b |-> |\c |-> |/ 2 |-> |\d |-> |\e |-> |/ |- |\CORRECT |\ANSWERS |\✔✔6, |\4, |\1, |\5, |\ 2 Insert |\keys |\7, |\10, |\25, |\12, |\17, |\ 34 |\into |\a |\hash |\table |\of |\size |\ 7 |\using |
open |\addressing, |\with |\the |\hash |\function |\h(k, |\i) |= |(k |+ |\i) |\mod |\ 7 |\and |
linear |\probing |\to |\resolve |\collisions. |\What |\does |\the |\final |\array |\look |
like? |- |\CORRECT |\ANSWERS |\✔✔[7, |\34, |\EMPTY, |\10, |\25, |\12, |\17]
Statement |\2: |\The |\chain |\is |\not |\maintained |\in |\sorted |\order. |- |
CORRECT |\ANSWERS |\✔✔Both |\statements |\are |\true. The |\use |\of |\a |\linked |\list |\has |\little |\effect |\towards |\the |\performance |\of |
dictionary |\operations. |
The |\element |\is |\simply |\inserted |\at |\the |\end |\of |\the |\chain, |\regardless |
of |\order. In |\the |\case |\of |\the |\max-priority |\queue, |\the |\minimum |\element |\is |\the |
priority |\element. |- |\CORRECT |\ANSWERS |\✔✔False |- |\name |\of |\the |
queue |\is |\self |\explanatory, |\the |\prioritized |\element |\is |\the |\max |
element. How |\do |\you |\insert |\a |\node |\into |\a |\heap? |- |\CORRECT |\ANSWERS |
✔✔Insert |\the |\node |\into |\the |\first |\available |\spot, |\then |\sort |\the |\heap. What |\is |\the |\height |\of |\a |\heap? |- |\CORRECT |\ANSWERS |\✔✔The |\amount |\of |\rows |\after |\the |\root. What |\is |\true |\about |\heaps? |- |\CORRECT |\ANSWERS |\✔✔Heapsort |\is |\an |
in |\place |\sorting |\algorithm. In |\a |\max-heap, |\the |\largest |\element |\is |\at |\the |\root.
The |\space |\complexity |\of |\heapsort |\is |\O(n). Why |\can |\we |\use |\a |\max-heap |\as |\a |\priority |\queue? |- |\CORRECT |
ANSWERS |\✔✔The |\root |\can |\be |\identified |\as |\the |\highest |\priority |
node. Given |\two |\heaps |\with |\n |\elements |\each, |\what |\is |\the |\run |\time |\to |
construct |\a |\single |\heap |\comprising |\all |\2n |\elements? |- |\CORRECT |
ANSWERS |\✔✔O(n) |\time In |\a |\binary |\search |\tree, |\either |\the |\left |\or |\the |\right |\sub-tree |\can |
have |\a |\key |\equal |\to |\the |\root's |\key. |- |\CORRECT |\ANSWERS |\✔✔True |- |
Inserted |\to |\the |\left |\is |\called |\left |\bias, |\and |\right |\is |\right |\bias. In |\double |\hashing, |\the |\hash |\function |\h |\for |\probe |\i |\uses |\two |\hash |
functions |\h1 |\and |\h2: h1(k) |= |\k h2(k) |= |\ 1 |+ |(k |\mod |(m |- |\1)) h(k, |\i) |= |[h1(k) |+ |\i*h2(k)] |\mod |\m
Which |\of |\the |\following |\statements |\are |\true? Statement |\1: |\Hash |\functions |\can |\be |\defined |\for |\keys |\that |\are |
strings. Statement |\2: |\Linear |\probing |\suffers |\from |\primary |\clustering. |- |
CORRECT |\ANSWERS |\✔✔Both |\statements |\are |\true. Hash |\functions |\are |\used |\to |\determine |\the |\key |\for |\the |\item |\that |\is |
to |\be |\hashed, |\items |\include |\strings. |\These |\functions |\usually |
includes |\the |\sum |\of |\the |\letters. |
Linear |\probing |\is |\a |\method |\used |\when |\there |\is |\a |\collision. |\This |
places |\in |\the |\first |\open |\space |\in |\the |\hash |\linearly, |\which |\can |\cause |
another |\collision |\and |\more |\probing. Assume |\that |\a |\hash |\table |\is |\implemented |\using |\open |\addressing |
with |\linear |\probing |\with |\hash |\function |\h(k) |= |\k |\mod |\7, |\for |\a |\hash |
table |\of |\size |\7. Insert |\the |\keys |\44, |\45, |\79, |\55, |\91, |\18, |\ 63 |(in |\that |\order) |\into |\the |
table. |\At |\what |\position |\in |\the |\table |\is |\key |\ 18 |\inserted? |- |\CORRECT |
ANSWERS |\✔✔ 5 |- |\Because |\the |\elements |\are |\hashed |\with |\linear |\
probing, |\order |\is |\important, |\therefore |\we |\must |\know |\where |
elements |\44, |\45, |\79, |\55, |\then |\91, |\are |\hashed. |\ 44 |\is |\hashed |\to |\2, |\ 45 |
to |\3, |\ 79 |\to |\ 2 |\and |\placed |\in |\4, |\ 55 |\to |\6, |\ 91 |\to |\0, |\and |\ 18 |\to |\ 4 |\and |
placed |\in |\5. What |\is |\separate |\chaining? |- |\CORRECT |\ANSWERS |\✔✔A |\collision |
resolution |\technique |\for |\hash |\tables. What |\is |\the |\output |\of |\the |\program |\fragment? struct |\site{ |\char |\name[] |= |"Quiz"; |\int |\pages |= |\200; }; struct |\site |*ptr; printf("%d |", |\ptr->pages); printf("%s", |\ptr->name); |- |\CORRECT |\ANSWERS |\✔✔Compiler |\error |- |\a |
new |\structure |\had |\not |\been |\allocated, |\only |\the |\ptr |\is |\declared, |
therefore |\when |\printing |\the |\program |\tries |\to |\access |\non |\existent |
values. Consider |\the |\struct |\definition |\and |\declaration:
|\if(start |== |\NULL) |
|\return; |\printf("%d |", |\start-data); |\if(start->next |!= |\NULL) |\f(start->next->next); |\printf("%d |", |\start->data); } |- |\CORRECT |\ANSWERS |\✔✔ 1 |\ 3 |\ 5 |\ 5 |\ 3 |\ 1 Given |\the |\following |\input |(4322, |\1334, |\1471, |\9679, |\1989, |\6171, |
6173, |\4199) |\and |\the |\hash |\function |\x |\mod |\10, |\which |\of |\the |\following |\statements |\are |\true? i. |\9679, |\1989, |\ 4199 |\hash |\to |\the |\same |\value ii. |\1471, |\ 6171 |\hash |\to |\the |\same |\value iii. |\All |\elements |\hash |\to |\the |\same |\value iv. |\Each |\element |\hashes |\to |\a |\different |\value |- |\CORRECT |\ANSWERS |
✔✔i |\and |\ii |\only Because |\the |\hash |\function |\is |\x |\mod |\10, |\the |\only |\part |\of |\the |
element |\that |\mattters |\is |\the |\ones |\place. |\So |\all |\the |\numbers |\with |
the |\same |\value |\in |\the |\ones |\place |\will |\hash |\to |\the |\same |\index. Given |\a |\hash |\table |\T |\with |\ 25 |\slots |\that |\stores |\ 1000 |\elements, |\what |
is |\the |\load |\factor |\a |\for |\T? |- |\CORRECT |\ANSWERS |\✔✔ 40
Load |\factor |= |# |\of |\elements |/ |# |\of |\slots Which |\traversal |\method |\of |\a |\BST |\produces |\the |\keys |\in |\sorted |
order? |- |\CORRECT |\ANSWERS |\✔✔In-order duh. The |\following |\numbers |\are |\inserted |\into |\an |\empty |\binary |\search |
tree |\in |\the |\given |\order: |\11, |\2, |\4, |\6, |\16, |\13, |\17. |\What |\is |\the |\height |\of |\the |\resulting |\binary |\search |\tree? |- |\CORRECT |\ANSWERS |\✔✔ 3 Which |\of |\the |\traversal |\methods |\is |\sufficient |\to |\reconstruct |\the |\BST |
from |\the |\traversal.
What |\is |\the |\run |\time |\to |\delete |\the |\maximum |\element |\in |\a |\max- heap? |- |\CORRECT |\ANSWERS |\✔✔O(log |\n) After |\deleting, |\Max-Heapify() |\is |\called |\to |\restore |\the |\max-heap |
property. What |\is |\the |\run |\time |\for |\Increase-Key() |\in |\a |\max-heap |\of |\n |\size? |- |
CORRECT |\ANSWERS |\✔✔O(log |\n) What |\is |\the |\run |\time |\for |\Quicksort's |\best |\case |\scenario? |- |\CORRECT |
ANSWERS |\✔✔O(n |\log |\n) What |\is |\the |\run |\time |\for |\Quicksort's |\worst |\case |\scenario |\when |\pivot |\is |\the |\median? |- |\CORRECT |\ANSWERS |\✔✔O(n |\log |\n) What |\is |\the |\run |\time |\of |\Select(A, |\i)? |- |\CORRECT |\ANSWERS |\✔✔O(n) What |\is |\true |\about |\the |\Select |\algorithm? |- |\CORRECT |\ANSWERS |
✔✔Select(A, |\i) |\returns |\the |\i-th |\order |\statistic. Select(A, |\1) |\returns |\the |\minimum |\element |\in |\A.
Calling |\Select(A, |\n/2) |\returns |\the |\median |\element |\if |\n |\is |\odd |\in |\O(n) |\time. What |\does |\each |\internal |\node |\in |\a |\decision |\tree |\represent? |- |
CORRECT |\ANSWERS |\✔✔A |\comparison |\made |\in |\the |\algorithm. What |\does |\each |\leaf |\node |\represent? |- |\CORRECT |\ANSWERS |\✔✔An |
outcome |\of |\the |\problem. What |\is |\the |\maximum |\number |\of |\comparisons |\made |\by |\the |\linear |
search: |
bool |\Search(int |\k, |\int |*A, |\int |\n){ |\for(int |\i |= |\0; |\i |< |\n; |\i++) |\if(A[i] |== |\k) |\return |\true; |\return |\false; } key |== |\A[0] |\T: |\return |\true |\F: |\key |== |\A[1] |\T: |\return |\true |\F: |\key |== |\A[2] |\T: |\return |\true
|\F: |\return |\false |- |\CORRECT |\ANSWERS |\✔✔2. Possible |# |\of |\comparisons |\when |\successful: |\1, |\2, |\3, |\ 4 Possible |# |\of |\comparisons |\when |\unsuccessful: |\ 4 Take |\the |\average: (1 |+ |\ 2 |+ |\ 3 |+ |\ 4 |+ |\4)/5 |= |\2. What |\is |\the |\average |\number |\of |\comparisons |\made |\in |\successful |
searches? bool |\Search(int |\k, |\int |*A, |\int |\n){ |\for(int |\i |= |\0; |\i |< |\n; |\i++) |\if(A[i] |== |\k) |\return |\true; |\return |\false; } key |== |\A[0] |\T: |\return |\true |\F: |\key |== |\A[1] |\T: |\return |\true
|\F: |\key |== |\A[2] |\T: |\return |\true |\F: |\key |== |\A[3] |\T: |\return |\true |\F: |\return |\false |- |\CORRECT |\ANSWERS |\✔✔2. Posssible |# |\of |\comparisons |\when |\successful: |\1, |\2, |\3, |\ 4 Take |\average: (1 |+ |\ 2 |+ |\ 3 |+ |\4)/4 |= |\2. When |\should |\you |\use |\dynamic |\programming? |- |\CORRECT |\ANSWERS |
✔✔When |\there |\is |\a |\repeated |\computation |\of |\subproblems Optimal |\substructure |\where |\the |\optimal |\solutions |\of |\subproblems |
are |\used |\to |\find |\the |\optimal |\solutions |\of |\larger |\subproblems. Recursive |\formulation |\of |\the |\problem. Given |\a |\rod |\of |\length |\n |\that |\we |\decide |\to |\cut |\at |\length |\i. |\How |
many |\subproblems |\are |\left |\after |\we |\make |\this |\cut? |- |\CORRECT |
ANSWERS |\✔✔ 1 |\subproblem |\of |\size |\n-i |\solved |\recursively. |\
What |\is |\the |\running |\time |\of |\the |\algorithm? |- |\CORRECT |\ANSWERS |
✔✔O(n^2) BottomUpCutRod(p, |\n) |\Array |\r[0 |... |\n] |\r[0] |= |\ 0 |\for |\j |= |\ 1 |\to |\n{ |\q |= |-infinity |\for |\i |= |\ 1 |\to |\j |\q |= |\max(q, |\p[i] |+ |\r[j-i]) |\r[j] |= |\q |} return |\r[n] What |\is |\true |\about |\the |\algorithm? |- |\CORRECT |\ANSWERS |\✔✔r[0] |
initialized |\to |\ 0 |\indicates |\that |\there |\is |\no |\revenue |\for |\a |\rod |\of |\length |\0. r[j] |\stores |\the |\solution |\to |\the |\rod |\of |\length |\j |\in |\line |\7. The |\exponential |\time |\recursive |\algorithm |\Cut-Rod |\is |\transformed |
into |\an |\iterative |\algorithm |\that |\runs |\in |\polynomial |\time.
-infinity |\is |\really |-MAXINT |\in |\a |\finite |\precision |\arithmetic |\of |\a |
computer. CutRod(p, |\n) |\if |\n== |\return |\ 0 |\q |= |-infinity |\for |\i |= |\ 1 |\to |\n |\q |= |\max(q, |\p[i] |+ |\CutRod(p, |\n |- |\i)) |\return |\q What |\is |\true |\about |\the |\recursive |\rod |\cutting |\algorithm? |- |\CORRECT |
ANSWERS |\✔✔To |\solve |\the |\original |\problem |\of |\size |\n, |\we |\solve |
smaller |\problems |\of |\the |\same |\type. The |\rod |\cutting |\problem |\has |\the |\optimal |\substructure |\property, |
because |\optimal |\solutions |\to |\a |\problem |\incorporates |\optimal |
solutions |\to |\smaller |\subproblems. Are |\recursive |\problems |\efficient? |- |\CORRECT |\ANSWERS |\✔✔Recursive |
problems |\are |\not |\efficient |\because |\they |\solve |\subproblems |\again |
and |\again.