Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review Multi-Dimensional Array Searching and Sorting in arrays Inheritance Graphics.

Similar presentations


Presentation on theme: "Review Multi-Dimensional Array Searching and Sorting in arrays Inheritance Graphics."— Presentation transcript:

1 Review Multi-Dimensional Array Searching and Sorting in arrays Inheritance Graphics

2 2-D Array and Table Int [][] e = new int[5][6] 0 1 2 3 4 054321 e[3][1]

3 # of Rows and Columns int [][] e = new int[5][6]; Get No of rows e.length ? Get No of columns e[0].length ? e[1].length ?

4 Print A Matrix Matrix is 2-d Array (rectangular) 1 2 3 4 5 6 7 8 9 print: 1 2 3 4 5 6 7 8 9 public static void Print(int[][] A) { int row = A.length; int col = A[0].length; for (int I=0; I<row; I++) for (int j=0; j<col; j++) System.out.prinln(A[I][j] + “ “); }

5 Matrix Addition 1 2 31 1 12 3 4 4 5 6 + 2 2 2 = 6 7 8 4 6 4 3 3 37 9 7 A B C formula: Cij = Aij + Bij public static int[][] Add(int[][] A, int[][] B) { }

6 Matrix Multiplication just for your fun 3 22 18 5 2 1 + 1 1= 5 3 formula: Cij = Ai * Bj public static int[][] Multiplication(int[][] A, int[][]B) { }

7 Sequential or Binary Search Can you perform sequential search on A1? A2? Can you perform binary search on A1? A2? A1: A2: 8694712 1246789

8 Summary Binary search takes advantage of the characteristics of sorted array, can only be performed on a sorted array. It’s fast Sequential search can be performed on both unsorted and sorted array It’s slow

9 Selection Sort: Select the smallest one Demo: http://www-courses.cs.uiuc.edu/~cs125/cs125/_nav/_framepage/notesPage.html

10 Insertion Sort: Maintain partial and sorted array Demo: http://www-courses.cs.uiuc.edu/~cs125/cs125/_nav/_framepage/notesPage.html

11 Sort Example Sort students by height Sort by height, but female student go first Sort students by height, if there is a tie, smaller studentID stay in front. Sort students by name Sort using insertionsort algorithm

12 Inheritance Constructor in child class will call constructor in parent class automatically method overriding method overloading

13 File I/O, GUI see Kiri’s handout: TextFileInputDemo.java TextFileOutputDemo.java ButtonDemo.java


Download ppt "Review Multi-Dimensional Array Searching and Sorting in arrays Inheritance Graphics."

Similar presentations


Ads by Google