Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Algorithms and data structures(CS2321) assignment 2 solution

Rating
-
Sold
-
Pages
5
Grade
A
Uploaded on
14-09-2021
Written in
2019/2020

the documents contain solutions for CS2321 exams and quizzes

Institution
Course

Content preview

Kingdom of Saudi Arabia ‫المملكة العـربية السعودية‬
Ministry of Higher Education ‫وزارة التعليم العالي‬
Prince Sattam bin Abdulaziz University ‫جامعة األمير سطام بن عبدالعزيز‬
College of Computer Engineering and Sciences ‫كلية هندسة وعلوم الحاسب‬
Computer Science Department ‫قسم علوم الحاسب‬
Course Title: Data Structures and Algorithms (CS2321) / 1438-1439 (1)
Homework 2 (Solutions)
(1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
A D C D B D D A C D C B C B C B
(2)
Sort the following functions in the decreasing growth rate:
3 N 2 3
N, N log N, N log log N, N log N, 2 , 2 , N log N, N
1 2 3 4 5 6 7 8
N 3 2 3
2 N N log N N log N N log N N log log N 2
N

(3)
Let the two functions f ( n )=n2 and g ( n )=4 n log n. Complete the following table:
n f (n) g( n)
2 4 8
4 16 32
8 64 96
16 256 256
32 1024 640
64 4096 1536
128 16384 3584
What is the turning point of the two functions f (n) and g( n)?
The Turning point is n=16 we can see that f ( n )=g ( n )=256. If n<16 , f ( n )< g ( n ) and If n>256 , f ( n )> g ( n )
Compare the growth rate of the two functions f (n) and g( n)?
The growth rate of f (n) is faster than the growth rate of g( n) .
(4)
1. The running time for this fragment is O(N).
Proof
N −1
∑ 1=N
i=0
2. The running time for this fragment is O(N2).
Proof
N −1 N−1 N−1
∑ ∑ 1= ∑ N=N . N =N 2
i=0 j=0 i=0


CS2321 – Homework 2 Page 1/2

, 3. The running time for this fragment is O(N3).
Proof
2
N −1 N −1 N −1
2 2 3
∑∑ 1 = ∑ N =N . N =N
i=0 j=0 i=0

4. The running time for this fragment is O(N2).
Proof
N −1 i−1 N −1 N−1
(N −1) N N 2−N
∑ ∑ 1= ∑ i= ∑ i= 2
=
2
i=0 j=0 i=0 i=1
5. The running time for this fragment is O(N5).
Proof
2
N −1 i −1 j−1 N −1 i 2 −1 N −1 2 2 N −1
(i −1 )i 1
∑ ∑ ∑ 1 =∑ ∑ j =∑ = ∑ (i4 −i2 )
i=0 j =0 k=0 i=0 j=0 i=0 2 2 i=0
N−1 N −1
=
1
2 [∑ i=0
i 4− ∑ i2

2
i=0
]
1 N ( N +1)(2 N +1)(3 N +3 N −1) N ( N +1)(2 N +1)
=
2 30[ 2

6 ]
1 N ( N +1)(2 N +1)(3 N +3 N −1)−5 N ( N +1 )(2 N +1 )
=
2 30 [ ]
1
= [ N ( 2 N 2 +3 N +1)(3 N 2 +3 N −1)−5 N ( 2 N 2 +3 N +1 ) ]
60
1
= [ 6 N 5 + polynomial in deg ree 4 ]
60

6. The running time for this fragment is O(N4).
Proof
j−1
∑ 1= j
The innermost loop running time is . k =0

The middle loop is executed only if j is a duplication of i. Then the running time for it is i
i i
i(i+1) i 3 +i
∑ li=i ∑ l=i 2
=
2 . Thus the total running time is
+ 2i + 3i + … + i2 = l=1 l=1
N −1 3 N −1 N−1
∑ i2 +i =12 ∑ i3+ ∑ i
i=1
2 2
[ i=1 i=1 ]
1 N ( N −1) ( N −1)N
=
2 4
4
[3
+
2
2 ]
N −2 N +3 N −2 N
=
8
Then the running time is O(N4).




CS2321 – Homework 2 Page 2/2

Written for

Institution
Course

Document information

Uploaded on
September 14, 2021
Number of pages
5
Written in
2019/2020
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
InformationSystemsSTD

Also available in package deal

Get to know the seller

Seller avatar
InformationSystemsSTD prince sattam bin abdulaziz university
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions