1,853 questions
1
vote
2
answers
101
views
Is there a bug in the method below (Data Structures & Algorithms by Robert Lafore)
The method below has been taken from the book Data Structures & Algorithms by Robert Lafore. This method is used to bubble sort a given array. nElems is the number of elements in the array. In my ...
-1
votes
1
answer
81
views
Ask for information about the Bubble sort algorithm [closed]
I have a question about the analysis of the bubble sort algorithm. I created the bubble sort algorithm in Python without including temporary storage. That means it directly swaps the adjacent pairs. ...
-1
votes
1
answer
71
views
How do I make the function edit a vector created outside the function in C++? [duplicate]
This is my code:
#include <iostream>
#include <vector>
using namespace std;
int BubbleSort(vector<int>, int);
int main(){
vector<int> lista_y2 {1, 2, 0};
cout <&...
0
votes
0
answers
33
views
Weird Behavior in Assembly, printing doesn't work when I loop it [duplicate]
I am learning assembly 64 bit in windows and I made a bubble sort algorithm but it doesn't work when I put the print in a loop instead of copying and pasting the same line with increasing amounts of ...
-4
votes
1
answer
78
views
Creating a bubblesort method to sort a list in C# [closed]
I seem to have a problem to sort my list (cities and temperatures) from coldest to warmest. Here is the code for the method.
static void bubblesort(List<Stad> städer, int n)
{
n = städer....
1
vote
1
answer
78
views
Insertion sort vs bubble sort vs selection sort: why is selection sort and insertion sort slower than bubbe sort although fewer steps?
I am implementing a script which compares bubble sort, insertion sort and selection sort.
Although all these have a time complexity of the order of N^2, selection sort is supposed to be twice as fast ...
-1
votes
1
answer
56
views
Bubble sort on Doubly Linked List not working
I have been doing DSA lately on python, this time tried bubble-sort algorithm on a doubly linked list.
Unfortunately, the method is not giving proper result.
Please correct me, tell me where I am ...
1
vote
1
answer
51
views
Multiple counts of "Invalid combination of opcode and operands" error
I have written an assembly program that sorts an array using bubble sort. I am getting errors.
This is the full code:
org 100h
section .data
array db 5, 3, 7, 1, 4, 9, 2, 8, 6
array_size db 9
...
1
vote
3
answers
180
views
Optimized bubble sorting algorithm takes more time than unoptimzed
I can't understand why do optimized version of my bubble sorting algorithm takes not less time than unoptimized version
Here is my files:
main.c - here I create arrays of different sizes and run both ...
1
vote
1
answer
162
views
How I can do a optimization for printing a large chunk of text?
So I was building a project that created a graph representing the bubble sort algorithm, but, the way I did is very slow and like to reorganize a vector with a hundred positions take about 3 minutes. ...
0
votes
1
answer
83
views
Terminating Bubble Sort Algorithm when the dataset has been sorted
This function goes through the dataset and then sorts it in ascending order.
What its meant to do is stop when the list has been sorted. However, the !changed control flow statement terminates it ...
0
votes
1
answer
173
views
What is the error I have in my MARIE code for sorting an array?
I am trying to solve the following task:
Write an assembly code in MARIE to sort the following numbers (Hexadecimal) from maximum to minimum.
Numbers (HEX): 5, 35, 75, 45, 85, 25, 95, 55, 15, 65
You ...
3
votes
5
answers
163
views
Bubble sort does not sort as expected
I have a problem with a C program that is supposed to sort the environmental variables by order based on their name. However, it doesn't seem to be sorting them correctly, as the strcmp is supposed to ...
1
vote
2
answers
92
views
I'm trying to do a bubble sort on integers that are imput by the user (java)
As mentioned above, I tried to implement a bubble sort method but every time I try to run it, it returns ones and zeroes instead of the sorted numbers.
So far I've tried to look at another example of ...
0
votes
1
answer
89
views
Vector Sorting Using Bubble Sorting Algorithm
I'm new to programming and currently working on an app to assist with managing my home budget. All the data is stored in an XML file. To sort vectors by date, I've implemented a bubble sort algorithm. ...
0
votes
1
answer
85
views
Sorting surnames alphabetically w/bubblesort
I have a question which needs me to sort out surnames. I'm using bubblesort, but I'm having trouble splitting the first name and the surnames. I have this going on before using my bubble sort method.
...
-1
votes
1
answer
165
views
How to properly count operations (time complexity) in a bubble sort algorithm in Python
This is my code:
def sort_bubble(list):
comp_counter = 0
swap_counter = 0
n = len(list)
for i in range(n-1):
for j in range(n-i-1):
comp_counter += 1
if ...
0
votes
1
answer
85
views
Sort an array with small numbers while having secondary array with initial indexes
I have a small array with 7 elements which can have values from 0 to around 6 (very small numbers). The counting sort is really very efficient with such configuration, but, I have another array to ...
0
votes
0
answers
93
views
Visualizing Bubble Sort - JavaFX
Beginner here. I tried to recreate the bubble sort animation on VisuAlgo using javaFX, but I can't get the code right:
public class BubbleSortController implements Initializable {
@FXML
...
1
vote
1
answer
81
views
why does my bubble sort only work for about 10 digits?
I am an absolute java beginner and have tried to write a bubble-sort. it seems to work up to 10 digits. I thought it might be because I used int. My names are in german. I hope that doesn't bother you....
0
votes
1
answer
64
views
Access violation writing location 0x00465004
I am writing the code for bubble sorting in assembly and my assembler is giving me "Access violation writing location" error inside the swap label. kindly help
INCLUDE irvine32.inc
.data
arr ...
-1
votes
2
answers
92
views
Why can't I get my pointer based linked list bubble swap to work?
class Node {
public:
int data;
Node* next;
Node() { //default constructor
data = NULL;
next = NULL;
}
Node(int value) {
this->data = value;
...
0
votes
1
answer
96
views
How does the Bubble Sort algorithm work on a 2D array of Strings in Java?
For an assignment I had to do a Bubble Sort on a 2D array of states and their state capitals. The name of the array is stateCapitals. I am supposed to sort by the state capitals.
This is the 2D array:
...
-2
votes
1
answer
44
views
How can I edit my code to make sure it prints out the efficient sorting algorithm for each txt file?
I wrote a program that tries to find out the most efficient sorting algorithm, starting from a very small unsorted txt file to a very large sorted txt file. I don't know why it is Insertion sort that ...
0
votes
2
answers
451
views
Sorting an Array of Pointers in C++
I'm trying to sort an array of pointers according to the values in an array, leaving the original dataset alone. However, when I output the pointer array and then the data array, they both have the ...
2
votes
1
answer
187
views
Where do I need to write in an output function in my code?
For a task I got a text file with integers in it. There can be a different number of integers in each line, but it can't be more than 30. All integers in the file are separated by spaces. I need to ...
1
vote
1
answer
350
views
Verilog BRAM sorting
I want to infer 8x4 Single port BRAM in Verilog, and I have to read the values of the RAM and sort them. In the sorting process, I need to sort the RAM data from smallest to largest by writing to the ...
1
vote
2
answers
71
views
When I try to sort strings by bubble sort algorithm, I do not see any strings at the output but only one string
Here is my code:
int main(int argc, char **argv) {
int numberOfStrings, remaining;
printf("Input number of strings:");
scanf("%d", &numberOfStrings);
// ...
0
votes
2
answers
110
views
Writing Bubble Sorting Function [closed]
I'm trying to write a simple bubble sort function to sort some random data. Whenever executed though it simply prints the unsorted list as it was written initially. Where did i go wrong???
Code:
#...
0
votes
1
answer
325
views
Can Bogo Sort Outperform Bubble Sort in Certain Scenarios?
In my recent comparison of the Bubble Sort and Bogo Sort algorithms, specifically analyzing their performance in sorting an array of length 9, Bubble Sort consistently exhibited faster sorting times (...
-1
votes
2
answers
322
views
How do i calculate the number of comparisons in a bubblesort worstcase scenario
I am new to math and algortithms and very confused. I am looking for the amount of times the numbers get compared in n. in my head it goes like this. if n = 3 in the worst case scenario: [3,2,1] 3 ...
-1
votes
1
answer
65
views
How can I access and rearrange (bubble sort) info stored within a struct?
This is my code so far. I want to sort patient records loaded from a text file. I am struggling to understand how I can access the info stored within the struct in order to rearrange it. For example, ...
2
votes
1
answer
345
views
How does this 8086 code of ascending-sort work?
I am currently learning 8086 programming and this one was demonstrated in our lab on a 8086 kit. The following code sorts sequence of numbers to ascending order:
mov si, 2000
mov cl, [si]
dec cl
loop1:...
-1
votes
1
answer
140
views
Time complexity of mixedsort (a modification on bubblesort)
So i tried solving this with master theorem but unsure if my solution is correct:
function MixedSort(A[1..n]){
if (n==1) {
return A[1];
}
m = n/2;
B[1 ... m] = bubbleSort(A[1......
0
votes
1
answer
114
views
Sorting singly linked list with bubble sort
I've written the following code for sorting a singly linked list using bubble sort. Sorting procedure should sort the nodes of the list on the basis of the data they contain. Sorting the nodes only ...
-7
votes
3
answers
614
views
For comparison in speed between C and Assembly language using bubble sort, which of it in general is faster? [closed]
I have researched bubble sort speed differences between C and Assembly language, and found that code optimization is one factor.
What other factors are there to consider for bubble sort speed ...
-2
votes
2
answers
152
views
Bubble sort using ADT in python
I am given an assignment, where the input will be a list and my task is to bubble sort the list to ascending order. Here's a sample input and output that I want.
Input:
45 22 34 79 23
Output:
22 45 ...
0
votes
3
answers
454
views
How do I create a bubble sort in C that can take in any type of array?
We are trying to create a bubble sort that can take in an int, float, or c-string array. We already wrote the swap function that allows us to do this, but now we cannot figure out how to get it to ...
0
votes
1
answer
22
views
Sorting a 2D Matrix using Bubble Sort in C - Not Producing the Expected Result
#include <stdio.h>
int main() {
int a;
printf("Enter the number of rows: ");
scanf("%d", &a);
int b;
printf("Enter the number of columns: ")...
-1
votes
1
answer
453
views
Trying a Hybrid Sort Algorithm (Bubble + Merge Sort) in Python
So, I was tasked to create a hybrid sort function in python that would utilize bubble and merge sorts. The idea is simple; as long as the value T (threshold) is exceeded, merge sort should run ...
1
vote
1
answer
71
views
Why is the list annotated twice after the foldl in haskell?
I'm trying to understand haskell, I can't really be convinced about what this line of code does, can someone detail the line of code for me?
Why does the foldl need to loop through the xs list twice?
...
1
vote
1
answer
66
views
Segmentation Error When Running Recursive Bubble Sort in C
I'm attempting to implement the bubble sort algorithm using recursion to sort an array of integers. However, I keep encountering a segmentation error when I compile and run the code. I've tried ...
0
votes
1
answer
89
views
Recursive bubble sort TLE in java
I have written code to do bubble sort recursive. But I am getting Time limit exceeded. Can anyone help me to figure out why?
public static void bubbleSort(int[] arr, int index, int j){
if (...
0
votes
0
answers
88
views
BubbleSort Algorithm with Kotlin
Trying to make a basic project which is going to get values from user and the values are going to be stored on an array. But the project is not succeed.
I want to fix the problem and make the project ...
-1
votes
1
answer
276
views
A three dimensional bubble sort algorithm?
Recently I’ve learned two basic sorting algorithms bubble and heap sort. It’s fairly clear that heap sort is a “2D” version of the “1D” bubble sort. For both algorithms, you find the largest element ...
-2
votes
1
answer
95
views
Algorithm of Bubble sort optimised way
I have 2 different codes for sorting an array:
static void bubbleSort2(int[] arr){
System.out.println( "bubble starts ");
int tmp =0;int cnt =0;
for (int i=0; i&...
0
votes
1
answer
36
views
How to sort a parallel array to get the greatest and smallest value
I have two parallel arrays. one is type String and the other, type int. I want to sort them in ascending order while maintaining data consistency, keeping them parallel, to get the entry with the ...
0
votes
1
answer
210
views
How to determine whether the minimum number of adjacent swaps required for sorting is odd or even?
I don't know if bubble sort is optimal under the condition that only adjacent swaps are allowed? Is there a more optimal algorithm that can directly determine the parity of the minimum number of swaps ...
1
vote
1
answer
312
views
How to find the number of swaps in bubble sort if the list is a range
I want to find the number of swaps (not comparisons) needed to sort an array of length N using bubble sort, when the array contains all numbers from 0 to N-1.
I wondered if you could, instead of ...
0
votes
1
answer
115
views
Getting "subscripted value is not an array, pointer, or vector" error and I don't know why
// Practice working with structs
// Practice applying sorting algorithms
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM_CITIES 10
...