QuickSort Recursion

Hello,
I am trying to create a programme where a user has to input 8 integers into an array, and it quicksorts them using an array.
I have the QuickSort programme ready which is:
* 8th of September 2008
* Let a user input different numbers, and quick sort them automatically
public class QuickSort
    public void quickS(int start, int finish, int [] array)
        int [] quickS = {a, b, c, d, e, 8, 1};
        int pivot, left, right, temp;
        left = start;
        right = finish;
        pivot = array[ (left+right)/2];
        while (right > left)
            while (array[ left] < pivot)
                left = left + 1;
            while (pivot < array[ right])
                right = right - 1;
            if (left <= right)
                temp = array[ left];
                array[ left] = array[ right];
                array[ right] = temp;
                left = left + 1;
                right = right - 1;
        if (start < right) quickS(start, right, array);
        if (left < finish) quickS(left, finish, array);
}Now I am trying to create another class, which lets a user input integers into an array of size 8. But how do I do that? I've tried several ways and it is not working.
Thank you,

I have 3 files, one called SavitchInt which reads entries from Keyboard, other QuickSort which is posted above, and one called QuickSortMain which is the main class.
The code is below:
public class QuickSortMain
    public static void main (String [] args)
        int[] quickS = new int[8];
        for (int i = 0; i < 8; i++)
            int num = SavitchIn.readLineInt();
            quickS[i] = num;
        System.out.println(quickS);
}Now somewhere here, I must send off the keyboard inputs to QuickSort
How should I do that?
Thanks

Similar Messages

  • A replacement for the Quicksort function in the C++ library

    Hi every one,
    I'd like to introduce and share a new Triple State Quicksort algorithm which was the result of my research in sorting algorithms during the last few years. The new algorithm reduces the number of swaps to about two thirds (2/3) of classical Quicksort. A multitude
    of other improvements are implemented. Test results against the std::sort() function shows an average of 43% improvement in speed throughout various input array types. It does this by trading space for performance at the price of n/2 temporary extra spaces.
    The extra space is allocated automatically and efficiently in a way that reduces memory fragmentation and optimizes performance.
    Triple State Algorithm
    The classical way of doing Quicksort is as follows:
    - Choose one element p. Called pivot. Try to make it close to the median.
    - Divide the array into two parts. A lower (left) part that is all less than p. And a higher (right) part that is all greater than p.
    - Recursively sort the left and right parts using the same method above.
    - Stop recursion when a part reaches a size that can be trivially sorted.
     The difference between the various implementations is in how they choose the pivot p, and where equal elements to the pivot are placed. There are several schemes as follows:
    [ <=p | ? | >=p ]
    [ <p | >=p | ? ]
    [ <=p | =p | ? | >p ]
    [ =p | <p | ? | >p ]  Then swap = part to middle at the end
    [ =p | <p | ? | >p | =p ]  Then swap = parts to middle at the end
    Where the goal (or the ideal goal) of the above schemes (at the end of a recursive stage) is to reach the following:
    [ <p | =p | >p ]
    The above would allow exclusion of the =p part from further recursive calls thus reducing the number of comparisons. However, there is a difficulty in reaching the above scheme with minimal swaps. All previous implementation of Quicksort could not immediately
    put =p elements in the middle using minimal swaps, first because p might not be in the perfect middle (i.e. median), second because we don’t know how many elements are in the =p part until we finish the current recursive stage.
    The new Triple State method first enters a monitoring state 1 while comparing and swapping. Elements equal to p are immediately copied to the middle if they are not already there, following this scheme:
    [ <p | ? | =p | ? | >p ]
    Then when either the left (<p) part or the right (>p) part meet the middle (=p) part, the algorithm will jump to one of two specialized states. One state handles the case for a relatively small =p part. And the other state handles the case for a relatively
    large =p part. This method adapts to the nature of the input array better than the ordinary classical Quicksort.
    Further reducing number of swaps
    A typical quicksort loop scans from left, then scans from right. Then swaps. As follows:
    while (l<=r)
    while (ar[l]<p)
    l++;
    while (ar[r]>p)
    r--;
    if (l<r)
    { Swap(ar[l],ar[r]);
    l++; r--;
    else if (l==r)
    { l++; r--; break;
    The Swap macro above does three copy operations:
    Temp=ar[l]; ar[l]=ar[r]; ar[r]=temp;
    There exists another method that will almost eliminate the need for that third temporary variable copy operation. By copying only the first ar[r] that is less than or equal to p, to the temp variable, we create an empty space in the array. Then we proceed scanning
    from left to find the first ar[l] that is greater than or equal to p. Then copy ar[r]=ar[l]. Now the empty space is at ar[l]. We scan from right again then copy ar[l]=ar[r] and continue as such. As long as the temp variable hasn’t been copied back to the array,
    the empty space will remain there juggling left and right. The following code snippet explains.
    // Pre-scan from the right
    while (ar[r]>p)
    r--;
    temp = ar[r];
    // Main loop
    while (l<r)
    while (l<r && ar[l]<p)
    l++;
    if (l<r) ar[r--] = ar[l];
    while (l<r && ar[r]>p)
    r--;
    if (l<r) ar[l++] = ar[r];
    // After loop finishes, copy temp to left side
    ar[r] = temp; l++;
    if (temp==p) r--;
    (For simplicity, the code above does not handle equal values efficiently. Refer to the complete code for the elaborate version).
    This method is not new, a similar method has been used before (read: http://www.azillionmonkeys.com/qed/sort.html)
    However it has a negative side effect on some common cases like nearly sorted or nearly reversed arrays causing undesirable shifting that renders it less efficient in those cases. However, when used with the Triple State algorithm combined with further common
    cases handling, it eventually proves more efficient than the classical swapping approach.
    Run time tests
    Here are some test results, done on an i5 2.9Ghz with 6Gb of RAM. Sorting a random array of integers. Each test is repeated 5000 times. Times shown in milliseconds.
    size std::sort() Triple State QuickSort
    5000 2039 1609
    6000 2412 1900
    7000 2733 2220
    8000 2993 2484
    9000 3361 2778
    10000 3591 3093
    It gets even faster when used with other types of input or when the size of each element is large. The following test is done for random large arrays of up to 1000000 elements where each element size is 56 bytes. Test is repeated 25 times.
    size std::sort() Triple State QuickSort
    100000 1607 424
    200000 3165 845
    300000 4534 1287
    400000 6461 1700
    500000 7668 2123
    600000 9794 2548
    700000 10745 3001
    800000 12343 3425
    900000 13790 3865
    1000000 15663 4348
    Further extensive tests has been done following Jon Bentley’s framework of tests for the following input array types:
    sawtooth: ar[i] = i % arange
    random: ar[i] = GenRand() % arange + 1
    stagger: ar[i] = (i* arange + i) % n
    plateau: ar[i] = min(i, arange)
    shuffle: ar[i] = rand()%arange? (j+=2): (k+=2)
    I also add the following two input types, just to add a little torture:
    Hill: ar[i] = min(i<(size>>1)? i:size-i,arange);
    Organ Pipes: (see full code for details)
    Where each case above is sorted then reordered in 6 deferent ways then sorted again after each reorder as follows:
    Sorted, reversed, front half reversed, back half reversed, dithered, fort.
    Note: GenRand() above is a certified random number generator based on Park-Miller method. This is to avoid any non-uniform behavior in C++ rand().
    The complete test results can be found here:
    http://solostuff.net/tsqsort/Tests_Percentage_Improvement_VC++.xls
    or:
    https://docs.google.com/spreadsheets/d/1wxNOAcuWT8CgFfaZzvjoX8x_WpusYQAlg0bXGWlLbzk/edit?usp=sharing
    Theoretical Analysis
    A Classical Quicksort algorithm performs less than 2n*ln(n) comparisons on the average (check JACEK CICHON’s paper) and less than 0.333n*ln(n) swaps on the average (check Wild and Nebel’s paper). Triple state will perform about the same number of comparisons
    but with less swaps of about 0.222n*ln(n) in theory. In practice however, Triple State Quicksort will perform even less comparisons in large arrays because of a new 5 stage pivot selection algorithm that is used. Here is the detailed theoretical analysis:
    http://solostuff.net/tsqsort/Asymptotic_analysis_of_Triple_State_Quicksort.pdf
    Using SSE2 instruction set
    SSE2 uses the 128bit sized XMM registers that can do memory copy operations in parallel since there are 8 registers of them. SSE2 is primarily used in speeding up copying large memory blocks in real-time graphics demanding applications.
    In order to use SSE2, copied memory blocks have to be 16byte aligned. Triple State Quicksort will automatically detect if element size and the array starting address are 16byte aligned and if so, will switch to using SSE2 instructions for extra speedup. This
    decision is made only once when the function is called so it has minor overhead.
    Few other notes
    - The standard C++ sorting function in almost all platforms religiously takes a “call back pointer” to a comparison function that the user/programmer provides. This is obviously for flexibility and to allow closed sourced libraries. Triple State
    defaults to using a call back function. However, call back functions have bad overhead when called millions of times. Using inline/operator or macro based comparisons will greatly improve performance. An improvement of about 30% to 40% can be expected. Thus,
    I seriously advise against using a call back function when ever possible. You can disable the call back function in my code by #undefining CALL_BACK precompiler directive.
    - Like most other efficient implementations, Triple State switches to insertion sort for tiny arrays, whenever the size of a sub-part of the array is less than TINY_THRESH directive. This threshold is empirically chosen. I set it to 15. Increasing this
    threshold will improve the speed when sorting nearly sorted and reversed arrays, or arrays that are concatenations of both cases (which are common). But will slow down sorting random or other types of arrays. To remedy this, I provide a dual threshold method
    that can be enabled by #defining DUAL_THRESH directive. Once enabled, another threshold TINY_THRESH2 will be used which should be set lower than TINY_THRESH. I set it to 9. The algorithm is able to “guess” if the array or sub part of the array is already sorted
    or reversed, and if so will use TINY_THRESH as it’s threshold, otherwise it will use the smaller threshold TINY_THRESH2. Notice that the “guessing” here is NOT fool proof, it can miss. So set both thresholds wisely.
    - You can #define the RANDOM_SAMPLES precompiler directive to add randomness to the pivoting system to lower the chances of the worst case happening at a minor performance hit.
    -When element size is very large (320 bytes or more). The function/algorithm uses a new “late swapping” method. This will auto create an internal array of pointers, sort the pointers array, then swap the original array elements to sorted order using minimal
    swaps for a maximum of n/2 swaps. You can change the 320 bytes threshold with the LATE_SWAP_THRESH directive.
    - The function provided here is optimized to the bone for performance. It is one monolithic piece of complex code that is ugly, and almost unreadable. Sorry about that, but inorder to achieve improved speed, I had to ignore common and good coding standards
    a little. I don’t advise anyone to code like this, and I my self don’t. This is really a special case for sorting only. So please don’t trip if you see weird code, most of it have a good reason.
    Finally, I would like to present the new function to Microsoft and the community for further investigation and possibly, inclusion in VC++ or any C++ library as a replacement for the sorting function.
    You can find the complete VC++ project/code along with a minimal test program here:
    http://solostuff.net/tsqsort/
    Important: To fairly compare two sorting functions, both should either use or NOT use a call back function. If one uses and another doesn’t, then you will get unfair results, the one that doesn’t use a call back function will most likely win no matter how bad
    it is!!
    Ammar Muqaddas

    Thanks for your interest.
    Excuse my ignorance as I'm not sure what you meant by "1 of 5" optimization. Did you mean median of 5 ?
    Regarding swapping pointers, yes it is common sense and rather common among programmers to swap pointers instead of swapping large data types, at the small price of indirect access to the actual data through the pointers.
    However, there is a rather unobvious and quite terrible side effect of using this trick. After the pointer array is sorted, sequential (sorted) access to the actual data throughout the remaining of the program will suffer heavily because of cache misses.
    Memory is being accessed randomly because the pointers still point to the unsorted data causing many many cache misses, which will render the program itself slow, although the sort was fast!!.
    Multi-threaded qsort is a good idea in principle and easy to implement obviously because qsort itself is recursive. The thing is Multi-threaded qsort is actually just stealing CPU time from other cores that might be busy running other apps, this might slow
    down other apps, which might not be ideal for servers. The thing researchers usually try to do is to do the improvement in the algorithm it self.
    I Will try to look at your sorting code, lets see if I can compile it.

  • How to limit threads in a Java QuickSort algorithm.

    With the following piece of code, I quickly run into OutOfMemory exceptions, since the code starts creating Threads exponentially. However, after waiting for a long time (for all the exception texts to print out, obviously making it slower than running it with one thread only), the program eventually ends with the correct result. Is there a way to run the code as is, but making sure that no more that x threads are running at a time?
    things I have tried:
    - sleeping the current thread - makes it slower than one-thread.
    - looping blank while Thread.activeCount() > x - doesnt work at all
    - suspending resuming threads based on the activeCount - doesnt work too
    Code:
    import java.util.*;
    import java.io.*;
    public class ThreadedSort extends Thread{
    private ArrayList<Integer> _list;
         public ThreadedSort()
              _list = new ArrayList<Integer>();
         public ThreadedSort(ArrayList<Integer> List)
              _list = List;
         public void run()
              threadQuickSort();
    public void threadQuickSort()
              try{
    if (_list.size() < 2)
    return;
    Integer pivot = new Integer(_list.get(_list.size()-1));
              ArrayList<Integer> left = new ArrayList<Integer>();
              ArrayList<Integer> right = new ArrayList<Integer>();
    //ListIterator iter = arr.listIterator();
              // *** optimize here
    for (int i = 0; i < _list.size()-1; i++) {
                   Integer next = (Integer)_list.get(i);
                   if (next <= pivot)
                        left.add(next);
                   else
                        right.add(next);
              ThreadedSort LeftThread = new ThreadedSort(left);
              ThreadedSort RightThread = new ThreadedSort(right);
    //          System.out.println(Thread.currentThread().getName()+" --> "+Thread.activeCount());
    //          Thread.sleep(4000);
              LeftThread.start();
              RightThread.start();
    //          System.out.println(Thread.currentThread().getName()+" --> "+Thread.activeCount());
              LeftThread.join();
              RightThread.join();
              _list.clear();
              list.addAll(LeftThread.list);
              _list.add(pivot);
              list.addAll(RightThread.list);
              }catch (InterruptedException ie) { ie.printStackTrace(); }
              return;
    public static void main(String[] args) { ///////////////////////////////////////////
              Random rand = new Random();
              ArrayList arr1 = new ArrayList();
              long before_threadedQuickSort, after_threadedQuickSort;
              try{
              FileWriter fout = new FileWriter("out.txt");
              BufferedWriter bw = new BufferedWriter(fout);
              before_populate = System.currentTimeMillis();
              for (int i = 0; i< 2000; i++){//***
                   arr1.add(rand.nextInt(2000000));
              after_populate = System.currentTimeMillis();
              ThreadedSort sorter3 = new ThreadedSort(new ArrayList(arr1));
              before_threadedQuickSort = System.currentTimeMillis();
              sorter3.start();
              sorter3.join();
              after_threadedQuickSort = System.currentTimeMillis();
              bw.write("time for threadedQuickSort: " + (after_threadedQuickSort - before_threadedQuickSort)); bw.newLine();
              bw.newLine();
              arr1.clear();
              bw.close();
              }catch (Exception IOException){};
              System.out.printf("\n\n");
    } //end of main
    } //end of class

    So you dont have to go thru the code:
    Quicksort:
    with one thread only I start the sorting by choosing a pivot from the initial list and then generating a left list (all values less then pivot) and a right list (all values greater then pivot).
    then i recursively call quicksort with the left and right lists.
    with one thread that works fine.
    threadedQuickSort:
    each thread object has a variable _list that keeps its list.
    from the initial thread, i do generate again two lists (left and right) but then i construct two threadable objects with those lists and start them, creating for each list a new thread.
    so each thread will create two new threads.
    for a initial list with up to 2000 rows, that yields to the correct result although much slower than the one-threaded version. maximum number of threads ever used was around 500~600.
    for a list with 20000 rows, my machine chokes at around 2600 threads. (OutOfMemory exception)
    My Processor is a 8 core (each core can run up to two threads) giving me a total of 16 actual threads i can work with.
    So the question is how to limit the threads that are created to 16. There is no method in the Thread class where you can specify the max number of threads in a threadgroup.
    @ jverd:
    I looked at ThreadPoolExecutor, but it looks kinda complicated. I see that the idea is creating a queue of jobs to be executed (which would be the different sublists (left and right lists), and then using the specified number of threads to work with the queued jobs, but im failing to understand how it works. Can you point to a simple example somewhere showing how to declare a ThreadPoolExecutor object and work with it. thanks

  • Sorting with TreeMap vs. quicksort

    I've been sorting lists by throwing them into a TreeMap then retrieving them in order (especially for fairly evenly distributed lists of strings), thereby leveraging its binary tree characteristics.
    My belief is that sorting this way takes N log N time, just as quicksort (as in Arrays.sort) does -- because adding items to a TreeMap takes log N time -- without any danger of stack overflows from recursing on a huge list as with quicksort, and fewer method calls which can get expensive.
    I'm figuring that even if this way of sorting uses more memory than an in-place sort as in Arrays.sort, at least it won't overflow the stack, and will mostly be eligible for garbage collection anyway.
    Could someone correct or confirm my conclusions, reasoning or assumptions? And how well do they apply to Collections.sort's merge sort?

    Using a tree guarentees worst case O(n log n) for n
    inserts.Amazing, my untrained intuition was correct.
    As for stack problems these are unlikely to occur until
    logn is at least a few thousand (think about stupidly large values of
    n).I regularly need to sort lists of tends of thousands of strings.
    .. its [quicksort's] gotcha is that
    performance can degrade well below this approaching
    O(n^2) (might be higher. I cant remember).Yes, O(n^2) for adversarial data. Does mergesort require a shallower recursion than quicksort does?
    Since temporary use of the heap is rarely a concern for me, and datasets are very large, it sounds like mergesort and the TreeMap are viable contenders for preferred sorting methods. But I'm still apprehensive about mergesort's use of recursion.
    Thank you, I gave you 5 duke dollars and matei 2.

  • Need help on quicksorting LinkedLists

    Ok so I have my code below. It's just standard methods for a linkedlist but we weren't allowed to use LinkedList itself. I know how quicksorting works but I don't know how I can make two separate lists to recursively sort those and then connect them again. It was recommended to use the first Node as the pivotNode. Can anyone help me out?
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.PrintStream;
    public class WordList {
         private class Node
              String data;
              Node next;
              Node(String dat, Node n)
                   data = dat;
                   next = n;
              Node(String dat)
                   data = dat;
                   next = null;
         private Node head;
         private Node last;
         BufferedReader br;
         FileReader fr;
         public WordList(File f)
              head = null;
              last = null;
              try
              fr = new FileReader(f);
              br = new BufferedReader(fr);
              catch(FileNotFoundException e)
                   System.out.println("This file was not found.");
         public WordList(BufferedReader br)
              head = null;
              last = null;
              this.br=br;
         public boolean isEmpty()
              return head == null;
         public int size()
              int count = 0;
              Node fir = head;
              while(fir!=null)
                   count++;
                   fir = fir.next;
              return count;
         public void add(String s)
              if(isEmpty())
                   head = new Node(s);
                   last = head;
              else
                   last.next = new Node(s);
                   last = last.next;
         public void add(int index, String s)
              if(index<0||index>size())
                   throw new IndexOutOfBoundsException(String.valueOf(index));
              if(index==0)
                   head = new Node(s, head);
                   if(last==null)
                        last = head;
                   return;
              Node prev = head;
              for(int i=1;i<=index-1;i++)
                   prev = prev.next;
              prev.next = new Node(s, prev.next);
              if(prev.next.next==null)
                   last=prev.next;
         public void display(PrintStream ps)
              Node fir = head;
              while(fir!=null)
                   ps.println(fir);
                   fir = fir.next;
         public String remove(int index)
              if(index<0||index>=size())
                   throw new IndexOutOfBoundsException(String.valueOf(index));
              String elt;
              if(index==0)
                   elt = head.data;
                   head = head.next;
                   if(head==null)
                        last = null;
              else
                   Node prev = head;
                   for(int i = 1;i<=index-1;i++)
                        prev = prev.next;
                   elt = prev.next.data;
                   prev.next = prev.next.next;
              if(prev.next==null)
                   last = prev;
              return elt;
         public boolean remove(String strData)
              if(isEmpty())
                   return false;
              if(strData.equals(head.data))
                   head = head.next;
                   if(head==null)
                        last = null;
                   return true;
              Node prev = head;
              while(prev.next!=null&&!prev.next.data.equals(strData))
                   prev = prev.next;
              if(prev.next==null)
                   return false;
              prev.next = prev.next.next;
              if(prev.next==null)
                   last = prev;
              return true;
         public void sort()
              Node pivotNode=head;
    }

    benman wrote:
    I know in quicksort you have to remove the pivot so obviously I'll remove head but what do you mean by replacing head at the end? I'm sorry; I'm overloading words.
    I mean, if your class is a wrapper to an internal linked list, and as such has a reference to the head, and you sort by creating new lists, then when you're done sorting you'll have a new linked list, so you'd make the head reference point to the head of this new list. By "at the end" I meant "when you're done sorting."
    wouldn't i just set last.next in the smaller list equal to head in the bigger?Yeah (assuming you're manipulating your own list implementation and not working through an abstraction like java.util.List); I was referring to something else.

  • Quicksort with Median of Medians Method.

    I am trying to test the MM, (Median of Medians method), to see that it has O(n) complexity. I can not get it to work, it is in part because I don't understand how to incorperate the MM code in to the Quicksort Method. Also note that there is an error in my Quick sort, the list sorts to some extent. I am trying to figure that out. So, all in all I have two problems... Here is what I have:
    public class MMQuickSort
         private static long comparisons = 0;
         private static long exchanges = 0;
         static final int numberofgroups = 5;
         private static int groupsize = 0;
              public static void Quicksort(int[] a)
                   // shuffle(a);           // to guard against worst-case and makes average = best = O(nlogn) without MM.
                    groupsize = a.length / numberofgroups;
              QuickSort(a, 0, a.length);
         public static void QuickSort(int[] inarray, int low, int high)
              int thepivot, position = 0;
                   if (low < high)
                        thepivot = Partition(inarray, low, high, high - 1);
                        QuickSort(inarray, low, thepivot - 1);
                        QuickSort(inarray, thepivot + 1, high);
         public static int Partition(int[] inarray, int low, int high, int pivot)
              int v = inarray[low];
              int j = low;
              int temp;
              //int moveleft = high + 1;
              //int v = inarray[low];
              for (int i = low + 1; i < high; i++)
                   if (inarray[i] < v)
                        j++;
                        temp = inarray;
                        inarray[i] = inarray[j];
                        inarray[j] = temp;
                   pivot = j;
                   temp = inarray[low];
                   inarray[low] = inarray[pivot];
                   inarray[pivot] = temp;
              return pivot;
         public static int Select(int a[], int n, int k)
              int pivot= 0;
              if (n <= numberofgroups)
                   Quicksort(a);
              else
                   pivot = Select(a, a.length / numberofgroups, ((int)Math.ceil(a.length / numberofgroups / 2)));
              if (k == pivot)
                   return k;
              else if (k < pivot)
                   return Select(a, pivot - 1, k);
              else
                   return Select(a, n - pivot, k - pivot);
    To get it to work I call:
    Quicksort(data) 
    where "data" is a dis-ordered array of n elements.
    Any thoughts would be much appreciated.
    Thank you,
    Brian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    it would be good if you posted the exception next time
    the exception occurs in the partition() method, on the line
    while (less(a[++i], v)) ;it appears that l = 13 and r = 12, and a[++i] = a[13], a[14], a[15]... are all less than v = a[12]
    "l" probably shouldn't be greater than "r"
    on closer examination, it appears that your quicksort() algorithm has no base case. it keeps partitioning and making recursive calls until the subarray you are partitioning over has negative size (?)

  • QuickSort Problems

    I am trying to write a QuickSort to sort an ArrayList of random integers passed from another class. If it is given 5 2 7 6 9 0 8 1 3 4 it finishes with the ArrayList holding 0 1 2 4 3 5 7 6 8 9
    is this a problem with my logic or just a minor programming error? I am using the first item in the ArrayList as the pivot, partitioning, and then swapping the pivot into position and recursively running quicksort(start,pivot-1) and quicksort(pivot+1,end)
    import java.util.*;
    public class QuickSort
    ArrayList<Integer> data;
    public QuickSort(ArrayList<Integer> datax)
    data=datax;
    public void quicksort(int start, int end)
    if (start < end)
    int pivot = partition(start, end);
    quicksort(start, pivot-1);
    quicksort(pivot+1, end);
    public int partition(int start, int end)
    int pivot = data.get(start);
    int l = start + 1;
    int r = end;
    while (l < r)
    while (l < end && data.get(l) < pivot) l++;
    while (r > start && data.get(r) >= pivot) r--;
    if (l < r)
    swap(l,r);
    swap(start,r);
    return r;
    public void swap(int index1, int index2)
    int temp=data.get(index1);
    data.set(index1,data.get(index2));
    data.set(index2,temp);
    }

    What happens when your partition method is passed a range that contains two numbers that are already sorted?

  • Problems defining the array for quicksort

    import java.io.*;
    import java.util.*;
    import chn.util.*;
    public class Store
              private Item [] myStore;
              public Store (String fileName) {
                   fileName = "file50.txt";
    /*          public void displayStore ()       
              public String toString () { }
              public void doSort () { }
    */          private void quickSort (Item[] lit, int lo, int hi)   // I don't exactly know what Item[ ] lit will do. please explain it for me.
              int h, l, p, t;
            if (lo < hi) { 
                l = lo;
                h = hi;
          /*      p = a[hi];     //my problem starts with the array 'a' (suppose to be item, but don't know how to modify that.
                do {
                    while ((l < h) && (a[l] <= p)) l++;
                    while ((h > l) && (a[h] >= p)) h--;
                    if (l < h) {
                        t = a[l];
                        a[l] = a[h];
                        a[h] = t;
                } while (l < h);
                t = a[l];
                a[l] = a[hi];
                a[hi] = t;
              private void loadFile (String inFileName)
                   FileInput inFile = new FileInput (inFileName = "file50.txt");
    }The array 'a' should be replaced with the array 'Item' but some how I'm getting the errors that Item's not a valid type.
    for more information, please see http://forum.java.sun.com/thread.jspa?threadID=699397&tstart=60 for more information (the original problem)

    Here is what I suggest.
    Use collections. I suggest an ArrayList. Using one array involves all sort of messy swapping around which really will make things difficult for you to grasp the basic concept of.
    So let us assume a method like this
    public void quicksort(List items)
    items is a List of Items.
    So here is how to write a quicksort
    1) If the size of the list is 1 then return the list because it is down to it's final piece and doesn't need to be sorted further
    2) Choose a pivot element of your list. The mid point is often chosen for this.
    3) Create two new Lists. One for lower elements and one for higher and equal to elements.
    4) Go through the list and use compareTo to compare the elements of the list with your pivot element. Take care to skip the pivot element. If elements are less than the pivot put them in the first list. If they are more than or equal to put them in the second list.
    5) Recursively call quicksort(list) on the sublists we made.
    6) Merge the sublists and pivot values back into one list
    7) return the merged list

  • Infinite recursion - base case ignored and stack overflowed

    Hi, I've been having this logic error for 2 days, and I cannot fix it. Right now, I can barely see anything because I was looking at computer screen for 10 hours. The code I'm writing is a program that allows the user to play a list of MP3 files in a folder. Among commands we have to make, we have to sort the list according to authors, dates, and titles as desired by the user. This specific problem I'm having is from the sorting method. We have to use quick sort, and through the help of textbook and online, I was able to write the code as follows. The problem is, I'm having an infinite recursion. The base case I wrote and if else statement are completely ignored and the method keeps calling itself. Perhaps, return statement is not how you are supposed to end a recurssive method? I have no idea. Any help will be appreciated. Thank you in advance.
    public void sort (Comparator<MP3File> comp) {
              System.out.println("first: " + first  + "last: " + last);
              quickSort(first, last, comp);
              System.out.println("done");
              return;
         public void quickSort (int left, int right, Comparator<MP3File> comp) {
              int leftBound= left;
              int rightBound= right;
              System.out.println("before sorting: left - " + left + " right - " + right);
              if (left>=right) {
                   return;
               if ( ( left < 0 ) || ( left >= listOfMP3.length ) ||
                         ( right < 0 ) || ( right >= listOfMP3.length ) ) {
                       throw new IndexOutOfBoundsException();
               if (right-left>=1) {
                    System.out.println("difference between right and left: " + (right-left));
                    MP3File pivot = listOfMP3[left];
                    while (rightBound>leftBound)
                         while (comp.compare(listOfMP3[leftBound], pivot)<= 0 && leftBound<=right &&rightBound>leftBound) {
                              leftBound++;
                              System.out.println("leftBound " + leftBound);
                         while (comp.compare(listOfMP3[rightBound], pivot)>0 && rightBound>=left &&rightBound>=leftBound) {
                              rightBound--;
                              System.out.println("rightBound " + rightBound);
                         if (rightBound>leftBound) {
                              swap (leftBound,rightBound);
                        swap(left, rightBound);
                        System.out.println("swapped");
                        System.out.println("calling left sorting");
                        quickSort(left, rightBound-1, comp);
                        System.out.println("calling right sorting");
                        quickSort(rightBound+1, right, comp);
               else {
                    System.out.println("wtf");
                    return;
               System.out.println("error");
               return;
         public void swap(int index1, int index2) {
              MP3File temp = listOfMP3[index1];
              listOfMP3[index1] = listOfMP3[index2];
              listOfMP3[index2] = temp;
         }

    naranja wrote:
    Enlighten me further please? How do you use sort method using collections?[http://www.google.com/search?q=java+sort+tutorial]

  • QuickSort Problem

    Alright, so I'm trying to do a quicksort for ArrayLists and here is what I have but I keep getting StackOverFlowErrors. I've been looking at it for an hour and this all makes sense to me but I'm missing how it's overflowing. Any help?
    import java.util.ArrayList;
    import java.util.Comparator;
    import java.util.Iterator;
    import java.util.Random;
    public class QuickSort<E>{
         public ArrayList<E> sort(ArrayList<E> list, Comparator<E> c) {
              Random random = new Random();
              ArrayList<E> list2 = new ArrayList<E>();
              int pivotIndex = random.nextInt(list.size());
              for (Iterator<E> it = list.iterator(); it.hasNext(); )
                   E next = it.next();
                   if(c.compare(next,list.get(pivotIndex))==-1)
                        list2.add(next);
                        it.remove();
              ArrayList<E> firstHalf;
              ArrayList<E> secondHalf;
              if(list2.size()>1)
                   firstHalf = sort(list2, c);
              else
                   firstHalf = list2;
              if(list.size()>1)
                   secondHalf = sort(list, c);
              else
                   secondHalf = list;
              for(int i = 0;i<secondHalf.size();i++)
                   firstHalf.add(secondHalf.get(i));
              return firstHalf;
    }

    Here's an authentic implementation of the quicksort algorithm. You should notice that:
    1) You should not need another lists to make. Use only the original list throughout.
    2) If you could use arbitrary value from the list as pivot, you don't need to use random number.
    3) You should not need to check the element sequence in any sublist(s) at each recursive call because the proper repositioning(swapping) of the pivots makes a correct ordering of list elements for you. (*)
    *: Edited later -- Your bad bad QuickSort.java could mimic this technique.
    /* save and compile as QuickSortCorrect.java and
    * run it as QuickSortCorrect
    import java.util.*;
    public class QuickSortCorrect<E>{
      ArrayList<E> list;
      Comparator<E> comp;
      public QuickSortCorrect(ArrayList<E> al, Comparator<E> c){
        list = al;
        comp = c;
      public ArrayList<E> getSorted(){
        sort(0, list.size() - 1);
        return list;
      public void sort(int left, int right) {
        if (right - left <= 0){
          return;
        else{
          E pivot = list.get(right);  //right-most val, == an arbitrary value
          int partp = partition(left, right, pivot);
          sort(left, partp - 1);  // leave previous pivot that is now
          sort(partp + 1, right); // in the correct position in the list
      /* make partitioning and return the partition index */
      int partition(int left, int right, E pivot){
        E temp;
        int leftp = left - 1; // first ++ get <left>
        int rightp = right; // right == always pivot, so first -- get <right - 1>;
        while(true){
          while (comp.compare(list.get(++leftp), pivot) < 0){
          while (rightp > 0 && comp.compare(list.get(--rightp), pivot) > 0){
          if (leftp >= rightp){
            break;
          else{ // swap smaller <-> bigger
            temp = list.get(leftp);
            list.set(leftp, list.get(rightp));
            list.set(rightp, temp);
        temp = list.get(leftp); // use this as next pivot, == arbitrary
        list.set(leftp, list.get(right)); // move current pivot to its correct pos
        list.set(right, temp);            // set next pivot at right-most
        return leftp;
      /* main() for test */
      public static void main(String[] args){
        ArrayList<String> ars = new ArrayList<String>();
        ars.add("850");
        ars.add("126");
        ars.add("030");
        ars.add("254");
        ars.add("110");
        ars.add("574");
        ars.add("920");
        ars.add("574");
        ars.add("182");
        ars.add("052");
        ars.add("423");
        ars.add("126");
        ars.add("574");
        ars.add("166");
        ars.add("774");
        QuickSortCorrect<String> qs
         = new QuickSortCorrect<String>(ars, new Comparator<String>(){
          public int compare(String s1, String s2){
            return s1.compareTo(s2);
        ars = qs.getSorted(); // get result
        for (String s : ars){
          System.out.println(s);
    }Edited by: hiwa on 2008/03/18 18:53

  • Recursion Help

    Ok, Our Assignment is, find the kth smallest item in an array using recursion. I have been reading the text, and it says that I need to have a "pivot point" somewhere in the array and then sort each array on either side of the pivot. Right now, I have picked out a pivot which is pretty much in the middle of the array not matter how big it is. Now I am trying to make two separate arrays, one array that is from index 0 of the array to the pivot -1 and another array that is from pivot + 1 to the last index of the array. After that I think I will try to use some kind of sort method to sort each of the smaller arrays. Anyhow, right now I am stuck on making the new array, from 0 to pivot - 1. If you need more explanation of what I am trying to do, please ask. An example would be: if I make my array from 0 - 999, my pivot would be 499 and I am trying to make a new array from 0 - 498 (this excludes the pivot). When I test my program, it gives me an error saying the array is out of bounds, I have kinda a clue what the means but I just cant figure out why it is happening, and I strongly feel it has something to do with this code I am showing you. I am wondering about my base case as well, could there be something wrong with the base case? If this makes no sense, I will try to answer your questions, or if that does not work I will post the whole code, but I am trying to refrain from posting the whole code due to other classmates might be on here stealing my code! Thanks in advance
    public static int[] arrPartition1(int[] fillerArr, int first, int pivotInd){
             int[] firstHalfArray;
             firstHalfArray = new int[pivotInd - 1];
             if(first < pivotInd - 1)
                  return firstHalfArray;
             if(first < pivotInd)
                  firstHalfArray[first] = fillerArr[first];
                  first++;
                  return arrPartition1(fillerArr, first, pivotInd);
        }

    and here is my whole program. it compiles, but there is the runtime error. and i am kind of clueless on what i am doing wrong here -
    import java.util.*;
    public class TEST
       public static void main(String[] args)
          Scanner scan = new Scanner(System.in);
          int n = 10;
          int k = 2;
          int first = 0;
          int last = 0;
          int kth = 0;
    //      n = scan.nextInt();
    //      k = scan.nextInt();
          int[] dA = new int[n];
          for(int i=0; i<n ; i++)
          dA[i] = (int) Math.round(1000*Math.random());
          System.out.println("array elements:" + dA);
    first = 0;
    last = n-1;
    quickSort(dA, first, last);
    for(int i=0; i<n; i++)
    System.out.println("sorted array: entry at "+i+" :" +dA[i]);
    // kth = kSmall(k, dA, first, last);
    // System.out.println(kth);
    public static void quickSort(int[] dA, int first, int last)
    int pivotIndex =1 ;
    // if(last<= first)
    // return;
    if(first<last)
    quickSort(dA, first, pivotIndex-1);
    quickSort(dA, pivotIndex+1, last);
    public static int kSmall(int k, int[] dA, int first, int last)
    int pivotIndex = 5;
    if(k < (pivotIndex - first + 1))
    return kSmall(k, dA, first, pivotIndex-1);
    else if(k==(pivotIndex-first+1))
    return dA[pivotIndex];
    else
    return kSmall(k-(pivotIndex-first+1), dA, pivotIndex+1, last);
    Edited by: aberrated on Feb 9, 2008 9:47 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Quick sort recursion

    this is my version of quick sort
    i cant seem to figure out how to make it a recursive code
    any line of code that helps me do this, along with an explanation of why it works will be welcomed. Recursion is just too hard to picture inside my head
        public static String[] quickSort (String[] A, int start, int end){
            //if size is 1 return
            if (A.length < 2 ) return A;
            int pivotIndex = start;
                //do the partition
                for (int i=pivotIndex+1; i<end; i++){
                    if (compareStrings(A,A[pivotIndex])){
    swapString(A, pivotIndex+1, i);
    swapString(A, pivotIndex, pivotIndex+1);
    pivotIndex++;
    return A;

    when i take the return type out of the method, aka i make it void, and i write those two lines i am getting a runtime error
    this is the code
        public static void quickSort (String[] A, int start, int end){
            //if size is 1 return
            if (A.length < 2 ) return;
            int pivotIndex = start;
                //do the partition
                for (int i=pivotIndex+1; i<end; i++){
                    if (compareStrings(A,A[pivotIndex])){
    swapString(A, pivotIndex+1, i);
    swapString(A, pivotIndex, pivotIndex+1);
    pivotIndex++;
    quickSort(A, start, pivotIndex);
    quickSort(A, pivotIndex+1, end);
    this is how i call it
            String[]  data2 = new String[10];
            data2[0]= "5";
            data2[1]= "2";
            data2[2]= "9";
            data2[3]= "7";
            data2[4]="8";
            data2[5]= "0";
            data2[6]="3";
            data2[7]= "1";
            data2[8]="4";
            data2[9]= "6";
            quickSort(data2);
            System.out.println("");
            System.out.println("============================================");
            System.out.println("");
            for (int i=0; i < data.length; i++) {System.out.println(data2);}

  • How can I implement a recursive update within triggers?

    Given
    INSTANCE (table)
    INST_ID
    etc.
    INSTANCE_STRUCTURE (table)
    PARENT_ID (fk to INST_ID)
    CHILD_ID (fk to INST_ID)
    And that I COULD write code which recursively navigates the hierarchy (ie. START WITH parent_id = ? CONNECT BY PRIOR child_id = parent_id) and issues UPDATEs to each "child" along the way, thereby propogating the desired update, how can I accomplish the same thing using triggers?
    Keep in mind I am using Oracle 7.3 and I have no choice. Also, the DBA is very difficult to get a hold of and I have no idea if there may be some server settings which are preventing some of my attempts from succeeding.
    Of course the simplest method is to make an update trigger on INSTANCE select all CHILD_ID from INSTANCE_STRUCTURE and issue UPDATE to each which, in turn, would invoke the same trigger, however, we can't have a mutating table, now can we?
    Next, I tried the old global variable in a package bit. That's when I first started getting this "end of channel" business which essentially disconnects me from Oracle (while using SQLPlus). I started to debug that, and then other users started getting errors ... apparently due to the global variable being global ACROSS sessions ... which I did not expect (correct me if I'm wrong and I can try it again), however, due to the amount of data I'm dealing with in any one particular line of hierarchy, I'm not sure I wouldn't get an error anyhow ... particularly if I have to maintain a global array for everyone at once. Anyhow, it was during that, that I realized the "too many open cursors" thing and so I started working with START WITH CONNECT BY to identify all rows which must be dealt with.
    Then, I tried setting up some new tables (as opposed to global variables) in which I would identify userenv('sessionid') and other data so that a BEFORE UPDATE, FOR EACH ROW trigger could check to make sure that the AFTER UPDATE trigger had not begun yet (IOW, not recursing yet). Basically, everything's fine until the AFTER UPDATE trigger tries to apply UPDATEs for the children (identified from a cursor on START WITH CONNECT BY) ... then I get the "end of channel" thing again.
    Obviously, this whole thing is an attempt to denormalize some data for performance reasons.
    Any help would be appreciated.
    Thanks.

    Nevermind, I figured somethin' out.

  • How to find square root, log recursively???

    I need to find the square root of a number entered recursively and log as well. Your help would be greatly appreciated. Thanks in advance!
    import java.io.*;
    /**Class provides recursive versions
    * of simple arithmetic operations.
    public class Ops2
         private static BufferedReader in = null;
         /**successor, return n + 1*/
         public static int suc(int n)
              return n + 1;
         /**predecessor, return n - 1*/
         public static int pre(int n)
              if (n == 0)
                   return 0;
              else
                   return n - 1;
         /**add two numbers entered*/
         public static int add(int n, int m)
              if (m == 0)
                   return n;
              else
                   return suc(add(n, pre(m)));
         /**subtract two numbers entered*/
         public static int sub(int n, int m)
              if (n < m)
                   return 0;
              else if (m == 0)
                   return n;
              else
                   return pre(sub(n, pre(m)));
         /**multiply two numbers entered*/
         public static int mult(int n, int m)
              if (m == 0)
                   return 0;
              else
                   return add(mult(n, pre(m)), n);
         /**divide two numbers entered*/
         public static int div(int n, int m)
              if (n < m)
                   return 0;
              else
                   return suc(div(sub(n, m), m));
         /**raise first number to second number*/
         public static int exp(int n, int m)
              if (m == 0)
                   return 1;
              else
                   return mult(exp(n, pre(m)), n);
         /**log of number entered*/
         public static int log(int n)
              if (n < 2)
                   return 0;
              else
                   return suc(log(div(n, 2)));
         /**square root of number entered*/
         public static int sqrt(int n)
              if (n == 0)
                   return 0;
              else
                   return sqrt(div(n, ));
         /**remainder of first number entered divided by second number*/
         public static int mod(int n, int m)
              if (n < m)
                   return 0;
              else
                   return mod(div(n, pre(m)), m);
         public static void prt(String s)
              System.out.print(s);
         public static void prtln(String s)
              System.out.println(s);
         public static void main(String [ ] args)
              prtln("Welcome to the amazing calculator");
              prtln("It can add, multiply and do powers for");
              prtln("naturals (including 0). Note that all the");
              prtln("HARDWARE does is add 1 or substract 1 to any number!!");
              in = new BufferedReader(new InputStreamReader ( System.in ) );
              int It;
              while ( (It = getOp()) >= 0)
                   prt("" + It + "\n");
            private static int getOp( )
            int first, second;
            String op;
            try
                System.out.println( "Enter operation:" );
                do
                    op = in.readLine( );
                } while( op.length( ) == 0 );
             System.out.println( "Enter first number: " );
                first = Integer.parseInt( in.readLine( ) );
                System.out.println( "Enter second number: " );
                second = Integer.parseInt( in.readLine( ) );
             prtln("");
             prt(first + " " + op + " " + second + " = ");
                switch( op.charAt( 0 ) )
                  case '+':
                    return add(first, second);
                  case '-':
                       return sub(first, second);
                  case '*':
                    return mult(first, second);
                  case '/':
                       return div(first, second);
                  case '^':
                    return exp(first, second);
                  case 'v':
                       return log(first);
                  case 'q':
                       return sqrt(first);
                  case '%':
                       return mod(first, second);
                  case 's':
                       return suc(first);
                  case 'p':
                       return pre(first);
                  default:
                    System.err.println( "Need +, *, or ^" );
                    return -1;
            catch( IOException e )
                System.err.println( e );
                return  0;
    }

    Hi,
    Is there any one to make a program for me in Turbo
    C++ for Dos, which can calculate the square root of
    any number without using the sqrt( ) or any ready
    made functions.
    The program should calculate the s.root of the number
    by a formula or procedure defined by the user
    (programmer).
    Thanks.This is a Java forum!
    If you want Java help:
    1. Start your own thread.
    2. Use code tags (above posting box) if you post code.
    3. No one will write the program for you. We will help by answering your questions and giving advice on how to fix problems in code you wrote.
    4. The formula you need to implement is given above by dizzy.

  • Confusion between references in recursion

    Hi all,
    I am trying to create B+ trees for a database. My algorithm for the insert function is:
    void insert(page_no, entry, newchildentry )
    if page_no is not a leaf ,say N
    find i such that Ki <= entry's key value < K i+1   //choose subtree
    insert(newPage(i), entry,newchildentry )
    if newchildentry is null, return;
    else
              if N has space, insert the newchildentry, set it to null and return
             else
             split the page in half, the newchildentry is set to a new value
             if N is the root , do some extra things return;
    if  page_no is a leaf, say L
    if  L has space, insert entry on to it, set newchildentry to null and return;
    else split L in half, populate the newchildentry to some new values
    return;
    }The problem that i am facing is that newchildentry is being populated by some values in the "if page_no is a leaf, say L" part and on collapsing the recursion, these values are being lost and I can't figure what the problem is. i'm new to java even though i have programmed in c/c++ before and i think this would work. is it because java is maintaining different placeholders for the newchildentry?
    thanks.
    ~dang_it

    Hi all,
    I am trying to create B+ trees for a database. My
    algorithm for the insert function is:
    void insert(page_no, entry, newchildentry )
    if page_no is not a leaf ,say N
    find i such that Ki <= entry's key value < K i+1
    //choose subtree
    insert(newPage(i), entry,newchildentry )
    if newchildentry is null, return;
    else
    if N has space, insert the newchildentry,
    hildentry, set it to null and return
    else
    split the page in half, the newchildentry is
    dentry is set to a new value
    if N is the root , do some extra things
    ra things return;
    if  page_no is a leaf, say L
    if  L has space, insert entry on to it, set
    newchildentry to null and return;
    else split L in half, populate the newchildentry to
    some new values
    return;
    }The problem that i am facing is that newchildentry is
    being populated by some values in the "if page_no is
    a leaf, say L" part and on collapsing the recursion,
    these values are being lost and I can't figure what
    the problem is. i'm new to java even though i have
    programmed in c/c++ before and i think this would
    work. is it because java is maintaining different
    placeholders for the newchildentry?
    thanks.
    ~dang_itIn the code that is failing, what type is newchildentry. You need to be aware that objects are not passed in the argument list. A copy of the object reference is passed. When the method finishes, even if the object contents have changed, the reference has not. So, to say that in some case you set newchildentry to null does not change the newchildentry object reference in the calling method.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Stuck in Windows Vista on a 2012 13' Pro with a Boot Camp disk error

    I am at the point in installation where I have just completed installing Vista. So I inserted the Boot Camp disk I was instructed to make earlier, and I receive the error message: D:\ The application has failed to start because its side-by-side confi

  • EFT for Oracle EBS 11.5.10.2

    Hello, We are looking into implementing EFT (Electronic Fund Transfer) functionality in Oracle Applications(Payables) 11.5.10.2. Any idea on what are the seeded payment format programs (i.e. BACS, NACHA,.??) that could be used with minimal or no cust

  • The App Store says I have Pages 5.0 installed, but I only have 4.3.

    The Apple App Store says that I already have Pages 5.0 installed, and my Pages app is up to date. But when I look in my "about Pages" it says I only have 4.3. This is a problem because I can't open any of my documents that I put in the icloud, becaus

  • How to play a DVD in QuickTime  first of many questions

    Hi, can someone please explain how to play a movie from DVD in QuickTime. I go to "Ablage" (don't know english word for that) -> open file -> klick on some *.VOB and klick play. But the Movie is very slow and I have no sound.

  • Database running but crs_stat showing its OFFLINE

    Yesterday, when I checked database and all RAC components status with crs_stat -t command, I saw database as offline although database and both of its instances are up and already running. oracle@hisdbs01[orcl1]:/u01/app/oracle/db/network/admin$ crs_