CS109A Notes For Lecture 3/8/96 Data Structures: Linked List Next Array
CS109A Notes For Lecture 3/8/96 Data Structures: Linked List Next Array
Data Structures
Operations
Note that we used the inductive hypothesis to talk about what happens on recursive calls, without having to imagine
an arbitrarily large sequence of calls.
Implementation Variants
1. Sorting the list.
We can search only as far as x to test
whether x is on the list (saves average
factor of 2).
2. Allow duplicates.
Insert in O(1).
Penalty is that lookup, delete may take
longer because lists with duplicates get
longer than number of elements.
3. Sentinels : Add x onto end of list before
searching for x.
Suitable only for array representation.
Saves time testing for end of list at each
step.
(1)
(2)
(3)
(4)
if (t != NULL) {
printf("%c\n", t->nodeLabel);
preorder(t->leftChild);
preorder(t->rightChild);
}