Getting Started - PowerPoint PPT Presentation

About This Presentation
Title:

Getting Started

Description:

Chapter 2 Getting Started – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 16
Provided by: edut1550
Category:

less

Transcript and Presenter's Notes

Title: Getting Started


1
Chapter 2
  • Getting Started

2
  • 2.1 Insertion Sort ??????????????
  • ??

524613
254613
245613
245613
124563
123456
3
  • 2.2 Analyzing Algorithms
  •  
  • RAM Random-access machine, ????????????????????,?
    ????????????
  •  
  • Running time ?????????,? input size ????????

4
  • ?? Insertion Sort
  • Insertion-Sort(A)
  • 1 for j ? 2 to lengthA
  • 2 do key ? Aj
  • 3 ?insert Aj into the sorted sequence
    A1..j - 1
  • 4 i ? j 1
  • 5 while i gt 0 and Ai gt key
  • 6 do Ai 1 ? Ai
  • 7 i ? i 1
  • 8 Ai 1 ? key
  • T(n) c1n(c2c4c8)(n-1)c5 (c6c7)

cost c1 c2 0 c4 c5 c6 c7 c8
times n n - 1 n - 1 n - 1 n - 1
5
  • Best-case
  • Each tj1. (?? A ?????)
  • T(n) (c1c2c4c5c8)n-(c2c4c5c8)
  • ?(n)
  • (rate of growth, order of growth)
  • Worst-case (upper bound)
  • Each tjj.
  • T(n) k1n2 k2n k3
  • ?(n2)

6
  • Average-case (Expected running time)
  • Each tjj/2
  • T(n) t1n2 t2n t3
  • ?(n2)
  • (rate of growth, order of growth)

7
  • 2.3 Designing Algorithms
  • Divide-and-Conquer
  • Divide(????????????????)
  • Conquer(????)
  • Combine(?????????????)

8
  • ?? Merge Sort

9
sorted sequence
12234566
merge
2456
1236
merge
merge
25
46
13
26
merge
merge
merge
merge
5
2
4
6
1
3
6
2
??????????????????????(?????? 1,?????? 2,????? 8)
10
  • Analysis (recurrence)
  • T(n)
  • ?(nlog n)

11
Exercises
  • Problem 1
  • ??????,?????? ASCII ????????????? ASCII ? 32
    ?????? 128 ???????????????????? \n ? \r
    ??,??????????????
  • ???????????????????? 1000????????????
  • ?????????,??????????? ASCII ??? ASCII
    ???????????(??????)??????????????????? ASCII
    ????????,?? ASCII ??????????

12
  • ???????????

Sample Input Sample Output
AAABBC 122333 67 1 66 2 65 3 49 1 50 2 51 3
13
Exercises
  • Problem 2
  • ?????????????????????????????????,???DAABEC?,
    ???????????? 5,?? D ???????????,E
    ?????????????????????????? inversion
    ?????AACEDGG???? inversion (E ?
    D),?????????ZWQM??? inversion
    (??????,????????????) ?
  • ???????? DNA ??(???? A, T, C, G
    ??????)???,????????????????,????????????,??????
    ?????????????????????????????????

14
Exercises
  • ?????????? M,???????????? M ????????????????????
    ???????????????????n (0 lt n 50) ???????m (0 lt
    m 100) ????????????? m ?,???????? n ? DNA ???
  • ?????????,??????????????????????????????????
    ,?????????????

15
  • ???????????

Sample Input Sample Output
1 10 6 AACATGAAGG TTTTGGCCAA TTTGGCCAAA GATCAGATTT CCCGGGGGGA ATCGATGCAT CCCGGGGGGA AACATGAAGG GATCAGATTT ATCGATGCAT TTTTGGCCAA TTTGGCCAAA
Write a Comment
User Comments (0)
About PowerShow.com