MH3400 Lecture 1 Jan 13 2015
MH3400 Lecture 1 Jan 13 2015
MH3400 Lecture 1 Jan 13 2015
Andrew Lim
Course Administration
Instructor Information
Andrew Lim
Email : andrewlim@ntu.edu.sg
Office Phone : 6513 8652
Skype Contact: limandrew@hotmail.com, please identify
yourself when contacting me for the first time
Lecture
Every TUE from 1330 1530 hrs SPMS LT2, please take
note of some changes
Tut/Lab
Every FRI from 08301030hrs COMPLAB1 from Wk2-Wk13
Some Tut/labs may be taught by my grad students.
2
Course Administration
Grading Criteria
2-hour Final Written Exam 50%
Continual Assessment
50%
Written and Lab Assignments, weights would be given for each
assignment.
Class participation coupon
Lect 1
Postponed
Postponed
Lect 2
Lect 3
Lect 4
Lect 5
**Makeup
1000-1200hrs Lect 6
1330-1530hrs Lect 7
Mar10:
Mar17:
Mar24:
Mar31:
Apr7:
Apr14:
Lect 8
Lect 9
Lect 10
Lect 11
Lect 12
Lect 13
Note that
Mar 2-6 term-break
4
Schedule Lab/Tutorial
Jan 16:
Jan 23:
Jan 30:
Feb 6:
Feb 13:
Feb 20:
Feb 27:
Mar 13:
No Lab
Mar20: Lab 7
Lab 1
Mar27: Lab 8
Lab 2
Apr3:
** Good Friday
Lab 3
Apr10:
Lab 9
Lab 4
Apr17:
Lab 10
** Lunar NY
Note that
Lab 5
Mar 2-6 term-break
Lab 6
Properties of an algorithm?
Input
Zero or more quantities are externally supplied
Output
At least one quantity is produced
Definiteness
Each instruction is clear and unambiguous
Finiteness
Terminates after a finite number of steps
Effectiveness
Every instruction must be very basic so that it can be
carried out in principle by a person using only pencil
and paper. It not only need to be definite, it has to be
feasible
Sorting
Selection Sort
//third attempt
Selection Sort
//third attempt
void selectionsort(Type a[], int n)
//sort the array a[1:n] into non-decreasing
order
{
for (i=1; i<=n, i++){
int j=i;
for (int k=i+1; k<=n; k++)
if (a[k]<a[j]) j=k;
Type t=a[i]; a[i]=a[j]; a[j]=t;
}
}
10
12
Insertion Sort
input array
sorted
right sub-array
unsorted
13
Insertion Sort
14
Bubble Sort
8
i=1
i=1
i=1
i=1
i=3
i=4
9
j
i=5
i=2
i=1
i=1
i=1
9
j
i=6
9
i=7
j
15
Mergesort - Divide
1
5 2
5 2
5 2
1 3
1 3
16
1 2
2 4
2 5
1 2
1 3
17
Quicksort
18
Type of Analysis
Worst case
Provides an upper bound on running time
Best case
Provides a lower bound on running time
Average case
Provides a prediction about the running time
Assumes that the input is random
** Benchmark case
Provide the prediction about the running on cases
that are relevant to the problem the algorithm is
solving
19
execution times?
Express
20
Selection Sort
21
Asymptotic Analysis
To
22
Rate of Growth
The
23
Asymptotic notation
24
Asymptotic notation
25
Asymptotic notation
26
O-notation
n4
Class Exercise
Method 2?
29
30
for all n
10
100 iterations is
< ( )100 < 2.04 x 10-10
31
< ( )
log
if we pick
Note that
x
log log x log y
y
-c log
< n-
a logb x x logb a
33
34
35
http://data.computationallogistics.org:8081/NTU2015MH3400/
Username: NTU2015MH3400
Password: diFAcyugLeDu
36
Data Sample
37
38
Assignment 1 - Individual
Part 2 100 marks
Write the relevant SQL statements to generate the
following and cut and paste the screenshot of the
results into a word document to show the results.
a) Find the # of product groups
b) Find the # of products
c) Find the # of sizes
d) Find the # of different colors
e) Find the # of stores
39
Assignment 1 - Individual
Part 2 100 marks
f) Find for each store what is its total
sales/revenue for year 2012, 2013, 2014
g) Find the total sales/revenue for each day of the
week (i.e. Monday, Tuesday, Wednesday, etc)
h) Find the total sales/revenue for 2012, 2013, 2014
i) Find the total sales/revenue for each month
from Jan to Dec for the year 2013
j) Find the total sales of each store for the year
2013
The assignment is not simple, start early!
40