0% found this document useful (0 votes)
256 views23 pages

JEDI Slides-DataSt-Chapter01-Basic Concepts and Notations

The document discusses key concepts related to data structures and algorithms, including: 1) It defines data types, abstract data types, and data structures, and explains how they are related. 2) It describes the problem solving process and how problems, machines, and solutions are linked. 3) It explains addressing methods like computed and link addressing used to access data structures. 4) It introduces complexity analysis using big-O notation to describe how efficiently algorithms use resources like time and space.

Uploaded by

Abdreyll Gerard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as SXI, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
256 views23 pages

JEDI Slides-DataSt-Chapter01-Basic Concepts and Notations

The document discusses key concepts related to data structures and algorithms, including: 1) It defines data types, abstract data types, and data structures, and explains how they are related. 2) It describes the problem solving process and how problems, machines, and solutions are linked. 3) It explains addressing methods like computed and link addressing used to access data structures. 4) It introduces complexity analysis using big-O notation to describe how efficiently algorithms use resources like time and space.

Uploaded by

Abdreyll Gerard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as SXI, PDF, TXT or read online on Scribd
You are on page 1/ 23

1 Basic Concepts and

Notations

Data Structures – Basic Concepts and Notations 1


Objectives
At the end of the lesson, the student should be able to:
Explain the process of problem solving
Define data type, abstract data type and data structure
Identify the properties of an algorithm
Differentiate the two addressing methods - computed
addressing and link addressing
Use the basic mathematical functions to analyze algorithms
Measure complexity of algorithms by expressing the
efficiency in terms of time complexity and big-O notation

Data Structures – Basic Concepts and Notations 2


Problem Solving Process
Programming – a problem-solving process which could be
viewed in terms of the following domains:
Problem domain
input or the raw data to process
output or the processed data
Machine domain
storage medium - consists of serially arranged bits that are addressable
as a unit
processing unit - allow us to perform basic operations
Solution domain - links the problem and machine domains

Data Structures – Basic Concepts and Notations 3


Problem Solving Process
Problem Domain

Data Structures – Basic Concepts and Notations 4


Problem Solving Process
Machine Domain

Data Structures – Basic Concepts and Notations 5


Problem Solving Process
Solution Domain

Data Structures – Basic Concepts and Notations 6


Problem Solving Process

Two related tasks at the solution domain


Structuring of higher level data representations
Synthesis of algorithms

Data structures and algorithms are the building blocks of


computer programs

Data Structures – Basic Concepts and Notations 7


Data Type, Abstract Data
Type and Data Structure
Data type - kind of data that variables can assume in a
programming language and for which operations are
automatically provided

Abstract Data Type (ADT) - mathematical model with defined


operations. In Java, an ADT can be expressed with an
interface

Data Structures – Basic Concepts and Notations 8


Data Type, Abstract Data
Type and Data Structure
public interface Stack{
public int size(); /* returns the size of the stack */
public boolean isEmpty(); /* checks if empty */
public Object top() throws StackException;
public Object pop() throws StackException;
public void push(Object item) throws StackException;
}

Data structure – the implementation of ADT in terms of the


data types or other data structures.In Java, a data structure
can be expressed with a class

Data Structures – Basic Concepts and Notations 9


Algorithm
Finite set of instructions which, if followed, will accomplish a
task
Finiteness - an algorithm must terminate after a finite number of steps
Definiteness - ensured if every step of an algorithm is precisely defined
Input - domain of the algorithm which could be zero or more quantities
Output - set of one or more resulting quantities; also called the range of
the algorithm
Effectiveness - ensured if all the operations in the algorithm are
sufficiently basic that they can, in principle, be done exactly and in
finite time by a person using paper and pen

Data Structures – Basic Concepts and Notations 10


Addressing Methods
Computed Addressing Method - used to access the elements
of a structure in pre-allocated space
int x[10][20];
a = x[4][3];
Link Addressing Method – used to manipulate dynamic
structures where the size and shape are not known
beforehand or changes at runtime
class Node{
Object info;
Node link;

Node() { }

Node (Object o, Node l){


info = o;
link = l;
}
Data Structures – Basic Concepts and Notations 11
}
Addressing Methods
Memory pool or avail list - source of the nodes from which linked
structures are built

class AvailList {
Node head;

AvailList(){
head = null;
}

AvailList(Node n){
head = n;
}
}
Data Structures – Basic Concepts and Notations 12
Addressing Methods
Two basic procedures that manipulate the avail list are getNode and
retNode, which requests for a node and returns a node respectively.

Node getNode(){
Node a;

if ( head == null) {
return null; /* avail list is empty */
} else {
a = head.link; /* assign node to return to a */
head = head.link.link;
return a;
}
}

void retNode(Node n){


n.link = head.link; /* adds the new node at the
start of the avail list */
head.link = n;
} Data Structures – Basic Concepts and Notations 13
Mathematical Functions
Floor of x (  x  ) - greatest integer less than or equal to x, x
is any real number

Ceiling of x (  x  ) - smallest integer greater than or equal to


x, where x is any real number

Modulo - given any two real numbers x and y,


x mod y = x if y = 0
=x-y* x/y  if y <> 0

Data Structures – Basic Concepts and Notations 14


Mathematical Functions
Identities
é x ù = ë xû if and only if x is an integer
é xù = ë x û if and only if x is not an integer
ë- x û = - é x ù
ë x û + ë y û <= ë x + y û
x = ë x û + x mod 1
z ( x mod y ) = zx mod zy

Data Structures – Basic Concepts and Notations 15


Complexity of Algorithms
Algorithm Efficiency
Space utilization - amount of memory required to store the data
Time efficiency - amount of time required to process the data
Execution time - amount of time spent in executing instructions of a given
algorithm. Notation: T(n). Several factors that affect the execution time
include:
input size
Instruction type
machine speed
quality of source code of the algorithm implementation
quality of the machine code generated from the source code by the
compiler

Data Structures – Basic Concepts and Notations 16


Complexity of Algorithms
The Big-Oh Notation (or simply O-Notation)
T(n) grows at a rate proportional to n and thus T(n) is said to have
“order of magnitude n” denoted by the O-notation: T(n) = O(n)
Formal definition:
g(n) = O(f(n)) if there exists two constants c and n0 such that
| g(n) | <= c * | f(n) | for all n >= n0.

Operations on the O-Notation:


Rule for Sums
Suppose that T1(n) = O( f(n) ) and T2(n) = O( g(n) ).
Then, t(n) = T1(n) + T2(n) = O( max( f(n), g(n) ) ).

Rule for Products


Suppose that T1(n) = O( f(n) ) and T2(n) = O( g(n) ).
Then, T(n) = T1(n) * T2(n) = O( f(n) * g(n) ).

Data Structures – Basic Concepts and Notations 17


Complexity of Algorithms
Rule for Sums
Suppose that T1(n) = O( f(n) ) and T2(n) = O( g(n) ).
Then, t(n) = T1(n) + T2(n) = O( max( f(n), g(n) ) ).

Proof: By definition of the O-notation,


T1(n) <= c1 f(n) for n >= n1 and
T2(n) <= c2 g(n) for n >= n2.

Let n0 = max(n1, n2). Then


T1(n) + T2(n) <= c1 f(n) + c2 g(n) n >= n0.
<= (c1 + c2) max(f(n),g(n)) n >= n0.
<= c max ( f(n), g(n) ) n >= n0.
Thus,

T(n) = T1(n) + T2(n) = O( max( f(n), g(n) ) ).

e.g. a. T(n) = 3n3 + 5n2 = O( n3 )


b. T(n) = 2n + n4 + n log n = O( 2n )
Data Structures – Basic Concepts and Notations 18
Complexity of Algorithms
Examples
Consider the algorithm below :
for (i=1; i <= n, i++)
for (j=1; j <= n, j++)
// steps which take O(1) time

Since the steps in the inner loop will take n + n-1 + n-2 + ... + 2 + 1 times, then the
running time is
n( n+1 ) / 2 = n2 / 2 + n / 2

= O( n2 )

Data Structures – Basic Concepts and Notations 19


Complexity of Algorithms
Examples
LINEAR SEARCH ALGORITHM
T( n ) = 3n + 3 so that T( n ) = O( n )
1 found = false;
2 loc = 1;
3 while ((loc <= n) && (!found)){ Since g( n ) <= c f( n ) for n >= n 0, then
4 if (item == a[loc]found = true;
5 else loc = loc + 1; 3n + 3 <= c n
6 }

STATEMENT # of times executed 3n + 3 <= c = 3 + 3 / n <= c


1 1 ---------
2 1
3 n+1 n
4 n
5 n Thus c = 4 and n0 = 3.

Data Structures – Basic Concepts and Notations 20


Complexity of Algorithms
The Big-Oh Notation
Big-Oh Description Algorithm
O(1) Constant
O(log2n) Logarithmic Binary Search
O(n) Linear Sequential Search
O(n log2n) Heapsort
O(n2) Quadratic Insertion Sort
O(n3) Cubic Floyd’s Algorithm
O( 2n ) Exponential

F(n) Running Time


log2n 19.93 microseconds
n 1.00 seconds
n log2n 19.93 seconds
n2 11.57 days
n3 317.10 centuries
2n Eternity

Data Structures – Basic Concepts and Notations 21


Complexity of Algorithms
General rules on determining the running time of an algorithm
FOR loops
At most the running time of the statement inside the for loop times
the number of iterations.
NESTED FOR loops
Analysis is done from the inner loop going outward. The total running
time of a statement inside a group of for loops is the running time of
the statement multiplied by the product of the sizes of all the for
loops.
CONSECUTIVE STATEMENTS
The statement with the maximum running time.
IF/ELSE
Never more than the running time of the test plus the larger of the
running times of the conditional block of statements.
Data Structures – Basic Concepts and Notations 22
Summary
Programming as a problem solving process could be viewed in
terms of 3 domains – problem, machine and solution.
Data structures provide a way for data representation. It is an
implementation of ADT.
An algorithm is a finite set of instructions which, if followed, will
accomplish a task. It has five important properties: finiteness,
definiteness, input, output and effectiveness.
Addressing methods define how the data items are accessed. Two
general types are computed and link addressing.
Algorithm efficiency is measured in two criteria: space utilization and
time efficiency. The O-notation gives an approximate measure of
the computing time of an algorithm for large number of input

Data Structures – Basic Concepts and Notations 23

You might also like