Skip to content

added stooge sort to sorting algorithms #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
/chapter01introduction/
/chapter02recursionandbacktracking/
/chapter03linkedlists/
/chapter04stacks/
/chapter05queues/
/chapter06trees/
/chapter07priorityqueues/
/chapter08disjointsets/
/chapter09graphs/
/chapter10sorting/
/chapter11searching/
/chapter12selectionalgorithms/
/chapter15stringalgorithms/
/chapter17greedyalgorithms/
/chapter18divideandconquer/
/chapter19dynamicprogramming/
/chapter21miscconcepts/
Binary file modified bin/chapter01introduction/LogNComplexityDown.class
Binary file not shown.
Binary file modified bin/chapter01introduction/LogNComplexityUp.class
Binary file not shown.
Binary file modified bin/chapter01introduction/NComplexity.class
Binary file not shown.
Binary file modified bin/chapter01introduction/NPower3By2Complexity.class
Binary file not shown.
Binary file modified bin/chapter01introduction/NSquareLogNComplexity.class
Binary file not shown.
Binary file modified bin/chapter01introduction/NlogNComplexity.class
Binary file not shown.
Binary file modified bin/chapter01introduction/SquareRootNComplexity.class
Binary file not shown.
Binary file modified bin/chapter02recursionandbacktracking/Factorial.class
Binary file not shown.
Binary file modified bin/chapter02recursionandbacktracking/FactorialTest.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/AddNumbersFromList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/CLLNode.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/CircularLinkedList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/DLLNode.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/DoublyLinkedList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/ExchangeAdjacentNodes.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/InsertionSortLinkedList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/LinkedList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/ListNode.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/LoopInALinkedList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/MergeKSortedLists.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/MergeSortedListsIterative.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/MergeSortedListsRecursion.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/NthNodeFromEnd.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/PartitionList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/PrintListInReverse.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/RandomListNode.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/RandomPointerLinkedList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/RemoveDuplicatesBruteForce.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/RemoveDuplicatesHashing.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/ReverseALinkedList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/ReverseKNodesAsBlcokIterative.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/ReverseKNodesAsBlockRecursive.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/RotateLinkedList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/SkipList$Node.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/SkipList.class
Binary file not shown.
Binary file modified bin/chapter03linkedlists/SkipListsTest.class
Binary file not shown.
Binary file modified bin/chapter04stacks/DynamicArrayStack.class
Binary file not shown.
Binary file modified bin/chapter04stacks/ExpressionEvaluation.class
Binary file not shown.
Binary file modified bin/chapter04stacks/FixedSizeArrayStack.class
Binary file not shown.
Binary file modified bin/chapter04stacks/LinkedStack.class
Binary file not shown.
Binary file modified bin/chapter04stacks/MaxRectangleAreaInHistrogram.class
Binary file not shown.
Binary file modified bin/chapter04stacks/SortingStack.class
Binary file not shown.
Binary file modified bin/chapter04stacks/StackForStackSets.class
Binary file not shown.
Binary file modified bin/chapter04stacks/StackSets.class
Binary file not shown.
Binary file modified bin/chapter04stacks/SymbolBalance.class
Binary file not shown.
Binary file modified bin/chapter05queues/DynamicArrayQueue.class
Binary file not shown.
Binary file modified bin/chapter05queues/FixedSizeArrayQueue.class
Binary file not shown.
Binary file modified bin/chapter05queues/LinkedQueue.class
Binary file not shown.
Binary file modified bin/chapter05queues/QueuewithTwoStacks.class
Binary file not shown.
Binary file modified bin/chapter05queues/StackwithTwoQueues.class
Binary file not shown.
Binary file modified bin/chapter06trees/BinarySearchTreeNode.class
Binary file not shown.
Binary file modified bin/chapter06trees/BinaryTreeNode.class
Binary file not shown.
Binary file modified bin/chapter06trees/BinaryTreeSizeLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/BinaryTreeSizeRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/CheckAVL.class
Binary file not shown.
Binary file modified bin/chapter06trees/CheckMirrors.class
Binary file not shown.
Binary file modified bin/chapter06trees/CheckPathForSum.class
Binary file not shown.
Binary file modified bin/chapter06trees/CheckStructurullySameTrees.class
Binary file not shown.
Binary file modified bin/chapter06trees/CheckValidBSTRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/CheckValidBSTRecursiveSingleVariable.class
Binary file not shown.
Binary file modified bin/chapter06trees/ConstructMirror.class
Binary file not shown.
Binary file modified bin/chapter06trees/CountBSTs.class
Binary file not shown.
Binary file modified bin/chapter06trees/DeepestNode.class
Binary file not shown.
Binary file modified bin/chapter06trees/DeleteBinaryTree.class
Binary file not shown.
Binary file modified bin/chapter06trees/DiameterOfTree.class
Binary file not shown.
Binary file modified bin/chapter06trees/FillNextSiblingsWithLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/FillNextSiblingsWithRecursion.class
Binary file not shown.
Binary file modified bin/chapter06trees/FindLevelwithMaxSum.class
Binary file not shown.
Binary file modified bin/chapter06trees/GenerateBSTs.class
Binary file not shown.
Binary file modified bin/chapter06trees/InOrderIterative.class
Binary file not shown.
Binary file modified bin/chapter06trees/InOrderRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/InsertInBinaryTreeLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/InsertInBinaryTreeRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/LCABST.class
Binary file not shown.
Binary file modified bin/chapter06trees/LCABinaryTree.class
Binary file not shown.
Binary file modified bin/chapter06trees/LevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/LevelOrderTraversalInReverse.class
Binary file not shown.
Binary file modified bin/chapter06trees/MaxDepthInBinaryTreeWithLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/MaxDepthInBinaryTreeWithStack.class
Binary file not shown.
Binary file modified bin/chapter06trees/MaxDepthRecursiveInBinaryTree.class
Binary file not shown.
Binary file modified bin/chapter06trees/MaxInBinaryTreeLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/MaxInBinaryTreeRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/MinInBinaryTreeRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/MinimumDepth.class
Binary file not shown.
Binary file modified bin/chapter06trees/MirrorOfBinaryTree.class
Binary file not shown.
Binary file modified bin/chapter06trees/NumberOfFullNodesInBTusingLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/NumberOfHalfNodesInBTusingLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/NumberOfLeavesInBTusingLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/PostOrderIterative.class
Binary file not shown.
Binary file modified bin/chapter06trees/PostOrderRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/PreOrderIterative.class
Binary file not shown.
Binary file modified bin/chapter06trees/PreOrderRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/PrintAllAncestors.class
Binary file not shown.
Binary file modified bin/chapter06trees/PrintPaths.class
Binary file not shown.
Binary file modified bin/chapter06trees/SearchBinaryTreeLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/SearchBinaryTreeRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/SiblingBinaryTreeNode.class
Binary file not shown.
Binary file modified bin/chapter06trees/SortedArrayToBST.class
Binary file not shown.
Binary file modified bin/chapter06trees/SumOfElementsInBinaryTreeLevelOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/SumOfElementsInBinaryTreeRecursive.class
Binary file not shown.
Binary file modified bin/chapter06trees/TreeFromInOrderAndPostOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/TreeFromInOrderAndPreOrder.class
Binary file not shown.
Binary file modified bin/chapter06trees/VerticalSum.class
Binary file not shown.
Binary file modified bin/chapter06trees/WidthOfTree.class
Binary file not shown.
Binary file modified bin/chapter06trees/ZigzagTraversal.class
Binary file not shown.
Binary file modified bin/chapter07priorityqueues/BinaryHeap.class
Binary file not shown.
Binary file modified bin/chapter07priorityqueues/ListNode.class
Binary file not shown.
Binary file modified bin/chapter07priorityqueues/MergingKSortedLists$1.class
Binary file not shown.
Binary file modified bin/chapter07priorityqueues/MergingKSortedLists.class
Binary file not shown.
Binary file modified bin/chapter08disjointsets/DisjointSets.class
Binary file not shown.
Binary file modified bin/chapter10sorting/ConvertArraytoSawToothWave.class
Binary file not shown.
Binary file modified bin/chapter10sorting/ConvertArraytoSawToothWaveLinearTime.class
Binary file not shown.
Binary file modified bin/chapter10sorting/MergeTwoSortedArrays.class
Binary file not shown.
Binary file modified bin/chapter10sorting/QuickSort.class
Binary file not shown.
Binary file modified bin/chapter10sorting/RemoveDuplicatesFromSortedArray.class
Binary file not shown.
Binary file modified bin/chapter11searching/BinarySearchRotatedIterative.class
Binary file not shown.
Binary file modified bin/chapter11searching/BinarySearchRotatedRecursive.class
Binary file not shown.
Binary file modified bin/chapter11searching/DutchNationalFlag.class
Binary file not shown.
Binary file modified bin/chapter11searching/GenerateNextNumFromReading.class
Binary file not shown.
Binary file modified bin/chapter11searching/MissingNumberFromTwiceRepetitions.class
Binary file not shown.
Binary file modified bin/chapter11searching/SearchInSorted2DMatrix.class
Binary file not shown.
Binary file modified bin/chapter11searching/TwoSumEqualToK.class
Binary file not shown.
Binary file modified bin/chapter12selectionalgorithms/KthLargest.class
Binary file not shown.
Binary file modified bin/chapter12selectionalgorithms/KthSmallest.class
Binary file not shown.
Binary file modified bin/chapter12selectionalgorithms/MedianInTwoSortedArrays.class
Binary file not shown.
Binary file not shown.
Binary file modified bin/chapter15stringalgorithms/MinLengthWindow.class
Binary file not shown.
Binary file modified bin/chapter15stringalgorithms/NumberCombinations.class
Binary file not shown.
Binary file modified bin/chapter15stringalgorithms/ReverseWordsinaSentence.class
Binary file not shown.
Binary file modified bin/chapter15stringalgorithms/Trie.class
Binary file not shown.
Binary file modified bin/chapter15stringalgorithms/WildCardMatch.class
Binary file not shown.
Binary file modified bin/chapter17greedyalgorithms/Huffman.class
Binary file not shown.
Binary file modified bin/chapter17greedyalgorithms/HuffmanTreeNode.class
Binary file not shown.
Binary file modified bin/chapter18divideandconquer/ExponentialDivideAndConquer.class
Binary file not shown.
Binary file not shown.
Binary file modified bin/chapter19dynamicprogramming/EditDistance.class
Binary file not shown.
Binary file modified bin/chapter19dynamicprogramming/FibonacciWithDP.class
Binary file not shown.
Binary file modified bin/chapter19dynamicprogramming/MaxSubSquareMatrixWith1s.class
Binary file not shown.
Binary file modified bin/chapter19dynamicprogramming/MaxSumSubArrayDP.class
Binary file not shown.
Binary file modified bin/chapter19dynamicprogramming/MaximumSumSubMatrix.class
Binary file not shown.
Binary file modified bin/chapter19dynamicprogramming/OptimalJumps.class
Binary file not shown.
Binary file modified bin/chapter19dynamicprogramming/RecursiveFibonacci.class
Binary file not shown.
Binary file modified bin/chapter21miscconcepts/AddOneToNumber.class
Binary file not shown.
Binary file modified bin/chapter21miscconcepts/CheckEndian.class
Binary file not shown.
Binary file modified bin/chapter21miscconcepts/Equilibrium.class
Binary file not shown.
Binary file modified bin/chapter21miscconcepts/MatrixSpiralPrint.class
Binary file not shown.
Binary file modified bin/chapter21miscconcepts/SwapOddEvenBits.class
Binary file not shown.
42 changes: 42 additions & 0 deletions src/chapter10sorting/StoogeSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*Copyright (c) 5 de out. de 2020 CareerMonk Publications and others.
* E-Mail : [email protected]
* Creation Date : 2015-01-10 06:15:46
* Last modification : 2006-05-31
by : Narasimha Karumanchi
* File Name : StoogeSort.java
* Book Title : Data Structures And Algorithms Made In Java
* Warranty : This software is provided "as is" without any
* warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose.
*
*/

package chapter10sorting;

import java.util.Arrays;

public class StoogeSort {
public static void main(String[] args) {
int[] nums = {1, 4, 5, 3, -6, 3, 7, 10, -2, -5};
stoogeSort(nums);
System.out.println(Arrays.toString(nums));
}

public static void stoogeSort(int[] L) {
stoogeSort(L, 0, L.length - 1);
}

public static void stoogeSort(int[] L, int i, int j) {
if (L[j] < L[i]) {
int tmp = L[i];
L[i] = L[j];
L[j] = tmp;
}
if (j - i > 1) {
int t = (j - i + 1) / 3;
stoogeSort(L, i, j - t);
stoogeSort(L, i + t, j);
stoogeSort(L, i, j - t);
}
}
}