Data Structures FINAL
Data Structures FINAL
Where a
A range query is: (1) record is
Where a record is returned if its unique identifier matches the search value returned if
it’s relevent
A way of efficiently locating the records in a database
key value
Another name for any database query for a key value falls
Where a record is returned if its relevant key value falls between a pair of between a
values pair of
values
To degin an
Which of these is more a concern for Software Engineering than for a data algorithm
structures course? (1) that is easy
to
To design an algorithm that is easy to understand, code, and debug
understand,
To design an algorithm that makes efficient use of the computer's resources code, and
debug
When a
A range query is: (1) record is
Another name for any database query for a key value returned if
its relevant
Where a record is returned if its unique identifier matches the search value
key value
A way of efficiently locating the records in a database falls
Where a record is returned if its relevant key value falls between a pair of between a
values pair of
values (1)
Where a
An exact-match query is: (1)
record is
Where a record is returned if its relevant key value falls within a specified range returned if
A way of efficiently locating the records in a database its unique
Another name for any database query that returns a key value identified
matches the
Where a record is returned if its unique identifier matches the search value
search value
It is correct to say that interfaces are abstract data types. True or false. (1) True
p.data =
r.data
public static Link changeNext(Link p, Link r){ return p;
// answer
}
r.next = p;
public static Link changeNext(Link p, Link r){ return p;
// answer
}
p = new
Link(“A”,
initial setup: p is null (2) null);
expected final: Image p.next =
newLink(“B”,
null);
p.next.next
public Link changeNext(Link p){ =
//answer newLink(“C”,
} null);
p.next
.next.next=
newLink(“D”,
null);
return p;
The
enqueue
operation
adds an
item to the
Explain how the enqueue operation works by selecting a position for where the new
end of a
item goes, and update "rear" and "front" if appropriate. (2)
queue. It
updates the
rear pointer
to the new
item.
The
dequeue
operation
removes an
item from
the front of
Show how the dequeue operation works by selecting an element to remove, and update
a queue. It
"rear" and "front" if appropriate. (2)
updates the
front
pointer to
the next
item in the
queue.
Stack A has entries a, b, c (in that order with a on top), while Stack B is initially
empty. When an entry is popped out of stack A, it can be printed immediately or
pushed to stack B. When an entry is popped out of stack B, it can only be printed.
Which of the following permutations of a, b, c is not possible to print? (2)
abc cab
bca
cab
bac
A problem is
mapping
What is true about the relationship between algorithms and problems? from inputs
A problem is a mapping from inputs to outputs. Since this mapping is fixed, to outputs,
there is only one right way to compute the mapping and there
might be
An algorithm is another term for a problem
many
A problem is mapping from inputs to outputs, and there might be many algorithms
algorithms that can accomplish this mapping that can
A problem is a recipe, and an algorithm is a solution to a problem accomplish
this
mapping
You are given this set of growth functions: (3) n!,2n,2n2,5nlogn,20n,10n
For the growth function 2n, type a value (a positive integer) for which this function is the
most efficient of the six. If there is no integer value for which it is most efficent, type 4
"none".
Note: Assume all logs are base 2.
You are given this set of growth functions: n!, 2^n, 2n^2, 5nlogn, 20n, 10n. (3)
For the growth function 2^n, type a value (a positive integer) for which this function is 4
the most efficient of the six. If there is no integer value for which it is most efficient, type
"none
You are given this set of growth functions: n!, 2^n, 2n^2, 5nlogn, 20n, 10n. (3)
For the growth function 5nlogn, type a value (a positive integer) for which this function 1
is the most efficient of the six. If there is no integer value for which it is most efficient,
type "none
You are given this set of growth functions: n!, 2^n, 2n^2, 5nlogn, 20n, 10n. (3)
For the growth function n!, type a value (a positive integer) for which this function is the 2
most efficient of the six. If there is no integer value for which it is most efficient, type
"none
You are given this set of growth functions: n!, 2^n, 2n^2, 5nlogn, 20n, 10n. (3)
For the growth function 2n^2, type a value (a positive integer) for which this function is none
the most efficient of the six. If there is no integer value for which it is most efficient, type
"none
Write the missing base case for function largest. Function largest should find the if (index ==
largest number in array numbers. When largest is first called, index will equal 0){
numbers.length-1. (4) return
Examples: numbers[0];
}
On a real computer, what will happen if you make a recursive call that never makes
the problem size smaller? (4)
The run-
The program keeps running until you stop it time stack
The results are nondeterministic overflows,
The operating system detects the infinite recursion because of the repeated halting the
state program
The run-time stack overflows, halting the program
An
Which of these is the best definition for a stable sorting algorithm? (4)
algorithm
An algorithm that does not change the relative ordering of records with that does
identical keys not change
An algorithm that is as fast as the best one known the relactive
An algorithm that always gives the same order for duplicate keys from run to ordering of
run records with
An algorithm that always gives the right answer identical
keys
Which of these is a traditional measure for the cost of a sorting algorithm? (4)
The number of records
The number
The memory size
of swaps
The number of swaps
The amount by which the values are out of order
Which of these is a traditional measure for the cost of a sorting algorithm? (4) The number
of
The amount by which the values are out of order comparisons
The number of comparisons
The memory size
The number of records
Assume that for some list implementation, a pointer requires 8 bytes and a data object
requires 15 bytes. Type a fraction (like "1/2") to show how full the array should be for
8+15 = 23,
the break even point, that is, the point beyond which the array-based list
15/23
implementation needs less space than the linked list implementation. Give your fraction
in lowest terms. (5)
Assume that for some list implementation, a pointer requires 4 bytes and a data object
requires 5 bytes. Type a fraction (like "1/2") to show how full the array should be for the
break even point, that is, the point beyond which the array-based list implementation 4+5 = 9, 5/9
needs less space than the linked list implementation. Give your fraction in lowest terms.
(5)
Which implentation is best to answer the question “what is the item at position i?” (5)
singly linkedlist array-based
array-based list list
doubly linked lsit
Given a doubly linked list implementation, inserting a new element to the current
position takes how long? (5)
Θ(nlogn) time
0(1) time
Θ(logn) time
Θ(n) time
Θ(1) time
Which data structure allows insertion only at the top, and deletion only at the top? Stack
(5)
Array-based list
Linked list
Stack
Tree
Queue
4
Trees have height, not depth
What is the minimum number of internal nodes in a binary tree with 8 nodes? (6) The number
of leaves:
n/2 = 8/2 =
4.
Remaining
nodes: n-
leaves = 8
-4 = 4.
Answer is 4.
Why does function preorder2() presented in the Traversal module make only half
as many recursive calls as function preorder()? (6)
Because half
Because there are half as many nodes of the
Because there are half as many leaf nodes pointers are
Because only internal nodes get called null.
Because half of the pointers are null
Height of
the tree: 3.
Nodes in
first h-1
levels: 2^0
+ 2^1 +
What is the minimum number of nodes in a complete binary tree with height 3? (6) 2^2 =
1+2+4 = 7.
Last level:
Minimum 1
node. 7+1 =
8. Answer is
8.
Range queries
Finding the maximum key value
All of these
None of these
Which is the best definition for collision in a hash table? (7) Two records
Two records are identical except for their keys with
different
Two records have the same key and the same hash value
keys have
Two records with different keys have the same hash value the same
Two records have the same key hash value
For the string hash functions, the size of the hash table limits the length of the
string that can be hashed. (7)
False
True
False
An open hashing table has an array size of 55. What is the maximum number of
records that can be stored in the table? (7)
54 There is no
There is no maximum maximum
55
None of the above
Given the following hash table, use hash function h(k) = k mod 10 and handle collisions
using Linear Probing by Steps with probe function P(K, i) = 2i. (7)
In which slot should the record with key value 186 be inserted? Slot 8
Slot 0: —, Slot 1: — , Slot 2: 582, Slot 3: 443, Slot 4: — , Slot 5: 145, Slot 6: 426, Slot 7:
837, Slot 8: 186, Slot 9: —
The special value used to signal a position in a hash table from which a record has Tombstone
been deleted is called a: (7)
Gravestone
Sentinal
Tombstone
Flag
A company wants to use a system where they randomly assign each customer a 9-
digit ID (so there are 1 billion possible ID numbers). Of course, there is a chance
that two customers will be assigned the same ID. But the company figures that risk
is OK if the odds are only one in a million. They expect to assign IDs to 1000 True
customers. But the chance of collision is much higher than one in a million. (7)
True
False