Screen Shot 2022-09-25 at 2
.png
keyboard_arrow_up
School
Moraine Valley Community College *
*We aren’t endorsed by this school
Course
240
Subject
Computer Science
Date
Dec 6, 2023
Type
png
Pages
1
Uploaded by ProfResolve12236
Question
1
1/1pts
A
sequential
search
of
a
list
assumes
that
the
list
is
in
sorted
order.
True
False
Question
2
1/1pts
On
average,
the
binary
search
algorithm
performs
faster
than
sequential
search.
True
False
Question
3
1/1pts
If
an
array
is
sorted
in
ascending
order,
the
values
are
stored:
from lowest
to
highest
from
highest
to
lowest
None
of
the
above
Question
4
0/1pts
After
one
pass
of
bubble
sort,
which
value
is
guaranteed
to
be
in
order?
The
first
value
The
middle
value
Correctanswer
'
The
Jast
value
You
Answered
No
values
are
guaranteed
to
be
in
order
Question
5
1/1pts
After
one
pass
of
selection
sort,
which
value
is
guaranteed
to
be
in
order?
The
first
value
The
middle
value
The
last
value
No
values
are
guaranteed
to
be
in
order
Question
6
1/1pts
Which
sort
usually
requires
fewer
data
values
to
be
swapped?
Bubble
sort
Selection
sort
No
answer
text
provided.
No
answer
text
provided.
Question
7
1/1pts
On
average,
with
an
array
of
1,000
elements,
how
many
comparisons
will
the
linear
search
perform?
(Assume
the
items
being
search
for
ARE
in
the
array)
log(1000)
square
root
of
1000
500
1000
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Lab 16 Implementing bubble sort
In this lab, you will implement the bubble sort algorithm. The bubble sort is so called because it
compares adjacent items, "bubbling" the smaller one up toward the beginning of the array. By
comparing all pairs of adjacent items starting at the end of the array, the smallest item is guaranteed
to reach the beginning of the array at the end of the first pass.
The second pass begins again at the end of the array, ultimately placing the second smallest item in
the second position. During the second pass, there is no need to compare the first and second items,
because the smallest element is guaranteed to be in the first position.
Bubble sort takes at most n - 1 passes for an array of n items. During the first pass, n - 1 pairs
need to be compared. During the second pass, n - 2 pairs need to be compared. During the ith
pass, n - i pairs need to be compared. During the last pass, n - (n - 1) or one pair needs to be
compared. If, during any pass, no two…
arrow_forward
Lab 16 Implementing bubble sort
In this lab, you will implement the bubble sort algorithm. The bubble sort is so called because it compares adjacent items, "bubbling" the smaller one up toward the beginning of the array. By comparing all pairs of adjacent items starting at the end of the array, the smallest item is guaranteed to reach the beginning of the array at the end of the first pass.The second pass begins again at the end of the array, ultimately placing the second smallest item in the second position. During the second pass, there is no need to compare the first and second items, because the smallest element is guaranteed to be in the first position.Bubble sort takes at most n - 1 passes for an array of n items. During the first pass, n - 1 pairs need to be compared. During the second pass, n - 2 pairs need to be compared. During the ith pass, n - i pairs need to be compared. During the last pass, n - (n - 1) or one pair needs to be compared. If, during any pass, no two…
arrow_forward
BUBBLE SORT
Sort the following list of elements using the bubble sorting algorithm. Show the passes until the list is sorted.
23 15 8 12 20 10
arrow_forward
The optimised bubble sort offers none of the following benefits over conventional sorts for items that have already been sorted.
arrow_forward
Language: Python 3
Autocomplete Ready O
1 v import ast
3. Hybrid Sort
input()
lst
%3D
3
lst = ast.literal_eval(lst)
4
Insertion sort is a simple sorting algorithm that builds the final sorted array one
item at a time. In each iteration, insertion sort inserts an element into an already
sorted list (on left). The position where the item will be inserted is found through
linear search. You decided to improve insertion sort by using binary search to
find the position p where
the new insertion should take place.
6
print(BinaryInsertionSort(lst))
Algorithm BinarylnsertionSort
Input/output: takes an integer array a = {a[0], ..., a[n – 1]} of size n
begin BinarylnsertionSort
for i =1 to n
val = a[i]
p = BinarySearch(a, val, 0, i – 1)
for j = i-1 to p
a[j + 1]= a[i]
j= j-1
end for
a[p] = val
i i+1
end for
end BinarylnsertionSort
Here, val = a[i] is the current value to be inserted at each step i into the already
sorted part a[0], ..., ați – 1] of the array a. The binary search along that part…
arrow_forward
Sorting refers to arranging data in a particular order. Apply Bubble Sort algorithm to
sort the given list of numbers in descending order. Show the results of each round of
the bubble sort algorithm.
27
59
81
62
35
56
31
23
6.
arrow_forward
Sort the following list using the bubble sort algorithm as discussed in this chapter. Show the
list after each iteration of the outer for loop.
26, 45, 17, 65, 33, 55, 12, 18
arrow_forward
Subject: Data structure
arrow_forward
Best Partition
You are given an array of positive numbers of size N and an integer K. You need to partition the array into K
continuous segments. For each segment, the sum of its elements needs to be calculated.
The segment with the minimum sum is called the bestSegment and the sum of the elements of the
bestSegment is called the bestSum.
For all possible combinations of partitions of the array when divided into K segments, their bestSum needs to be
calculated and the one among them with maximum value needs to be returned.
Input Specification:
input1: an array of N positive numbers
input2: an integer N denoting the length of the array
input3: an integer K
Output Specification:
Return an integer denoting the maximum value of all possible bestSum.
Example 1:
input1: (1,2,3,4}
input2: 4
input3: 2
Output: 4
Explanation:
You can partition the given array into 2 continuous segments in the following manner-
• 123 14- the sum of individual segments is (6,4) and the bestSum is 4
• 12134- the…
arrow_forward
Question in image
Please explain how to do with answer
arrow_forward
Write a version of the sequential search algorithm that can be used to search a sorted list.
arrow_forward
True or False
For each statement below, indicate whether you think it is True or False.
Inserting elements into a sorted array is O(n) because you have to find the location to add the new element and then shift the remaining elements
If the sorted array gets too large, the performance of binary search becomes O(n)
For the delete algorithm, after you find the element to delete, you can make the algorithm run faster by replacing it with the last element in the array
If you used binary search to find the element to delete, the performance is still O(n) because you may have to shift all elements
arrow_forward
The minimum height of a binary search tree win n keys is log2 n
Select one:
OTrue
OFalse
arrow_forward
OBJECT
Lab Session 03
Application of the Linear and binary search on a list of elements stored in an array.
THEORY
Linear Search
A nonempty array DATA with N numerical values is given. This algorithm finds the location LOC and required value of elements of DATA. The variable K is used as a counter.
ALGORITHM
1. Set k := 1 & loc : = 0
Repeat step 3 & 4 while loc : = 0 &k < = n
If (item = data[k]) loc : = k
Else
K = k + 1
If loc > = 0 or If (item = data[k]) then
Print “loc is the location of item”
Else
Print “no. not found”
Exit
Binary Search
Suppose DATA is an array that is sorted in increasing (or decreasing) numerical order or, equivalently, alphabetically. Then there is an extremely efficient searching algorithm, called binary search, which can be used to find the location LOC of a given ITEM of information in DATA.
The binary search algorithm applied to our array DATA works as follows: During each stage of our algorithm, our search for ITEM is…
arrow_forward
OBJECT
Lab Session 03
Application of the Linear and binary search on a list of elements stored in an array.
THEORY
Linear Search
A nonempty array DATA with N numerical values is given. This algorithm finds the location LOC and required value of elements of DATA. The variable K is used as a counter.
ALGORITHM
1. Set k := 1 & loc : = 0
Repeat step 3 & 4 while loc : = 0 &k < = n
If (item = data[k]) loc : = k
Else
K = k + 1
If loc > = 0 or If (item = data[k]) then
Print “loc is the location of item”
Else
Print “no. not found”
Exit
Binary Search
Suppose DATA is an array that is sorted in increasing (or decreasing) numerical order or, equivalently, alphabetically. Then there is an extremely efficient searching algorithm, called binary search, which can be used to find the location LOC of a given ITEM of information in DATA.
The binary search algorithm applied to our array DATA works as follows: During each stage of our algorithm, our search for ITEM is…
arrow_forward
6 All sorting algorithms require a certain number of comparisons, which is determined by the initial permutation position of the elements to be sorted. 7 Bubble sort is more efficient than rapid sort when the data is loosely ordered?
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Related Questions
- Lab 16 Implementing bubble sort In this lab, you will implement the bubble sort algorithm. The bubble sort is so called because it compares adjacent items, "bubbling" the smaller one up toward the beginning of the array. By comparing all pairs of adjacent items starting at the end of the array, the smallest item is guaranteed to reach the beginning of the array at the end of the first pass. The second pass begins again at the end of the array, ultimately placing the second smallest item in the second position. During the second pass, there is no need to compare the first and second items, because the smallest element is guaranteed to be in the first position. Bubble sort takes at most n - 1 passes for an array of n items. During the first pass, n - 1 pairs need to be compared. During the second pass, n - 2 pairs need to be compared. During the ith pass, n - i pairs need to be compared. During the last pass, n - (n - 1) or one pair needs to be compared. If, during any pass, no two…arrow_forwardLab 16 Implementing bubble sort In this lab, you will implement the bubble sort algorithm. The bubble sort is so called because it compares adjacent items, "bubbling" the smaller one up toward the beginning of the array. By comparing all pairs of adjacent items starting at the end of the array, the smallest item is guaranteed to reach the beginning of the array at the end of the first pass.The second pass begins again at the end of the array, ultimately placing the second smallest item in the second position. During the second pass, there is no need to compare the first and second items, because the smallest element is guaranteed to be in the first position.Bubble sort takes at most n - 1 passes for an array of n items. During the first pass, n - 1 pairs need to be compared. During the second pass, n - 2 pairs need to be compared. During the ith pass, n - i pairs need to be compared. During the last pass, n - (n - 1) or one pair needs to be compared. If, during any pass, no two…arrow_forwardBUBBLE SORT Sort the following list of elements using the bubble sorting algorithm. Show the passes until the list is sorted. 23 15 8 12 20 10arrow_forward
- The optimised bubble sort offers none of the following benefits over conventional sorts for items that have already been sorted.arrow_forwardLanguage: Python 3 Autocomplete Ready O 1 v import ast 3. Hybrid Sort input() lst %3D 3 lst = ast.literal_eval(lst) 4 Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time. In each iteration, insertion sort inserts an element into an already sorted list (on left). The position where the item will be inserted is found through linear search. You decided to improve insertion sort by using binary search to find the position p where the new insertion should take place. 6 print(BinaryInsertionSort(lst)) Algorithm BinarylnsertionSort Input/output: takes an integer array a = {a[0], ..., a[n – 1]} of size n begin BinarylnsertionSort for i =1 to n val = a[i] p = BinarySearch(a, val, 0, i – 1) for j = i-1 to p a[j + 1]= a[i] j= j-1 end for a[p] = val i i+1 end for end BinarylnsertionSort Here, val = a[i] is the current value to be inserted at each step i into the already sorted part a[0], ..., ați – 1] of the array a. The binary search along that part…arrow_forwardSorting refers to arranging data in a particular order. Apply Bubble Sort algorithm to sort the given list of numbers in descending order. Show the results of each round of the bubble sort algorithm. 27 59 81 62 35 56 31 23 6.arrow_forward
- Sort the following list using the bubble sort algorithm as discussed in this chapter. Show the list after each iteration of the outer for loop. 26, 45, 17, 65, 33, 55, 12, 18arrow_forwardSubject: Data structurearrow_forwardBest Partition You are given an array of positive numbers of size N and an integer K. You need to partition the array into K continuous segments. For each segment, the sum of its elements needs to be calculated. The segment with the minimum sum is called the bestSegment and the sum of the elements of the bestSegment is called the bestSum. For all possible combinations of partitions of the array when divided into K segments, their bestSum needs to be calculated and the one among them with maximum value needs to be returned. Input Specification: input1: an array of N positive numbers input2: an integer N denoting the length of the array input3: an integer K Output Specification: Return an integer denoting the maximum value of all possible bestSum. Example 1: input1: (1,2,3,4} input2: 4 input3: 2 Output: 4 Explanation: You can partition the given array into 2 continuous segments in the following manner- • 123 14- the sum of individual segments is (6,4) and the bestSum is 4 • 12134- the…arrow_forward
- Question in image Please explain how to do with answerarrow_forwardWrite a version of the sequential search algorithm that can be used to search a sorted list.arrow_forwardTrue or False For each statement below, indicate whether you think it is True or False. Inserting elements into a sorted array is O(n) because you have to find the location to add the new element and then shift the remaining elements If the sorted array gets too large, the performance of binary search becomes O(n) For the delete algorithm, after you find the element to delete, you can make the algorithm run faster by replacing it with the last element in the array If you used binary search to find the element to delete, the performance is still O(n) because you may have to shift all elementsarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage