Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 23.6, Problem 23.6.3CP
Program Plan Intro
Complete binary tree:
- A binary tree is said to be a complete if every level of the tree are full except the last level.
- The last level need not be full and all the leaves on the last level are placed left most.
Heap:
- A heap is considered to be binary tree if it has following properties
- When it is complete binary tree.
- Every node is greater than or equal to its children.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Please help with C++ question in image. Thank you.
A data structure known as a drop-out stack functions exactly like a stack, with the exception that if the stack size is n, the first element is lost when the n + 1 element is pushed. Use an array to implement a drop-out stack. (Hint: It would make sense to implement a circular array.)
4. Sort elements in an array-based stack in ascending order, i.e. make the smallest element
to be the top element of the stack. E.g. given the stack elements (from bottom to top):
90, 70, 80, 10, sort the elements to make the stack elements become (from bottom to
top): 90, 80, 70, 10. The only data structure you can use is array-based stack. In addition
to the given stack, you can use only one extra stack to store some temporary data. Given
a stack st, use one extra stack, tmpst, to store temporary data. Here are some hints of the
idea.
Pop out the top element of st to a variable tmp. If the stack tmpst is empty, push tmp
onto tmpst; if tmpst is not empty, pop out its top element and push that element
onto st until the top element of tmpst is smaller than tmp, then push tmp onto
tmpst ..
a. Write a program to implement the stack based sorting.
b. Take the input (90, 70, 80, 10) as an example.
c. Print all the push and pop operations in proper format.
d. At the end, print the sorted…
Chapter 23 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 23.2 - Prob. 23.2.1CPCh. 23.2 - Prob. 23.2.2CPCh. 23.2 - Prob. 23.2.3CPCh. 23.3 - Prob. 23.3.1CPCh. 23.3 - Prob. 23.3.2CPCh. 23.3 - Prob. 23.3.3CPCh. 23.4 - Prob. 23.4.1CPCh. 23.4 - Prob. 23.4.2CPCh. 23.4 - What is wrong if lines 615 in Listing 23.6,...Ch. 23.5 - Prob. 23.5.1CP
Ch. 23.5 - Prob. 23.5.2CPCh. 23.5 - Prob. 23.5.3CPCh. 23.5 - Prob. 23.5.4CPCh. 23.6 - Prob. 23.6.1CPCh. 23.6 - Prob. 23.6.2CPCh. 23.6 - Prob. 23.6.3CPCh. 23.6 - Prob. 23.6.4CPCh. 23.6 - Prob. 23.6.5CPCh. 23.6 - Prob. 23.6.6CPCh. 23.6 - Prob. 23.6.7CPCh. 23.6 - Prob. 23.6.8CPCh. 23.6 - Prob. 23.6.9CPCh. 23.7 - Prob. 23.7.1CPCh. 23.7 - Prob. 23.7.2CPCh. 23.8 - Prob. 23.8.1CPCh. 23 - Prob. 23.1PECh. 23 - Prob. 23.2PECh. 23 - Prob. 23.3PECh. 23 - (Improve quick sort) The quick-sort algorithm...Ch. 23 - (Check order) Write the following overloaded...Ch. 23 - Prob. 23.7PECh. 23 - Prob. 23.8PECh. 23 - Prob. 23.10PECh. 23 - Prob. 23.11PECh. 23 - Prob. 23.12PECh. 23 - Prob. 23.13PECh. 23 - (Selection-sort animation) Write a program that...Ch. 23 - (Bubble-sort animation) Write a program that...Ch. 23 - (Radix-sort animation) Write a program that...Ch. 23 - (Merge animation) Write a program that animates...Ch. 23 - (Quicksort partition animation) Write a program...Ch. 23 - (Modify merge sort) Rewrite the mergeSort method...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Programming language: Java Topic: linked listarrow_forwardHeap Operation 1. pq.Enqueue(28); 2. pq.Enqueue(2); 3. pq.Enqueue(40); 4. pq.Dequeue(x); 5. pq.Dequeue(y); 6. pq.Dequeue(z); 56 27 42 26 15 3 19 Values x, y, z? 25 24arrow_forwardConsider the Stack ADT: Stack: push(x) adds x to top of stack pop() removes top element of stack and returns it size() returns number of elements in stack Select all options that allow for an efficient implementation based on the discussions from class. For any array implementation, you can assume the array is large enough so that making a larger one is not needed when pushing an item to the stack. Using an array with the top at the front of the array. Using an array with the top at the back of the array. Using a singly linked list with the top at the head of the list. Using a singly linked list with the top at the tail of the list. ENGarrow_forward
- List-Based Heap Implementations: The book starts out by discussing the concept of a priority queue and how to implement it conceptually. Then, the first implementation is presented: using an array or Python sequence to represent the heap. Data Storage: The book stores elements of a priority queue within a custom object (an _Item) which wraps and provides almost no support for the stored data. For this section, you will be storing your key and value as an ordered pair (or tuple) of two values where the first element is the key and the second element is the value. 1. What are the inherent benefits and drawbacks of this (array-based) backing representation? Discuss with respect to implementation, efficiency, and memory usage. (PI 1.2/ABET[1], PI 6.1/ABET[6])arrow_forwardC-Language. Stacks or Trees. I am having issues with this program. I am trying to achieve this currently by using a stack in the C language. But I have reached a lull.arrow_forwardQ2- Draw the following list of numbers as a heap with the first number as the root: 77, 66, 55, 44, 60, 33, 55. After that insert 40. Note: Method of Solution based on book (Object-Oriented Data Structures Using Java Dale. Daniel T. Joyce: Chip Weems)arrow_forward
- The puzzle includes various sizes of coins. It starts with an order of size, taking the top one the least. The puzzle needs to be constructed to have a conical shape and consider these laws: In every step, you can push one coin; every move includes taking the upper coin from the stack and putting it on top of other stack or starting a new stack. None of the coins can be put on top of the smaller coin; finally, at any moment, at most L, various stacks can be in use. Make PDDL in a way it will not rely on A and L.arrow_forwardLab 18: Stack, SentenceReverser Use a stack to reverse the words of a sentence. Keep reading words until you have a word that ends in a period, adding them onto a stack. When you have a word with a period, pop the words off and print them. Stop when there are no more words in the input. For example, you should turn the input Mary had a little lamb. Its fleece was white as snow. into Lamb little a had mary. Snow as white was fleece its. Pay attention to capitalization and the placement of the period.arrow_forwardConsider the following code segment , The variable q is an object of type Queue, the variable s is an object of type Stack. peek method looks at the first element in the queue without removing it. the remove method removes the first element from the queue. add method adds an element to the and of the queue or add an element to the top of the stack. pop method removes an element from the top of the stack What would be the content of the variable q (8 numbers) after we complete the second while loop in the code for (int i = 30; i <= 40; i ++) { if(i % 3 == 0) q.add(i); } while (!q.isEmpty()) { s.add(q.peek()); s.add(q.peek()); q.remove(); } while (!s.isEmpty()) { q.add(s.pop()); }arrow_forward
- There is a data structure called a drop-out stack that behaves like a stack in every respect except that if the stack size is n, when the n + 1 element is pushed, the first element is lost. Implement a drop-out stack using an array. (Hint: A circular array implementation would make sense.)arrow_forwardData structures Javaarrow_forwardTowers of Hanoi. There is a story about Buddhist monks who are playing this puzzle with 64 stone disks. The story claims that when the monks finish moving the disks from one post to a second via the third post, time will end. Eschatology (concerns about the end of time) and theology will be left to those better qualified; our interest is limited to the recur- sive solution to the problem. A stack of n disks of decreasing size is placed on one of three posts. The task is to move the disks one at a time from the first post to the second. To do this, any disk can be moved from any post to any other post, subject to the rule that you can never place a larger disk over a smaller disk. The (spare) third post is provided to make the solution possible. Your task is using c++ write a recursive function that describes instructions for a solution to this problem. We don’t have graphics available, so you should output a sequence of instructions that will solve the problem. Hint: If you could…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education