CPSC 250 Fall 2011
Lab 1:Get familiar with Linux
By Dr. Yingwu Zhu, Seattle University
Tasks (You should perform the following tasks step by step):
1.
2.
3.
4.
5.
Check out your CS1 account
Set up your CPSC250 class directory (using basic Linux commands)
ADT: Design & Implementation
Dr. Yingwu Zhu
Outline
Concept: ADT
Demonstration of ADTs design and
implementation
List as an ADT (our focus)
Stack & Queue as ADTs (exercises)
Abstract Data Type (ADT)
ADT = data items + operations on the data
Design o
Quicksort
Dr. Yingwu Zhu
Quicksort
A more efficient exchange sorting scheme than
bubble sort
A typical exchange involves elements that are far apart
Fewer interchanges are required to correctly position an element.
Quicksort uses a divide-and-conquer
Hashing
Dr. Yingwu Zhu
What do I have?
Recall order of magnitude of searches
Linear search O(n)
Binary search O(log2n)
Balanced binary tree search O(log2n)
Unbalanced binary tree can degrade to O(n)
Hash Tables
Sometime faster search is needed
Solu
Tree Balancing: AVL Trees
Dr. Yingwu Zhu
Recall in BST
The insertion order of items determine the
shape of BST
Balanced: search T(n)=O(logN)
Unbalanced: T(n) = O(n)
Key issue:
Need to keep a BST balanced!
Tree balancing techniques
AVL Tree Definitio
Algorithm Complexity Analysis: Big-O
Notation (Chapter 10.4)
Dr. Yingwu Zhu
Measure Algorithm Efficiency
Space utilization: amount of memory
required
Time efficiency: amount of time required to
accomplish the task
As space is not a problem nowadays
Ti
Binary Search Trees (BST)
Dr. Yingwu Zhu
Review: Linear Search
Collection of data items to be searched is
organized in a list
x1, x2, xn
Assume = and < operators defined for the
type
Linear search begins with item 1
continue through the list until tar
Review: C+ Basic Concepts
Dr. Yingwu Zhu
Outline
C+ class declaration
Constructor
Overloading functions
Overloading operators
Destructor
Redundant declaration
A Real-World Example
Question #1: How to use a C+ class to
represent a simple polynomial ax + b
Basic Sorting Algorithms
Dr. Yingwu Zhu
Sorting Problem
Consider list
x1 , x 2 , x 3 , x n
Goal: arrange the elements of the list in
order
Ascending or descending
Some O(n2) schemes
easy to understand and implement
inefficient for large data sets
Basic So
Introduction
Dr. Yingwu Zhu
What to learn?
ADT design & implementation using different
data structures
Algorithm time efficiency analysis by Big-O
ADTs operations & applications
Binary search trees, AVL trees, Heaps, Priority queues
Hashing: collisio
CPSC 250 Data Structures by Dr. Zhu
Homework Assignments #1
Due by 9:20AM, Sept 30, Friday
1. Goals
This assignment aims to further understanding of some basic C+ concepts weve discussed in class,
which include C+ class, constructor, destructor, overloadi
Solutions to Mid-Term Exam #1
Part I: Algorithm Efficiency Using Big-O Notations. (16 points)
1. True
2. Since T(n) = O(n2), we have
T(n) Cn2
(where C is a constant)
3
C n
(where n 1)
3
= O(n )
3. T(n) =
= O(n2)
4. T(0) = 1
T(n) = T(n/2) + 1
By telescopi
Assignments #2
Due by 9:20 AM, Wednesday, 10/12/2011
Note: 16 points in total. Hardcopy submission is required! Please staple your
HW solution papers if it has multiple pages!
1. Explain why, if T(n) is O(n), then it is also correct to say T(n) is O(n 2).