# Quick Sort significantly slower

Advertisements I am working on my lab assignment which is all about sorting algorithms, Heap Sort, Merge Sort, and Quick Sort. I finished the assigment pretty much, but after taking time measurements for each algorithm I got suprising results. [***** [Merge Sort] *****] [Original]: [54599, 62697, 92032, 19179, 17296, 27068, 99563, 9829, 89929, 57140] [Sorted]:… Read More Quick Sort significantly slower

# randomized quick sort base case not working (sometime)

Advertisements while implementing quick sort i thought that when there’s two or three element in the arr there’s no need to continue dividing the arr since if you just partitioned the pivot you will end up with a sorted array the problem is after adding started fluctuating between if e-s == 2 or e-s ==… Read More randomized quick sort base case not working (sometime)

# Is there something wrong with this quicksort implementation that uses a random pivot?

Advertisements const swap = (arr, i, j) => { const temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }; const partition = (arr, left, right) => { const pivot = arr[Math.floor(Math.random() * (arr.length – left) + left)]; while (left <= right) { while (arr[left] < pivot) { left++; } while (arr[right] > pivot) {… Read More Is there something wrong with this quicksort implementation that uses a random pivot?

# How to quick sort list of objects by different attributes using the same method?

Advertisements My class is as below: class Member: def __init__(self, name, zip, hire_date, birth_date): self.id = id self.name = name self.zip = zip self.hire_date = hire_date self.birth_date = birth_date def get_name(self): return self.name def get_birth_date(self): return self.birth_date def get_hire_date(self): return self.hire_date def get_zip_code(self): return self.zip I have need to quick sort a list of this… Read More How to quick sort list of objects by different attributes using the same method?

# A peculiar case of quicksort pivot

Advertisements I implemented quicksort in C which runs perfectly fine. Then I started to play with the pivot element, now I am stuck in a bizzare situation. What I have implemented runs fine some times but doesnt run at all the other times(shows no output) and I am unable to pinpoint why is this happening.… Read More A peculiar case of quicksort pivot

# QuickSort C implementation not working as expected

Advertisements I am trying to implement the QuickSort algorithm in C, however it’s giving me a pretty hard time, I don’t know what I’m doing wrong but sometimes the output isn’t what I expected it to be: #include <stdio.h> #include <stdlib.h> void printArray(int array[], int size){ for(int i=0;i<size;i++) printf("%d ",array[i]); printf("\n"); } void swap(int *a,… Read More QuickSort C implementation not working as expected

# How can I return values from a recursive function?

Advertisements I have my code which does a quick sort on a list of values: def Quick_sort_random(random_list): r = random_list.copy() def inner(r): if len(r) < 2: return r p = random.randint(0, len(r) – 1) pivot = r[p] left = list(filter(lambda x: x <= pivot, r[:p] + r[p + 1:])) right = list(filter(lambda x: x >… Read More How can I return values from a recursive function?

# python time complexity quick sort algorithm

Advertisements def partition(A, l, r): p = A[l] stack = A[l] A[l] = A[r] A[r] = stack s = l for i in range(l, r): if A[i] <= p: stack2 = A[i] A[i] = A[s] A[s] = stack2 s += 1 stack3 = A[s] A[s] = A[r] A[r] = stack3 return s def quicksort(A, l,… Read More python time complexity quick sort algorithm