Filters
Question type

Study Flashcards

Bubble sort is the most efficient searching algorithm.

A) True
B) False

Correct Answer

verifed

verified

Suppose we have algorithms that solve a particular problem that have the following complexities. Which one is most efficient?


A) O(1)
B) O(log2n)
C) O(n2)
D) O(n3)
E) O(2n)

F) A) and C)
G) A) and E)

Correct Answer

verifed

verified

Write a method that accepts an integer and an array of integers, and returns true if the integer is contained in the array. You may assume that the array is sorted, and your method should use a binary search..

Correct Answer

verifed

verified

public boolean binarySearch(int a, int[] array) { int first = 0; int last = array.length-1; int mid; while(first <= last) { mid = (first+last)/2; if(array[mid] == a) return true; else if(array[mid] > a) last = mid - 1; else last = mid + 1; } return false; }

A _______________ search is more efficient than a linear search.


A) binary
B) selection
C) insertion
D) bubble
E) none of the above

F) B) and C)
G) A) and B)

Correct Answer

verifed

verified

_____________________ is the process of finding a designated target element within a group of items.


A) Sorting
B) Searching
C) Recursing
D) Helping
E) none of the above

F) A) and B)
G) A) and C)

Correct Answer

verifed

verified

Write a method that accepts an integer and an array of integers, and returns true if the integer is contained in the array. The method should use a linear search.

Correct Answer

verifed

verified

public boolean linearSearch(in...

View Answer

____________________ is the process of arranging a group of items into a defined order.


A) Searching
B) Sorting
C) Selecting
D) Helping
E) none of the above

F) A) and B)
G) A) and C)

Correct Answer

verifed

verified

B

Explain what O(1) means.

Correct Answer

verifed

verified

An algorithm's growth rate is ...

View Answer

Explain why a faster computer can never make an exponential time algorithm run faster than a polynomial time algorithm on all inputs.

Correct Answer

verifed

verified

While a faster computer may make a polyn...

View Answer

Which of the following algorithms has a time complexity of O(log2 n) ?


A) insertion sort
B) selection sort
C) bubble sort
D) linear search
E) binary search

F) B) and D)
G) A) and E)

Correct Answer

verifed

verified

How many times will the following code print out Hello World (in terms of the length of the array)? for(int i = 0; i < array.length; i++) { for(int j = 0; j < array.length; j++) { for(int k = 0; k < array.length; k++) { System.out.println("Hello World!"); } } }

Correct Answer

verifed

verified

11eddcf1_9996_d01d_8512_fbd29aaab956_TB2841_00

A linear search is more efficient than a binary search.

A) True
B) False

Correct Answer

verifed

verified

What is the complexity of the following code (in terms of the length of the array), assuming someMethod has a complexity of O(1)? for(int i = 0; i < array.length; i++) for(int j = 0; j < array.length; j++) someMethod(array[j]);

Correct Answer

verifed

verified

The comple...

View Answer

Which of the following is not a sorting algorithm?


A) Bubble sort
B) Quick sort
C) Merge sort
D) Selection sort
E) all of the above are sorting algorithms

F) B) and E)
G) D) and E)

Correct Answer

verifed

verified

In the binary search algorithm, if the number of elements in the search pool is even, which value is used as the midpoint? Explain.

Correct Answer

verifed

verified

If the number of elements in the search ...

View Answer

The ___________________ algorithm sorts values by repeatedly comparing neighboring elements in the list and swapping their position if the are not in order relative to each other.


A) insertion sort
B) selection sort
C) bubble sort
D) quick sort
E) merge sort

F) D) and E)
G) None of the above

Correct Answer

verifed

verified

Write out the state while being sorted using the insertion sort algorithm: Write out the state while being sorted using the insertion sort algorithm:

Correct Answer

verifed

verified

6 91 3 55 110 8 1 703
3 6 91 5...

View Answer

Suppose we would like to swap the elements at index i and index j in an array. Does the following code work? If so, explain how. If not, explain why it fails. array[i] = array[j]; array[j] = array[i];

Correct Answer

verifed

verified

This fails because the first step overwr...

View Answer

As the number of items in a search pool grows, the number of comparisons required to search _______________ .


A) increases
B) decreases
C) stays the same
D) goes to 0
E) none of the above

F) A) and E)
G) All of the above

Correct Answer

verifed

verified

A __________________ search looks through the search pool one element at a time.


A) binary
B) clever
C) insertion
D) selection
E) linear

F) B) and E)
G) A) and B)

Correct Answer

verifed

verified

Showing 1 - 20 of 40

Related Exams

Show Answer