CSCI2100C Course Review
course review
1
The Textbook:
Fundamentals of Data Structures in C
by Ellis Horowitz, Sartaj Sahni and Susan
Anderson-Freed, Computer Science Press
An e-copy can be found in CUHK library
Exercise Solutions can be found at
http:/www
CSCI2100C
Linked List
Jeffrey [email protected]
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 ti
CSCI2100C
Graph
Jeffrey [email protected]
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 an
Merge Sort
~ is classified as external sort that allows portion
of the data to be stored in secondary memory during
the sorting process.
Algorithm mergeFiles
/ Merge two sorted files into one file.
open files
read (file1 into record1)
read (file2 into rec
Graphs - Introduction
Examples
Show real-life problems using graphs.
Give algorithms to solve common graph
problems.
Show how the choice of data structures can
drastically reduce the running time of these
algorithms.
See how depth-first search can be used
Sorting - Introduction
Sorting - Introduction
Sorting is simply the ordering of your data in a
consistent manner.
(e.g., cards, telephone#s, student names)
Each element is usually part of a collection of
data called a record.
Each record contains a key, w
CSCI2100C
Sorting
Jeffrey [email protected]
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.
When a user types a new name, the system will tell
the user whether the name has been use
CSCI2100C
Hashing
Jeffrey [email protected]
Search Records
Consider a collection of records, where a record
has several fields.
Given a collection of records
, ,
, where
each
has a key .
We want to search a record by some key, where a
key is a field in a record.
CSCI2100C
Arrays & Structures
Jeffrey [email protected]
Variables and Pointers (1)
A variable is to declare a space
(box) to hold a value.
int val, a;
A pointer is to declare an
address of a space.
int *ptr, *b;
When using a variable/pointer,
A variable keeps a
CSCI2100a
DataStructure
Tutorial4
Sorting&programmingassignmentA
Outline
1.
sorting
2.
Programming assignment
2
Sorting
3
Shell Sort
Idea of Shell Sort
Modify the comparison method so that it first compares distant
keys.
The distance between comparisons d
CSCI2100a
DataStructures
Tutorial6
StackandQueue
1
Outline
1.
Review
2.
Exercises
2
1.1TheJosephusProblem
N people have to elect a leader by arranging themsel
ves in a circle,
the counting begins at some point in the circle and procee
ds around the circle
CSCI2100a
DataStructures
Tutorial7
HashTable
1
Outline
1.
Review
2.
Exercises
2
Whatsahashtable?
Hash Table
a data structure for implementing dictionaries operations:
insert, search, and delete.
expected time O(1)
uses a hash function to map keys to their
CSCI2100a
Data Structure
Tutorial 9
Tree
Outline
1.
Overview
2.
Exercises(focus)
2
Overview
3
Binary tree
Binary tree
A
Traversal
Pre-order
In-order
Post-order
B
D
C
E
F
G
4
Preorder:
ABDCEGFHJ
Inorder:
D BA E G C H F J
Postorder:
D B G E H J F CA
H
J
Bin
Binary Tree Traversals
Inorder: visit the left subtree,
the root, and the right subtree.
void inorder(node *ptr)cfw_
if (ptr) cfw_
inorder(ptr->left_child);
printf("%c", ptr->data);
inorder(ptr->right_child);
void inorder(node *ptr)cfw_
if (ptr) cfw_
in
CSCI2100C
Tree
Jeffrey [email protected]
Trees
Tree
5-2
Trees
A tree is a finite set of one or more nodes such that
There is a specially node called the root.
The remaining nodes are partitioned into
0
disjoint sets 1, , where each of these sets is
a tree.
We