Data Structures and Algorithm Analysis Introduction - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Data Structures and Algorithm Analysis Introduction

Description:

Data Structures and Algorithm Analysis Introduction Lecturer: Ligang Dong, egan Email: donglg_at_zjgsu.edu.cn Tel: 28877721 13306517055 Office: SIEE Building 305 – PowerPoint PPT presentation

Number of Views:573
Avg rating:3.0/5.0
Slides: 23
Provided by: educ5480
Category:

less

Transcript and Presenter's Notes

Title: Data Structures and Algorithm Analysis Introduction


1
Data Structures and Algorithm AnalysisIntroductio
n
  • Lecturer Ligang Dong, egan 
  • Email donglg_at_zjgsu.edu.cn
  • Tel 28877721,13306517055
  • Office SIEE Building 305

2
Textbook
  • Mark Allen Weiss, Data Structures and Algorithm
    Analysis in C, China Machine Press.
  • E-book is available. http//netcom.zjsu.edu.cn/per
    son/dlg/data_structure.htm

3
Scheduling
  • Instruction Lectures Tuesday 805am
  • Programming Practices Friday 950am

4
Grading
  • Final exam 55
  • Weekly Homeworks45(153)
  • Posted every Tuesday
  • Due Next Tuesday before class (solution posted
    after class)
  • If you have difficulties in solving the homework,
    please ask for help during Programming Practices
    in Friday.
  • No late submission accepted

5
Why Learn Data Structures and Algorithms?
  • One of the basic rules concerning programming is
    to break the program down into modules.
  • Each module is a logical unit and does a specific
    job. Its size is kept small by calling other
    modules.
  • Two types of modules
  • data module ------ data structure
  • procedure module ------ algorithm

6
Why Learn Data Structures and Algorithms?
  • Modularity has several advantages.
  • It is much easier to debug small routines than
    large routines
  • It is easier for several people to work on a
    modular program simultaneously
  • A well-written modular program places certain
    dependencies in only one routing, making changes
    easier.

7
What are Data Structures and Algorithms?
  • Data Structures are methods of organizing large
    amounts of data.
  • An algorithm is a procedure that consists of
    finite set of instructions which, given an input
    from some set of possible inputs, enables us to
    obtain an output through a systematic execution
    of the instructions.

8
Data Structure
ADT(Abstract Data Types)
Algorithms
Programming Languages
Programs
Software
Software Engineering
9
Abstract Data Types (ADTs)
  • An abstract data type (ADT) is a set of objects
    such as lists, sets, and graphs, along with their
    operations (e.g., insert, delete)
  • Integers, reals, and booleans are data types.
    Integers, reals, and booleans have operations
    associated with them, and so do ADTs.
  • Nowhere in an ADTs definition is there any
    mention of how the set of operations is
    implemented.

10
Example
  • Problem Given 10 test results (80, 85, 77, 56, 68
    , 83, 90, 92, 80, 98) of C language programming
    of Tom, what is the average score?

11
Example
  • Solution
  • main()
  • int sum,average
  • int t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
  • t180t285t377t456t568
  • t683t790t892t980t1098
  • sum t1t2t3t4t5t6t7t8t9t10
  • averagesum/10
  • printf(Sumd\n,sum)
  • printf(Averaged\n, average)

12
Example
By using an array instead of n variables, with a
loop instead of n assignments, the program is
simpler.
  • Better Solution
  • main()
  • int sum,averageint i
  • int t10 80,85,77,56,68,83,90,92,80,98
  • sum0
  • for(i0 ilt10 i)
  • sumsumti
  • averagesum/10
  • printf(Sumd\n,sum)
  • printf(Averaged\n, average)

13
Contents
  • Chapter 1 Introduction(0.5 Week)
  • C Review(1.5 Week)
  • Chapter 2 Algorithm Analysis(1 Week)
  • Chapter 3 Lists, Stacks, and Queues(1 Week)
  • Chapter 4 Trees (2 Weeks)
  • Chapter 5 Hashing(1 Week)
  • Chapter 6 Priority Queues (Heaps) (1 Week)
  • Chapter 7 Sorting (2 Weeks)
  • Chapter 8 Disjoint Set ADT(1 Week)
  • Chapter 9 Graph Algorithms(2 Weeks)
  • Chapter 10 Algorithm Design Techniques (2 Weeks)

14
Mathematical Foundation
Series and summation 1 2 3 . N
N(N1)/2 (arithmetic series)
1 r2 r3 rN-1 (1- rN)/(1-r),
(geometric series)
? 1/(1-r) , r lt 1, large N
Sum of squares 1 22 32 N2 N(N
1)(2N 1)/6
15
Mathematical Foundation
logxa b if xb a
we will use base 2 mostly, but may use other
bases occasionally
Will encounter log functions again and again!
log (ab ) log a log b log (a/b ) log a -
log b log ab b log a
logba logca/ logcb
alog n nlog a
amn (am )n (an)m
amn am an
(2?n)0.5 (n/e)n ? n? ? (2?n)0.5 (n/e)n
(1/12n)
16
Mathematical Foundation
  • Proof Method1 Proof By Induction
  • Prove that a property holds for input size 1
  • Assume that the property holds for input size n.
    Show that the property holds for input size n1.
  • Then, the property holds for all input sizes, n.

17
Mathematical Foundation
  • Example of Proof By Induction Prove that the sum
    of 12..n n(n1)/2
  • Holds for n 1
  • Let it hold for n
  • 12.n n(n1)/2
  • When n1
  • 12.n(n1) n(n1)/2 (n1)
    (n1)(n2)/2.

18
Mathematical Foundation
  • Proof Method2 Proof By Counter Example
  • Want to prove something is not true!
  • Give an example to show that it does not hold!

19
Mathematical Foundation
  • Proof Method3 Proof By Contradiction
  • Suppose, you want to prove something.
  • Assume that what you want to prove does not hold.
  • Then show that you arrive at an impossiblity.

20
Mathematical Foundation
  • Example of Proof By ContradictionThe number of
    prime numbers is not finite!
  • Suppose there are finite number of primes, k
    primes. (we do not include 1 in primes here)
  • We know k?2.
  • Let the primes be P1, P2 , Pk
  • Z P1 P2 Pk 1
  • Z is not divisible by P1, P2 , Pk
  • Z is greater than P1, P2 , Pk Thus Z
    is not a prime.
  • We know that a number is either prime or
    divisible by primes. Hence contradiction.
  • So our assumption that there are finite number of
    primes is not true.

21
Homework 1
  • At least complete two of the following
  • 1.1 Prove the following formulas
  • 1.2 Write a program to solve the selection
    problem. (Suppose you have a group of n numbers
    and would like to determine the kth largest.)
  • 1.3 Based on 1.2, let k n/2, show the original
    location of kth largest. And draw a table showing
    the running time of your program for various
    values of n (4ltnlt20).

22
Hint
  • You should submit the homework using the WS Word
    file through email.
  • Your program must be submitted with output.
  • DO NOT write any code until you understand what
    the program does, the design of the program, and
    the output that it produces.  Writing code before
    understanding the program will simply be a waste
    of your time, and will result in a program that
    does not work!!
  • As with any large program, it is probably a good
    idea to finish the easy parts first and then
    slowly complete the harder parts.
  • Develop your code in small pieces, and test each
    part of your code as you write it. 
  • Your program is graded according to
    correctness, readability, robustness, efficiency.
Write a Comment
User Comments (0)
About PowerShow.com