Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8720817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:07:07+00:00 2026-06-13T07:07:07+00:00

Insertion-sort works also on unordered array, like the example here shows. This statement in

  • 0

Insertion-sort works also on unordered array, like the example here shows. This statement in the title (or here) for some odd reason requires that you have an ordered array to implement priority-queue for the insertion sort, why does it have such requirement? What does this Wikipedia -thing here actually mean (the below screenshot)?

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:07:08+00:00Added an answer on June 13, 2026 at 7:07 am

    The article relates the usage of priority queue for sorting and how different implementations of priority queue correspond with familiar sorting algorithms.

    Let us consider ADT priority queue with operation pop() which takes out the “smallest” element as defined by a comparison function and push() which put a new element in the priority queue. Then sorting can be done by calling push() to push all elements in the unsorted array into the priority queue and calling pop() until the priority queue is empty and put the popped out element into an array (well, you can define a method empty() to check whether the ADT is empty).

    Psuedocode:

    unsorted[]
    sorted[]
    priority_queue q
    
    foreach element in unsorted
        q.push(element)
    
    i = 0
    while !q.empty()
        sorted[i] = q.pop()
        i = i + 1
    

    Then we talk about how to implement the priority queue. Typically, it is efficiently implemented with heap. However, it is not necessary to be heap – you can implement it in less efficient ways, which is with unordered array or ordered array as mentioned in Wikipedia article. As long as the implementation satisfy the requirement for the push() and pop() operations then it is fine.

    For unordered array, you can push() by placing the element directly just after the last element – since it is unordered. When you pop(), since the array is unordered, you need to search through the whole array and pick out the largest element. (Removal can be done easily, by swapping the last element in the unordered array to the position of the element being popped out). It is similar to selection sort, since you are essentially go through the list of unsorted elements (which is in the priority queue) and pick out the largest element to put into sorted portion.

    You can see that insertion operation in insertion sort is being done in the push() operation here.

    For ordered array, you can pop() by just taking out the first element (removal can be done easily by maintaining a starting index). But push() will require you to find out where to place the element to maintain the order (since it is an ordered array). This is the part where it closely resembles insertion sort, since you are trying to insert the current element to the sorted portion (the priority queue implemented as ordered array).

    You can see that selection operation in selection sort is being done in the pop() operation here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is about the analysis of insertion sort in the book 'Introduction to Algorithms'.
I have to sort an array of 10 numbers using insertion sort and display
I am making a c insertion sort and it works fine except that after
This program sorts the first n words from a file using insertion sort .
I am trying to sort an array using the insertion sort algorithm. The array
Insertion sort requires insertion of an element in sorted order by shifting the elements
Im using c++ and is using insertion sort Where in the insertion sort algoithm
The name says it all really. I suspect that insertion sort is best, since
The associativity of stream insertion operator is rtl, forgetting this fact sometimes cause to
So here is my problem: I am trying to do a form of insertion

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.