Top Banner
Data Structures and Algorithms Lecturer : MSc. Tran Dac Tot HCMC University of Food Industry Email : [email protected] facebook: https://www.facebook.com/totkhtn Reference : Dr. Halena Wong – www.cs.cityu.edu.hk
10

Data Structures and Algorithms

Mar 03, 2023

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data Structures and Algorithms

Data Structuresand

Algorithms

Lecturer : MSc. Tran Dac Tot

HCMC University of Food Industry

Email : [email protected]

facebook: https://www.facebook.com/totkhtn

Reference : Dr. Halena Wong – www.cs.cityu.edu.hk

Page 2: Data Structures and Algorithms

Reference Books

Thomas H. Cormen, Charles E. Leiserson, Ronald L.

RivestandClifford Stein, Introduction to Algorithms, The MIT

Press © 2001.

Adam Drozdek, Data Structures and Algorithms in C++

Second Edition, Brooks/Cole 2001.

P. S. Deshpande, O. G. Kakde. C & Data Structures, 2004.

A.V. Aho, J.E Hopcroft, J.D Ullman. Data structures and

Algorithms, Addison Wesley, 1983.

MARK ALLEN WEISS, Data Structures and Algorithm

Analysis, In C. The Benjamin/Cummings Publishing

Company, 1993.

Page 3: Data Structures and Algorithms

Reference Books

Data Structures and Algorithms with Object-Oriented Design

Patterns in C#, Bruno R. Preiss, 2004.

Tiêng Viêt

[1] Trần Văn Thọ, Cấu trúc dữ liêu và giải thuật, Trường ĐH CNTP

Tp.HCM, 2012.

[2] Trần Văn Thọ, Thực hành cấu trúc dữ liêu và giải thuật,

Trường ĐH CNTP Tp.HCM, 2012.

Page 4: Data Structures and Algorithms

Nội Dung Chương Trình

Buổi 1: Giới thiêu về CTDL & Giải Thuật.

Các thuật toán tìm kiêm.

Buổi 2: Interchange Sort, Selection Sort, Bubble Sort,

Insertion Sort.

Buổi 3: Shaker Sort, Shell Sort, Heap Sort.

Buổi 4: Quick Sort, MergeSort, Radix Sort.

Buổi 5: Cấu trúc động, Danh sách liên kêt đơn.

Page 5: Data Structures and Algorithms

Nội Dung Chương Trình

Buổi 6: Stack, Queue.

Buổi 7: Danh sách liên kêt kép.

Buổi 8: Cây, Cây nhị phân, cây nhị phân tìm kiêm.

Buổi 9: Cây cân bằng (AVL).

Buổi 10: Các CTDL mở rộng.

Buổi 11: Ôn tập.

Page 6: Data Structures and Algorithms

Programming Language and Tools

• We will write programs in C language

• Assignment/exercises can be use with Visual C++

Week 1,2 (at home)

• Review C programming

• If you have missed

something, find your tutor

immediately!

If you consider other C programming tools:

eg. Visual Studio.Net, Pelles C (http://www.smorgasbordet.com/pellesc/)

- The compiler acts in the same way as Visual C++? Mostly not.

Page 7: Data Structures and Algorithms

Comments (Enough but not excess!)

• Describe the program at the beginning

• Describe important variables and

global declarations

• Describe each function before the

function

• Explain any complex logic

Indentation (use tabs) / format:

if (x>y)

county++;

else

if (x>z)

{countz++;

countx++;}

Hard coding should be avoided:

if (x >36)

{ x=0;

y++;

}

GOOD

const int WIDTH=36;..if (x >WIDTH){ x=0;

y++;}

if (x>y)

county++;

else

if (x>z)

{countz++;

countx++;}

GOOD

Global variables:

only if 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

Page 8: Data Structures and Algorithms

Program bugs are normal -- You should fix them!

Trust yourself:

Your program is based on a

workable logic, right?

Now, the error is probably due

to careless mistakes only .

With 99.9% sure these

mistakes can be caught by

using the debugger.

Design of logic ..

Coding ..

Testing ..

!! ERROR

But after I have corrected the bug,

the program still goes wrong.

Should I undo the correction?

No. Don’t undo the correction.

Now there is probably another

small bug that you need to fix.

Don’t give up. You are

approaching to success.

Page 9: Data Structures and Algorithms

Any problem in fixing a program bug?• First of all: solve for all compilation warnings(these are usually hints of bugs)

• A general debugging cycle:

1. Test it again with simple test cases (increase complexity gradually)

2. Select a simplest test case that your program runs incorrectly.

3. With the test case, trace the code with pencil and paper.

(write down all intermediate results obtained step-by-step)

4. Run your program with debugger to trace the program

(adding breakpoints / tracing line by line)

Locate the statement that causes any difference compared with

your pencil-and-paper tracing.

5. Fix the bug.

6. Test the program with another test case.

Trust yourself on the logic: “the bug should be a careless mistake and can be

fixed” – otherwise you will never start debugging.

get Help (MSDN): a convenient reference for C.

Page 10: Data Structures and Algorithms

• Send me emails to ask any question of this course.

• Email subject should be relevant eg. “help”.

• Attach any related program source code and test case.

Any problem in this course?

I may contact you by email.

If you prefer NOT to receive my email,

please inform me as soon as possible.