Data Structures Final Exam

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Suppose that p is a reference to a Node in a LinkedList, and it is not the tail node. What are the steps to removing the node after p?

...Node pTemp = p.next; p.next = pTemp.next; delete pTemp;

Which of the following is the algorithm for insertion in a heap?

Insert the new item in the next position at the bottom of the heap. While new item is not at the root and new item is smaller that is parent. Swap the new item with it's parent, moving the item up the heap

Adjacency

Martix uses a two- dimensional array to represent the graph.

___________________ technique is often used to prove the correctness of a recursive method?

Mathematical Induction

For fill = 0 to n -2 do Set posMin to the subscript of the smallest item starting ab subscript fill.

Selection Sort

Void fun(Int arr[], int start_index, int end_index { If(start_index >= end_index) Return; Int min_index; Int temp; Min_index = minIndex(arr, start_index, end_index); Temp = arr(start_index); Arr(start_index) }

Selection Sort

Nodes that have the same parent are

Siblings

A() ____ is a data Structure in which objects are inserted into and removed from the same end

Stack

When is insertion sort a good choice for sorting an array?

The array has only a few items out of place.

Push

The operation for adding entry to stack. Push = insert Push = O(N): Big - O Time for stack of size using Array Push = O(1): Big - O Time for stack of size using linked list

Pop

The operation for removing an entry from a stack Pop = Erase/Remove Pop = O(1)

Any Graph that is connected and contains no cycle can be viewed as tree by picking one its vertices as the root

True

ArrayIndexOutBoundsException is thrown by the JVM when an index value used to access an element in an array is less than zero or greater than or equal to the Array's length

True

Bubble sort is considered a quadratic Sort

True

Character ch = "x" in JAVA 5.0 is equivalent to Character ch = new Character('x') in earlier Java Versions

True

Constant multiplers do not affect Big - O. For example, 10000 n^2 and 0.00005 n^2 are both O(n^2) Lower order terms do not affect Big O. For example, 2^n + n ^1000 is still O(2^n).

True

If node n is not the root of Tree t, its level 1+ the level of its parent

True

The Statement Stack <String> myStack = new Stack<String>(); defines a stack that holds string object

True

The actual object type stored in an object of type CollectionClassName<E> is specified when the object is created.

True

You can use a Deque object to implement a stack

True

IN java 6.0 the () interface represents a double ended queue

deque

You can use a () to implement a stack

deque

The ____________ is the number of nodes in the longest path from the root node to a leaf node

head

The _____ is used to implement a priority queue

heap

A set of Nodes T is binary search tree

if T is not empty, its root node has two subtrees, TL and TR, such that TL and TR are binary search trees and the value in the root node of T is greater than all values in TL and is less than all values in TR

Non leaf nodes are also known as internal nodes, and leaf nodes are also known as _____ nodes

internal nodes

Binary search can only be performed on an array that has been

sorted

When a queue is implemented using a circular array, removal from the rear is

(O) 1

If the data is a circular array of CAPACITY elements, and rear is an index into that array, what is the formula for the index after rear?

(rear + 1) % capacity

In Directed Graph

A graph that contains undirected edges

Weighted

A graph with weighted edges

Path

A sequence of vertices in which each successive vertex is adjacent to its predeccessor

O(2ⁿ)

Algorithm that will double with each additional element of input

O(log N)

An Algorithm on a growth curve where the size of input set has little effect on growth.

Time Formula: 1. 10n 2. 2n^2 3. 3 times log (base 2) of n 4. 2n^2 + 10n

Big - O 1. O(n) 2. (N^2) 3. log(n) 4. O(n^2)

In a LinkedList is use insertion at the rear of queue is a

Big O operation.

If a linked list is used, insertion at the rear of a queue is a(n) _____________ operation

Big(O)

In java 6.0, the Deque interface represents a _______ queue

Double

In the linked list version of the stack class, which operations requires linear time for their worse case behavior?

E. None of these operations require linear time.

False statement about binary tree

Every non root node has exactly one parent

A double linked List requires the same amount of storage as that of single Linked List

False

There is only one stack interface in Java

False

Partitions the array to two parts

Insertion Sort

Method descriptions in an interface are called

Method

True statement about binary tree

No binary tree is both complete and full

In the circular array version of the queue class, which operations require linear time for their worst case behavior?

No operation requires linear time

In the circular linked list. What operation requires linear time?

No operation requires linear time

If the queue is empty, element() method throws a(n)____________

NoSuchElement Exception

If the queue is empty, element() method throws a

NoSuchElementException

When a queue is implemented using a circular array, removal from the rear is

O(1)

When queue is implemented using a circular array insertion at the front is

O(1)

Infix

Operates appear between it's operands

A () ___ is a string that reads the same in either direction, left or right or right to left.

Palindrome

The predecessor of a node is called its

Parent

A () _______ is a data structure in which only the highest - priority is accessible

Priority que

The node at the top of a tree is called its

Root

If the tree is empty Return null (target is not found) Else if the target matches the root node's data Return the data stored at the root node. Else if the target is less than the root node's data Return the result of searching the left subtree of the root Else Return the result of searching the right subtree of the root

Searching a binary tree

A() is a data structure with the property that only the top element is accessible

Stack

A() is a data structure with the property that only the top element is accessible.

Stack

Complete the following algorithm which recursively inserts an item into a binary search tree: If the root is null Replace empty tree with a new tree with the item at the root and return true Else if the item is equal to root.data Else if the item is less than root.data Recursively insert the item in the left subtree Else Recursively insert the item in the right subtree

The item is already in the tree; return false

In for(int i = 0; i <=x.length; i++)

This will cause ArrayIndexOutBoundsExceptions

Which of the following is the postorder traversal of a binary tree?

Traverse TL, TR, and visit root node

Which of the following can be done with an array object?

Traverse the list structure without having to manage a subscript.

If node A is the parent of node B, which is the parent of node C, node A is node C , ancestor, and node C is Node A's descendants

True

Underflow in a stack?

When the stack is empty and there is nothing to be removed.

for (i = 1; i < N; ++i)

Write the simplest big-O expressions to describe the number of operations required for the following algorithm:

Breadth - first

a search, we visit the start node first, then all nodes that are adjacent to the next, then all nodes that can be reached by a path from the start node containing two edges, three edges, and so on.

Searching a binary search tree is an ____ process

b) O(log n)

An array of size 16 requires at most

base two probes in the worst case binary search

If an array is used to implement a queue, insertion at the rear of the array can be done in

constant time

Which of the following stack operations could result in stack overflow?

push operation may result in stack overflow

Poll

removes the entry of the deque and return its as null if the deque is empty.

Edge

represent paths or connections between vertices

Peek

returns the value of the top of the collection without removing the element from the collection

If you want to remove two consecutive elements in a linked list a separate call must occur each call to remove

to next

Connect

An undirected graph that there is a path from every vertex to every other vertex

When a queue is implemented using a circular array, insertion at the front is

(O) 1

Directed H

are represented as lines with an arrow on one end

What is written to the screen for the input "carpets"? Consider the following pseudo code: declare a stack of characters while (there are more characters in the word to read ) { read a character push the character on the stack } while ( the stack is not empty) { pop a character off the stack write the character to the screen }

(b) steprac

Public static void test_b(int n) If(n > 0) Test_b(n-2): System.out.println(n + ""); What is printed by the call test _b(4).

0, 2, 4

A priority queue is implemented as a Max- Heap. Initially, it has 5 elements. The level - order traversal of the heap is given below: 10, 8, 5, 3, 2. Two new elements "1" and "7" are inserted in the heap in that order. The level order traversal of the heap after the insertion of the elements is:

10, 8, 7, 3,2,1,5

How many queues are needed to implement a stack. Consider the situation where no other data structure like arrays. Linked list is available to you.

2

How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays. Linked list is available to you

2 stacks

Public static void test_a(int n) System.out.println(n + ""); If(n > 0) Test_a(n-2): What is printed by the call test _a(4). Test_a(2) = 2 Test_a(0) = 0

4, 2, 0

Suppose that a selection sort of 100 items has completed 42 iterations of the main loop: How many items are now guaranteed to be in their final spot(never to be moved again)

42

Which of the following is true about linked list implementation of queue?

A) In push operation, if new nodes are inserted at the beginning of linked list, then in pop operator nodes must be removed from end B) In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning.

Which of the following is a balanced Expressions?

A. (a +b {c [d-e]}) + d(/e)

How are loops represented in an adjacency list representation of a graph?

A. A vertex will be on its own adjacency list.

Which graph representation allows the most efficient determinations of the existence of a particular edge in a graph?

A. An adjacency Martix

What graph traversal algorithm uses a queue to keep track of vertices which need to be processed?

A. Breath First search

Suppose a circular queue of capacity(n-1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are:

A. Full: (REAR + 1) mod n == FRONT, empty: REAR == FRONT

In the linked list implementation of the stack class, where does the push method place the new entry on the linked list?

A. at the head

Java maintains a run time stack, on which it saves new information in the form of a(n)

Activation Frame

Two Java classes that implement the Deque are

Array Deque and LinkedList

In the linked list implementation of the stack class, where does the push method place the new entry on the linked list

At the Head

Where does the offer() method place the new entry on the linked list?

At the tail

Which of the following is the preorder traversal of binary tree?

B) visit root node TL, TR

In the Linkedlist implementation of the queue class, where does the offer() method place the new entry on the Linked List?

B. At the tail

Consider the implementation of the Stack using an array, What goes wrong if we try to store the top of the stack at location[0] and the bottom of the stack at the last used position of the array?

B. Both push and pop would require linear time.

Which of the following statements is true?

B. Graph Vertices may be linked in any manner.

Suppose we have a circular array implementation of the queue class, with ten items in the queue stored at data[2] through data[11]. The current capacity is 24. Where does the insert method place the new entry in the array?

B. data[2]

How many linked lists are used to represent a graph with n nodes and m edges, when using an adjacency list representation?

B. n

Removal from the front of a queue is a(n)__________ operation

Big(O)

What goes wrong if we try to store the top of the stack at the location?

Both Push and Pop would require linear time

Which of these reference variables will change during an insertion into a empty queue?

Both rear and Front Changes

The links from a tree node to its successors are called

Branches

Take an arbitrary start vertex, mark it identified and place it in a queue. While the queue is not empty. Take a vertex, u out of the queue and visit u For all vertices, v, adjacent to this vertex u If v has not been identified or visited Mark, it identified Insert vertex v into the queue We are now finished visiting u

Breath First Search

Do For each pair of adjacent array elements If the values in a pair are out of order, then Exchange the values until the array is sorted

Bubble sort

________ sort compares adjacent array elements (~if the array elements are out of order, the switch them)

Bubble sort

What is the worst case time for heap sort to sort an array of n elements?

C) O(n log n)

Suppose we are sorting an array of ten integers using a quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: [1234506789]

C) The algorithm must be insertion sort, but could not be selection sort.

What is the maximum number of parentheses that will appear on the stack at any one time when the algorithm analyzes ( ( ) ( ( ) ) ( ( ) ) ) ?

C. 3.

A priority queue can efficiently implemented using which of the following data structures? That the number of insert and peek

C. Heap data structure

The operation for removing an entry from a stack is traditionally called

C. Pop

Consider the implementation of the Queue using a circular array. What goes wrong if we try to keep all the items at the front of a partially-filled array(so that data[0] is always the front)

C. The poll() method would linear time

In a(n) ________________ array, the elements wrap around so that the first element actually follows the last

Circular Array

What is the max depth of recursive calls a method may make?

D) No fixed Maximum

If G is an directed graph with 20 vertices, how many boolean values will be needed to represent G using adjacency martix?

D. 400

Which of the following applications may use a stack?

D. All of above

Suppose we have an array implementation of the stack class, with ten items in the stack stored at Data[o] through Data[9]. The CAPACITY is 42. Where does the push method place the new entry in the array?

D. Data[10]

The operation for adding an entry to a stack is traditionally called

D. Push

If the characters 'D', 'C', 'B', 'A' are placed in a queue( in that order and then removed one at a time, in what order will they be in.

DCBA

L1: Mark the current vertex, u, visited and enter it in the discovery order list L2: For each vertex, v, adjacent to the current vertex, u L3: if v has not been visited L4: Set parent of v to u L5: Recursively apply this algorithm starting at v L6: Mark u finished and enter u into the finish order list

Depth first search:

In the array version of the stack class, which operations require linear time for their worse case behavior?

E. none of these operations require linear time.

A double linked list requires the same amount of storage as that of a single linked list

False

Although reallocating an array is an O(n) operation, it is amortized over n items, so the cost per item is O(N)^2

False

Although relocating an array is O(n) operation, it is amortized over n items, so the cost per item is O(n)^2.

False

An abstract class can be instantaited

False

An abstract class cannot declare abstract methods

False

For all possible inputs, a linear algorithm to solve a problem must perform faster than a quadratic algorithm to solve the same problem.

False

The improvement of shell sort over insertion sort is much more significant for small arrays?

False

Using Huffman codes to encode text files should give you files with more bits than you would get using other codes

False

Because an Arraylist<E> is an indexed Collection, you can access its elements using subscript.

False Subscript = index of Array

The ArrayList<E> has the limitation that the add and remove methods operate in 0(n^2) time

False You have to add and remove method in Arraylist

The EmptyQueueException is associated with the action of attempting to remove an item from an empty queue

False - noSuchElement

Linear search is an O(n^2) algorithm)

False - suppose to be big O(N)

The NoSuchEmptyException is associate with the action of attempting to remove an item from an empty queue.

False. It should say NoSuchEmptyException

With respect to selection sort, the number of comparisons is O(n)

False: The correct answer is O(N)^2

Removal from a heap is always from the bottom

False; Removal is always at the top of heap)

The Arraylist<E> class is part of the package called

Java.util.Arraylist

The storage policy used by a stack is

LIFO

What term is used to describe an O(n) algorithm?

Linear

Two Java classes that implement the Deque are ______ and ___________

LinkedList and Array

Access the first item from both sequences. While not finished with either sequence Compare the current items from the two sequences, copy the smaller current it's the output sequence, and Access the next item from the input sequence whose item was copied

Merge Sort

What are the minimum and maximum numbers of elements in a heap of height h?

Min: 2(^h-1) Max: 2^h-1

If the queue is empty, element[] method throws a(n) _________ Exception

NoSuchElementException

What are the steps to inserting a new item at the head of a LinkedList?

Node nodeRef = head; // You need this Node to point to the current head.

Express the formula (n-2) * (n-4) using big O notation?

None of above

In the array version of the stack class, which operations require linear time for their worst case behavior?

None of these operations require linear time.

In the lInked List version of the stack class, which operations require linear time for their worst case behavior?

None of these operations require linear time.

If an array is used to implement a queue, insertion at the rear of the array can be done in ______________ time

O(1) or constant time

In terms of efficiency, all stack operations using an array structure are

O(1).

With respect to merge sort, additional space usage is

O(N)

Which of following formulas in big O notation best represent the expression n^2 + 35n + 6?

O(N^2)

Which of these is the correct big - O expression for 1 + 2 + 3 + ... n?

O(N^2)

Insertion into and removal from a heap is

O(log n)

while (n >=1) { n = n/2; // use integers division } What is the worst case time analysis for the above loop?

O(log n)

In Merge sort, the total effort to reconstruct the sorted array through merging is

O(n log n)

The best sorting algorithms provide ___ average case behavior and are considerably fast

O(n log n)

If a non- circular array is used to implement a queue, insertion at the front is a(n) ______________ operation instead of O(1)

O(n)

Which of the following formulas in big O notation best represent the expression n^2 + 35n + 6?

O(n^2)

Which of these reference variables will change during an insertion into a nonempty queue?

Only rear changes

If a non Circular array is used to implement a queue, insertion at the front a(n)

Operation instead of O(1)

Public E_____() { If(size() == 0) Return null; Else Return theQueue.getFirst(); }

Peek

O(N²)

Performance is directly proportional to square of size of input

O(N)

Performance will grow linearly and in direct proportion with the size of input

Which of the following stack operation could result in stack underflow?

Pop

The methods that make up the Stackint interface are

Push(); Pop(); Peek(); Empty():

Bubble sort is an example of a(n) __________ sorting algorithm.

Quadratic

One difference between a queue and a stack is:

Queue uses two ends of the structure Stack uses only one

___________ An array by making several passes through the array, selecting the SMALLEST item each time

Selection sorts

Set the initial value of gap to n/2. While gap > 0

Shell

is to sort many smaller subarrays using insertion before sorting the entire array (~ It has O(N^3/2 or better performance time)

Shell Sort

Whenever a recursive method is called a copy of the local variables is saved on tree runtime

Stack

The exception _________ implies that the memory area used to store information about method calls has been used up

Stack overflow error exception

Directed Graph

The edges of a graph if the existence of an edge from A to B does not necessarily guarantee that there is a path in both directions

Weighted Graph

The edges of a graph may have values associated with them known as

Suppose we are sorting an array of eight integers using a quick sort, and we have just finished the first partitioning with the array looking like this: [2 5 1 7 9 12 11 10]

The pivot could be either the 7 or the 9

What goes wrong if we try to keep all the items at the front of partially filled array(so that data[0] is always the front)

The poll method would require linear time

In a real computer, what will happen if you make a recursive call without making the problem smaller.

The run time stack overflows, halting the programs

A characteristic of a recursive algorithm is that there must be at least one case(the base case), for a small value n, that can be solved directly

True

A node is generally defined inside another class, making in a(n) inner Class(definitions pg. 91) class

True

An array can be used for storage of a stack instead of using Java's Arraylist class.

True

Each class that implements an interface must provide the complete definitions of all methods

True

For an undirected graph, symmetric entries are required

True

If it is easier to conceptualize an algorithm using recession, then you should code it is a recursive method

True

If the set of vertices is empty, the set of edges must be applying

True

In CSC, Queues are used in operating systems to keep track of task waiting for a scarce resource and to ensure that the task are carried out in the order that they were generated.

True

In Computer science, queues are used in operating systems to keep track of tasks waiting for a scarce resource and to ensure that the tasks are carried out in the order that they were generated.

True

In a priority que, the poll method first saves the item at the top of the heap

True

In the Java API, class java.util.Stack<E> implements a stack; there is no stack interface

True

Interface is a class

True

Parentheses are not stored in a binary tree, because the tree structure dictates the order of operator evaluations

True

The Node class for a double linked List, which stores String type of data has references to the data and to the next and previous nodes.

True

The number of comparisons for a bible sort is represented by the series: (n-1) + (n-2) + ... + 3 + 2 + 1

True

Whenever a method is called, Java pushes a new activation frame onto the run time stack and saves this information on the stack

True

You can implement a queue as a single -linked list

True

You can implement a queue as a singled Listed List

True

O(1)

Will execute in the same time regardless of the size of input

If(x == 0) { Return; Else print(*); Test(x-1); Print(!); }

Write A recursive method that has one parameter which is an int valued called followed by x exclamation points.

You could create a circular list from a single Linked list by executing the statement.

a. Tail.next = head;

private static int method (int Current, int Previous, int n) { if(n == 1) return current; else return method1(current + previous, current, n -1); }

calculates the nth Fibonacci

In a the elements wrap around so that the first element actually follows the last.

circular array

Graph

is a data structure that consists of sets of vertices nodes and a set of edges between the pairs of vertices

The ________ of a node is a measure of its distance from the root

level

The simplest way to search an array is a

linear search

In a(n) )_______ search

linear, we examine one array element at a time, starting with element or the last element, to see whether it matches the target

In a selection sort of n elements, how many times is the swap function called in the complete execution of the algorithm?

n -1

In the Java API documentations inner classes are called

nested classes

PostFix

operators appear after their operands and remove parentheses

Prefix

operators appear before their operands and remove parentheses

In Java, a variable of a superclass type can reference an objet of a subclass type

true


Set pelajaran terkait

Exam Cram NCLEX-PN PRACTICE QUESTIONS

View Set

ATI Medical-Surgical: Gastrointestinal

View Set

Atomic numbers and electron configurations assignment and quiz

View Set

Equal Rights: Struggling Towards Fairness

View Set

Emergency Preparedness ------- Final

View Set

Unit 4 (chapter 15) History of Graphic Design

View Set