0% found this document useful (0 votes)
125 views4 pages

Written Assignment1 Sample Solution

This document provides sample solutions to a written assignment on data structures and algorithms. It includes 6 questions covering topics like asymptotic analysis, recursion, stacks, trees, linked lists, and merging two sorted lists. The questions test concepts like determining time complexities, preorder/inorder/postorder tree traversals, implementing operations on data structures, and performing sorting and merging tasks. Full marks are awarded for providing correct solutions and steps in the allotted space.

Uploaded by

jackaccyou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views4 pages

Written Assignment1 Sample Solution

This document provides sample solutions to a written assignment on data structures and algorithms. It includes 6 questions covering topics like asymptotic analysis, recursion, stacks, trees, linked lists, and merging two sorted lists. The questions test concepts like determining time complexities, preorder/inorder/postorder tree traversals, implementing operations on data structures, and performing sorting and merging tasks. Full marks are awarded for providing correct solutions and steps in the allotted space.

Uploaded by

jackaccyou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

COMP2015 Data Structure and Algorithms

Semester 2, Academic Year 2016-2017

Written Assignment 1

Sample Solutions (Full mark is 90)

1. 0.9999100n < 5log(n+100)10 < nlg20n < 1000n2+10lgn+1 < 1.00010.01n < 2n < (0.001n)n < n!
(8 marks)

Hint: according to Stirling's approximation, i.e. ! 2 , we have:
!
lim = lim 2 = lim 2 (370.37) =
(0.001) 0.001
Hence, ! grows faster than (0.001)

2.
(a) (5 marks)
Let T(n) be the running time of the method call func(n). There are log n iterations for the while
loop, and within the loop body the running time is some constant value, thus:
() = log() = (log )
(b) (5 marks)
Let T(n) be the running time of the method call func(n). There are lg n iterations for the outter
while loop, n iterations for the inner loop, and within the inner loop body the running time is
some constant value, thus:
() = = ( log )

(c) (10 marks)


Let T(n) be the running time of the method call func(n).
1 = 1
() =
+ + > 1
2 2

Thus () = 2 2 + = 4 4 + = = (1) + = ()

3.
(a) (5 marks)
Input Stack Output Input Stack Output
A empty A C +*( ABC-C
+ + A + +*(+ ABC-C
( +( A D +*(+ ABC-CD
B +( AB ) +* ABC-CD+
- +(- AB / +/ ABC-CD+*
C +(- ABC E +/ ABC-CD+*E
) + ABC- null empty ABC-CD+*E/+
* +* ABC- / +/ ABC-CD+*
( +*( ABC-
(b) (5 marks)
Detailed steps are as follows:

(c) (5 marks)
Preorder traversals: +A/*-BC+CDE
Inorder traversals: A+B-C*C+D/E
Postorder traversals: ABC-CD+*E/+

4.
(a) Detailed steps are as follows: (10 marks)
(b) Detailed steps are as follows: (10 marks)

5.
(a) The result is as follows: (5 marks)

(b) The result is as follows: (2 marks)


(c) Detailed steps are as follows: (10 marks)

6.
(a) The output is: 13, 6, 24, 3, 18 (2 marks)

(b) The output is: 30, 15, 7, 5, 21 (2 marks)

(c) The result is as follows: (6 marks)

Node Data Next


[0] 24 2
[1] 21 -1
[2] 3 -1
Second_List_start [3] 15 5
First_List_start [4] 13 0
[5] 5 1

Note: for question 6(c), if the length of 2D array is 10 and results are correct (i.e. deletion is done
in-place), full marks would also be given. If (i) and (ii) are done in separate 2D arrays and results
are correct, 2 marks would be deducted.
< END >

You might also like