Computer Science 201: Data Structures & Algorithms

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the difference between 'merge' and 'meld' operations of the heap? 'merge' joins or combines two heaps into one heap and destroys the original heap, 'meld' joins or combines two heaps into one heap and preserves the original heaps. 'merge' joins or combines two heaps into one heap and also preserves the original heaps, 'meld' also combines two heaps into one heap but destroys the original heaps. 'merge' splits one heap into two heaps. 'meld' splits one heap into two heaps.

'merge' joins or combines two heaps into one heap and also preserves the original heaps, 'meld' also combines two heaps into one heap but destroys the original heaps. Both operations combine two heaps into one heap but 'merge' preserves the original heaps while 'meld' destroys the original heaps.

Which of the following pseudocodes is appropriate to compute area of a triangle? - Enter base length, B | Enter height, H | Compute the area = 1/2 * B * H - Display area - Enter the base length B and height H and compute area - Display area - Enter base length, B - Compute the area=2*B*H - Compute the area using the formula 1/2 * Base * Height - Display the area

- Enter base length, B | Enter height, H | Compute the area = 1/2 * B * H - Display area

What is an example of multi-line comment? * / The beginning of a multi-line * / the end of the comment // The beginning of a multi-line the end of the comment // /* The beginning of a multi-line the end of the comment */ * / The beginning of a multi-line the end of the comment * /

/* The beginning of a multi-line the end of the comment */

What is an example of a documentation comment? /* This is the beginning and this is the end */ // This is the beginning and this is the end *// / This is the beginning and this is the end **/ /** This is the beginning and this is the end */

/** This is the beginning and this is the end */

If a list contains three objects, what is the index number of the last object? 2 3 0 1

2

Given a second hash function of I(k) = (1 + k%7) , in which position in the table below would the key 53 be stored using the double hashing technique? [0][1][2][3][4][5][6][7][8][9] [E][E][E][3][E][E][E][E][E][E] 4 6 8 3

8 We calculate the base address H(53) = 53%10 = 3 Since position 3 is occupied, we need to resolve the collision by computing the alternative location using double hashing with second hash equation as: I(k) = (1 + k%7) The full equation to use when a collision occurs the first time: (1*I(k) + base address)%(table length) Position for 53 = (1*I(53) + 3)%10 = ((1+53%7) + 3)%10 = ((1+4) +3)%10 = 8%10 = 8

Why is cloning multi-dimensional arrays in Java not available using the clone method? A Java multi-dimensional array is an array of objects Java doesn't support pointers A Java multi-dimensional array is an array of primitives Only the copyArray or arraycopy methods work in Java

A Java multi-dimensional array is an array of objects Because a multi-dimensional array is an array of arrays, it means it's an array of objects. We are not able to create a deep copy of an array of objects using clone or arraycopy methods.

How does using a debugger in an integrated development environment benefit an individual who is writing code? It is best not to use a debugger, but instead to be thorough and read through all of the lines of code to find the bugs. A debugger can assist with generating test case scenarios which can then be used to test the code to find the bugs. A debugger can automatically fix the broken code for the individual once the bugs have been identified. A debugger walks through code in a systemic and automatic manner to find bugs, making the process less time consuming.

A debugger walks through code in a systemic and automatic manner to find bugs, making the process less time consuming.

What is natural order? Chronological First-In A sort order such as numeric or alphabetic First-Out

A sort order such as numeric or alphabetic The default order of priority queues is referred to as natural order. That simply means that if the elements are numbers, they will be numerically ordered, and if they are strings, they will be alphabetized.

What is a pseudocode? Simple programming language. A text editor. A way of writing programming code in English. A structured method which can be compiled.

A way of writing programming code in English.

Why is it necessary to analyze an algorithm? To write a program for it. To check the time and space it consumes. All of the above To check the correctness of an algorithm

All of the above

A Java statement can be thought of as which one of the following? An expression An instruction A prompt A loop

An instruction

What type of data can a priority queue contain? Integers Any type of data Arrays Strings

Any type of data

Which of the following sets are implemented classes of the List interface? ArrayList, LinkedList, Stack, and Vector ArrayList, DynamicLinkedList, Stack, and Sort ArrayList, LinkedList, Stack, and Sort ArrayList, RoleResolvedList, Add, and Role

ArrayList, LinkedList, Stack, and Vector There are 10 implemented classes, including ArrayList, LinkedList, Stack, and Vector.

Which of the following Java code items correctly performs the binary search method from the Arrays class? Arrays.binarySearch(myList, Math.min(j, size), searcher); Arrays.binarySearch(myList, (j/2), Math.min(j, size), searcher, i/2, myList); Arrays.binarySearch(searcher); Arrays.binarySearch(myList, (j/2), Math.min(j, size), searcher);

Arrays.binarySearch(myList, (j/2), Math.min(j, size), searcher); The method can take 2 or 4 parameters. The correct answer sends the array (myList), starting at index /2 (j/2), and goes to the smallest value of j or the size of the array. It looks in that range for the value (searcher)

int marker = 10; What type of statement is the following? Integer Void Control Assignment

Assignment

Given the following Java code that performs a sequential search, what is missing? public static double sequentialSearch(int[] arr, int searchKey) { int arraySize = arr.length; for(int i = 0; i < arraySize; i++) { } return -1; } A) This code will compile as written. B) if(arr[i] == searchKey) { return i; } C) return i; D) if(searchKey == searchKey) { return i; }

B) if(arr[i] == searchKey) { return i; }

In which of the following data tree structures does a parent node have more than two child nodes? Heap Hash B-tree Binary tree

B-tree

Which of the following is NOT a type of binary tree traversal? Backorder traversal Inorder traversal Preorder traversal Postorder traversal

Backorder traversal Preorder, postorder and inorder traversals are valid types of binary tree transversals. Backorder is not a type of binary tree traversal.

_____ are the most efficient type of tree data structures. Hierarchical trees Balanced trees Sorted trees Binary trees

Binary trees

Which of the following data tree structures has a parent node that can't have more than two child nodes? Heap Both Binary tree and Heap B-tree Binary tree

Both Binary tree and Heap

if (i == 10) System.out.printIn("10") i += 10; Examine the following code. What is missing on the ''if statement''? Brackets/braces A semicolon An ''else statement'' An ''end if'' statement

Brackets/braces

When performing an exponential search in Java, what is the first thing you should do? Check to see if the element is first in the list. Perform a recursive search to find the element. Check if the element is in the middle of the list. Perform a binary search.

Check to see if the element is first in the list.

Which of the following is a benefit of using the Java Collections Framework? Code portability More robust codebase More readable code Coding shortcuts

Code portability Writing code using the Java Collections Framework capitalizes on common behaviors for the entire collection.

_____ occurs when there is an attempt to store a value in an occupied space in a hash table. Collision Delay Clustering Hashing

Collision

Which interface must we implement in order to compare elements in a priority queue? PriorityQueue Comparable Driver Comparator

Comparable The Comparable interface permits us to compare instances of elements in a priority queue.

Which interface requires the compareTo method to be overridden? Comparable Driver PriorityQueue Comparator

Comparable When we implement the Comparable interface, we are required to provide an @Override the abstract method compareTo.

What is the compareTo method used for? Select the most complete answer. Compares new elements Compares the first and last elements Compares two queues Compares two elements in the queue

Compares new elements The compareTo method is used to compare new elements as they are added to the priority queue. This determines their priority.

Contrapositive and contradiction fall under which category of algorithm analysis? Loop Variants Induction Contra Attack Asymptotic

Contra Attack

Which method is used to prove a mathematical statement true, by assuming the negation of it to also be true? Manual analysis Induction Contrapositive Contradiction

Contrapositive A contrapositive method first proves the negative of a given statement true, and then concludes that the original statement is also true.

What is the main characteristic of binary trees? Each parent only has two children. Each node is connected twice. Search time can be reduced. Each root only has two nodes.

Each parent only has two children.

Which of the following location states will be treated the same when doing an INSERT operation into the hash table in open addressing? None of the states will be treated the same in open addressing Occupied and Deleted Empty and Deleted Occupied and Empty

Empty and Deleted When doing an INSERT operation, both Empty and Deleted spaces in the table will have values inserted into them. Deleted spaces will be treated differently from Empty spaces when doing data retrieval only.

What will be the result of the following code? int j = 0; while (j < 1000) { j = j - 1; }

Endless loop

Which major application uses B-tree data structure? Designing heap sort algorithm Writing routing algorithms Database building and indexing Priority Queuing

Database building and indexing B-tree is used majorly in building a database and its indexing.

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

Deep copy

What happens if an element is not found in a sequential search? Every item in the list was evaluated. The program crashes. An error is displayed in the output. A value of 0 is returned.

Every item in the list was evaluated.

What is the main property of a binary tree? Every leaf node must have exactly two children. Every node can have a maximum of 0, 1 or 2 children. Every node must have at least 1 child. Every node should have exactly two children.

Every node can have a maximum of 0, 1 or 2 children. The main property of a binary tree is that each node can have either 0, 1 or 2 children.

When performing an exponential search in Java, what is the order of operations? Find the range for the element. Then complete a binary search. Perform a binary search. Then split the array in thirds. Complete a binary search. Then find the range for the element. Find the range for the element. Then perform a reverse logarithmic search.

Find the range for the element. Then complete a binary search.

Which of the following is NOT a typical component of an Integrated Development Environment? Debugger Grammar checking Autocompletion Syntax checking

Grammar checking

What determines if a value being stored in a tree needs to go to the right or to the left side of the root? If the value being stored is less or greater than the value in the root. If there is an existent root in the tree or not. If the tree being used is a binary tree or not. If all the children in the tree are in the same level.

If the value being stored is less or greater than the value in the root.

Huffman code binary trees are used in which of the following? Image and video compression 3D video games Cryptography Job scheduling queues

Image and video compression

A while loop is considered _____ if you don't know when the condition will be true Indefinite Passive Infinite Positive

Indefinite

Which of the following is TRUE about pseudocode? It cannot be modified. It cannot be compiled. It can be compiled in any language you use. It is harder to write than making flowcharts.

It cannot be compiled.

Which of the following best describes an abstract data type (ADT)? It does not require knowledge of how operations are carried out. Knowledge of the data and underlying code is required. Knowledge of Java's ADT library and insertion methods is required. Java does not support ADT.

It does not require knowledge of how operations are carried out. An abstract data type (ADT) does not require that you know the underlying code, or how the data is structured. It provides the access and methods.

Which statement is NOT an advantage of pseudocode? It is written easily in a word processing application. It is standardized. It is easy to modify. It can be used with structured programming languages.

It is standardized.

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 prints out 'Some of the students are not graduating' It prints out 'All the students in this class are graduating' It prints out to the console 'Error: The 2 arrays are String arrays that can not be compared' It throws an error on the line where the 2 arrays are being compared because the s is missing on Array.equals

It prints out 'All the students in this class are graduating' The Method is called Arrays.equals and it loops through each of the string elements of the 2 arrays to compare them (The elements) using the equals method, which for this case would prove that the 2 arrays are equivalent since they all contain the same elements but it will throw an error since the Method is spelled wrong.

Set < Integer > counts = new TressSet() counts.add(9343): counts.add(847); Based on the following Set, which of the following correctly iterates over all items in the Set?

Iterator < Integer > itr = counts.iterator(); while (itr.hasNext( )) { itr.next( ); }

What does JDK stand for? Java Developers Kit Java Developers Environment Junior Developers Kit Java Development Kit

Java Development Kit

What type of structure uses data stored inside a tree node? Hash-code Primary key Hash-map Key-value

Key-value

Which of the open addressing methods involves the simplest calculation for collision resolution? Quadratic Linear Chaining Double hashing

Linear Linear probing is the simplest collision resolution technique, because we simply add the constant 1 to the current position until we get an empty location. Quadratic and double hashing techniques both involve additional equations for calculating the alternative location. Chaining is not an open addressing technique.

What are the two types of heap data structure? Min-heap and Max-heap Median-heap and Min-heap Median-heap and Full-heap Max-heap and Median-heap

Min-heap and Max-heap Heaps can be min-neap (where the root node has the lowest value) or max-heap (where the root node has the highest value).

The compiler is giving an error on the following statement. Why? float hoursWorked Missing brackets Missing a value Missing a variable Missing semicolon

Missing semicolon

What is the default sort order for priority queues? Natural order Null Numeric Alphabetic

Natural order Priority queues use a natural order to determine priority.

In a singly linked list, the tail node points to what? The head Null The node before the tail 0

Null

A while loop can evaluate _____ condition(s). Only one Exactly two Zero One or more

One or more

In Big O notation, what is the significance of O(n)? Performance will increase exponentially. Performance increases linearly. Performance decreases at a logarithmic rate. There is no performance impact.

Performance increases linearly.

In relation to a binary search, what does the notation O(log n) indicate about performance? Performance is worse at the beginning, then evens out. Performance gets exponentially worse as n increases. There is no performance impact to the system. Performance is worse at the beginning and worsens toward n.

Performance is worse at the beginning, then evens out. Because binary searches incrementally split the data set in half, the first iteration brings the heaviest load. The data set then shrinks and evens out as you approach n.

Which two structures does a positional list combine? Queue, array Queue, stack Stack, array Index, array

Queue, stack A queue lets you add only to the end of the list. A stack lets you only add to the top. A positional list provides the opportunity to perform either or both.

Which of the following is an important property of heap data structure? The right child of any node must always be greater than its left child. Every node has a maximum of 3 children in heap data structure. Heap follows binary search tree principles. The nodes must be inserted from left to right.

The right child of any node must always be greater than its left child. Heap data structure does not follow binary search tree principle and thus there is no need for a node to have lesser value at the left child and greater value at the right child. The maximum number of children for any node on heap is either 0, 1 or 2.

Which of the following is NOT a type of binary tree? Recursive binary tree Perfect binary tree Complete binary tree Full binary tree

Recursive binary tree There are three types of binary trees described in the lesson. These are full, complete and perfect binary trees.

What is the name of the initial node of a tree data structure? Bunch Root Branch Leave

Root

In max heap type, which node has the element with the greatest value? First child node Last node of right sub tree Root node Last child node

Root node

Gwen is an IT programmer for a small, non profit company. She's been assigned to write some new code for her company's payroll department to assist with the roll-out of a new pay for performance system. The new code will affect employees' pay grades, salaries, and bonuses. Gwen has written pseudo-code and the actual code. What should be her next step in the process? Test and debug the code Release the code to the production environment Test the code with real-world users Train end users on the changes to the payroll program

Test and debug the code

Given an array of 2.5 billion elements, what is the average case for a sequential search? The element is not found. The element is found at n/2. The element is found at n. The list is too large. There is no best case.

The element is found at n/2.

How does the IDE component, known as syntax highlighting, aid developers with writing program code? The tool highlights misspelled words. The tool automatically corrects common typos while typing. The tool makes it easier to recognize the various elements of code . The tool automatically corrects text formatting while typing.

The tool makes it easier to recognize the various elements of code Explanation Syntax highlighting includes displaying code using different colors to indicate the different types of elements in code.

Which of the following statements is NOT correct? None of these statements are incorrect. The value of every parent node is greater than or equal to that of their child or node in min-heap. The value of every parent node is lesser than that of their children in min heap. Heap is a binary tree.

The value of every parent node is greater than or equal to that of their child or node in min-heap. In min-heap the value of every parent is less than or equal to that of their children with the root node having the minimum element value.

Which of the following is a property of max-heap? The value of the root element is the smallest of all other nodes in max-heap. The value of the root element is the greatest of all other nodes in max-heap. The value of level 0 left child element is the greatest of all other nodes in max-heap. The value of a child element is greatest of all other nodes in max-heap.

The value of the root element is the greatest of all other nodes in max-heap. In a max-heap, the value of the root element must be greater than all the other nodes.

A recursive algorithm has the following expression for its time complexity: T(n) = 2n. Considering this, mark the answer that is undoubtedly correct. This algorithm has a double linear time complexity. This algorithm has a linear time complexity. This algorithm has a linear time complexity and a linear space complexity. This algorithm has a double linear complexity.

This algorithm has a linear time complexity.

Consider the following Java code. Which part of an exponential search is it performing? while (j < size && array[j] <= key) { j = j * 2; } This code is finding the range of the key value. This code will not compile and is in error. This code performs the binary search. This is a recursive function.

This code is finding the range of the key value. This code is looking for the range of the key value. It is the first step in the exponential search. Once it exits the while loop, the binary search can then be performed.

In the Tower of Hanoi recursive method, why do we need calls to the method twice? solvePuzzle(n-1, begin, end, temp); solvePuzzle(n-1, temp, begin, end); This will prevent the program from crashing This is an error and the program can run with only one line To move a disc from start to the middle, then move it from the middle to end The code changes the last peg to the first peg by moving all pegs over from the third

To move a disc from start to the middle, then move it from the middle to end

A while loop runs code as long as the condition(s) is/are: False Positive True Negative

True

How many forms of the add method can be used with lists? Three Two One Four

Two The add method can be used with and without passing an index value.

How is a single line comment created in Java? Two backward slashes at the beginning indicate that the line is a comment. Two forward slashes at the beginning indicate that the line is a comment. A forward slash followed by two asterisks at the beginning indicate that the line is a comment. A forward slash followed by an asterisk at the beginning indicate that the line is a comment.

Two forward slashes at the beginning indicate that the line is a comment.

Which of the following binary trees is a binary search tree?

Which of the following binary trees is a binary search tree? number 1

When compared to an array, why is a linked list less efficient? All elements are indexed. You need to traverse each node. You can access any node's index. Pointers cannot be reset.

You need to traverse each node.

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

arraycopy

One of the important considerations when writing pseudocode is to _____. specify a programming language write everything in a paragraph write only one statement per line write only a portion of the program that is important

write only one statement per line

Which method can we use to sort a priority queue by multiple elements? compareTo sort multiSort comparator

compareTo The compareTo method can be used to sort priority queues by one, two, or more elements.

To create a list, which of these packages must be imported? java.util.Dictionary java.util.Collections java.util.LinedList java.util.List

java.util.List In order to work on a list, we need to first create one. We must import both the java.util.ArrayList and java.util.List packages.

If you are performing a sequential search in Java, the data _____. does not need to be sorted must be Boolean must be an integer must be sorted

does not need to be sorted

If you are performing a sequential search in Java, the data _____. must be sorted must be Boolean does not need to be sorted must be an integer

does not need to be sorted

Which of the following is a correctly written Java statement? double conversions = 15.34; for(int i =0; i<15;i++) while(f<3); new String - "joey"

double conversions = 15.34;

Which of the following Java statements will make a clone of an array? double[] rates = oldRates.clone(); oldRates.arraycopy() = new rates[] double[] rates = new oldRates[].clone(); double[] rates = oldRates.arraycopy();

double[] rates = oldRates.clone();

Which method does the List interface inherit from the Iterable interface? removeIf forEach stream parallelStream

forEach The List interface only inherits one method from the Iterable interface, and that is the forEach method.

A code editor that is used to check syntax, format, run, and test code is known as a/an _____. integrated development environment test environment artificial intelligence system integrated developer extension

integrated development environment

In loop variants, the relationship between the variables _____. is none of the above is different before and after the loop cannot be determined is the same before and after the loops

is the same before and after the loops The relationship of the variables immediately before and after a loop must hold true.

Which package does the List interface belong to? java.String java.lang java.ArrayList java.util

java.util The List interface belongs to the java.util package.

Which package does the sort method belong to? java.util.ArrayList java.util.List java.util.Collections java.util.LinedList

java.util.Collections In order to sort our list, we will use the sort method that belongs to the Collections class. So, we must import the java.util.Collections package.

Which keyword is used to create a PriorityQueue instance? new create queue add

new We use the 'new' keyword to create the priority queue as in the following example: PriorityQueue<String> myPriorityQueue = new PriorityQueue<>();

Select the correct Java code that completes the method for inserting an element into a positional list. Node newNode = new Node(info); Node currentNode = head; while(--index > 0) { currentNode = currentNode.next; } No method exists for inserting an element into a positional list. newNode.previous = newNode.previous; node.previous = node.next; newNode = node; node = newNode; newNode.next = currentNode.next; currentNode.next = newNode;

newNode.next = currentNode.next; currentNode.next = newNode; This code moves the existing node forward, and slides in the new node just before it.

An element within a positional list in Java is also called a(n) _____. head tail root node

node Elements are called nodes. A node can be a head (at the start of the list), or a tail (at the end of the list)

Which method is a combination of the peek and remove methods? offer clear comparator poll

poll

Which method retrieves and removes the highest priority item of a priority queue? clear poll remove retrieve

poll The poll method will retrieve the item with the highest priority and remove it.

An important use of heap data structure is _____. indexing databases priority queue building databases storing routing tables

priority queue Since heaps are very useful in the data structures that require an element to be removed with highest or lowest priority, one of its major application areas is designing priority queues.

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

shallow

Which List algorithm is used for arranging the List elements in a random order? shuffle swap randomize reverse

shuffle The shuffle algorithm puts the List elements in random order.

Which method is used to retrieve the number of elements in a list? count size max length

size

In algorithm analysis, space complexity describes _____. the total time taken by the algorithm the total memory space consumed None of the above. the correct output for an algorithm

the total memory space consumed Space complexity calculates total memory space consumed an an algorithm.

Which is the correct syntax for a while loop? while 1=0 { minute++; } while (total_panic < 1) { minute++; } while int panic { minute--; } while if i=7 then { minute++ }

while (total_panic < 1) { minute++; }


Kaugnay na mga set ng pag-aaral