IIIa. Linked List
This is the definition of a linked list node:
struct Node
cfw_
int data;
Node * next;
Write the following function in C+. You may use any other data structures you wish for assistance.
a) Write a function called removeLast that del
Artificial Intelligence Assignment 2
February 8th, 2017
I have not received unauthorized aid on this assignment. I understand the answers that I have
submitted. The answers submitted have not been directly copied from another source, but
instead are writt
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
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)
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).
Multi-core Architectures
Dr. Yingwu Zhu
What is parallel computing?
Using multiple processors in
parallel to solve problems more
quickly than with a single
processor
Examples of parallel computing
A cluster computer that contains multiple PCs
combined to
Virtualization
Dr. Yingwu Zhu
What is virtualization?
Virtualization allows one computer to do the
job of multiple computers.
Virtual environments let one computer host
multiple operating systems at the same time
Virtualization
Definition
Framework or
Synchronization
Dr. Yingwu Zhu
Concurrency
Concurrent threads/processes
The threads run at the same time in multiprocessing
environments or their execution is interleaved through
preemption
Asynchronous
Threads require occasional synchronization & com
Signals & Shared Memory
Dr. Yingwu Zhu
Topics
Signals
Shared memory for IPC
Question
Q: How does the OS communicate to a
process?
A: Signals
Signals
What if something unexpected or
unpredictable happens?
a floating-point error
a power failure
an a
File Systems
Dr. Yingwu Zhu
What is a file system?
Organization of data and metadata
Whats metadata?
Data of data
Attributes; things that describe the data
Name, length, type of file,
creation/modification/access times, permissions,
owner, location o
Process Scheduling
Dr. Yingwu Zhu
Process Behavior
Most processes exhibit:
Large # of short CPU bursts between I/O requests
Small # of long CPU bursts between I/O requests
Interactive process: mostly short CPU bursts
Compute process: mostly long CPU
Memory Management
Dr. Yingwu Zhu
Big picture
Main memory is a resource
A process/thread is being executing, the
instructions & data must be in memory
Assumption: Main memory is infinite
Allocation of memory to processes
Address translation
Real worl
Processes
Dr. Yingwu Zhu
Process
Growing Memory
Stack expands automatically
Data area (heap) can grow
via a system call that
requests more memory
- malloc() in c/c+
Contexts
Entering the kernel (mode)
Hardware interrupts
Asynchronous events (I/O, clock
Threads
Dr. Yingwu Zhu
Processes are expensive
Recall that a process includes many things
An address space (defining all the code and data pages)
OS resources (e.g., open files) and accounting information
Execution state (PC, SP, regs, etc.)
Creating
Solution
1.
Using one lock and two semaphores.
Lock lock;
Semaphore barber; / initialized to 1
Semaphore customers; /initialized to 0
int empty_chairs = n; /number of empty chairs
Pseudocode for customers:
acquire(lock);
if (empty_chairs = 0) cfw_
leave t
Written Assignment #1
Due by 6:25PM, Monday, May 13, 2013
(Hardcopy is required)
1. Synchronization: the sleeping-barber problem. [8 points]
A barbershop consists of a waiting room with n chairs and a barber room with one barber chair. If there
are no cus
Final Exam Review
Here's a list of the material we covered in the course (disclaimer: some topics not listed may be on the
exam and some listed topics may not, but if you know the list, you can do very well on the exam):
Processes
o Program vs. process
o
Introduction to Classes
(Chapter 13.1 13.12)
Dr. Yingwu Zhu
13.1
Procedural and Object-Oriented Programming
Procedural and Object-Oriented
Programming
Procedural programming focuses on the
process/actions that occur in a program
Object-Oriented programm