0% found this document useful (0 votes)
31 views

Find Big O Notation: CS 2321 (Data Structures and Algorithms) Assignment 1 (Algorithm Analysis)

This document outlines an assignment for a data structures and algorithms course. It includes problems analyzing the time complexity of code snippets using Big O notation. Students are asked to prove time complexities, determine Big O for functions, and analyze the worst-case time complexity of nested loops and a simple for loop that assigns values to an array.

Uploaded by

Mahmoud Albatie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Find Big O Notation: CS 2321 (Data Structures and Algorithms) Assignment 1 (Algorithm Analysis)

This document outlines an assignment for a data structures and algorithms course. It includes problems analyzing the time complexity of code snippets using Big O notation. Students are asked to prove time complexities, determine Big O for functions, and analyze the worst-case time complexity of nested loops and a simple for loop that assigns values to an array.

Uploaded by

Mahmoud Albatie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 2321 (Data Structures and Algorithms)

Assignment 1 (Algorithm Analysis)

1. 𝑷𝒓𝒐𝒗𝒆
 𝟓𝒏 𝒍𝒐𝒈 𝟐 𝒏 + 𝟖𝒏 − 𝟐𝟎𝟎 = 𝑶(𝒏 𝒍𝒐𝒈 𝟐 𝒏)

 𝒏𝟐 + 𝟒𝟐𝒏 + 𝟕 = 𝑶(𝒏𝟐 )

2. Find Big O notation

 𝟐 𝒍𝒐𝒈 𝟐 𝒏 + 𝟐 = 𝑶…………….

 𝒏 + 𝟐 = 𝑶…………….

 𝟐𝒏 + 𝟏𝟓𝒏𝟏/𝟐 = 𝑶…………….

 𝟓 𝒍𝒐𝒈 𝟐 𝒏 + 𝟐𝒏𝟑 = 𝑶…………….

 𝒏 𝒍𝒐𝒈 𝟐 𝒏 + 𝒏𝟐 = 𝑶…………….

3. What is the worst-case complexity of the each of the following code


fragments?

a) Two loops in a row:


for (i = 0; i < N; i++) {
sequence of statements
}
for (j = 0; j < M; j++) {
sequence of statements
}

……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
How would the complexity change if the second loop went to N instead of M?

b) A nested loop followed by a non-nested loop:


for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
sequence of statements
}
}
for (k = 0; k < N; k++) {
sequence of statements
}

……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………

c) A nested loop in which the number of times the inner loop executes
depends on the value of the outer loop index:
for (i = 0; i < N; i++) {
for (j = N; j > i; j--) {
sequence of statements
}
}

……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………

4. Consider the following (simple) code:


for (int i = 0 ; i < N; i++) {
a[i] = i ;
}

 Calculate the number of operations Find Big O, Ω and 𝜽 notation

……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………

 Find Big O, Ω and 𝜽 notation


……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………

Do your best
Wamda

You might also like