0% found this document useful (0 votes)
4 views

Data Structures FINAL

Uploaded by

bibianeparadis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Data Structures FINAL

Uploaded by

bibianeparadis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

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

An array-based list is an implementation of a(n) ______ (1) List


Graph
List
Linked list
Array

"Data type" and "data structure" are synonyms. (1)


True False
False

An integer variable is an example of a(n) ________(1)


Composite type
Simple data
List
type
Simple data type
Array

Which of the following is NOT an example of a data type? (1)


Array
List None of the
Integer above
Boolean
None of the above

Object-oriented programming is a programming paradigm based around _______


(1)
Polymorphism
Objects
Inheritance
Objects
Overriding

In polymorphism, types are determined at ______ (1)


Compile time
Run time Both
Both
Neither

Object-oriented programming is a programming paradigm based around _______


(1)
Overriding
Objects
Polymorphism
Inheritance
Objects
Which class type inherits from one or more base classes? (1)
Base class
Parent class Subclass
Subclass
Suber class

An individual instance in OOP is called a(n) _______(1)


Constructor
Function Object
Class
Object

Which of the following statements is correct? (1)


A class is an instance of a data type. An object is
A class is an instance of an object. an instance
An object is an instance of a data type. of a class
An object is an instance of a class.

Initial setup: (2)


p → 1/o → 2/o → 3/-, r → 3
Expected: Image

p.data =
r.data
public static Link changeNext(Link p, Link r){ return p;
// answer
}

Initial setup: (2)


p → 1/o → 2/o → 3/-, r → 3
Expected: Image

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.

It is an error to push data onto a(n) _______ stack. (2) Full


Array-based
Initialized
Linked
Empty
Full

In the linked implementation of a queue, a new item would be added: (2)


After all other entries that are greater than the new entry
After all other entries that are smaller than the new entry
At the rear
At the current position
At the head
At the rear

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

The Stack is best characterized as: (2)


Just-in-Time
Last-In,
First-In, First-Out
First-Out
Last-In, First-Out
First come, First Served

It is an error to dequeue data from a(n) _______ queue. (2)


Array-based
Empty Empty
Linked
Full

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.

What is the smallest integer k such that n log n is in O(n^k)? (3) 2

The sequential search algorithm is in O(n²). (3)


True
True or false

For sequential search, the best case occurs when: (3)


the search
the array is small target is
the search target is near the front of the array near the
the search key is small front of the
the algorithm is implemented efficiently array

What is the smallest integer k such that sqrt(n) is in O(n^k)? (3) 1

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];
}

largest({2, 4, 8}, 2) -> 8

public int largest(int[] numbers, int index){


//answer here
return Math.max(numbers[index], largest(numbers, index-1));
}

A recursive function causes an infinite recursion (run-time error) if: (4)


the base
It has no recursive call. case is never
All of the stated reasons. executed or
The base case is never executed or does not exist. does not
None of the stated reasons. exist.

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 of the following is not a linear data structure? (5)


Linked list
Tree
These are all linear data structures Tree
Stack
Queue
Array-based list

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

Which data structure would be used to implement recursion?(5)


Linked list
Stack
Stack
Queue
Tree
Array-based list

What is the depth of this tree? (6)


0
1
Trees have
2 height, not
3 depth

4
Trees have height, not depth

How many leaf nodes does this tree have? (6) 4

Consider a node RR of a complete binary tree whose value is stored in position ii of an


array representation for the tree. If RR has a parent, where will the parent's position be
in the array? (6)
2∗i+2 None of the
above
i+2
i+1
None of the above

The n nodes in a binary tree can be visited in: (6)


Θ(1) time
Θ(logn) time
O(n) time
Θ(n) time
Θ(nlogn) time
Θ(n​) time
2​

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.

Select the one true statement. (6)


Every binary tree is either complete or full
Every complete binary tree is also a full binary tree None of the
Every full binary tree is also a complete binary tree above
No binary tree is both complete and full
None of the above

Which feature of heaps allows them to be efficienty implemented using an array?


(6)
Heaps are binary search trees Heaps are
complete
Heaps are complete binary trees
binary trees
Heaps are full binary trees
Heaps are binary trees

Hashing is good for which queries? (7) Exact match


Exact match queries queries

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

The simple mod hash function makes use of: (7)


The high order digits or bits in the key The low
order digiits
The middle digits or bits of the key
or bits in the
The low order digits or bits in the key key
None of the above

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

Bucket hashing works well for disk-based hash systems. (7)


True True
False

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

What is a disadvantage of linear probing? (7)


You tend to get secondary clustering You tend to
You tend to get primary clustering get primary
The algorithm is difficult to program clustering
None of the above

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

You might also like