Search Header Logo

Data Structures & Algorithms Quiz

Authored by John Alvin Omiles

Other

2nd Grade

Used 1+ times

Data Structures & Algorithms Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

51 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Given the following code snippet: int[] arr1 = {1, 2, 3}; int[] arr2 = new int[3]; arr2 = arr1; arr2[0] = 10 System.out.println(arr1[0]); What will the output be?

A) 1

B) 10

C) 0

D) An error will occur at runtime.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following code snippets will result in a compilation error?

A) Int[] numbers = new int[5]; numbers[0] = 1;

B) double[] fractions = {1.2, 2.4, 3.6}; System.out.println(fractions[2]);

C) char letters[] = new char[3]; letters[3] = 'A';

D) String[] names = new String[2]; names[0] = "Alice"; names[1] = 123;

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following code? int[] arr = {1, 2, 3, 4}; System.out.println(arr[arr.length - 1]);

A) 1

B) 4

C) 3

D) An error will occur

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Analyze the following code: String[] fruits = {"Apple", "Banana", "Orange"}; System.out.println(fruits[fruits.length]); What will happen when this code is executed?

A) It prints Orange.

B) It prints null.

C) An ArrayIndexOutOfBoundsException will be thrown.

D) It prints the length of the array.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Analyze the following scenario: If the base address in a 1D integer array arr is 2000, and each integer takes 4 bytes, what will be the address of the 5th element (arr[4])?

A) 2004

B) 2020

C) 2016

D) 2008

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Identify the issue in the following computed addressing formula in a 1D Array: Address = Base Address + (Index + 1) * Element Size

A) It will compute the wrong address for the first element.

B) It skips over even elements.

C) It results in a runtime error for negative indices.

D) It correctly computes addresses for all elements.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

If ArrayKo is an integer array having 6 elements with a base address of 1000, and each integer occupies 2 bytes, what happens if you try to access A[6]?

A) It will access memory at address 1012.

B) It will access memory at address 1016.

C) It will result in an out-of-bounds error if the array has more than 6 elements.

D) It will access memory at address 1018.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?