Data Structures

Ace your homework & exams now with Quizwiz!

Which of the trees from FIGURE 1 is not an AVL tree?

Figure 1.D

Which of the following would be the Big-O function for the funtion (5x2 + 4x4 + 3)?

O( x4 )

The O( ) complexity for insert into a binary search tree is (select the best answer):

O(N) - linear time

The O( ) complexity for insert into an AVL (balanced) binary search tree is (select the best answer):

O(log N) - logrithmic time

Consider the following code segment where "n" was passed in as a parameter. for (int i = n; i >= 1; i = i / 2) { System.out.println(i); } Of the following, which best characterizes the running time of this code segment?

O(log n)

In a height balanced binary search tree (AVL), when do you make an adjustment in the tree?

When the height difference between two sides of a node is greater than or equal to two

The function ____ implies that the growth rate is exponential.

g(n) = 2n

!!! Items in a stack are added to the _______, and removed from the __________. (answers are in the order of the blanks).

head for both

You are writing a pointer-based, doubly linked, non-circular list using a Node class with fields called "prev", "data" and "next". Which code fragment would remove the first node in the list?

head.next.prev = null; head = head.next;

!!!! How is a circular, doubly-linked list different from a non-circular, doubly-linked list?

"next" points to the "prev" and "prev" points to "next" for the head and tail nodes

!!! If a SORTED, array based list size is 1024 a binary search would approximately take how many comparisons to do a search?

10 (log N comparisons)

Which statement is true for a B-tree?

All leaves are at the exact same depth.

Suppose that X is a B-tree leaf containing 41 entries (keys) and having at least one sibling. Which statement is true?

Any sibling of X is also a leaf..

Given an unsorted list of items, the selection sort algorithm complexity for the number of assignments (memory moves) is:

O(n)

Every subtree of a "binary search tree" is also a "binary search tree".

True

Every subtree of an AVL tree is another AVL tree

True

Suppose variable named "cursor" refers to a node in a singly-linked, non-circular list (using a Node class with instance variables called "data" and "next"). What statement changes cursor so that it refers to the next node?

cursor = cursor.next;

The function _____ implies that the growth rate is constant and thus does not depend on n, the size of the problem.

g(n) = 1

The balance value of an AVL node is calculated by finding the MAX height of the two children and adding 1.

'False'

Suppose a variable named "cursor" is a pointer to a node in a singly linked, non-circular list (using a Node class with fields called "data" and "next"). What boolean expression will always be true when cursor refers to the tail node of the list?

(cursor.next == null)

!!!! If a Queue is set up as a circular array of CAPACITY (a constant) size, and rear is an index into that array, what is the formula for the next index after rear (the slot where the next item will be added)?

(rear + 1) % CAPACITY

In an AVL tree, when the height of both children of a node are the same, this indicates that the balance factor of this node is:

0

When comparing equations, some equations will give you relatively larger values for smaller input values. However, as values of n become larger, which of the following will give you the smallest value?

20000*log2n

Suppose that a non-leaf node in a B-tree has 41 entries (keys). How many children will this node have?

42

If a SORTED list size is 1024, on average, a sequential search would take how many comparisons for elements that are found in the list?

512 (N/2 comparisons)

If both the left and right subtrees of a binary tree T meet the definition of an AVL tree, then T must be also meet the definition of an AVL tree.

False

If the depth of x is greater than the depth of y in a tree, then x is a descendant of y.

False

In a B-tree of order 8, the root node must have at least 4 subtrees.

False

AVL trees are efficient because they provide Θ(n) access/search time and insert time.

False.

Binary search trees are efficient because they guarantee Θ(logn) access time.

False.

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

Linear

What kind of list has the best performance when answering questions such as "What is the item at position n?"

Lists implemented with an array.

What term is used to describe a O(log N) algorithm?

Logarithmic

In a circular array implementation of a Queue class, which operation would require linear time for the worst-case behavior?

None of these operations require linear time.

Consider the following code segment where "n" was passed in as a parameter. for (int i = 1; i <= n; i++) { for (int j = n; j >= 1; j = j / 2) { System.out.println(i + " " + j); } } Of the following, which best characterizes the running time of this code segment?

O(n log n)

Consider the following code segment where "n" was passed in as a parameter. for (int i = n; i >= 1; i--) { System.out.println(i); } Of the following, which best characterizes the running time of this code segment?

O(n)

Adding an item to an array that were the problem does not allow duplicate items in the array requires approximately how many comparisons of elements?

O(n) comparisons between elements

Consider the following code segment where "n" was passed in as a parameter. for (int i = 1; i <= n; i++) { for (int j = n; j >= 1; j = j - 1) { System.out.println(i + " " + j); } } Of the following, which best characterizes the running time of this code segment?

O(n2)

The selection sort algorithm comparison complexity does not depend on the initial arrangement of the data. The number of comparisons is always:

O(n2)

!!!! Which of the following formulas in big-O notation best represent the expression: n3+35n+6

O(n3)

What term is used to describe a O(n2) algorithm?

Quadratic

We are writing a program to simulate traffic flow at a 4-way stop. Which is the best data structure choice for simulating the cars waiting at each stop sign?

Queue

Which of the following describe a difference between a queue and a stack is:

Queues modify both ends of the structure; stacks modify only one.

What does Big-O time complexity measure?

Relative complexity of algorithms

Which of the following is NOT an example of empirical analysis?

Showing that C2 = A2 + B2 for all right triangles where A, B, and C are the lengths of the sides, and C is the length of the hypotenuse.

How is a non-circular, doubly-linked list different from a circular, doubly-linked list?

The "next" of tail node is null, and the "previous" of the head node is null

Suppose that a B-tree has MAXIMUM branching of 11 and that a node already contains the keys/values 1 through 10. If a new value, 11, is added to this node, the node will split into two nodes. What values will be in these two nodes?

The first node will have 1 through 5 and the second node will have 7 through 11..

!!! Given an array implementation of a Queue. Which of the following is true if we keep all the items at the front of a partially-filled array (so that data[0] is always the front/head).

The remove/dequeue method would require linear time.

The depth of a node in a tree is equal to the number of its ancestors.

True

All the leaves of a B-tree are at the same level.

True.

When analyzing a search algorithm, we count the number of _____ because this number gives us the most useful complexity information.

key comparisons

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

pop

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

push

A breadth first traversal of a tree or a graph is commonly implemented with a(n):

queue.

!!!!! For which of the following structures can a binary search be used?

sorted, array-based lists

!!!!! Items in a queue are added to the _______, and removed from the __________. (answers are in the order of the blanks).

tail, head

You are writing a pointer-based, doubly linked, non-circular list using a Node class with fields called "prev", "data" and "next". Which code fragment would remove the last node in the list?

tail.prev.next = null; tail = tail.prev;


Related study sets

stress and health exam questions

View Set

International Business Chapter 6

View Set

Chapter 23 GastroIntestinal disorders

View Set

FRL 3000: Ch 10 Smartbook: Making Capital Investment Decisions

View Set

Resource Management Chapter Quizzes

View Set

Bio 121 Test 2 Chapter 3 & 4 MASTERING BIOLOGY

View Set

hinkle chapter 26 peripheral vascular and arterial disorders

View Set

Compensation Ch. 2- Strategy the Totality of Decisions

View Set

Ch. 23 Modern Industry and Mass Politics, 1870–1914

View Set