Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Data Collections
Start Practice TestPractice Test
About Exam
hard Solved by 1 students

Hashing With Linear Probing

Mark
< Prev
Next >

What is the output when the following program is executed?

public class HashTest {
    public static void main(String[] args) {
        int[] table = new int[5];
        int[] keys = {7, 12, 17, 22};
        
        // Simple hash function with linear probing for collisions: index = key % 5
        for (int key : keys) {
            int hash = key % 5;
            while (table[hash] != 0) {
                hash = (hash + 1) % 5;
            }
            table[hash] = key;
        }
        
        for(int i = 0; i < table.length; i++){
            System.out.print(table[i] + " ");
        }
    }
}
A

0 22 7 12 17

B

22 7 12 17 0

C

22 7 12 0 17

D

22 0 7 12 17

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1upadhgau00001 - -10
#2angelajxi1101 - -10
#3test111101 0m 03s -13
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|