Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
More Graph Algorithms:
Shortest Paths
Last updated: 13/04/2014
Term 2, 201314
Graph: Paths
Given a graph G = (V, E), a path is a sequence of verti

CSCI2100B
Data Structure
Tutorial: Stack
Stack
Stack:
Definition: an ordered list in which
insertions and deletions are made at
one end called top.
Operation: Push & Pop
Characteristic: First-In-Last-Out
typedef struct
cfw_
int size;
int top;
int *stack;

Koenigsberg Bridge Problem
Knigsberg in Prussia (now Kaliningrad in Russia) is a
town. The town is set on both sides of the Pregel River,
and includes two islands. There are seven bridges.
Can you start from any island and walk across all the
bridges ex

Programming Languages?
Natural Languages
Chinese, English, Japanese,
Programming Languages (PLs)
CSCI2100C
Data Structures
High Level PLs
Low Level PLs
Pascal, C, Java,
Assembly Languages
A Machine Language executed by a CPU
Jeffrey [email protected]
Progr

Trees
CSCI2100C
Tree
Jeffrey [email protected]
Tree
Trees (contd)
Trees
A tree is a finite set of one or more nodes such that
A root
There is a specially node called the root.
The remaining nodes are partitioned into 0
disjoint sets 1, , where each of these sets

Search Records
Consider a collection of records, where a record
has several fields.
CSCI2100C
Given a collection of records 1 , 2 , , , where
each has a key .
Hashing
We want to search a record by some key, where a
key is a field in a record.
Jeffrey Y

Stack
Last-In-First-Out (LIFO): The last element being
pushed onto a stack is the first element pop out.
CSCI2100C
The efficiency comes with restricted accesses.
Stacks & Queues
Jeffrey [email protected]
Stacks and Queues
Stack ADT
A Railroad Switching Network
To

Variables and Pointers (1)
A variable is to declare a space
(box) to hold a value.
CSCI2100C
Arrays & Structures
int val, a;
A pointer is to declare an
address of a space.
Jeffrey [email protected]
int *ptr, *b;
When using a variable/pointer,
A variable keeps a

Create a New Account
Google Mail and Yahoo Mail have hundreds of
millions of users.
A user can create a new account at any time.
CSCI2100C
When a user types a new name, the system will tell
Sorting
the user whether the name has been used or not
immedia

The Chinese University of Hong Kong
Department of Systems Engineering and Engineering
Management
CSCI-2100-C
2016-2017
Data Structures
Assignment 2 (C Programming)
The C programming assignment is to implement the polynomial ADT discussed
and some addition

Problems of Arrays in Implementation
Let the base address of an array to be a. The
address of the i-th element is located at
a + (i - 1) * sizeof(theTypeOfElement). We can
access an element in an array in constant time if we
know its array index.
But, s

BSOJ - Create a new
account
http:/sepc498.se.cuhk.edu.hk/register
Please use your student ID as username!
BSOJ - Log into your
account
http:/sepc498.se.cuhk.edu.hk/login
BSOJ View the problem
set
http:/sepc498.se.cuhk.edu.hk/problem
s
et
BSOJ View problem

Tutorial: Trees
Tree Terminology
Extension of Linked List structure:
Each node connects to multiple nodes
A tree is a non-linear data structure
Conceptualize trees upside down:
the top node is the root
nodes are connected by edges
edges define parent

CSCI2100C Tutorial 2
An Implementation of a Stack
An Introduction to Stack
A stack is an ordered container and generally supports the
following several operations.
Create, Push, Pop, Top
remove
the top
element
3
(a) create
2
2
(b) push 2
(c) push 3
2
(d

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
Term 2,
Elementary Graph Algorithms 2013-14
Last updated: 06/04/2014
Applications of Graphs
Many computational applications naturally involve
both

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
AVL Tree
Last updated: 22/03/2014
Term 2
2013-2014
AVL Trees
An AVL (Adelson-Velskii and Landis) tree is a binar
y search tree (BST) with a balanc

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
More Graph Algorithms:
Minimum Spanning Tree
Last updated: 1/04/2014
2013-14
Supplement
The Wiring Problem
In circuit design, we often have to con

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
Trees: Fundamental
Last updated: 08/03/2014
Term 2
2013-2014
Definition of Tree
The tree structure means a branching relationship between n
odes.

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
Linked Lists
Last updated: 04/02/2014
2013-2014
Term 2
Contents
Linked lists
Basic list operations
Circular/empty list conventions
Memory allocati

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
Binary Heap & Priority Queue
Last updated: 03/11/2013
Term 1
2013-14
Binary Heap (or Just Heap)
Heaps have two properties
Structure property & Hea

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
Stacks & Queues
Last updated: 17/03/2014
Term 2
2013-2014
Stack ADT
A stack is a list that can only insert and delete at only
one position - top o

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100A DATA STRUCTURES
Stacks & Queues (b)
Last updated: 23/02/2014
Term 2
2013-2014
Defining the Type stackADT
To define the stack ADT, we shall first write the ADT de

CSCI2100 Data Structures
Homework #4
Due: April 3
Specification: Solutions of Q1, Q2, and Q3 should be written in .pdf file and not hand writing.
Solution of Q4 should be written in a single source file (the name as "main.c") with
functions for sub-tasks.

Sorting
Divide & Conquer
Solves a big problem by dividing the big problem into small o
nes and solve the small problems, and combine the solutions
of small problems to get the solution of the original big probl
em
F(N) = 2*F(N/2) + O(N)
Example
QuickS

The Chinese University of Hong Kong
Department of Systems Engineering and Engineering
Management
CSCI-2100-C
2016-17
Data Structures
Assignment 3
The third assignment counts for 20% of the total assessment, and is due at
11:59pm on April 26, 2017. Late su

The Chinese University of Hong Kong
Department of Systems Engineering and Engineering
Management
CSCI-2100-C
2016-17
Data Structures
Assignment 1
The first written assignment counts for 15% of the total assessment, and is due
at 11:59pm on February 28, 20

Open
Hashing
Close
Hashing
Linear Probing
Quadratic
Probing
Double
Hashing
Advantages
a.Saving space
b. simple and efficient collision
handling
In general, it saves time to
allocate cells and pointers to cells.
And there is no need to implement
a second

CSCI2100D
Data Structures
Graphs
Graph in daily life
2
What is a Graph?
A graph consists of some vertices (a.k.a.
nodes) and some edges (a.k.a. arcs).
v1
Vertices:
v 1, v 2, v 3, v 4, v 5
e1
v2
e2
v3
e3
e4
v5
v4
e5
A graph with 5 vertices and 5 edges.
Ed

Department of Computer Science and Engineering
The Chinese University of Hong Kong
CSCI2100D: Data Structures
& Applications
Tutorial Note 3
Spring 2015
<Hashing>
Instructor: James Cheng
TA: Fan Yang
Agenda
1.
Hashing
2.
Exercise for Practice
3.
Open Ques

CSCI2100D
Data Structures
Trees
What is a Tree?
A plant
2
What is a Tree?
Family tree
Source: Wikipedia
3
What is a Tree?
Biological classification
4
Source: Wikipedia
What is a Tree?
Organization chart
5
Source: HK Govt Web Page
What is a Tree?
leaf

Introduction:
Example
Solutions
A k selection problem - given a set of
numbers, select the k highest number in
the list.
How do you do the above task?
Solution 1
Read the N numbers into an array, sort the
array in decreasing order by some simple
algorith

CSCI2100D Data Structures 2015-2016 Second Term
The Chinese University of Hong Kong
Due date: 14th Feb, 2016 (Sun)
Due time: 23:59:59
Assignment 1(Written)
Full mark: 100
Expected time spent: 1-2 hours
Aims: To understand the basic concepts and use of ADT