24
CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Embed Size (px)

Citation preview

Page 1: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

CSE 326: Data StructuresLecture #25

Class Wrap-up

Steve Wolfman

Winter Quarter 2000

Page 2: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Today’s Outline

• Finish algorithms• Wrap-up of class

Page 3: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Game Search

• Search space is composed of board positions• Transitions are moves• Levels alternate between us and them• We can evaluate any given board position

according to a scoring heuristic

How should we decide the next move?

Page 4: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Backtracking Game Search (MiniMax)

44

44 36

44 4078 36

27 4068 3644 2778 36

42 7368 6886 2778 5527 4073 3644 8779 36

42 7350 5772 1978 527 3073 299 6479 1225 2368 6886 2717 557 4031 3644 8737 36

us

them

us

Page 5: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

- Pruned Game Search

44

7 44

42 8627 44

42 7350 5772 1978 527 3073 299 6479 1225 2368 6886 2717 557 4031 3644 8737 36

us

them

us

Page 6: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Randomized Algorithms

• Define a property (or subroutine) in an algorithm• Sample or randomly modify the property• Use altered property as if it were the true property

Can transform average case runtimes into expected runtimes (remove input dependency).

Sometimes allows substantial speedup in exchange for probabilistic unsoundness.

Page 7: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Randomization in Action

• Treaps• Quicksort• Randomized back-off• Primality testing

Page 8: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Properties of Primes

P is a prime 0 < A < P and 0 < X < P

Then:AP-1 = 1 (mod P)

And, the only solutions to X2 = 1 (mod P) are:

X = 1 and X = P - 1

Page 9: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Calculating Powers

HugeInt pow(HugeInt x, HugeInt n, HugeInt modulo)

{

if (n == 0)

return 1;

if (n == 1)

return x;

HugeInt squared = x * x % modulo;

if (isEven(n))

return pow(squared, n / 2);

else

return (pow(squared, n/2) * x) % modulo;

}

// If 1 < x < modulo - 1// but squared == 1, // then modulo isn’t prime!

Page 10: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Checking PrimalitySystematic algorithm:

– For prime P, for all A such that 0 < A < P

– Calculate AP-1 mod P using pow

– Check at each step of pow and at end for primality conditions

Randomized algorithm: use just one random A

If the randomized algorithm reports failure, then P really isn’t prime.

If the randomized algorithm reports success, then P might be prime.– P is prime with probability > ¾– Each new A has independent probability of false positive

Page 11: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Evaluating Randomized Primality Testing

Your probability of being struck by lightning this year: 0.00004%

Your probability that a number that tests prime 11 times in a row is actually not prime: 0.00003%

Your probability of winning a lottery of 1 million people five times in a row: 1 in 2100

Your probability that a number that tests prime 50 times in a row is actually not prime: 1 in 2100

Page 12: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Randomized Greedy Algorithms:Simulated Annealing

-10

-5

0

5

10

15

20

25

Page 13: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Randomized Backtracking forHeavy-Tailed Distributions

Some backtracking algorithms have a few (fruitless) branches that are very large, both deep and broad.

Algorithms which choose randomly at a split point will have a small probability of getting caught in one of these branches.

Therefore, some runs finish very quickly, most runs take some time, and a few runs take orders of magnitude more time than the median.

Solution: cut off long runs and reseed the randomizer.

Page 14: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Data Structures and ADTs

Course Overview

Dictionary

Priority Queue

List, Stack,Queue, Multilist

Linked listsArrays

BSTsAVL treesSplay treesB-TreesHash tables TreapsSkip lists

Binary heapsd-HeapsLeftist heapsSkew heapsBinomial queues

Page 15: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Data Structures and ADTs

Course Overview

Up-tree forest

k-D treesQuad treesBSP trees

Adjacency listAdjacency matrix

Disjoint SetUnion/Find ADT

Graph

MultidimensionalDictionary

Page 16: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Algorithms and Algorithm Analysis

• Analysis of algorithms– proofs of correctness

– asymptotic analysis (relative runtimes in the limit)

– strict analysis (actual number of operations)

– greedy vs. divide&conquer vs. backtracking etc.

• Actual algorithms– searching (linear search, binary search, tree search,

hashing)

– sorting (heapsort, mergesort, quicksort, radixsort)

– graph algorithms (Dijkstra’s, Kruskal’s)

Course Overview

Page 17: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Evaluating Algorithms

Use of space and time:– asymptotic analysis for high-level comparison

• worst case

• best case

• average case

• expected case

– stricter analysis, experiments for practical performance

Course Overview

How fast is fast enough?

Page 18: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Criteria for Good Running Time

Your resources– how much time/memory can you afford?

Nature of the problem– some problems are just harder than others

(e.g., sorting is harder than finding)

Characteristics of your application– what problem sizes/types of inputs will you be running on?– how might they change in the future?

Ease of Coding/Maintainability– sometimes coding and maintenance time and costs dominate

Course Overview

Page 19: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Games Theoreticians Play

Sour Cove Review

Prove that an algorithm is (f(n)) by nature– e.g., sorting using only comparisons cannot be done in

less than n log n

What’s wrong with this claim?

“I wrote a FindMin() operation that runs in in O(log n) time on an unsorted list of integers!”

Page 20: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

More Games Theoreticians Play

Take an operation and– see how fast you can do it

(e.g., decreaseKey in amortized O(1))

– see how simple you can make it(e.g., Treaps)

– see how you can put it together with other operations

Receives Our Vow

Page 21: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Observation

• All programs manipulate data– programs process, store, display, gather

– data can be information, numbers, images, sound

• Each program must decide how to store data• Choice influences program at every level

– execution speed

– memory requirements

– maintenance (debugging, extending, etc.)

Or Cues Overview

Page 22: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Goals of the Course

• Become familiar with some of the fundamental data structures in computer science

• Improve ability to solve problems abstractly– data structures are the building blocks

• Improve ability to analyze your algorithms– prove correctness

– gauge (and improve) time complexity

• Become modestly skilled with the UNIX operating system and X-windows (you’ll need this in upcoming courses)

Course Overview

Page 23: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

To Do

• Study for the final

Page 24: CSE 326: Data Structures Lecture #25 Class Wrap-up Steve Wolfman Winter Quarter 2000

Coming Up

• Fun stuff on Friday• Final Exam (March 13th)