Question

C++ 6. Insertion sort is n^2 because every item has to be compared against every item....

C++

6. Insertion sort is n^2 because every item has to be compared against every item. What if instead of looping through the left hand you used a binary search on the left hand to find the insertion place. What would the new Big O be and why?

Homework Answers

Answer #1

Insertion Sort:

The insertion sort algorithm starts from the second element and puts this element at its exact location by swapping or interchange with the first element and so on until the end of the array.

  • Best case running time = O(n)
  • Worst-case running time = O(n2 )
  • Average case running time = O(n2)

In an already sorted array of size n, the total number of comparisons is n-1.

If we use binary search to find the location of the inserted element then also the run time complexity will remain the same as O(n2) but the number of comparisons will decrease.

The binary search will take O(log n) compare.

So, the total number of compare for sorting will be O(n log n).

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
Labour Relations- Chapter 3- U n i o n s : O b j e c...
Labour Relations- Chapter 3- U n i o n s : O b j e c t i v e s , P r o c e s s e s , S t r u c t u r e , a n d H i s t o r y Case Study- Little Eagle School Board The Little Eagle School Board employs 1300 full-time and 200 occasional elementary school teachers. Occasional teachers fill in for full-time teachers who...
CASE: Atlantic Airlines Case Atlantic Airlines issued $100 million in bonds in 2008. Because of the...
CASE: Atlantic Airlines Case Atlantic Airlines issued $100 million in bonds in 2008. Because of the firm's low credit rating (B3), the bonds were considered junk bonds. At the time of the issue, the 20 year bonds were paying a yield of 12 percent. Investor Tom Phillips thought the yield on the bonds was particularly attractive and called his broker, roger Brown, to ask for more information on the debt issue. Tom currently held Treasury bonds paying four (4) percent...
CASE STUDY: DATA WAREHOUSING AT VOLVO Every Volvo car has hundreds of microprocessors and sensors. Their...
CASE STUDY: DATA WAREHOUSING AT VOLVO Every Volvo car has hundreds of microprocessors and sensors. Their data is used in diagnosis and repair. It is also captured by Volvo, integrated with the company's CRM, dealership and product data stores, and stored for analysis. This enables Volvo to spot design and construction flaws early, enable proactive correction of faults, and see how its cars respond in accidents. Volvo sells about 400,000 cars per year. Each generates 100–150 kB of data per...
URGENT!! 6 Multiple Choice Questions with the correct answers from the article below. Authenticity has become...
URGENT!! 6 Multiple Choice Questions with the correct answers from the article below. Authenticity has become the gold standard for leadership. But a simplistic understanding of what it means can hinder your growth and limit your impact. Consider Cynthia, a general manager in a health care organization. Her promotion into that role increased her direct reports 10-fold and expanded the range of businesses she oversaw—and she felt a little shaky about making such a big leap. A strong believer in...
Item 5 In the case below, the original source material is given along with a sample...
Item 5 In the case below, the original source material is given along with a sample of student work. Determine the type of plagiarism by clicking the appropriate radio button. Original Source Material Student Version Other major issues involve the accepted methods by which fidelity is measured. There are two major methods described in the literature for fidelity measurement. The first is through mathematical measurement that calculates the number of identical elements shared between the real world and the simulation;...
QUESTION 6 Starbucks got it "right" because they created a consistent ________ no matter what franchise...
QUESTION 6 Starbucks got it "right" because they created a consistent ________ no matter what franchise you are in anywhere in the world. organization experience intervention effort 2 points QUESTION 7 Group conflict can lead to high quality decisions. True False QUESTION 9 Beth was recently hired to conduct a survey of employee attitudes for a large organization. As an OD consultant, her first step should be providing relevant scientific research. data gathering and diagnosis. joint action planning. evaluation. 2...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
In the case below please answer the following 4- 6 pages 1. State the ethical issues...
In the case below please answer the following 4- 6 pages 1. State the ethical issues 2. State the legal issues 3. Discuss the options/debate the issues 4. Discuss extra info needed to make decision Rina Cummings has worked three 12-hour shifts every week at Amazon’s gargantuan New York City warehouse, called JFK8, on Staten Island since it first began operations in late 2018. As a sorter on the outbound ship dock, her job is to inspect and scan a...