Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 6 - Friday.  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem.

Similar presentations


Presentation on theme: "Week 6 - Friday.  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem."— Presentation transcript:

1 Week 6 - Friday

2  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem

3

4 Recursion

5 Infix to Postfix Converter

6

7  a is the number of recursive calls made  b is how much the quantity of data is divided by each recursive call  f(n) is the non-recursive work done at each step

8

9

10

11

12  Base case: List has size less than 3  Recursive case:  Recursively sort the first 2/3 of the list  Recursively sort the second 2/3 of the list  Recursively sort the first 2/3 of the list again

13

14

15  We need to know log b a  a = 3  b = 3/2 = 1.5  Because I’m a nice guy, I’ll tell you that the log 1.5 3 is about 2.7

16  We know that binary search takes O(log n) time  Can we use the Master Theorem to check that?

17

18

19  A symbol table goes by many names:  Map  Lookup table  Dictionary  The idea is a table that has a two columns, a key and a value  You can store, lookup, and change the value based on the key

20  A symbol table can be applied to almost anything:  The key doesn't have to be a String  But it should be unique KeyValue SpidermanClimbing and webs WolverineSuper healing Professor XTelepathy Human TorchFlames and flying DeadpoolSuper healing Mr. FantasticStretchiness KeyValue 121Programming I 122Programming II 221Data Structures and Algorithms 322Formal methods 361Computer Graphics 363Computer Security

21  We can define a symbol table ADT with a few essential operations:  put(Key key, Value value) ▪ Put the key-value pair into the table  get(Key key): ▪ Retrieve the value associated with key  delete(Key key) ▪ Remove the value associated with key  contains(Key key) ▪ See if the table contains a key  isEmpty()  size()  It's also useful to be able to iterate over all keys

22  The idea of order in a symbol table is reasonable:  You want to iterate over all the keys in some natural order  Ordering can give certain kinds of data structures (like a binary search tree) a way to organize

23  An ordered symbol table ADT adds the following operations to a regular symbol table ADT:  Key min() ▪ Get the smallest key  Key max() ▪ Get the biggest key  void deleteMin() ▪ Remove the smallest key  void deleteMax() ▪ Remove the largest key  Other operations might be useful, like finding keys closest in value to a given key or counting the number of keys in a range between two keys

24  Like other ADTs, a symbol table can be implemented in a number of different ways:  Linked list  Sorted array  Binary search tree  Balanced binary search tree  Hash table  Note that a hash table cannot be used to implement an ordered symbol table  And it's inefficient to use a linked list for ordered

25  We know how to make a sorted array symbol table  A search is Θ(log n) time, which is great!  The trouble is that doing an insert takes Θ(n) time, because we have to move everything in the array around  A sorted array is a reasonable model for a symbol table where you don't have to add or remove items

26  Trees will allow us to make a sorted symbol table with the following miraculous properties:  Θ(log n) get  Θ(log n) put  Θ(log n) delete  Θ(n) traversal (iterating over everything)  Unfortunately, only balanced binary search trees will give us this property  We'll start next week with binary search trees and then built up to balanced ones

27

28  Binary trees  Read section 3.2

29  Finish Assignment 3  Due tonight!  Keep working on Project 2  Due next Friday  No class on Monday!


Download ppt "Week 6 - Friday.  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem."

Similar presentations


Ads by Google