Describe a sorting algorithm using one stack

Assignment Help Basic Computer Science
Reference no: EM131544518

Use pseudocode to describe a sorting algorithm using one stack, one queue, and a constant number of variables. The integers to sort are initially stored in unsorted order on the stack; once the algorithm terminates, they should appear in sorted order on the stack, with the largest element at the bottom. Your pseudocode can use the following data items:

  • A stack S that can store elements of type int, and supports the operations push, pop, peek, and isEmpty;
  • a queue Q that can store elements of type int, and supports the operations add, remove, element, and isEmpty;
  • a constant number of variables of type int.

No other data structures can be used by your algorithm.

Your algorithm should satisfy the following pre- and postconditions:

Precondition: The stack S contains n distinct integers a1, . . . , an and the queue Q is empty.

Postcondition: The stack S contains n distinct integers b1,...,bn in the order from bottom to top, such that b1 > b2 > ··· > bn and {a1,...,an} = {b1,...,bn}.

Ideally, your algorithm has a worst-case running time of O(n2), assuming each stack and queue operation takes only constant time. You will get partial marks for an implementation that does not achieve this running time.

Argue informally why your algorithm is correct and state its running time.

Reference no: EM131544518

Questions Cloud

What are appropriate loan rates for each firm : What are the appropriate loan rates for each firm?
Describe the areas of potential interference : Frequencies used in each one of the access points. Describe the areas of potential interference. Describe your solutions to interference.
Adopting and implementing a policy governance model : "Adopting and Implementing a Policy Governance Model" discusses the mergers of two hospitals with different philosophies of governance.
Money manager seeking to increase portfolio yield : You are a money manager seeking to increase portfolio yield.
Describe a sorting algorithm using one stack : Use pseudocode to describe a sorting algorithm using one stack, one queue, and a constant number of variables.
Creation of a data warehouse : Use the credit card database from Week One as a basis for the creation of a data warehouse.
What has scott already tried to help improve his situation : Watch the STPC demonstration video in the Mental Health Facilitator Module "Solving Problems and Setting Goals."
Term paper-website migration project : Tony's Chips has recently been sold to a new independent company. The new company has hired you to manage a project that will move the old Website.
How can you use myplate to create a healthy meal plan : Why is it important to eat a balanced snack? What can you do to ensure your snacks are nutritious? How can you use MyPlate to create a healthy meal plan

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What is meant by artificial intelligence

What is meant by artificial intelligence? What are two essential differences between human brains and the central processing unit of a computer.

  Design and implement a user interface

Design and implement a user interface that provides search and display functions.

  The poisson distribution with parameter ramda?

a) the "distribution" where N is the same fixed number with probability 1?b) the Poisson distribution with parameter ramda?

  Performs file management and backups

A corporate executive contacts you, the systems administrator, to ask how your company performs file management and backups.

  Key concept in information systems

Use the Internet or the Strayer Library to research one (1) concept in information systems that you have studied in this course. You may select a topic of your choice or you may use one (1) of the following:

  Determining the president of united states

Who is the president of united states? and how old is the president? does she have a daughter?

  Factors affect storage speed

What factors affect storage speed?

  Explaining health insurance portability-accountability act

Based on your knowledge of IT security management, argue for or against assertions that Epworth system is in compliance with Health Insurance Portability and Accountability Act (HIPAA).

  Formula for the exponential function

Find a formula for the exponential function passing through the points ( -3, 3/8) and (3, 24)

  Draw the flow graph for computation

Develop an inverse radix-2 DIT FFT algorithm starting with the definition. Draw the flow graph for computation and compare with the corresponding flow graph for the direct FFT. Can the IFFT flow graph be obtained from the one for the direct FFT?

  Analyze the network and propose improvement plans

Select a network you are familiar with, or from one of the Virtual Organizations (Riordan Manufacturing or Kudler Foods).  Write a 5- to 8-page paper (use diagrams, tables and charts whenever possible) to analyze the network and propose improvement..

  Explaining the most common security threats

Create a 10-slide basic or interactive presentation explaining the most common security threats, modern threats to current Client and Network Operating Systems, Encryption, Authentication, and Hashing. Include the narrator notes as a separate atta..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd