Computer Science 201: Data Structures & Algorithms Ch. 3

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

If you only want to clone a portion of an array in Java, which method do you use?

arraycopy

The following code declares a character array with 3 rows and 5 columns:

char [] [] matrix; matrix = new char[3][5];

Which of the following Java statements will make a clone of an array?

double[] rates = oldRates.clone();

Which of these code samples correctly processes a 2-dimensional array?

https://study.com/cimages/multimages/16/java_2d_answer1.png

Which of the following Java code snippets correctly starts at the end of a Node called m?

if(m.next == null)

How many dimensions does the following array have? float[][][] complexCube;

3

What will the list look like if the following code is run: myList.addNodeToHead(75); myList.addNodeToTail(100); myList.addNodeToHead(50);

50, 75, 100

Why is cloning multi-dimensional arrays in Java not available using the clone method?

A Java multi-dimensional array is an array of objects

Which of the following is a practical example of a doubly linked list?

A quest in a game that lets users retry stages.

What is the result of executing the code shown below? import java.util.Arrays; public class Main { public static void main(String args) { String student1 = {"John", "Doe", "Jane"}; String student2 = {"John", "Doe", "Jane"}; Object objectArray1 = {student1}; Object objectArray2 = {student2}; if(Arrays.equals(objectArray1, objectArray2)) { System.out.println("Same Students List"); } else { System.out.println("Different Students List"); } } }

It prints 'Different Students List'

What is the result of executing the program shown? import java.util.Arrays; public class Main { public static void main(String args) { String classList = {"John", "Jean","James"}; String graduatesList = {"John", "Jean", "James"}; if(Array.equals(classList, graduatesList)) { System.out.println("All the students in this class are graduating"); } else { System.out.println("Some of the students are not graduating."); } } }

It throws an error on the line where the 2 arrays are being compared because the s is missing on Array.equals

What is Range sorting?

It's used when you only need some part of an array sorted.

What is the purpose of the following Java code in context of a doubly-linked list? Node myNode = new Node(element); Node end = head; while(end.next != null) { update }

Looping until the last node is found.

If you need to remove an element from the tail of a circular linked list, what special step is needed?

Make sure the tail is really the last item

If you use sorting methods contained in the Java library, do you have to code the sorting algorithm?

No, the library does all the sorting according to the set criteria

Which of the following correctly checks to see if the current node is the head of a doubly linked list?

Node myNode = new Node(element); if(myNode.prev == null) { }

The components of a linked list are most commonly referred to as _____

Nodes

Why would an enhanced for loop not work with a circular linked list?

Nodes are all connected, it would result in infinite loop

In a singly linked list, the tail node points to what?

Null

Which of the following is the correct way to declare and fill an int array?

int[] gameScores = {3, 4, 8, 9};

Which is the Java library that will help you access more tools to manipulate and sort arrays?

java.util.Arrays

Which of the following correctly appends a new value specifically to the tail of the following linked list: LinkedList l = new LinkedList(); l.add("M"); l.add("A"); l.add("R");

l.addLast("S");

In the following linked list (named m in your code), you need to change the Z to an S. Which code example accomplishes this? [M, A, R, Z];

m.set(3, "S");

The following code correctly references the fourth row, fifth column, and seventh plane in a 3D array named matrix:

matrix[3][4][6];

If you had a Java class called myDll, how would you create a new doubly linked list instance?

myDll dll = new myDll();

In Java, a _____ copy would copy only the double data types of an array.

shallow

The following linked list, called j, exists in your program: [J, U, P, I, T, E, R] If you execute the following code, what will be the final value? j.add(2, "CERES");

[J, U, CERES, P, I, T, E, R]

Although we use the term multidimensional arrays, a multidimensional array is really an array of _____

Arrays

Which of the following is the most appropriate example of a doubly linked list?

Browsing history

What type of an array is this? chat[] enterCustomerName;

Character

In this type of linked list, the tail node points to the head node.

Circular linked

If a program needed to create a copy of an array with new references to an object, what type of copy would be performed?

Deep copy

When an item is removed from a linked list, what happens to the other element references?

Element indexes are re-ordered.

What does the binarySearch method allow us to do?

Find the position of the item we're looking for in the array

How does Insertion-Sort work?

Finding if each item is in the right position of the array according to the criteria

What is the most common type of loop used to step through an array?

For

The number that references the row/column in a multidimensional array is called a(n) _____

Index

When you add a new element to the tail of a circularly linked list, what is true of the current tail?

It connects to the head

What is the function of the following code? tail = head; head = head.next;

Rotating the list

When would it be most appropriate to create a linked list in Java?

Storing elements in a dynamic array.

Which of the following is TRUE about checking if two arrays of the same set of elements are equivalent using the comparison operator (==) ?

The two arrays are references to 2 different objects in memory hence not equivalent

Which of the following is TRUE about the comparison of two objects of the same parent class for equivalency on which one of the objects overrides a parent class method

The two objects are not equal because the overriding method introduced replaces the initial parent class method

A Java array that would have rows and columns is called a _____ array?

Two-dimensional

Which of the following would lead to two arrays with the same set of values not being equivalent when compared using the Arrays.equals() method?

When one or more elements in the second array is of a different data type to corresponding element(s) in the first array

When compared to an array, why is a linked list less efficient?

You need to traverse each node.


संबंधित स्टडी सेट्स

Environmental Policy Midterm- Dr. King

View Set

Chapter 3: Vectors and Coordinate Systems

View Set