Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lec 09 Agenda 1/ Searching and sorting, logs

Similar presentations


Presentation on theme: "Lec 09 Agenda 1/ Searching and sorting, logs"— Presentation transcript:

1 Lec 09 Agenda 1/ Searching and sorting, logs
(2:12) 2/Data structures Build an LinkedList. From this basic strcture, we can build most of the datastuctures we want. Except for binary trees. 3/ Game features. MovableAdapter,

2 Get source code labJava >git fetch origin lab09g
>git checkout -b lab09g origin/lab09g

3 Arrays versus Collections
Holds objects of known type. Fixed size. Collections Generalization of the array concept. Set of interfaces defined in Java for storing Objects. Multiple types of objects. Resizable.

4 Using Interfaces with Collections
Interfaces are used for flexibility reasons Programs that use an interface are not coupled to a specific implementation of a collection. It is easy to change or replace the underlying collection class with another class that implements the same interface. Map map = new HashMap(); Map map = new TreeMap();

5 Searching Linear search O(n) --slow Binary search O(log2n) --fast
Refresher on logs: If 23 = 8 then log28 = 3 Hashed search O(1) –fastest Search driver class (2:12) 5

6 6

7 Sorting SelectionSort O(n2) –-slow MergeSort O(n * log2n) –- fast
HeapSort O(n * log2n) –- fast QuickSort O(n * log2n) –- fast 7

8 Applications of logs If you're playing in single-elimination (sudden- death) tournament with 16 players in your draw, how many matches would you need to win in order to win the tournament? Log216 You're searching a sorted set of 64 elements, what is the maximum number of times you would need to search this set? Log264 8

9 Applications of logs The radioactive half-life of Carbon-14 is years. You find a fossil whose Carbon-14 signature has a radioactive strength of 1/128 of the original strength. How old is this fossil? 9

10 Intro to Data Structures in Java
Single Lined List Stack Binary Tree others...

11 http://people. cs. aau. dk/~torp/Teaching/E01/Oop/handouts/collections
11

12

13

14 Iterator 14

15

16

17

18

19

20

21

22

23

24


Download ppt "Lec 09 Agenda 1/ Searching and sorting, logs"

Similar presentations


Ads by Google