Download presentation

Presentation is loading. Please wait.

Published byMina Riles Modified over 2 years ago

1
CSC 345 Sample Test 2 - Answers APPLE = 0 PEAR = 6 BANANA = 7 ORANGE = 4 GRAPE = 7 public static void prob1() { System.out.println("APPLE = " + hashnum("APPLE")); System.out.println("PEAR = " + hashnum("PEAR")); System.out.println("BANANA = " + hashnum("BANANA")); System.out.println("ORANGE = " + hashnum("ORANGE")); System.out.println("GRAPE = " + hashnum("GRAPE")); } public static int hashnum(String str) { int hnum = 0; for(int i=0;i

2
public static int comb2(int n, int k) { int[][] c = new int[n+1][k+1]; int p; if(k>n) return 0; else { for(int i=0;i<=n;i++) { p = Math.min(i,k); for(int j=0;j<=p;j++) { if(j==0 || j==i) c[i][j] = 1; else c[i][j] = c[i-1][j-1] + c[i-1][j]; } } return c[n][k]; } } } 6! = 720 1 11 121 133 1 146 4 15 012345012345 012 3 N i loop K j loop 10 public static int comb(int n, int k) { if(k==0 || k==n) return 1; else return comb(n-1,k-1) + comb(n-1,k); }

3
Q Q Q Q Q Q Q Q Every other pattern is obtainable from one of these by flipping or rotation. i j i+1 j+1 i i+1 j j+1 Imagine that the line connecting the list S of points in R2 crosses over itself at some location in the list. Lets say that line segment connecting point i to point i+1 is crossed over at some point by the line segment connecting points j and j+1. These four points represent a generic four-sided figure (quadrilateral) in which the line segments defined here are the internal diagonals. If we assume that the sum of the lengths of these two line segments is greater than the sum of the lengths of the opposite sides of the quadrilateral the we can reorder the points in S to achieve a shorter total line length. That is if dist(i,i+1) + dist(j,j+1) is greater than dist(i,j) + dist(i+1,j+1) then we can reverse the order of the list of points between i+1 and j, inclusive to obtain a shorter total line length. reverse N! = N factorial = (N)(N-1)(N-2)...(2)(1)

Similar presentations

Presentation is loading. Please wait....

OK

Classifying Quadrilaterals

Classifying Quadrilaterals

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on festivals of punjab Hrm ppt on recruitment process Ppt on nuclear family and joint family advantages Ppt on introduction to object-oriented programming examples Ppt on effect of global warming on weather Ppt on west bengal shops and establishment act Ppt on as 14 amalgamation process Ppt on power system transient stability Ppt on op amp circuits projects Ppt on carburetor diagram