To add code to the merge sort algorithm to count the number of comparisons performed and at the end of the program that outputs "comparisons: " followed by the number of comparisons performed check the code given below.
What is sort algorithm?A sorting algorithm is a set of instructions that takes an input array, applies certain operations to the array (also known as a list), and outputs a sorted array.
Sorting algorithms are frequently covered early on in computer science courses because they offer a simple way to introduce other important concepts like Big-O notation, divide-and-conquer strategies, and data structures like binary trees and heaps.
When selecting a sorting algorithm, many factors need to be taken into account.
"""
Python version: 3.6
Python program to sort a list of numbers in ascending order using merge sort
"""
# add a global variable to count number of key comparisons in merge sort and initialize it to 0
comparisons = 0
def read_nums():
"""
Function that takes no inputs and returns a list of integers entered by the user
"""
# read a string of integers and split it into list of strings using default delimiter whitespace
nums = input().split()
# convert the list of strings to list of integers and return it
return [int(num) for num in nums]
def print_nums(numbers):
"""
Function that takes as input a list of numbers and display the
numbers on screen in one line separated by space ending with a newline
"""
for num in numbers:
print (num, end=' ')
print()
def merge(numbers, i, j, k):
"""
Function that takes as input a list of numbers and 3 integers
representing the start and ends of the sorted left[i, j] and sorted right[j+1, k] sublists
"""
global comparisons # use the global variable comparisons
# calculate the total size of the list after merging the sublists
merged_size = k - i + 1
# create a list of size merged_size and initialize all elements to 0
merged_numbers = []
for l in range(merged_size):
merged_numbers.append(0)
# set merge_pos to start index of merged_numbers, left_pos to start index of left sublist and right_pos to start index of right sublist
merge_pos = 0
left_pos = i
right_pos = j + 1
# loop until end of a sublist is reached
while left_pos <= j and right_pos <= k:
comparisons += 1 # increment comparisons by 1
# current element of left sublist is less than current element of right sublist
if numbers[left_pos] < numbers[right_pos]:
# insert current element of left sublist into merged_numbers and increment left_pos by 1
merged_numbers[merge_pos] = numbers[left_pos]
left_pos = left_pos + 1
else:
# else insert current element of right sublist into merged_numbers and increment right_pos by 1
merged_numbers[merge_pos] = numbers[right_pos]
right_pos = right_pos + 1
merge_pos = merge_pos + 1 # increment merge_pos by 1
# loop to copy the remaining elements of left sublist to merged_numbers
while left_pos <= j:
merged_numbers[merge_pos] = numbers[left_pos]
left_pos = left_pos + 1
merge_pos = merge_pos + 1
# loop to copy the remaining elements of right sublist to merged_numbers
while right_pos <= k:
merged_numbers[merge_pos] = numbers[right_pos]
right_pos = right_pos + 1
merge_pos = merge_pos + 1
# loop to copy the sorted list from merged_numbers to numbers in the range [i, k]
merge_pos = 0
while merge_pos < merged_size:
numbers[i + merge_pos] = merged_numbers[merge_pos]
merge_pos = merge_pos + 1
def merge_sort(numbers, i, k):
"""
Function that takes as input an unsorted list of numbers and start and end index
of the list to sort and sorts the list in ascending order using merge sort
"""
j = 0
# current list range contains at least 1 element
if i < k:
# get the index of middle element of the current range
j = (i + k) // 2
# output the range for the left and right sublists to sort
print(i, j, "|", j + 1, k)
# recursively sort the numbers in the range [i,j] and [j+1, k]
merge_sort(numbers, i, j)
merge_sort(numbers, j + 1, k)
# merge the sorted lists [i,j] and [j+1,k] to get the sorted list in the range [i,k]
merge(numbers, i, j, k)
if __name__ == '__main__':
# get the list of numbers entered by the user
numbers = read_nums()
# display the unsorted list
print ('unsorted:', end=' ')
print_nums(numbers)
print()
# sort the list in ascending order using merge sort passing the numbers list and 0 and 1 less than size of list as i and k
merge_sort(numbers, 0, len(numbers) - 1)
# display the sorted list
print ('\nsorted:', end=' ')
print_nums(numbers)
# display the number of comparisons using the global variable
print("comparisons:",comparisons)
# end of program
Learn more about sorting algorithm
https://brainly.com/question/14698104
#SPJ4
Which sentence best descibes an activity stream
Answer: a list of recent activities performed by an individual, typically on a single website.
Explanation:
Name the processes that the information processing cycle consist of:
Answer:
Hello Dear!...Explanation:
The information-processing cycle consists of four basic operations: input, processing, output, and storage.
Hope that helps you Buddy..
Buhbye!
Take care!
Alicia wants to change the display of the Outlook Today window on her computer. After clicking on Customize Outlook Today, which steps should she follow to change the display from three columns to one column?
In the Startup area, click 1 from the drop-down menu.
In the Startup area, click Standard (one column) from the drop-down menu.
In the Styles area, click Standard (one column) from the drop-down menu.
In the Styles area, click 1 from the drop-down menu.
Outlook is the mailing program used to receive and send emails. The display from three columns to one column can be changed by clicking in the style's area and selecting the standard. Thus, option c is correct.
What is the style's area?The styles area is the option in the Outlook used to change the format of how the display looks to the users in the mail area. They are found in the format text tab.
In the tab select the style's area and choose the standard option which is the one-column option that can be selected from the drop-down buttons.
Therefore, option c. choosing the standard option in the style area is used to change the display.
Learn more about outlook here:
https://brainly.com/question/19755799
#SPJ1
Which of the following is a document view you can select using Button on the status bar?
a. share view
b, web layout view
Answer:
la b
Explanation:
The web layout view is the document view that can be selected using the buttons on the status bar. Thus, option b. is correct.
What is web layout view?The web layout view is the feature of Microsoft word, that helps the user to view their document in the form as it could be seen in the webpage if the document is published.
The status bar of the Microsoft word allows the user to view their document in the web layout view simply by clicking a button on the status bar.
Therefore, option b. is correct.
Learn more about web layout view, here:
https://brainly.com/question/1327497
#SPJ2
Components of micro computer with diagram
Answer:
CPU, Program memory, Data memory, Output ports, Input ports and Clock generator.
Explanation:
There are six basic components of a microcomputer which includes CPU, Program memory, Data memory, Output ports, Input ports and Clock generator. CPU is the central processing unit which is considered as the brain of the computer. It is the part of a computer that executes instructions. Data memory is the place where data is stored that is present in the CPU.
For python, Write a function named getResults that accepts radius of a sphere and returns the volume and surface area. Call this function with radius = 3.5 , and display results in one decimal format.
volume = 4/3 * pi * r ^ 3
Surface Area = 4pi * r ^ 2
import math
def getResults(r):
return "Volume = {}\nSurface Area = {}".format(round((4/3)*math.pi*(r**3),1), round((4*math.pi)*(r**2),1))
print(getResults(3.5))
I hope this helps!
What is the overall purpose of the app?
Answer:
To help students with homework and their education
Explanation:
Brainly is a Polish education technology company based in Kraków, Poland, with headquarters in New York City. It provides a peer-to-peer learning platform for students, parents, and teachers to ask and answer homework questions. In an ideal world, Brainly would be a supportive group learning environment where students could teach each other what they know. ... The point system can encourage students to give valuable answers, but points (and the "Brainliest" title) are awarded by the question asker, not an expert.
It's a rapid sign-up process and, if you're looking for answers for something specific, the search function is simple to use and gives instant gratification. We also like that you can quickly scan for verified answers, which have been vetted by Brainly expert volunteers and are determined to be correct and accurate.
Hope this helped! Have a nice day!
Please give Brainliest when possible!
:3
3
Drag each tile to the correct box.
Put the sequence of steps involved in software design in proper order.
Consolidate data elements.
Develop an operational timeline.
Define the interface.
Take into account concurrency and real-
time considerations.
The correct steps to be taken for software design are:
Define the interface.Consolidate data elements.Take into account concurrency and real-time considerations.Develop an operational timeline.The correct succession of methods necessary for software design is shown below:To begin, establishing the interface is essential because it delineates how the software will interact with either the user or any other related software assets.
Subsequently, assembling all necessary data elements is imperative to guarantee that the software can process and regulate data correctly.
Considering both concurrency and immediate conditions is also requisite to make sure the software works proficiently and instantly responds to user input when under strain.
And lastly, introducing an operational timeline permits timely delivery of the program and keeps costs within estimation.
Read more about software design here:
https://brainly.com/question/26135704
#SPJ1
Use the drop-down menu to complete the sentences about pseudocode.
Pseudocode provides a
Pseudocode
of what is happening in the computer program.
detail(s) every single step of the program.
Pseudocode provides a high-level overview of what is happening in a computer program
How does pseudocode do this?Pseudocode presents a broad perspective of the operations performed within a program by a computer. Acting as an intermediate phase bridging human-understandable language and executable code.
Although not outlining each step in a comprehensive manner, pseudocode captures the key steps and algorithms that are crucial in accomplishing the requested functionality.
The emphasis is on the coherence of the sequence of steps, the methods for making choices, and the significant functions, empowering developers to skillfully design and articulate the framework of their program well in advance of actual implementation in a given coding language.
Read more about pseudocode here:
https://brainly.com/question/24953880
#SPJ1
Question 11 (2.5 points)
A start-up company has hired you to implement an email strategy for its organization.
The company wants all of its employees to have an enterprise-level email client and
is considering Windows Live Essentials. They ask you if there are any limitations
about this email solution. Which of the following is a major limitation?
Answer:
the dot
Explanation:
the dot is a good day forecast for a bit
Use function GetUserInfo to get a user's information. If user enters 20 and Holly, sample program output is:Holly is 20 years old. #include #include void GetUserInfo(int* userAge, char userName[]) { printf("Enter your age: \n"); scanf("%d", userAge); printf("Enter your name: \n"); scanf("%s", userName); return;}int main(void) { int userAge = 0; char userName[30] = ""; /* Your solution goes here */ printf("%s is %d years old.\n", userName, userAge); return 0;}
Answer:
Replace
/*Your solution goes here*/
with
GetUserInfo(&userAge, userName);
And Modify:
printf("%s is %d years old.\n", userName, userAge)
to
printf("%s is %d years old.", &userName, userAge);
Explanation:
The written program declares userAge as pointer;
This means that the variable will be passed and returned as a pointer.
To pass the values, we make use of the following line:
GetUserInfo(&userAge, userName);
And to return the value back to main, we make use of the following line
printf("%s is %d years old.", &userName, userAge);
The & in front of &userAge shows that the variable is declared, passed and returned as pointer.
The full program is as follows:
#include <stdio.h>
#include <string.h>
void GetUserInfo(int* userAge, char userName[]) {
printf("Enter your age: ");
scanf("%d", userAge);
printf("Enter your name: ");
scanf("%s", userName);
return;
}
int main(void) {
int* userAge = 0;
char userName[30] = "";
GetUserInfo(&userAge, userName);
printf("%s is %d years old.", &userName, userAge);
return 0;
}
pls Which of the following statements is false? a. Having a first aid kit in an office is necessary b. Accidents happen, so it is not necessary to prepare for them c. Your company does need an emergency action plan d. OSHA inspects workplaces to look for unsafe conditions Please select the best answer from the choices provided A B C D
The statement that is false is that Accidents happen, so it is not necessary to prepare for them.
What is accident?The definition of an accident is that it is an unexpected event that occurs that is known to have not being planned.
Note that The statement that is false is that Accidents happen, so it is not necessary to prepare for them and it is false because it is not good to prepare for it as one will be in constant fear always.
Learn more about Accidents from
https://brainly.com/question/16798121
#SPJ2
Write a Boolean function named isPrime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Use the function in a program that prompts the user to enter a number then displays a message indicating whether the number is prime.
Answer:
public static lotsof verbosekrap(String args[]) {
int num;
printf("Enter this nonsense BF: ");
scanf("%d", &num);
isPrime(num);
}
public boolean isPrime(int num) {
if (num == prime) {
returns true;
} else {
returns "your mom sucks and fails";
}
Explanation:
this is a mix of C and Java, I don't care
Ranjan have received an email saying that he won a free gift project to climb the gift voucher Ranjana give some personal details suggest Bank account number Bank name exact graph which type of security threat is indicated in the mail? should he answer the mail?
"An operating system is an interface between human operators and application software". Justify this statement with examples of operating system known to you.
An operating system acts as the interface between the user and the system hardware. It is responsible for all functions of the computer system.
It is also responsible for handling both software and hardware components and maintaining the device's working properly. All computer programs and applications need an operating system to perform any task. Users are the most common operating system component that controls and wants to make things by inputting data and running several apps and services.
After that comes the task of implementation, which manages all of the computer's operations and helps in the movement of various functions, including photographs, videos, worksheets, etc. The operating system provides facilities that help in the operation of apps and utilities through proper programming.
learn more about operating systems at -
https://brainly.com/question/1033563
Discuss the Von-Neumann CPU architecture?
The Von Neumann architecture is a traditional CPU design named after John von Neumann and widely implemented since the mid-20th century.
What is the Von-Neumann CPU architecture?Basis for modern computers, including PCs, servers, and smartphones. Von Neumann architecture includes components for executing instructions and processing data. CPU is the core of Von Neumann architecture.
It manages operations, execution, and data flow in the system. Von Neumann architecture stores both program instructions and data in a single memory unit. Memory is organized linearly with each location having a unique address. Instructions and data are stored and retrieved from memory while a program runs.
Learn more about Von-Neumann CPU architecture from
https://brainly.com/question/29590835
#SPJ1
FILL IN THE BLANK analysis tools that support viewing all or selected parts of data, querying the database, and generating reports include query-by-example as well as a specialized programming language called __________blank.
So-called "SQL" databases are the most widely used sort of database. Structured Query Language, or SQL, is a specialized language used to make queries to databases and obtain results from them (or data into it).
Data analysis: What is it?
In order to find relevant information, support inferences, and help decision-making, data analysis is the process of analyzing, cleaning, manipulating, and modeling data.
What are some examples of data analysis?
Every time we make a decision in our daily lives, we may observe a basic example of data analysis by assessing what has happened in the past or what will happen if we take that action. Basically, this involves looking at the past or future and making a decision in light of that analysis.
To know more about Data analysis visit;
https://brainly.com/question/13103333
#SPJ4
What unit on a digital camera gives added illusions
The measure of software complexity that measure how complex a software is in machine's viewpoint in terms of how the size of the input data affects an algorithm's usage of computational resources is known as Computational Complexity.
a. True
b. False
Answer:
a. True
Explanation:
In Computer science, an algorithm can be defined as a standard formula or procedure which comprises of set of finite steps or instructions for solving a problem on a computer.
Basically, the time complexity of an algorithm is defined by f(n) if; for all "n" and all inputs with length "n" the execution of the algorithm takes a maximum of f(n) steps. Therefore, this is a measure of the efficiency of an algorithm.
Hence, the time complexity is a measure of the amount of time required by an algorithm to run till its completion of the task with respect to the length of the inpu
Computational complexity can be defined as a measure of software complexity that measure how complex a software is in machine's viewpoint in terms of how the size of the input data affects an algorithm's usage of computational resources such as memory or running time.
It is important to know the terms of use of any website because why
e requirements of Phase 3 are as follows:
In this third phase, you will be obtaining the case, power supply, and monitor for your computer. You will also include a printer.
Case:
Analyze the specifications for the case. Discuss what stood out to you about your choice. For example, "Why did you choose this specific component?" What stood out to you (price, specifications, etc.)?
What are the specifications, source, and price of the case? How did each of these components influence your decision to select it?
Power Supply:
Analyze the specifications for the power supply. Discuss what stood out to you about your choice. For example, "Why did you choose this specific component?" What stood out to you (price, specifications, etc.)?
What are the specifications, source, and price of the power supply? How did each of these components influence your decision to select it?
Monitor:
Analyze the specifications for the monitor. Discuss what stood out to you about your choice. For example, "Why did you choose this specific component?" What stood out to you (price, specifications, etc.)?
What are the specifications, source, and price of the monitor? How did each of these components influence your decision to select it?
Printer:
Analyze the specifications for the printer. Discuss what stood out to you about your choice. For example, "Why did you choose this specific component?" What stood out to you (price, specifications, etc.)?
What are the specifications, source, and price of the printer? How did each of these components influence your decision to select it?
References:
List references used.
References should relate to decision-making articles in addition to a website where one could purchase the product.
All references must be in APA format.
Any images used must be cited properly.
Format:
APA formatted cover page as well as the entirety of the document.
Paragraphs are coherently organized, including the use of proper grammar and correct spelling.
Clearly organized using graphics and tables (where appropriate).
Acronyms are spelled out on first use.
Because this is a research that should b carried out, I will guide you on how to do same. Pay attention to the requirement on APA Formatting.
How can the above research be executed?In order to make an informed decision on each component, it is imperative that you conduct thorough research on their specifications, source and price.
Reliable sources of information such as reputable tech review websites should be utilized in the comparison of features and prices for each option available.
Proper citation using APA format will need to be observed together with inclusion of any images used. Organizing your document with clear and coherent structure will further enhance readability- utilizing tables and graphics where applicable.
Learn more about APA Formatting:
https://brainly.com/question/12548905
#SPJ1
which of the following definitions best matches the concept of an account from a security standpoint? group of answer choices an arrangement in which a person may use computer or network services a record or statement of financial expenditure and receipts relating to a particular purpose a report or description of an event or experience to consider or regard in a specified way
from a security perspective, the idea of accountability keeping records of the actions you took or being accountable for keeping such records.
The correct option is C.
In a computer network, what is security?Any action intended to safeguard the integrity and usefulness of your network and data is referred to as network security. Software and hardware technologies are also a part of it. Numerous threats are targeted by it. They can't get on your network or spread there because of it. Network access is controlled by effective network security.
How critical is network security?The protection of sensitive data from cyberattacks and the maintenance of a reliable and functional network are two reasons why network security is crucial. Proper network security strategies use a variety of security tools to shield users and companies against malware and online threats like distributed denial of service.
To know more about computer network visit:
https://brainly.com/question/14276789
#SPJ4
Question is:
Which of the following definitions best matches the concept of accountability from a security standpoint?
A. Being able to explain your actions to figures of authority, such as a police officer or a manager
B. Having or being responsible to your records of actions you performed
C. The trustworthiness of a web site in holding bank account information
D. The principle of being judged for the purpose of punishment or reward
Recall your technology experience in the workplace or at home. When adopting a new technology, what specific problems were you or your employer trying to resolve?
Describe your biggest challenge in adopting new technologies based on your experience.
Share how you or your employer overcame these issues.
Answer:
Use of technology helps solve issues like file management, receipt tracking, report generation and growth tracking that often hamper employee productivity. Modern workplaces extensively rely on computer-aided tools for efficiency. These tools help cut down both the time and money needed for getting the job done.
How do you implement new technology in the workplace?
To help you streamline the process, here are steps for integrating new technology into your organization:
Identify Your Organization's Needs.
Investigate Technologies That Will Solve Problems for Your Organization.
Develop a Plan for Implementing Your New Technology.
Train Other Employees in Using the New Technology
Suppose you observe that your home PC is responding very slowly to information requests from the net. And then you further observe that your network gateway shows high levels of network activity, even though you have closed your email client., Web browser, and other programs that access the net. What types of malware could cause these symptoms
ANSWER: BOT
EXPLANATION: When a PC is experiencing the listed effects, it thus depicts that the PC is under attack by a bot, which is a type of script or software application that establishes automated tasks via command.
However, a bad bots often initiate malicious tasks that gives room for attackers to take control over an affected PC remotely, most especially for fraudulent activities.
When several affected computers are connected, they form a botnet connection.
Is it possible to beat the final level of Halo Reach?
wellconnect reflection
. A binary search has a right subtree but no left subtree. What noes contains that least element in the tree
The root node will contain the smallest element
The previous Discussions have provided the opportunity to share some elegant solutions to programming challenges, and many of them share one common trait—they all handle multiple objects with ease. Forget, for the moment, about some of the complexity involved. The formulas may seem strange, but do not worry. At this stage of programming, you are not expected to generate such things on your own; very few new programmers can. Instead, stop to consider the ways programs embrace the computer’s true assets.
Machines do not mind doing the same thing over and over again; they never get bored. They are also capable of handling massive amounts of data in an impeccably organized manner. One of your challenges as a programmer is to communicate, through code, in an efficient way that plays to the computer’s strengths.
Consider, for example, having to write a program to manage personnel records for all of the people working for your company. You certainly would not want to have to write a program with a unique variable for each unique person in the company. Every time a new employee was hired, someone would have to modify the program to add a new variable for that employee. Every time an employee left the company, someone would have to modify the program to remove that employee’s variable and data from the program. Clearly, this would be a very tedious way to automate personnel records. Instead, you need a way to manage that collection of personnel information in a more organized manner. In fact, you need a way of representing the collection of individual employees as just that, a single variable that provides access to all of the employees. Then, you can use loops to process the employee data. Fortunately, Java provides the concept of an array (and other similar collections, such as the ArrayList) to manage collections of similar objects.
It takes time to truly grasp how powerful object-oriented programming can be and how you can harness its "objects-first" focus to make your own programs concise and elegant. Unfortunately, some programmers do not invest that time. They rely on brute force—repetitive methods resulting in long programs that are, by nature, hard to review and debug.
Return to the open source repositories you previously explored. Find a program that (A) uses at least one loop and a list effectively or (B) could use a loop and a list to improve the program.
*. Response that summarizes your findings. The post should:
1. Include a copy of the code that either (A) exemplifies concise, generalized code or (B) presents the perfect opportunity to apply loops, arrays, and lists to reduce the length of the program using a more elegant solution. Do not undertake a lengthy program; limit your code to approximately 20 lines.
2. If the code is an exemplar of good coding, explain what leads you to that conclusion. Be specific.
3. If the code needs improvement, include a rewritten version of the code, in which you apply one of the methods described above to improve the program. Explain how your solution better embraces a computer’s strengths as a tool that can perform calculations quickly, perform repetitive tasks, and/or manage data effectively.
4. Add or revise comments in the code to accurately describe the function of the loop and list.
Do not include the entire source code of the program you choose. Select just the portion with the necessary information, such as variable declarations and methods called from outside the class or method.
Answer:
I can't make out the question
Is this real? Please help.
Answer: This is not real. the person is using bots to answer questions speedily.
Explanation:
The is context sensitive, meaning it will display options that relate to an active tool.
Answer:
Option bar
Explanation:
The Options Bar seems to be the parallel bar in photo editing software that operates under it's main menu. You will use the Software panel to turn it on and off, but if you're not seeing it on your phone, you probably want Software > Settings to power it on. The role of the Options Bar is to customize the tool settings when you're about to use.
Answer:
(A) The ribbon
Explanation: