Grading key for Question 3:


Alef (5 points):
There were a number of possible solutions. The classic one is:
  1. public class RandomIterator implements Iterator{
  2.  Object[] arr;
  3. int size;
  4. }

Beit (5 points):
There were a number of possible solutions. The classic one is:

  1. public randomIterator(Object[] inputArr){ 
  2.     arr=new Object[inputArr.length];
  3.  
  4.     for (int i=0 ;i < inputArr.length;i++)
  5.         arr[i]=inputArr[i];
  6.         size=arr.length-1;        
  7.     }

Grading Key:

F[-5]:מכיוון שיש תלות מוחלטת בין הסעיפים, סעיפים א ו-ב קיבלו ניקוד אם ורק אם התשובה בכללותה נכונה: סעיפים ג ו-ד היו נכונים.

Gemel (5 points):
There were a number of possible solutions. The classic one is:

  1. public Object next(){
  2.  
  3.         int randomIndex=(int)(Math.random()*(size));
  4.         int tmp;
  5.         Object ans=arr[randomIndex];
  6.         tmp=arr[randomIndex];
  7.         arr[randomIndex]=arr[size];
  8.         arr[size]=tmp;
  9.         size=size-1;
  10.         return ans;        
  11. }
Dalet (5 points):
There were a number of possible solutions. The classic one is:
  1. public boolean hasNext(){
  2. return size>=0;        
  3. }

Grading key:


A[-2]: חוסר יעילות חמור.

B[-1]: טעות מקומית.

C[-1]: יש מצב של אי עצירה

D[-1]: חוסר יעילות.

E[-1 – -5]: פתרון לא נכון.

G[-4]: רק תהליך רנדומאלי נכון.

H[-1]: חריגה מוגזמת מהשורות המסומנות.

I[-1]: קוד מסורבל מדיי.

J[-1]: לולאה אין סופית.

K[-2]: שימוש בפונקציות עזר.