CSE220: Midterm Exam Solution
Instuctor: Saswati Sarkar
Problem 1 (6pts)
There can be many heaps from the given inputs.
2 = O(n3 pn) is True
Problem 2 (4pts)
n
1 = O(log n) is True
3
2
n = o(n + nlog n) is False
n
p log = ( ) is True
n
n
on
Problem 3 (10p
Solutions for Midterm Practice Questions
sn the rst stepD the list is prtitioned with element
Q s the pivot elementF he result is one list e with I P H S nd nother
list f with W S R S T PI QF he two sulists re sorted y reursive lls to
quiksortF vist e giv
Solutions for Homework 4
Problem 1: 8 pts Design an algorithm for deletion in an AVL tree (lazy
deletion not allowed). You have to maintain the AVL property after deletion.
Deletion in AVL trees while maintaining the AVL property is somewhat
more complica
Homework 3 Solutions
enlyze the reorder rverslF ou hve list of n rel numersD nd you wnt to
form inry serh tree with themF ht is the tree formtion omplexityc ould your nswer
hngeD if s tell you tht when your tree hs k nodes then its depth vries from tht of
Solutions for Homework 5
Consider a generalization of the binary heap structure. Every
node has children. It is an almost complete,d-ary tre, and a node must be
less than or equal to all its children. Design an array representation of the
heap. Design a D
Solutions for Homework 6
qive n
@ A lgorithmF
Solution: gonsider the representtion of integers in seE F en integer
requires logn CI digits in seE representtionF sn se tht a 2D
the ove formul gives logn 2 C I a Q digitsF
e n use rdixEsort on this represent
Solutions for Homework 2
ou hve seen the implementtion of stk using n rryF sn
the implementtion shown in lssD you dd the rst element t position HD next element t position
ID etF ou lwys dd nd delete elements from the end of the listF gonsider n rry of siz
Homework 7
row mny its do you need to store the size nd height of the trees in the nion
pind dt struturec qive your nswer for dierent implementtions @eFgFD ritrry unionsD unions
y sizeD union y heightD pth ompression etFAF
he size for every implementtion
Homework 11 Solutions
Problem 1 Solution: Both algorithms work if some edges have negative
weight edges. Their correctness is not aected by the negative weight edges.
In Kruskal's algorithm the safe edge added to A (subset of a MST) is always
a least weig
CSE220: Midterm Exam
Instructor: Saswati Sarkar
Friday, March 9 2001
Your answers should be brief and to the point. If you think you are
having diculty, don't panic. Move to another problem and do your best.
Good luck!
Problem 1: 6 pts Construct a binary
CSE220: Midterm Practice Questions
Instructor: Saswati Sarkar
Exam Rules: You can bring an A4 page of formulas, algorithms, or
whatever else you would like to remember with you. Everything there should
be in your own hand-writing.
Problem 1 Consider the l
Solutions for Homework 2
ou hve seen the implementtion of stk using n rryF sn
the implementtion shown in lssD you dd the rst element t position HD next element t position
ID etF ou lwys dd nd delete elements from the end of the listF gonsider n rry of siz
Homework 3 Solutions
enlyze the reorder rverslF ou hve list of n rel numersD nd you wnt to
form inry serh tree with themF ht is the tree formtion omplexityc ould your nswer
hngeD if s tell you tht when your tree hs k nodes then its depth vries from tht of
Solutions for Homework 4
Problem 1: 8 pts Design an algorithm for deletion in an AVL tree (lazy
deletion not allowed). You have to maintain the AVL property after deletion.
Deletion in AVL trees while maintaining the AVL property is somewhat
more complica
Solutions for Homework 5
Consider a generalization of the binary heap structure. Every
node has children. It is an almost complete,d-ary tre, and a node must be
less than or equal to all its children. Design an array representation of the
heap. Design a D
Solutions for Homework 6
qive n
@ A lgorithmF
Solution: gonsider the representtion of integers in seE F en integer
requires logn CI digits in seE representtionF sn se tht a 2D
the ove formul gives logn 2 C I a Q digitsF
e n use rdixEsort on this represent
Homework 7
row mny its do you need to store the size nd height of the trees in the nion
pind dt struturec qive your nswer for dierent implementtions @eFgFD ritrry unionsD unions
y sizeD union y heightD pth ompression etFAF
he size for every implementtion
D P F 3Q V D 3 3Q
%aaaEi4~1y1&VGF8Xa"52" `t g
3Q 3 f5q D w 5 Y FQA V H SA 5 3 V 39Tx D1 pFQ S5 D P H5 3A D1A P
G&9E4&1`4aU32W&H4Qau@&[email protected]&Qt3f4Gvi48XSEcfw_4~1HE@&FCE&5&D4Cu41
P1 Dw 5 3 V HQ F 3Axf V T H D5 D 5 3
4e&1G@&9uxFu4uyU1&[email protected]&VsW4g" egtaa
Homework 11 Solutions
Problem 1 Solution: Both algorithms work if some edges have negative
weight edges. Their correctness is not aected by the negative weight edges.
In Kruskal's algorithm the safe edge added to A (subset of a MST) is always
a least weig
D P F 3Q V D 3 3Q
%aaaEi4~1y1&VGF8Xa"52" `t g
3Q 3 f5q D w 5 Y FQA V H SA 5 3 V 39Tx D1 pFQ S5 D P H5 3A D1A P
G&9E4&1`4aU32W&H4Qau@&[email protected]&Qt3f4Gvi48XSEcfw_4~1HE@&FCE&5&D4Cu41
P1 Dw 5 3 V HQ F 3Axf V T H D5 D 5 3
4e&1G@&9uxFu4uyU1&[email protected]&VsW4g" egtaa