AP (Advanced Placement) · AP Computer Science A

Ethical and Social Issues Around Data Collection: แบบฝึกหัด

ข้อปรนัย 5 ข้อ ตรวจให้ทันทีที่ตอบ และข้อเขียน 2 ข้อ พร้อมวิธีทำละเอียด ทั้งหมดจากเรื่อง Ethical and Social Issues Around Data Collection

7 ข้อ17 คะแนนฟรี ไม่ต้องสมัคร
ข้อ 1
1 คะแนน

A method findMax is intended to return the largest value in an array of integers.
public int findMax(int[] nums) {
  int max = nums[0];
  for (int i = 1; i < nums.length; i++) {
    if (nums[i] > max) {
      max = nums[i];
    }
  }
  return max;
}

Which of the following preconditions must be true for the method to work without throwing an exception?

ข้อ 2
1 คะแนน

Consider the following method that processes a 2D array:
public void process(int[][] mat) {
  for (int r = 0; r < mat.length; r++) {
    for (int c = 0; c < mat[0].length; c++) {
      if (r == c) {
        mat[r][c] *= 2;
      }
    }
  }
}

If mat is initialized as {{1, 2}, {3, 4}}, what is the value of mat after process(mat) is called?

ข้อ 3
1 คะแนน

Consider the following method designed to reverse the elements in an array:
public void reverse(int[] data) {
  for (int i = 0; i < data.length / 2; i++) {
    int temp = data[i];
    data[i] = data[data.length - 1 - i];
    data[data.length - 1 - i] = temp;
  }
}

If data is {1, 2, 3, 4, 5, 6}, how many total assignments to elements within data (lines involving data[...] = ...) are executed?

ข้อ 4
1 คะแนน

Consider the following code segment:
int[] arr = {1, 2, 3, 4, 5};
for (int i = 0; i < arr.length - 1; i++) {
  arr[i] = arr[i + 1];
}

What will be the contents of arr after the loop finishes execution?

ข้อ 5
1 คะแนน

Given a 2D array int[][] table = {{5, 10, 15}, {20, 25, 30}}, which expression correctly accesses the value 30?

ข้อ 6
5 คะแนน

Consider a scenario where you are managing a library system using a 1D array of Book objects named libraryShelf.
Part a: Write a code segment that iterates through the array and counts how many books have a price higher than \(P\), where \(P = 50.0\).
Part b: If the array is currently full with \(n\) elements, describe the steps and code logic required to 'remove' a book at index \(k\) while maintaining the relative order of the remaining books.
Part c: Calculate the minimum number of comparisons needed to find a specific book title in an unsorted array of size \(n = 100\) in the worst-case scenario.

ลองเขียนคำตอบด้วยตัวเองก่อน แล้วค่อยเทียบกับวิธีทำ

ข้อ 7
7 คะแนน

A 2D array int[][] matrix of size \(M \times N\) represents a grayscale image where each value is an intensity between 0 and 255.
Part a: Write a nested loop structure to identify if the matrix is 'horizontally symmetric'. A matrix is horizontally symmetric if for every row \(i\) and column \(j\), matrix[i][j] == matrix[i][N - 1 - j].
Part b: Write a method applyThreshold(int limit) that modifies the 2D array: any value greater than limit becomes 255, and any value less than or equal to limit becomes 0.
Part c: Analyze the time complexity of the symmetry check in terms of \(M\) and \(N\). If \(M = 1000\) and \(N = 1000\), how many total comparisons are performed in the worst case?

ลองเขียนคำตอบด้วยตัวเองก่อน แล้วค่อยเทียบกับวิธีทำ

* เนื้อหาของ thinka สร้างโดย AI อาจไม่ถูกต้องสมบูรณ์ในทุกกรณี กรุณาใช้เป็นสื่อเสริมและตรวจสอบกับเอกสารอ้างอิงอย่างเป็นทางการ

คุณเห็นเฉลยแล้ว ทีนี้มาตรวจคำตอบของคุณบ้าง

หน้านี้บอกได้ว่าคำตอบที่ดีเป็นอย่างไร แต่บอกไม่ได้ว่าคำตอบของคุณขาดอะไร thinka ตรวจข้อเขียนของคุณตามเกณฑ์ให้คะแนนจริงในราว 15 วินาที

อยากฝึกโจทย์แบบนี้เพิ่มไหม เริ่มฝึกหัวข้อนี้ได้เลย ตรวจให้ทันทีทุกข้อ

เริ่มฝึกเลย