






















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document from the university of san francisco's department of computer science discusses the implementation and running times of ordered lists using both ordered arrays and unordered arrays, as well as the concept of binary trees, including full binary trees, complete binary trees, binary search trees, and finding and printing elements in a binary search tree.
Typology: Study notes
1 / 62
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/