Data Structures and Algorithm Prelim Quizzes

0.0(0)
studied byStudied by 10 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/38

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

39 Terms

1
New cards

If an array component is of a primitive type, the component can be passed as a parameter to a method. (TRUE OR FALSE)

TRUE

2
New cards
int[] hit = new hit[5];
 
hit[0] = 3;
hit[1] = 5;
hit[2] = 2;
hit[3] = 6;
hit[4] = 1;
 
System.out.println(hit[1 + 3]);

What is the output of the code fragment above?

1

3
New cards

A method can have both a variable length formal parameter and other formal parameters. (TRUE OR FALSE)

TRUE

4
New cards

In a method call statement, when passing an array as an actual parameter, you use only its name. (TRUE OR FALSE)

TRUE

5
New cards
int[] num = new int[100];
 
for (int i = 0; i < 50; i++)
    num[i] = i;
 
num[5] = 10;
num[25] = 100;

What is the index number of the last component in the array above?

99

6
New cards
int[] alpha = new int[5];
int j;
 
alpha[0] = 5;
for (j = 1; j < 5; j++)
{
  if (j % 2 == 0)
      alpha[j] = alpha[j – 1] + 2;
  else
      alpha[j] = alpha[j – 1] + 3;
}

What is the value of alpha[3] after the following code executes? (TYPE OUTPUT OR NONE)

13

7
New cards

Arrays can be initialized when they are created. (TRUE OR FALSE)

TRUE

8
New cards
int[] list = new int[25];

The statement creates list to be an array of 26 components because array index starts at 0. (TRUE OR FALSE)

FALSE

9
New cards

If a method has both a variable length formal parameter and other types of formal parameters, then the variable length formal parameter must be the last formal parameter of the formal parameter list. (TRUE OR FALSE)

TRUE

10
New cards

If an array index is less than zero, an InvalidIndexException exception is thrown. (TRUE OR FALSE)

FALSE

11
New cards

Suppose alpha is an array of 50 components. Which of the following about alpha is true?

(1) The base address of alpha is the address of alpha[0].

(2) The base address of alpha is the address of alpha[1].

(WRITE 1, 12, 2, OR NONE)

1

12
New cards

A method can have two variable length formal parameters. (TRUE OR FALSE)

FALSE

13
New cards
int[] x = new int[10];
 
x[0] = 34;
x[1] = 88;
 
System.out.println(x[0] + " " + x[1] + " " + x[10]);

What is the output of the code fragment above? (TYPE OUTPUT OR NONE)

NONE

14
New cards

Arrays have a fixed number of components. (TRUE OR FALSE)

TRUE

15
New cards
int[] list = new int[20];
list[12] = list[5] + list[7];

Given the declaration and the statement, it updates the content of the twelfth component of the array list. (TRUE OR FALSE

FALSE

16
New cards

The method toString creates a string that is the name of the object’s class, followed by the hash code of the object. (TRUE OR FALSE)

TRUE

17
New cards
<p><span>According to the UML class diagram above, which of the following is a data member? (</span>Clock(), min, printTime(), Clock)</p>

According to the UML class diagram above, which of the following is a data member? (Clock(), min, printTime(), Clock)

min

18
New cards

Members of a class are usually classified into three categories: static, public, and void. (TRUE OR FALSE)

FALSE

19
New cards

Every object has access to a reference to itself. (TRUE OR FALSE)

TRUE

20
New cards
public class MyClass
{
    private int x;
 
    public void print()
    {
        System.out.println("x = " + x);
    }
}

MyClass aa = new MyClass();

 

aa.print();

The aa.print(); statement is legal based on the code above. (TRUE OR FALSE)

TRUE

21
New cards

A mutator method of a class changes the values of the data members of the class. (TRUE OR FALSE)

TRUE

22
New cards

The modifier static in the heading specifies that the method can be invoked by using the name of the class. (TRUE OR FALSE)

TRUE

23
New cards

How many finalizers can a class have? (NUMBER ONLY)

1

24
New cards
public class Rectangle
{
    private double length;
    private double width;
 
    public Rectangle()
    {
        length = 0;
        width = 0;
    }
 
    public Rectangle(double l, double w)
    {
        length = l;
        width = w;
    }
 
    public void set(double l, double w)
    {
        length = l;
        width = w;
    }
 
    public void print()
    {
        System.out.println(length + " " + width);
    }
 
    public double area()
    {
        return length * width;
    }
 
    public double perimeter()
    {
        return 2 * length + 2 * width;
    }
}

 

Suppose that you have the following declaration.

 

Rectangle bigRect = new Rectangle(10, 4);

Which of the following statements are valid in Java? (Assume that console is Scanner object initialized to the standard input device.)

 

(i)

   bigRect.length = console.nextDouble();
   bigRect.width = console.nextDouble();

(ii)

   double l;
   double w; 
   l = console.nextDouble();
   w = console.nextDouble();
   bigRect.set(l, w);

(TYPE 1, 12, 2, OR NONE)

2

25
New cards

Members of a class consist of packages, methods, and libraries. (TRUE OR FALSE)

FALSE

26
New cards

An accessor method of a class first accesses the values of the data members of the class and then changes the values of the data members. (TRUE OR FALSE)

FALSE

27
New cards

If a member of a class is a method, it can (directly) access any member of the class. (TRUE OR FALSE)

TRUE

28
New cards

Modifiers are used to alter the behavior of the class. (TRUE OR FALSE)

TRUE

29
New cards

A ____ is a collection of a fixed number of components. (TYPE IN CAPS)

CLASS

30
New cards

A constructor has the same name as the class. (TRUE OR FALSE)

TRUE

31
New cards

What is the arrangement of the array [11,2,13,21,25,19] after ONE iteration of outer loop to sort the data in INCREASING order using bubble sort algorithm (correct bubble sort).

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[2,11,13,19,21,25]

32
New cards

What is the arrangement of the array [11,2,13,21,25,19] after ONE iteration of the outer loop to sort the data in INCREASING order using insertion sort algorithm.

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[2,11,13,21,25,19]

33
New cards

What is the arrangement of the array [11,2,13,21,25,19] after TWO iterations of outer loop to sort the data in INCREASING order using bubble sort algorithm (correct bubble sort).

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[2,11,13,19,21,25]

34
New cards

What is the arrangement of the array [10,52,63,1,85,9] after THREE iterations of the outer loop to sort the data in DECREASING order using selection sort algorithm.

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[85,63,52,1,10,9]

35
New cards

What is the arrangement of the array [11,2,13,21,25,19] after FOUR iterations of the outer loop to sort the data in DECREASING order using insertion sort algorithm.

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[25,21,13,11,2,19]

36
New cards

What is the arrangement of the array [11,2,13,21,25,19] after FOUR iterations of the outer loop to sort the data in DECREASING order using bubble sort algorithm (correct bubble sort).

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[25,21,19,13,11,2]

37
New cards

What is the arrangement of the array [11,2,13,21,25,19] after ONE iteration of the outer loop to sort the data in INCREASING order using selection sort algorithm.

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[2,11,13,21,25,19]

38
New cards

What is the arrangement of the array [10,52,63,1,85,9] after ONE iteration of the outer loop to sort the data in INCREASING order using selection sort algorithm.

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[1,52,63,10,85,9]

39
New cards

What is the arrangement of the array [10,52,63,1,85,9] after TWO iterations of the outer loop to sort the data in INCREASING order using insertion sort algorithm.

Do not add spaces in the answer, follow this format [#,#,#,#,#,#].

[10,52,63,1,85,9]