JEDI Slides-DataSt-Chapter01-Basic Concepts and Notations
JEDI Slides-DataSt-Chapter01-Basic Concepts and Notations
Notations
Node() { }
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;
}
}
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 )