Computer Science: An Overview (12th Edition)
12th Edition
ISBN: 9780133760064
Author: Glenn Brookshear, Dennis Brylow
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 8, Problem 28CRP
Explanation of Solution
The algorithm for given case is shown below:
Step 1: Move “targetValue1” to “QueueB”
Step 2: Move “targetValue2” to “QueueA”
Step 3: Repeat “QueueB” up to “targetValue1”
Set the “targetValue1” to the end of “QueueA”
Step 4: Repeat “QueueA” up to all its entries apart from the reversed elements are back in their original places...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write an algorithm that searches a sorted list of n items by dividing it into three sublists of almost n/3 items. This algorithm finds the sublist that might contain the given item and divides it into three smaller sublists of almost equal size. The algorithm repeats this process until it finds the item or concludes that the item is not in the list. Analyze your algorithm and give the results using order notation.
In a bank, customers wait in a queue (q0) for their turn to complete a transaction. Customers who come first are
served first. At a certain point when there are lots of customers waiting, a decision is taken to split the queue
elements into two empty queues q1 and q2. The customers are split based on the alphabetical order of their first
names. Customers with first name starting A-H are added to q1 while the others (first name starting I-Z) are
added to q2.
In an application, write a method named splitQueue (in an application) that accepts as parameters 3 queues, the
original queue (q0) and two empty queues (q1 and q2) to be filled as described above. Write also a main
method in which you read the first names of customers from the user, fill them into q0 and call the method
splitQueue to split q0 elements into q1 and q2. After the split display the elements of q1 first then those of q2.
The header of the method is:
public static void splitQueue ( Queue q0, Queue q1, Queue q2)
Note:…
Write a program for multilevel queue scheduling algorithm in Java. There must be two queues. First queue should use Round Robin algorithm with Time Quantum = 2 ms and the second queue should use First Come First Serve algorithm.
Chapter 8 Solutions
Computer Science: An Overview (12th Edition)
Ch. 8.1 - Give examples (outside of computer science) of...Ch. 8.1 - Prob. 2QECh. 8.1 - Prob. 3QECh. 8.1 - Prob. 4QECh. 8.1 - Prob. 5QECh. 8.2 - In what sense are data structures such as arrays,...Ch. 8.2 - Prob. 2QECh. 8.2 - Prob. 3QECh. 8.3 - Prob. 1QECh. 8.3 - Prob. 2QE
Ch. 8.3 - Prob. 3QECh. 8.3 - Prob. 4QECh. 8.3 - Modify the function in Figure 8.19 so that it...Ch. 8.3 - Prob. 7QECh. 8.3 - Prob. 8QECh. 8.3 - Draw a diagram representing how the tree below...Ch. 8.4 - Prob. 1QECh. 8.4 - Prob. 2QECh. 8.4 - Prob. 3QECh. 8.4 - Prob. 4QECh. 8.5 - Prob. 1QECh. 8.5 - Prob. 3QECh. 8.5 - Prob. 4QECh. 8.6 - In what ways are abstract data types and classes...Ch. 8.6 - What is the difference between a class and an...Ch. 8.6 - Prob. 3QECh. 8.7 - Suppose the Vole machine language (Appendix C) has...Ch. 8.7 - Prob. 2QECh. 8.7 - Using the extensions described at the end of this...Ch. 8.7 - In the chapter, we introduced a machine...Ch. 8 - Prob. 1CRPCh. 8 - Prob. 2CRPCh. 8 - (Asterisked problems are associated with optional...Ch. 8 - Prob. 4CRPCh. 8 - (Asterisked problems are associated with optional...Ch. 8 - Prob. 6CRPCh. 8 - Prob. 7CRPCh. 8 - Prob. 8CRPCh. 8 - Prob. 9CRPCh. 8 - Prob. 10CRPCh. 8 - Prob. 11CRPCh. 8 - Prob. 12CRPCh. 8 - Prob. 13CRPCh. 8 - Prob. 14CRPCh. 8 - Prob. 15CRPCh. 8 - Prob. 16CRPCh. 8 - Prob. 17CRPCh. 8 - Prob. 18CRPCh. 8 - Design a function to compare the contents of two...Ch. 8 - (Asterisked problems are associated with optional...Ch. 8 - (Asterisked problems are associated with optional...Ch. 8 - Prob. 22CRPCh. 8 - Prob. 23CRPCh. 8 - Prob. 24CRPCh. 8 - (Asterisked problems are associated with optional...Ch. 8 - Prob. 26CRPCh. 8 - Prob. 27CRPCh. 8 - Prob. 28CRPCh. 8 - Prob. 29CRPCh. 8 - Prob. 30CRPCh. 8 - Design a nonrecursive algorithm to replace the...Ch. 8 - Prob. 32CRPCh. 8 - Prob. 33CRPCh. 8 - Prob. 34CRPCh. 8 - Draw a diagram showing how the binary tree below...Ch. 8 - Prob. 36CRPCh. 8 - Prob. 37CRPCh. 8 - Prob. 38CRPCh. 8 - Prob. 39CRPCh. 8 - Prob. 40CRPCh. 8 - Modify the function in Figure 8.24 print the list...Ch. 8 - Prob. 42CRPCh. 8 - Prob. 43CRPCh. 8 - Prob. 44CRPCh. 8 - Prob. 45CRPCh. 8 - Prob. 46CRPCh. 8 - Using pseudocode similar to the Java class syntax...Ch. 8 - Prob. 48CRPCh. 8 - Identify the data structures and procedures that...Ch. 8 - Prob. 51CRPCh. 8 - In what way is a class more general than a...Ch. 8 - Prob. 53CRPCh. 8 - Prob. 54CRPCh. 8 - Prob. 55CRPCh. 8 - Prob. 1SICh. 8 - Prob. 2SICh. 8 - In many application programs, the size to which a...Ch. 8 - Prob. 4SICh. 8 - Prob. 5SICh. 8 - Prob. 6SICh. 8 - Prob. 7SICh. 8 - Prob. 8SI
Knowledge Booster
Similar questions
- A company "XYZ" is manufacturing two types of grinders, called X and Y. The grinders X and Y are kept in a row. Write an algorithm using the queue data structure to replace all grinders X in the row with grinder Y. Illustrate your algorithm for any sample input.arrow_forwardWrite a program to maintain a list of items as a circular queue, which is implemented using an array. Simulate insertions and deletions to the queue and display a graphical representation of the queue after every operation.arrow_forwardBasics of Nested Lists in Python Problem Description Consider an 8 × 8 table for a board game. Using two nested loops, initialize the board so that zeroes and ones alternate, as on a checkerboard: 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 . . . 1 0 1 0 1 0 1 0 Hint: Check whether i + j is even. In Python Pleasearrow_forward
- Suppose that we would like to implement a queue system for a commercial website. Given that the website offers 3 items for sale (or a list of items), each item has a limit quantity in stock. Implement a queue of customers, each customer can buy only a few number product among the available three items. Determine the item name, their quantity in stock; Specify a queue of n customers, each customer can buy k products from one item (k is different for each customer); Customers take turn to enter (enqueue) and leave (dequeue) the queue according to the FIFO order to purchase wanted products; If a customer successfully purchased products, then display a message and reduce the number of products in stock; otherwise, if the item has been run out, display a warning message. Implement the above problems in C/C++ using a Queue data structur. Write a main function for testing all written functions.arrow_forwardImagine a ballroom with two kinds of dancers: leaders and followers. Dancers of both kinds wait in two separate queues before entering the dance floor. When a leader arrives, it checks to see if there is a follower waiting. If so, they can both proceed. Otherwise it waits. Similarly, when a follower arrives, it checks for a leader and either proceeds or waits, accordingly. Make sure that the next pair of leader/follower may dance only after the previous pair is done.Write the pseudocode for leaders and followers that enforces these constraints.arrow_forwardWrite a pseudocode algorithm that sorts a list of n items by dividing it into three sublists of about n/3 items, sorting each sublist recursively and merging the three sorted sublists.arrow_forward
- In computer science and mathematics, the Josephus Problem (or Josephus permutation) is a theoretical problem. Following is the problem statement: There are n people standing in a circle waiting to be executed. The counting out begins at some point (rear) in the circle and proceeds around the circle in a fixed direction. In each step, a certain number (k) of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle. The task is to choose the place in the initial circle so that you are the last one remaining and so survive. For example, if n = 5 and k = 2, then the safe position is 3. Firstly, the person at position 2 is killed, then person at position 4 is killed, then person at position 1…arrow_forwardDevelop a Java program to traverse a graph using the breadth first strategy. You will need to use a queue to keep track of nodes visited. Your algorithm should visit every node in the graph. Make sure to mark nodes as visited so that they are not processed more than once. Use an adjacency list to represent the graph. Test your program on the graph shown below, starting with node A. The output of your program should be a string of characters (A, B, etc.) in the correct sequence of nodes traversed. A D Farrow_forwardDesign an algorithm to find the sorted list from two separate sorted lists of numbers and implement it in a programming language of your choice. For example, for the lists 2, 5, 7, 12, 13, 24 and 1, 6, 15, 17, 35, the output should be 1, 2, 5, 6, 7, 12, 13, 15, 17, 24, 35. What is the maximum number of comparisons your algorithm makes if the lengths of the two given lists are m and n, respectively? If one comparison takes one millisecond then how much time your algorithm will take for m = 10000, and n = 20000.arrow_forward
- Write a program in Java to implement Quick sort algorithm to sort a given set of elements and determine the time required to sort the elements. Repeat the experiment for different values of n, the number of elements in the list to be sorted and plot a graph of the time taken versus n. The elements can be read from keyboard, a file or can be generated using the random number generator.arrow_forwardI. Given a pointer to a singly linked linear list write an algorithm which will take every node that has in the information field a negative number and put it at the front of the list and deletes every node that has a value between 250 and 500 in its information field. You have one external pointer to the front of the list (don't forget trailing pointers).arrow_forwardDesign and implement an algorithm that gets as input a list of k integer values N1, N2,..., Nk as well as a special value SUM. Your algorithm must locate a pair of values in the list N that sum to the value SUM. For example, if your list of values is 3, 8, 13, 2, 17, 18, 10, and the value of SUM is 20, then your algorithm would output either of the two values (2, 18) or (3, 17). If your algorithm cannot find any pair of values that sum to the value SUM, then it should print the message ‘Sorry, there is no such pair of values’arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning