Features of Data Structures Flashcards

1
Q

Best data structure for minimizing number of copies between disk and memory

A

B-Tree (copies a large chunk at once, minimizes number of reads)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Big-O to search a sorted array

A

O(log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Worst-case performance of a binary search tree

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Worst-case performance of a 2-3 tree

A

O(log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define adaptive sorting algorithm

A

algorithm that varies in efficiency depending on input.

example: plain bubble sort will always perform n^2 operations regardless of input. Insertion sort is much more efficient if the input is close to sorted. Insertion sort would make many less moves in that case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In a sorting algorithm are moves or comparisons more likely to change based on input?

A

moves are much more likely to change based on input

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In the class implementation of quicksort what do the indices i and j refer to?

A

i refers to the index on the left, j refers to the index on the right.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What must happen for one iteration of quicksort’s partition method to conclude?

A

The partition method in quicksort finishes when the index i (left index) is no longer less than j (right index).

  • the partition method returns j
  • at the end, j refers to the index of the rightmost element in the left subarray
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Consider the first recursive call that would occur during mergesort (i.e. the first time that the recursive method calls itself). What would the array look like after that recursive call returns.

A
/** mSort - recursive method for mergesort */
    private static void mSort(int[] arr, int[] tmp, int start, int end) {
        if (start >= end)
            return;
    int middle = (start + end)/2;
    mSort(arr, tmp, start, middle);
    mSort(arr, tmp, middle + 1, end);
    merge(arr, tmp, start, middle, middle + 1, end);
}

Note that the first call to mSort here calls sort on the left half of the array. Basically, the left half would be sorted and the right half would not.

Note: watch out for the use of integer division to determine the midpoint!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Breadth First Search

A
  • Complete
  • best at finding solutions near the top of the tree
  • very expensive in terms of memory

Performance:

  • O(b^d) (b = breadth, d = depth) (class definition)
  • O(V + E)

Space:
-O(b^d)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Iterative Depth Search

A

-Complete
-Like DFS with max-depth of 1 at each level
-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Greedy Search

A

-Similar to BFS
-informed state-space search
-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Level Order Traversal

A

Visits all nodes on a level from left to right

-implemented with a queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Advantages of breadth first search

A
  • guaranteed to be complete
  • good at finding solutions relatively close to the node/vertex of origin
  • does well in situations where all operators (cost of pursuing a path) have identical costs. Example: 8-puzzle moves all have the same cost.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Disadvantages of breadth first search

A
  • very high space-complexity (uses an exponential i.e. batshit crazy amount of memory)
  • makes it impossible to use on very large data sets
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the efficiency of heapify?

A

O(n log n)

-each item (n) must be sifted down (log n)

17
Q

How does heapify work?

A
  • start with the parent of the last node in the heap
  • sift down that parent, if necessary
  • check every other parent on the same level as the initial parent, sifting as necessary
  • go to the next level up, sifting as necessary
  • continue this process for the entire heap
18
Q

polynomial complexity

A

problems that can be solved in O(n^2) or better

19
Q

Tour

A

visit every other vertex no more than once, then return to original

20
Q

What is the performance of the merge part of merge sort?

A

O(n) linear