






















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























































Chris BrooksDepartment of Computer ScienceUniversity of San Francisco^ Department of Computer Science — University of San Francisco – p.1/
We will often want to have a list in which all the elementsare ordered. As we add or remove elements, order is maintained.^ List of names in alphabetical order^ List of files from smallest to largest^ List of records from earliest to most recent
Department of Computer Science — University of San Francisco – p.2/
Using an Ordered Array – Running times:CheckInsertRemovePrint
Department of Computer Science — University of San Francisco – p.4/
Using an Ordered Array – Running times:Check
Insert
Remove
Department of Computer Science — University of San Francisco – p.5/
Using an^ Unordered
Array – Running times: Check
Insert
^ Remove
(Given a fast sorting algorithm) Keeping the array ordered makes insertion require
time. Department of Computer Science — University of San Francisco – p.7/
Using an Ordered Linked List – Running times:CheckInsertRemovePrint
Department of Computer Science — University of San Francisco – p.8/
Linked Lists – Insert fast / Find slow Arrays – Find fast / Insert slow The only way to examine nth element in a linked list is totraverse (n-1) other elements 4 8
12 15
22 25
28
If we could leap to the middle of the list ...
Department of Computer Science — University of San Francisco – p.10/
4 8
12 15
22 25
(^28) Department of Computer Science — University of San Francisco – p.11/
4 8
12 15
22 25
28
Move the initial pointer to the middle of the list:^4 8 12
15 22
25 28
We’ve cut our search time in half! Have we changed the
running time?Repeat the process!
Department of Computer Science — University of San Francisco – p.13/
4 8
12 15
22 25
28
4 8
12 15
22 25
28
4 8
12 15
22 25
28 Department of Computer Science — University of San Francisco – p.14/
Binary Trees are Recursive Data Structures^ Base Case: Empty Tree^ Recursive Case: Node, consisting of:^ Left Child (Tree)^ Right Child (Tree)^ Data
Department of Computer Science — University of San Francisco – p.16/
The following are all Binary Trees (Though not Binary
Search
Trees)
A B C^ D^ E^ F
A B C D A B C^ F^ GD E^ Department of Computer Science — University of San Francisco – p.17/
Each node has 0 or 2 children Full Binary Trees Not^ Full Binary Trees
Department of Computer Science — University of San Francisco – p.19/
Can be build by starting at the root, and filling the tree bylevels from left to right Complete Binary Trees Not^ Complete Binary Trees
Department of Computer Science — University of San Francisco – p.20/