Quizzes Questions/answer Flashcards
Suppose you want to define a data structure that is fast in search, which of the following data structure would you choose?
ordered array
Rank the following time complexity orders with the slowest one comes first.
- O(1)
- O(logn)
- O(n)
- O(nlogn)
- O(n^2)
- O(n^3)
- O(2^n)
O(1) means a process operates in __ time.
constant
In general, ordered arrays, compared with unordered array, are: (select all that are correct)
- slower Insertion
- Quicker at searching
In an unordered array, it is generally faster to find out an item is not in the array than to find out it is. True or False?
False
Select all the correct statements about the following operation:
Inserting an item into unordered array:
1.takes time proportional to the size of the array
2. requires multiple comparisons
3. requires shifting other items to make room
4. takes the same time no matter how many items there are
- takes the same time no matter how many items there are
The maximum number of elements that must be examined to complete a binary search in an array of 200 elements is:
1.200
2. 8
3. 1
4. 13
8
What is the output of the following code segments?
int n=9; Stack<Integer> s = new Stack<Integer>(); while (n>0){ s.push(n%2); n=n/2; } while (!s.isEmpty()){ System.out.print(s.pop()+" "); } System.out.println();
1 0 0 1
Suppose that a minus sign in the input indicates pop a stack, and other string indicates push the string into a stack. What will be the content (from top to bottom) of the stack with the following inputs
A C - G H - - F C - - M P
PMA
Suppose to sort an arbitrary array using selection sort, we need to use 1024ms. How much time do we need to sort it using bubble sort?
1024ms
Given the array: 0 6 3 2 10 7 9 8.
Show what the array will look like using Bubble Sort to sort it for the first three iterations. (iterations happen based on the rule of the sort, ex bubble 1st iteration finishes after it switches les and right and done.
1st) 0 3 6 2 10 7 9 8
2nd). 0 3 2 6 10 7 9 8
3rd) 0 3 2 6 7 10 9 8
Given the array: 0 6 3 2 10 7 9 8.
Show what the array will look like using Selection Sort to sort it for the first three iterations.
1st) 0 6 3 2 10 7 9 8
2nd). 0 2 3 6 10 7 9 8
3rd) 0 2 3 6 10 7 9 8
Given the array: 0 6 3 2 10 7 9 8
Show what the array will look like using Insertion Sort to sort it for the first three iterations.
1st) 0 3 6 2 10 7 9 8
2nd). 0 3 2 6 10 7 9 8
3rd). 0 2 3 6 10 7 9 8
How many iterations are needed in bubble sort?
n-1
Given an arbitrary array with N elements, how many iterations do you need to sort it into ascending order using Insertion sort?
-N^2
-N-1