... edition of DataStructuresandAlgorithmsin C++ is designed to pro-
vide an introduction to datastructuresand algorithms, including their design, analy-
sis, and implementation. In terms of ... objects and pointers. We discuss casting
with fundamental types here, and we consider casting with objects in Section 2.2.4.
We begin by introducing the traditional way of casting in C++, and later ... is to involve the students in
lively interactive classroom sessions that bring out the intuition and insights behind
data structuring and algorithmic techniques. Dr. Tamassia has taught Data Struc-
tures...
... Generics,
and the Timing Class
T
his book discusses the development and implementation of data structures
andalgorithms using C#. The datastructures we use in this book are found
in the .NET ... shown in Figure 1.4.
Queues are used in both systems programming, for scheduling operating
system tasks, and for simulation studies. Queues make excellent structures
for simulating waiting lines in ... declare, instantiate, and assign data
to an array in one statement. You can do this in C# using an initialization
list:
int[] numbers = new int[] {1,2,3,4,5};
The list of numbers, called the initialization...
... exists.
•
30
What kind of data, and
which data need to be
push into the stack?
Goal Seeking (cont.)
Tasks depend on each goal seeking problem:
Determine what kind of data included in graph (format ... empty board and, moving according
to the rules of chess, must visit each square exactly once.
Parsing
Parsing is any logic that breaks data into
independent pieces for further processing.
Ex. ... GoalSeeking2
There are two different types of elements to push into the stack:
• The node in the valid path.
• The backtracking point (with “B” flag).
26
Goal Seeking (cont.)
Infix
Postfix
Infix
Postfix
a+b*c-(d*e...
... Push (val DataIn <DataType>)
Pushes new data into the stack.
Pre DataIn contains data to be pushed.
Post If stack is not full, DataIn has been pushed in;
otherwise, stack remains unchanged.
Return ... fully inhirited from a List ADT, inside its operations
calling List’s operations.
Ex.:
<ErrorCode> Push (val DataIn <DataType>)
// Call List::InsertHead(DataIn)
or
// Call List::Insert(DataIn, ... Allocated Array)
Linked Implementation: linked stack.
11
Push data into a Linked Stack
1. Allocate memory for the new node and set up data.
2. Update pointers and count:
• Point the new node to...
... December 2008
Cao Hoang Tru
CSE Faculty - HCMUT
Open Addressing
• There are different methods:
– Linear probing
– Quadratic probing
– Double hashing
– Key offset
3
01 December 2008
Cao Hoang Tru
CSE ... element in.
26
01 December 2008
Cao Hoang Tru
CSE Faculty - HCMUT
Pseudorandom
Pseudorandom
Number Generator
Key
Random
Number
Modulo
Division
Address
y = ax + c
For maximum efficiency, a and c ... in combination with fold shift
original key rotated key
600101 → 62 160010 → 26
600102 → 63 260010 → 36
600103 → 64 360010 → 46
600104 → 65 460010 → 56
600105 → 66 560010 → 66
Spreading the data...
... Science and Engineering – HCMUT
a b c
head
a b
Result:
Insert Node Algorithm
Algorithm insertNode (ref list <metadata>,
val pPre <node pointer>,
val dataIn <dataType>)
Inserts data ... HCMUT
pPre
is pointer data s logical predecessor
dataIn contains data to be inserted
Post data have been inserted in sequence
Return true if successful, false if memory overflow
Insert Node
Allocate ... Parameter Passing Techniques
void func(int* a, int* b){
int *t;
t = a;
a = b;
b = t;
}
void main() {
int *p1 = new int;
*p1 = 10;
int *p2 = new int;
*p2 = 20;
func(p1, p2);
printf
(“%d”,
*
p1);
Slide...
... picture and leave the detailed
computations to the computer.
28
Subprogram implementation
5
Print List in Reverse
19
Recursion
14
Tree and Stack frames of function calls
6
Designing Recursive Algorithms
33
The ... long chain of partial
results and then go back through it to complete the work.
Ex.:
When we use recursion, we need to think in somewhat difference terms
than with other programming methods.
... removal
Backtracking
Examples of backtracking and recursive algorithms:
Factorial
Fibonacci
The towers of Hanoi
Eight Queens Problem
Tree-structured program: Look-ahead in Game
1
Fibonacci...
... <ErrorCode> InsertHeap (val DataIn <DataType>) // Iterative version
Inserts new data into the min-heap.
Post DataIn has been inserted into the heap and the heap order property
is maintained.
Return ... queue
<ErrorCode> RetrieveMin (ref MinData <DataType>)
Retrieves the minimum element in the heap.
Post MinData receives the minimum datain the heap and the heap
remains unchanged.
Return underflow or ... Create
• InsertElement: Inserts new data to the position accordingly to its
priority order in queue.
• DeleteMin: Removes the data with highest priority order.
• RetrieveMin: Retrieves the data...
... last_small is increased and two entries at position
last_small and i are swapped:
49
Selection Sort
24
Straight Insertion Sort
12
Sorting
4
31
Straight Selection Sort
Sorting
3
Straight Insertion Sort
6
Bubble ...
receive more new information.
• Incremental values should not be multiples of each other,
other wise, the same keys compared on one pass would be
compared again at the next.
• The final incremental ... QuickSort
27
Straight Selection Sort
Straight Insertion Sort
7
Sorting
2
Build Heap (first stage)
34
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
Choosing incremental values
• From more of...
... make room.
Pre node is pointer to node to contain data.
newEntry contains data to be inserted.
entryNdx is index to location for new data.
Post data have been inserted in sequence.
1 shifter ... index location of parent.
upEntry contains entry being inserted into split node.
Post upEntry now contains entry to be inserted into parent.
1 minEntries = minimum number of entries
2 allocate ... - HCMUT
B-Tree Insertion
Algorithm BTreeInsert (val root <pointer>, val data <record>)
Inserts data into B-tree. Equal keys placed on right branch.
Pre root is a pointer to the B-tree....
... possible.
http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/mf1201.htm (14 of 37) [1.7.2001 18:58:22]
Data Structuresand Algorithms: CHAPTER 1: Design and Analysis of Algorithms
w of newclr and examine the graph ... of.
http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/mf1201.htm (36 of 37) [1.7.2001 18:58:23]
Data Structuresand Algorithms: CHAPTER 1: Design and Analysis of Algorithms
"pointed to" by ... }
http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/mf1201.htm (7 of 37) [1.7.2001 18:58:22]
Data Structuresand Algorithms: CHAPTER 1: Design and Analysis of Algorithms
When we are writing a program...
... necessary and appropriate
int i, j;
void count()
{ for (i=0;…
…
}
void main()
{ for (i=0;…
…
}
const int SIZE=10;
int table[SIZE][SIZE];
void PrintTable()
{
}
void main()
{
}
OK
Data Structuresand ...
[
P
r
e
n
t
i
c
e
H
a
l
l
]
Data Structuresand
Algorithm Analysis in C
By Mark Allen Weiss
[Addison Wesley]
Data Structuresand Algorithms
City Univ of HK / Dept of CS / Helena Wong
0. Course Introduction ... are approaching to success.
Data Structuresand Algorithms
City Univ of HK / Dept of CS / Helena Wong
0. Course Introduction - 3
http://www.cs.cityu.edu.hk/~helena
Programming Language and Tools
•
We...