ye junjie n.
Skip this Video
Loading SlideShow in 5 Seconds..
Ye Junjie PowerPoint Presentation
Download Presentation
Ye Junjie

Loading in 2 Seconds...

play fullscreen
1 / 14

Ye Junjie - PowerPoint PPT Presentation

  • Uploaded on

Asympto t ic Notations & Pseudocode CSC3160 tutorial (1 st week) Office: SHB 913 Office hour: M10:00-12:00 Email: Ye Junjie. About the course . CSCI 3160 Design and Analysis of Algorithms Instructor : Prof. CAI Leizhen 蔡雷震 Tutor: Ye Junjie 叶俊杰 (SHB 913)

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Ye Junjie' - gerodi

Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
ye junjie

Asymptotic Notations & PseudocodeCSC3160 tutorial (1st week)Office: SHB 913Office hour: M10:00-12:00Email:

Ye Junjie

about the course
About the course

CSCI 3160 Design and Analysis of Algorithms

Instructor: Prof. CAI Leizhen蔡雷震

Tutor: Ye Junjie叶俊杰 (SHB 913)

Office HourM10:00 - 12:00

Course Homepage:

Textbook: Algorithms (S.Dasgupta, C.Papadimitriou and U.Vazirani)


Asymptotic Notations

Big O natation

Other notations: Ω, Θ



Sitting Plan Problem

asymptotic notations big o
Asymptotic notations: Big O


We say f(n) = O(g(n)) if there exist constants c, n0 such that |f(n)| ≤ c |g(n)|

For all n ≥ n0


n = O(2n), n = O(0.5n), n = O(n2), 10000n = O(0.0000001n2).

n2 ≠ O(n), n≠ O(log n).

asymptotic notations big o1
Asymptotic notations: Big O

How to determine?

f(n)=O(g(n)) means when , the order of f(n) ≤ g(n)

If or constant, then f(n)=O(g(n))

Spectrum of functions…

Smaller Larger

Exponential functions are faster than polynomial functions

Polynomial functions are faster than logarithmic functions

log n = O(n)

n = O(2n)

O(1) … loglog n, … log n, log2 n, …

n1/3, n1/2 , n, n2, n3 … 2n, 2n^2 … 22^n …

asymptotic notations
Asymptotic notations: Ω & Θ


We say f(n) = Ω (g(n)) if there exist constants c, n0 such that

|f(n)| ≥ c |g(n)|

For all n ≥ n0

We say f(n) = Θ(g(n)) if there exist constants c1, c2, n0 such that

c1 |g(n)| ≤ |f(n)| ≤ c2 |g(n)|

For all n ≥ n0


f(n) = O(g(n)) if and only if g(n) = Ω(f(n)).

f(n) =Θ(g(n)) if and only if f(n) = O(g(n)) and f(n) = Ω(g(n)).

O means “upper bound”, Ω means “lower bound”.

examples o
Examples:O, Ω, Θ

f(n)= __(g(n))

(a) f(n) = n-100 ; g(n) = n-200

(b) f(n) = n1/2 ; g(n) = n2/3

(c) f(n) =100n + log n ; g(n) = n + (log n)2

(d) f(n) = n1.01 ; g(n) = n log2n

use of pseudocode
Use of Pseudocode

BEFORE Composing an argument  structures organization

BEFORE Writing a program  Pseudocode

Like a flow chart:

Aims: To make everything clear and readable

Attend lecture


tutorial is useful



Attend tutorial

Skip tutorial

Do homework



1 attend lecture

2 if tutorial is useful

attend tutorial


skip tutorial

3do homework

what is pseudocode
What is Pseudocode

Pseudocode is not a programming language.

not C/C++, not Java, not Assembly Language, ……

Pseudocode is an description of algorithm.

Pseudocode is any idea of a computer program intended for human reading rather than machine reading.

In this course, we use Pseudocode to present algorithms.

example 1 bubble sort
Example 1: Bubble sort
  • A simple sorting algorithm
    • Sort a list of numbers from small to large
  • It works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order.
example 1 bubble sort1
Example 1: Bubble sort
  • Pseudocode:
  • 1 BUBBLE-SORT ( A : list of numbers )
  • 2 for i ← length(A) down to 1
  • 3 for j ← 1 to i-1
  • 4 if A [j] > A [j+1] then
  • 5 swap A [j] and A[j+1])
  • 8 end if
  • 9 end for
  • 10 end for
sitting plan problem
Sitting Plan Problem

Sitting Plan: How to remove k students(totally n students) so that the minimum distance between two students is at least d?

Seats in a Line: linear time

Seats in a loop: hints O(n^2) O(dn) ?

General model: vertex cover

example 2
Example 2

Seats in a Line: linear time


1 Seat_Line ( S[1] to S[n] denote the places of n students)

2 preseat← S[1], count ← 0

3 for i← 2 to n-1

4 if S[i] – preseat =< d then

5 remove S[i], count++

6 if count > k then

7 answer NO!

8 end if

9 else

10 preseat ← S[i]

11 end if

12 end for