Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Data Structures
CSE, POSTECH
1
What The Course Is About?
The computer program development process
requires us to
– represent data in an effective way
– develop a suitable step-by-step procedure (algorithm),
which can be implemented as a computer program
Effective data representation ⇒ data structures
Development of a suitable step-by-step procedure
⇒ algorithm design methods
The study of data structures and algorithms is
fundamental to computer science.
2
Prerequisites
CS101 & CS103
C or C++ programming
– Those who did not learn C++ are strongly recommended to get a
C++ book (e.g., Richard Johnsonbaugh and Martin Kallin, "Object-
Oriented Programming in C++," 2nd Edition, Prentice Hall, 2000)
and study!
Logical and analytical thinking
3
Course Homepage
http://dpnm.postech.ac.kr/cs233
Announcements, handouts, syllabus, assignments, useful
links, TA info., etc.
POVIS eClass
4
Questions?
Questions related to lectures, concepts, data structures,
algorithms, exams…
– Use CS 233 BBS in POVIS
5
Organization of the Textbook
Three parts
Part 1 : Chapters 1-4, Background
Part 2 : Chapters 5-16, Data Structures
Part 3 : Chapters 17-21, Algorithm Design Methods
Each chapter : Concepts + Applications
6
Evaluation
1. Assignments - 30%
2. Midterm Exam - 30%
3. Final Exam - 35%
4. Class Participation - 5%
7
Class Schedule: 1st half
Week 1 : Overview of C++, Program performance
Week 2 : Performance Measurement
Week 3 : Array-based and linked representations
Week 3 : Week 4 : Arrays and matrices
Week 5 : Stacks
Week 6 : Queues
Week 7 : Skip lists and hashing
Week 8 : Review and Midterm Exam
8
Class Schedule: 2nd half
Week 9 : Binary and other trees
Week 10 : Priority queues, heaps, and leftist trees
Week 11 : Tournament trees and bin packing
Week 12 : Binary Search trees
Week 13 : AVL trees
Week 14 : Graphs
Week 15 : Graph Search Methods
Week 16 : Review and Final exam
9
Lecture 1: Programming in C++
Introduction
“A better C”
Support for data abstraction
Support for object-oriented programming
10
Introduction
C++ programming language is designed to
– Be a better C ⇒
better support for procedural and modular
programming
– Support data abstraction ⇒
ability to define and use new data types (classes)
– Support object-oriented programming ⇒
ability to express type hierarchies
11
A Better C
Program and Output
#include <iostream.h>
int main()
{
cout << “Hello, World!\n”;
}
12
A Better C
Variables and Arithmetic
double d;
int i;
short s;
// ..useful comments
d = d+i;
i = s*i;
13
A Better C
Pointers and Arrays
14
A Better C
Tests and Loops
char ch = 0;
cin >> ch;
if (ch == ‘i’) { /* … */ }
else if (ch == ‘c’) { /* … */ }
else { /* … */ }
int v1[10];
int v2[10];
// …
for (int i = 0; i < 10; i++)
v1[i] = v2[i];
15
A Better C
Functions
16
A Better C
Functions (swap) What would be the output for the
following calls?
template<class T> int a = 2, b = 3;
void Swap1(T *a, T *b) Swap1(&a, &b);
{T temp = *a; *a = *b; *b = temp;} cout << a << ' ' << b << endl;
32
template<class T>
Swap2(a, b);
void Swap2(T& a, T& b)
cout << a << ' ' << b << endl;
{T temp = a; a = b; b = temp;} 23
#include <math.h>
#include “math1.h”
18
Support for Data Abstraction
Initialization and Cleanup
class vector {
int sz; // number of elements
int *v; // pointer to integers
public:
vector(int); // constructor
~vector(); // destructor
int& operator[](int index);
};
19
Support for Data Abstraction
Initialization and Cleanup
vector::vector(int s)
{
if (s <= 0) error(“bad vector size”);
sz = s;
v = new int[s]; // allocate an array of s integers
}
vector::~vector()
{
delete[] v; // deallocate the array
// pointed to by v
}
20
Support for Data Abstraction
Assignment and Initialization
class vector {
int sz;
int *v;
public:
// …
vector(const vector&); // initialization
void operator=(const vector&); // assignment
};
21
Support for Data Abstraction
Assignment and Initialization
vector::vector(const vector& a)
{
sz = a.sz; // same size
v = new int[sz];
for (int i = 0; i < sz; i++) v[i]= a.v[i];
}
22
Support for Data Abstraction
Templates
void f()
{
Vector<int> v1(100); // vector of 100 integers
Vector<complex> v2(200); // vector of 200 complex
// numbers
24
Support for Data Abstraction
Exception Handling
try {
int **x = new int* [10];
for (int i = 0; i < 10; i++)
x[i]= new int [5];
return true;
} catch (xalloc) {
return false;
}
25
Support for Object-Oriented Programming
Inheritance
– Superclass (or base class) and subclass (derived class)
– inherits attributes and functions of base class
26
Support for Object-Oriented Programming
Access Control
1. Public: can access from other class functions
2. Private: can only be accessed from within the class
member functions
3. Friend: can be accessed by other classes or functions
4. Protected: behave like private members except that
derived classes can access protected members