Professional Documents
Culture Documents
1 - Introduction To Data Structures and Algorithms
1 - Introduction To Data Structures and Algorithms
+ +
TOPICS
BIG-O NOTATION
Introduction to Data Structures and Algorithms
Data Structures PSEUDOCODES
+ +
TOPICS DATA STRUCTURES VS ALGORITHMS
+ +
Example of Data Structure DATA STRUCTURES VS ALGORITHMS
1
10/13/2020
+ +
DATA STRUCTURES VS ALGORITHMS Example of Algorithm
+ +
TOPICS ROLE OF ALGORITHMS IN COMPUTING
+ +
ROLE OF ALGORITHMS IN COMPUTING ROLE OF ALGORITHMS IN COMPUTING
2
10/13/2020
+ +
ROLE OF ALGORITHMS IN COMPUTING ROLE OF ALGORITHMS IN COMPUTING
+ +
ROLE OF ALGORITHMS IN COMPUTING ROLE OF ALGORITHMS IN COMPUTING
+ +
ROLE OF ALGORITHMS IN COMPUTING ROLE OF ALGORITHMS IN COMPUTING
For a concrete example, let us pit a faster Suppose that computer A executes 10
computer (computer A) running insertion billion instructions per second (faster than
sort against a slower computer (computer any single sequential computer at the time
B) running merge sort. They each must of this writing) and computer B executes
sort an array of 10 million numbers. only 10 million instructions per second, so
that computer A is 1000 times faster than
computer B in raw computing power.
3
10/13/2020
+ +
ROLE OF ALGORITHMS IN COMPUTING ROLE OF ALGORITHMS IN COMPUTING
To make the difference even more Suppose further that just an average
dramatic, suppose that the world’s programmer implements merge sort, using
craftiest programmer codes insertion sort a high-level language with an inefficient
in machine language for computer A, and compiler, with the resulting code taking
the resulting code requires 2n2 instructions 50n lg n instructions.
to sort n numbers.
+ +
ROLE OF ALGORITHMS IN COMPUTING ROLE OF ALGORITHMS IN COMPUTING
To sort 10 million numbers, computer A To sort 10 million numbers, computer B
takes takes
+ +
ROLE OF ALGORITHMS IN COMPUTING ROLE OF ALGORITHMS IN COMPUTING
By using an algorithm whose running time The advantage of merge sort is even more
grows more slowly, even with a poor pronounced when we sort 100 million
compiler, computer B runs more than 17 numbers: where insertion sort takes more
times faster than computer A! than 23 days, merge sort takes under four
hours. In general, as the problem size
increases, so does the relative advantage
of merge sort.
4
10/13/2020
+ +
TOPICS BIG-O NOTATION
+ +
BIG-O NOTATION BIG-O NOTATION
+ +
BIG-O NOTATION BIG-O NOTATION
5
10/13/2020
+ +
BIG-O NOTATION BIG-O NOTATION
+ +
NOTATION BIG-O NOTATION
+ +
BIG-O NOTATION BIG-O NOTATION
6
10/13/2020
+ +
BIG-O Notation BIG-O Notation
+ +
BIG-O NOTATION BIG-O NOTATION
+ +
BIG-O NOTATION TOPICS
BIG-O NOTATION
PSEUDOCODES
7
10/13/2020
+ +
PSEUDOCODES PSEUDOCODES
Is a plain language description of steps in For the most part interpreting the
an algorithm or another system. pseudocode is trivial as it looks very much
like a more abstract C++, or C#:
Often uses structural conventions of
normal programming language, but is
intended for human reading rather than
Pre-conditions should always be enforced.
machine reading.
+ +
PSEUDOCODES PSEUDOCODES
For the most part interpreting the For the most part interpreting the
pseudocode is trivial as it looks very much pseudocode is trivial as it looks very much
like a more abstract C++, or C#: like a more abstract C++, or C#:
+ +
PSEUDOCODES PSEUDOCODES
For the most part interpreting the All algorithms start with a simple algorithm
pseudocode is trivial as it looks very much signature, e.g.
like a more abstract C++, or C#:
1) algorithm AlgorithmName(arg1, arg2, ...,
argN)
All primitive language constructs are 2) ...
explicitly begun and ended. n) end AlgorithmName
8
10/13/2020
+ +
PSEUDOCODES PSEUDOCODES
Immediately after the algorithm signature we list any Pre algorithm Add(value)
Pre: value is the value to add to the list
or Post conditions. Post: value has been placed at the tail of the list
1) algorithm AlgorithmName(n) n ← node(value)
if head = ∅
2) Pre: n is the value to compute the factorial of head ← n
3) n≥0 tail ← n
else
4) Post: the factorial of n has been computed tail.Next ← n
tail ← n
5) // ... end if
n) end AlgorithmName end Add
+
PSEUDOCODES
PROGRAM CleanTheFridge
for EACH item in the fridge DO
IF(the item is rotten) THEN
throw away the item
ELSE
put the item back in the fridge
END
END
Make Dinner
END