CSC2103 Lecture01
CSC2103 Lecture01
○ Algorithms
○ Properties of algorithms
○ Data Structures
CSC2103 – Data Structures ○ Examples
○ Some mathematical Revision
& Algorithms ○ Some Programming Revision
1 2
OVERVIEW ALGORITHMS
○ What is an algorithm?
○ Algorithm
● A procedure or formula for solving a
● What is an algorithm? problem
● Where do they come from?
findMax(Array)
● Why do we need algorithm? {
declare a variable to store
maximum value
max = Array[0]
Start do loop
Compare max with all array
values
if array_value > max
max = array_value
3
End Loop 4
print max value
CSC2103 - Data Structures & Algorithms } CSC2103 - Data Structures & Algorithms
3 4
ALGORITHMS ALGORITHMS
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
5 6
7 8
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
7 8
PROPERTIES OF ALGORITHMS PROPERTIES OF ALGORITHMS
Efficiency Applicability
○ Usually this is a measure of speed, how ○ Generally, what is the domain of the
many basic steps are needed to complete a algorithm?
task.
○ Sometimes it is a measure of space, how
○ More importantly, what sub domain is the
much storage is needed. algorithm efficient in?
○ Rarely, it is a measure of some other
property or combination of properties
9 10
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
9 10
○ A data structure is a systematic way of Data structures – more than just data?
organizing a collection of data.
○ Organized collection of data
○ A static data structure is one whose
capacity is fixed at creation. ○ Represents an abstract data type in an
E.g.: array. efficient way
○ A dynamic data structure is one whose ○ Efficient? In what way?
capacity is variable, so it can expand or
contract at any time. ● Allows for efficient access by the algorithm
E.g.: linked list, binary tree. ● Uses a minimum of storage
○ For each data structure we need algorithms
for insertion, deletion, searching, etc.
12
11 12
ALGORITHMS-EXAMPLE ALGORITHM- EXAMPLE
○ A Recipe ○ Multiplication
○ Tying shoes ● Long multiplication (Grade School)
○ Multiplication ● Multiplication à la russe
● Divide and conquer multiplication
○ Programming in Visual basic
13 14
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
13 14
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
15 16
MULTIPLICATION À LA RUSSE MULTIPLICATION À LA RUSSE
931 88 931 88
17 18
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
17 18
931 88 931 88
Continue
the 465 176 465 176
division 232 352 232 352
and 116 704
doubling
process
until the
left column
number
becomes 1.
19 20
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
19 20
MULTIPLICATION À LA RUSSE MULTIPLICATION À LA RUSSE
931 88 931 88
58 1408 58 1408
29 2816
21 22
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
21 22
58 1408 58 1408
29 2816 29 2816
14 5632 14 5632
7 11264
23 24
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
23 24
MULTIPLICATION À LA RUSSE MULTIPLICATION À LA RUSSE
931 88 931 88
58 1408 58 1408
29 2816 29 2816
14 5632 14 5632
7 11264 7 11264
3 22528 3 22528
1 45056
25 26
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
25 26
58 1408 58 1408
14 5632 14 5632
The result of
7 11264 the addition of 7 11264 11264
27 28
EXERCISE 1 DIVIDE & CONQUER MULTIPLICATION
29 30
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
29 30
○ For example, to obtain the result of 931 x ○ Let’s first look at how the two numbers are
1234 using divide and conquer method: actually multiplied using some
○ Split each of the numbers into two halves, representational symbols.
the right half and the left half, ○ Let the two numbers as 931 and 1234 as a
○ each with n/2 digits; e.g., and b respectively.
○ Thus, Left-half of a (al) = 09, Right-half of
931 is split into 09 – left half and 31 right half a (ar) = 31, Left-half of b (bl) = 12 and
1234 is split into 12 –left half and 34 right half Right-half of b (br) = 34.
31 32
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
31 32
DIVIDE & CONQUER MULTIPLICATION DIVIDE & CONQUER MULTIPLICATION
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
33 34
bl x 10n/2 x (bl x 10n/2 x ar) ○ Note: The 10n position value can be obtained by
al x 10n/2 shifting to the left the value n position.
(bl x al)10n + [(br x al)+(bl x ar)] x 10n/2 + (br x ar)
35 36
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
35 36
DIVIDE & CONQUER MULTIPLICATION
37 38
○ Exponents
○ Analysis of algorithms 1.
2.
3.
4.
39 5. 40
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
39 40
ANALYSIS OF ALGORITHMS ANALYSIS OF ALGORITHMS
41 42
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
41 42
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
43 44
THEORETICAL ANALYSIS
45 46
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
47 48
ARRAY ARRAY – OPERATION COMPLEXITY
49 50
CSC2103 - Data Structures & Algorithms CSC2103 - Data Structures & Algorithms
49 50
ARRAY EXAMPLE
52
51
51 52
MULTIPLICATION
○ Japanese way
● 22 x 33
● 123 x 231
53
53