Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Programming Radix Sort 
You will implement Radix Sort on arrays of base 10 integers between 0 and 2,147,483,647
(Integer.MAX_VALUE). You will implement RadixSort in a new way using an array of Queues
to sort the values by digit. Your algorithm must run in at most O(n) time. I have given you a
simple implementation of a Queue (Queue.java) that inserts and removes elements in
constant time.

This is method signature Class to use Programming Radix Sort:

package sorting;

import java.util.Arrays;

public class RadixSorter{
    
    //returns the max value in the array
    //used to provide the k to counting sort
    private static int getMax(int[] arr) {
        int max = Integer.MIN_VALUE;
        for(int i: arr) {
            if(i>max)
                max = i;
        }
        return max;
        
    }
    
    public static void radixSort(int[] arr) {
        //Get the maximum to know how many digits I have
        int max = getMax(arr);
        
    }

}

 

 


And this is queue Class:

package sorting;

import java.util.NoSuchElementException;

public class Queue {
    
    private static class Node {
        int data;
        Node next;
        
        public Node(int data) {
            this.data = data;
            next = null;
        }
        
    }
    
    private Node front;
    private Node back;
    private int size;
    
    public void enqueue(int i) {
        Node toInsert = new Node(i);
        if(size==0) {
            front = toInsert;
            back = toInsert;
            size++;
        }
        else {
            back.next = toInsert;
            back = back.next;
            size++;
        }
    }
    
    public int dequeue() {
        if(size==0) {
            throw new NoSuchElementException("Queue is Empty");
        }
        int frontData = front.data;
        if(size==1) {
            front = null;
            back = null;
        }
        else {
            front = front.next;
        }
        size--;
        return frontData;
        
        
    }
    
    public int peek() {
        if(size==0) {
            throw new NoSuchElementException("Queue is Empty");
        }
        
        return front.data;
        
    }
    
    public boolean isEmpty() {
        return size==0;
    }

}

Expert Solution
Check Mark
Still need help?
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

The updated code doesn't handle the arary with negative numbers. Can you help update the code to handle negative numbers?

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

The updated code doesn't handle the arary with negative numbers. Can you help update the code to handle negative numbers?

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education