COMPUTER 2430 Object Oriented Programming and Data Structures
COMPUTER 2430 Object Oriented Programming and Data Structures I 1
Containers • • • Bag Set Stack Queue Sorted List. . . Array Linked List 2
Reference and Object Class variable is a pointer (reference) and keeps the address of an object Class Variable 3
public class Node { private Student student. Info; private Node next; // Note the type! public Node (Student x, Node p ) { student. Info = x; next = p; } public Node (Student x ) { student. Info = x; next = null; }. . . } 4
Linked Lists Linked lists can have their data "scattered" all over memory list 5
CS 2630 – OOPS II • • Linked List Tree Recursion. . . 6
Quiz 6 h 1(key) = key % 13 h 2(key) = 1 + key % 11 Key 25 38 12 47 34 21 61 35 22 h 1(key) 12 12 12 8 8 8 9 9 9 h 2(key) 4 6 2 4 2 11 7 3 1 7
Linear Probe h 1(key) = key % 13 ( h 2(key) = 1 + key % 11 ) Key 25 38 12 47 34 21 61 35 22 h 1(key) 12 12 12 8 8 8 9 9 9 h 2(key) 4 6 2 4 2 11 7 3 1 0 1 2 3 38 12 35 22 4 5 6 7 8 9 10 11 12 47 34 21 61 25 8
Double Hashing h 1(key) = key % 13 h 2(key) = 1 + key % 11 Key 25 38 12 47 34 21 61 35 22 h 1(key) 12 12 12 8 8 8 9 9 9 h 2(key) 4 6 2 4 2 11 7 3 1 0 1 2 12 35 3 4 5 6 38 21 7 8 9 10 11 12 47 61 34 22 25 9
Two Formulas • How Many larger(last/first) – smaller(first/last) + 1 • What is the sum? (first + last) * (number of items) / 2 10
Quiz 6 for (int I = 3; I < N + 5; I ++) for (int J = N + 5; J >= I – 2; J --) Quiz 6(); The total number of times Quiz 6 is called: __________ Pass I First of J Last of J # of calls 3 4 5. N+2 N+3 N+4 N+5 N+5 1 2 3. N N+1 N+2 N+5 N+4 N+3. 6 5 4 11
Quiz 6 The total number of times Quiz 6 is called: (N+5) + (N+4) + (N+3) +. . . + 6 + 5 +4 = 4 + 5 + 6 +. . . + (N+3) + (N+4) + (N+5) = (4 + (N+5)) * ((N+5) – 4 + 1) / 2 = (N+9) * (N+2) / 2 = (N 2 + 11 N + 18) / 2 12
Binary Search • Code – Array of integers – Array of Date – Array of Comparable • Tracing – In array – Not in array – Format 13
Quiz 6 • Call Compara. To multiple times – No Good! • Interface Comparable – Compare. To returns an integer • 0 • > 0 • < 0 14
Test 3 • Wednesday, December 12 • Quiz 5 • Quiz 6 • LSP 15
Prog 6 • Total Points: 35 • Plan in SE Tool • Punch In/Out in SE Tool 16
Course Outcomes Survey About the course Not the instructor 17
- Slides: 17