Professional Documents
Culture Documents
CS611 - L01 - Data Structures - Introduction - Saleh
CS611 - L01 - Data Structures - Introduction - Saleh
CS611 - L01 - Data Structures - Introduction - Saleh
…
Correctness:
Does the algorithm do what is intended.
Performance:
Whatis the running time of the algorithm.
How much storage does it consume.
(Simplified) Definitions.
Best-Case Execution Time (BCET): The shortest time that the
algorithm takes to solve the problem.
Worst-Case Execution Time (WCET): The longest time that the
algorithm takes to solve the problem.
Average-Case Execution Time (ACET): The expected time that the
algorithm takes to solve the problem on average.
The average execution time is the arithmetic mean of all execution
times if all inputs are equally likely to occur, otherwise we use
probability distributions to compute it.
Algorithm Execution-Time Analysis
Algorithm A1
A1 computes the result in a constant number of steps at
runtime.
What is the execution time T(A1) for A1?
T(A1) = β1 (β1 is some constant)
T(A1) does not depend on the input.
If input is 1, 10, 100, etc. T(A1) will not change (significantly).
Algorithm A2
A2 computes the result in a variable number of steps at
runtime depending on input size.
What is the time T(A2) for A2?
T(A2) = α2n + β2 (α2, β2 are some constants)
T(A2) depends on the input size
If input is 1, 10, 100, etc. T(A2) will change.
Algorithm Execution-Time Analysis
T(A1) = β1
T(A2) = α2n + β2
Name Symbol
Constant O(1)
Logarithmic O(log n)
Linear O(n)
Log-linear O(n log n)
Quadratic O(n2)
Cubic O(n3)
Polynomial O(np)
Exponential O(bn)
Factorial O(n!)
Incomputable O(∞)
Algorithms vs Programs
19
The memory address of each array’s cell can be computed from its index using a
very simple mathematical formula.
The address of the first cell of the array is:
address(A[0]) = s.
This is implementation dependent.
The linked lists we have seen so far are called singly linked lists.
A node points to its successor in the list.
A node has one pointer only.
There are also doubly linked lists.
A node points both to its successor and its predecessor in the list.
The node has two pointers.
Consume more space but allow easier traversal for some algorithms.
There are also circularly singly linked lists.
The tail points back to head.
There is no “real” head or tail.
A special node is used called cursor e.g. to know where to start and
finish traversing the circularly list.
Concrete Data Structures and Abstract Data Structures/Types
Stack of books
Stack of Plates
Queues
Please learn to queue
in your everyday life,
and teach/tell people
around you to queue.
• Queuing is an important
rule in life.
• By not queuing:
• You take other
people’s rights.
• You show you are
A queue of people. not civilised.