Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cse 373 April 12th – TreEs.

Similar presentations


Presentation on theme: "Cse 373 April 12th – TreEs."— Presentation transcript:

1 Cse 373 April 12th – TreEs

2 Assorted minutiae HW2 due tonight Wrong submissions
Static functions for your test cases HW3 out tonight Dictionaries – LL, Array, BST Empirical testing Regrade system up by Friday

3 Lecture Style Too fast More time-in-class examples
Lots of material to cover, but it isn’t doing any good if no one understands Too mathy A bit tougher, abstract concepts are the most important part of the course More physical examples

4 Today Review of Dictionaries BSTs as dictionaries Analysis of BSTs
Tree traversals

5 Dictionary Data is inserted in <Key,Value> pairs.
Keys must be comparable Implements three functions: Insert (key, value) Find (key) Delete (key) Monday, we discussed 4 implementations

6 Implementations Simple implementations Unsorted linked-list
insert find delete Unsorted linked-list Unsorted array Sorted linked list Sorted array * Unless we need to check for duplicates Simple implementations O(1)* O(n) O(n) O(1)* O(n) O(n) O(n) O(n) O(n) O(n) O(log n) O(n)

7 Implementations Other implementations? Binary Search Tree (BST)
Sort based on keys (which have to be comparable) How do we implement this? What changes need to be made? Discuss how your 143 BST is different from a dictionary BST Consider particularly how the BST Node changes

8 Implementations BST Node: Before: Now? Node left Node right Value data
Key k Value v

9 Implementations BST Changes:
Insert(), find() and remove() remain similar Key is the primary comparison Value is attached to the key Dictionary fact: All values have an associated key For now, assume all keys are unique, i.e. each key only has one value

10 Implementations BST Analysis:
What is our time for the three functions? Insert()? Delete()? Find()? Take 5 minutes to discuss Consider average and worst-case. What are the inputs for average and worst-case?

11 Implementations BST Analysis: Insert(): Worst case: O(n)
Average case: O(height) What is “average” data? Best case: O(log n)

12 Average case Interesting concept Average to the user?
Average among all possible inputs? Random data trials Produce random test cases and observe the result Timer?

13 Average case Timing cases Advantages and disadvantages
+ Actual runtime performance - Can be skewed + Easy to implement - Difficult to ascertain asymptotic growth

14 Average case HW3 will have you do timing cases
Many runs will reduce hardware uncertainty Running at many sizes will make trends more apparent Demonstrate some real implementation behavior

15 Binary Search Tree Back to BST
How do we test average case for a dictionary? We want varied input, without repititions One solution: Create a bunch of keys in a range Select without replacement Add into the dictionary “Shape” of a dictionary is determined by insert() order, so ordering is critical.

16 Intro for Next Week Tree traversals How do we search through a tree?
Multiple ways? What if it isn’t a search tree?

17 Intro for Next Week

18 Intro for Next Week

19 Intro for Next Week If we have search!

20 Intro for Next Week If we have search!

21 Intro for Next Week What if we don’t? Say it’s a heap

22 Intro for Next Week

23 Intro for Next Week

24 Intro for Next Week

25 Intro for Next Week

26 Intro for Next Week Possible to interrupt early

27 Intro for Next Week

28 Intro for Next Week

29 Intro for Next Week Any other ways?

30 Intro for Next Week Any other ways?

31 Intro for Next Week Any other ways?

32 Intro for Next Week Any other ways?

33 Intro for Next Week Any other ways?

34 Intro for Next Week Any other ways?

35 Intro for Next Week Any other ways?

36 Intro for Next Week Any other ways?

37 Intro for Next Week Any other ways?

38 Intro for Next Week Any other ways?

39 Intro for Next Week Any other ways?

40 Intro for Next Week Any other ways?


Download ppt "Cse 373 April 12th – TreEs."

Similar presentations


Ads by Google