data struc review
a file system is best stored in what type of data structure?
tree
if you have a doubly-linked list and you remove the last item in the list, how many pointers are updated (not including the temp pointer to the element)?
2
the number of nodes in a perfect binary tree of height 5 is..
2(h+1)-1. 2^(5+1)-1. 64-1=63(ans)
if the height of a binary search tree is h, what is the largest number of nodes in that tree?
2^(h+1) -1
when we talk about Big O notation and worst case complexity, we often refer to n. what is in?
the size (amount) of the data
in a tree, if we have N nodes then
there are N-1 edges
what does it mean for a graph to be complete?
there is an edge from every node to every other node
when an exception occurs, it must be
thrown to the calling method or handled in a ty-catch block in the current method
what kind of data structure would be the best for implementing a file system like the one on your hard drive?
tree
which of the following is a non-linear data structure?
tree
what data structure is most useful for keeping track of relationships between gang members?
tree?
a had function may generate the same index for different inputs
true
a node can be both a root and a leaf
true
a singly try block can have multiple catch blocks for different exceptions
true
in a heap the ight item can be less than the left item key
true
is it possible to use both comparator and comparable for the same class?
true
most hash functions involve the use of what operator?
%
a queue processes items in what order?
FIFO first in first out
how many employee objects are created by the following? Employee[] myEmployees = new Employee[52];
0, because it points to an array of 52 nulls
true about comparators?
1. a comparator is a small class that is used to specify a sorting order for some other class. 2. a comparator can use generics 3. a comparator requires overriding the compare method
what differentiates an array from an ArrayList?
1. arrays can hold primitives, ArrayLists cannot 2. arrays are a set size, whereas ArrayLists expand
which of the following are valid assertion statements?
1. assertTrue(instance.isEmpty()); 2. assertEquals(result, expectedResult); for asserts there are two types; 1. boolean: assertTrue and assertFalse which each take only one parameter. 2. comparison: takes two paramet3ers that are compared to each other
for a graph to be connected, what must be true?
1. for every node, there must be a path to every other node. 2 there cannot be any nodes that are 'off on their own'
which of the following are non-linear data structures?
1. graph and 2. tree
which of the following operations is O(1) for ArrayLists?
1. returning the size (i.e. the number of elements) of the list. 2. returning true if the list is empty. 3. creating a new, empty list. 4. adding an element to the end of the list
in a perfect binary tree with 128 leaf nodes, how many internal nodes are there?
128-1=127(ans)
in a perfect binary search tree, every internal node has exactly two children. if there are 64 leaf lodes in the tree, how many internal nodes are there in the tree? count the root as an internal node
63
what is the load factor for a hash table?
the percentage full at which you increase the size of the hash table
the items in a list are processed in what order?
LIFO ( last in first out), FIFO (first in firs out) or in whatever way the programmer using the list decides to do
a hash function
maps key values to array indices
traversing a BST by which method would cause the values to appear in an ascending sorted sequence?
In-Order
in a tree with N nodes, how many edges will there be?
N-1
a well designed hash table and function will give what complexity for retrieval of items?
O(1)
in a list implemented with linked nodes, what is the big O complexity of the addLast(item) method?
O(1)
what is the efficiency of searching a hash table, if you are searching by the hashed value?
O(1)
if a binary search tree is balanced, what is the complexity of a search?
O(log n)
a method that returns the position (index) of a specific element in an ArrayList would have the complexity of...
O(n)
assuming you have a list that is implemented with linked nodes, what is the worst case complexity of the remove(index) method?
O(n)
if a binary search tree is unbalanced, what is the complexity of an add?
O(n)
the add(Object) operation in a sorted list with a linked implementation has what level of complexity? assume a linear search algorithm is used.
O(n)
the addToFront() operation on a list with an array implementation has what level of complexity?
O(n)
the set(index, Object) operation in a linked list implementation of a list has what level of complexity?
O(n)
what is the worst case complexity of linear search?
O(n)
what would be the complexity of the size() method for a linked list if there was no count variable?
O(n)
what is the worst case complexity of insertion sort?
O(n^2)
if an algorithm has two parts that are linear (O(n)), and one part that is constant (O(1)) and one part that is 1uadratic (O(n^2)), what is the overall order of the algorithm?
O(n^2) , all lower order terms drop n^2+n+1, which would just break down to be just O(n^2)
determine the simplified big O notation of O(3n+n^2+8)
O(n^2), all constants should be dropped
this sorting algorithm makes use of a pivot
QuickSort
which sorting algorithm uses a pivot to divide the items to be sorted into two groups?
QuickSort
an adjacency matrix is normally implemented as:
a 2D array
after executing the following line of code, what best describes myClass? Student[] myClass = new Student[25];
a pointer to an array of 25 nulls
for the following binary tree, what nodes would be visited in the search for node 5?
all the nodes going directly to node 5
what type of graph would you need to represent cities an the distance between them?
an undirected, weighted graph
where should we use 'fail' statements when you are writing JUnit test cases?
anywhere you think the execution path should not go
what should be considered when evaluation the efficiency of an algorithm?
assignments, comparisons
when you add to a heap, you first put the new element:
at the bottom left-most open slot
the data structure best to find and remove an item efficiently is a ...
balanced binary search tree
the elements in a particular collection, myCollection...
can be the type of object defined for the collection when it is instantiated, or an object created from a subclass of that object (if you create a collection of something, that only that think and sub-class objects can be put into it)
the run-time complexity of O(42) is
constant
assuming this would compile correctly, what would it do? Bear smokey = new Bear();
create a bear reference variable and a new bear object
what does the following code do? Turtle[] turtles;
creates a reference variable that can point to an array of turtles
a heap can become unbalanced if the same number is added repeatedly
false
by implementing the Comparable interface, a java class can allow sorting by different fields
false
most graphs are complete
false
what queue methods might throw an exception?
first, dequeue
which data structure is most useful or looking up people by their social security number?
hash table
of what use is a hash table's load factor?
indicates the percentage full at which you increase the size of the hash table
if a hash function is given a StudenRecord object as an input, what will the hash function produce?
int
what is the difference, if any, between the length field of an array and the size() method of an ArrayList?
length returns the capacity of the array but size() returns the number of elements stored in the ArrayList
linked nodes have what advantages over arrays when implementing collections?
no capacity issues
in recursive methods, if a temporary variable is used to store intermediate results, how many copies of that variable will exist from the first call to the last one when the recursion finishes?
one for each recursive call
what can be stored in myReaders? ArrayList<FilterReader> myReaders = new ArrayList<>();
only FilterReader objects
you need to process phrases in the order they are spoken in a real-time language translation app, each phrase object should be put into what?
queue
which sorting algorithm is continually looking for the smallest (or largest) element in the unsorted set?
selection sort
in a recursive algorithm, the base case represents
solving the problem directly
a perfect hash function requires:
that every key value maps to a unique index
what is required for a class to use the Comparable interface?
the class must implement a compareTo method
who might catch excpetions?
the data structure programmer, the end user programmer or the programming language programmer
what is a hash tables load factor?
the number of keys stored in the hash table divided by the capacity of the table
a collision occurs when
two key values map to the same index
what equation represents the number of nodes (i) in a complete binary tree that has height h?
undetermined without seeing the tree
airports and distances between them would best be represented by what type of graph, assuming you wanted to keep track of customers' flown miles?
undirected, weighted
a graph consists of
vertices and esges
big O notation is used to describe the
worst-case performance