Grading key for Question 3:
Alef (5 points):
There were a number of possible solutions. The classic one is:
- public class RandomIterator implements Iterator{
- Object[] arr;
- int size;
- }
Beit (5 points):
There were a number of possible solutions. The classic one is:
- public randomIterator(Object[] inputArr){
- arr=new Object[inputArr.length];
- for (int i=0 ;i < inputArr.length;i++)
- arr[i]=inputArr[i];
- size=arr.length-1;
- }
Grading Key:
F[-5]:מכיוון שיש תלות מוחלטת בין הסעיפים, סעיפים א ו-ב קיבלו ניקוד אם ורק אם התשובה בכללותה נכונה: סעיפים ג ו-ד היו נכונים.
Gemel (5 points):
There were a number of possible solutions. The classic one is:
- public Object next(){
- int randomIndex=(int)(Math.random()*(size));
- int tmp;
- Object ans=arr[randomIndex];
- tmp=arr[randomIndex];
- arr[randomIndex]=arr[size];
- arr[size]=tmp;
- size=size-1;
- return ans;
- }
There were a number of possible solutions. The classic one is:
- public boolean hasNext(){
- return size>=0;
- }
Grading key:
A[-2]: חוסר יעילות חמור.
B[-1]: טעות מקומית.
C[-1]: יש מצב של אי עצירה
D[-1]: חוסר יעילות.
E[-1 – -5]: פתרון לא נכון.
G[-4]: רק תהליך רנדומאלי נכון.
H[-1]: חריגה מוגזמת מהשורות המסומנות.
I[-1]: קוד מסורבל מדיי.
J[-1]: לולאה אין סופית.
K[-2]: שימוש בפונקציות עזר.