626 questions
2
votes
0
answers
124
views
Complicated issue selecting optimal scoring tests with and constraints, trying in R
this is my first stack post so forgive me for any social transgressions!
I have an optimisation(?) issue that begins incredibly simply but has a conditions that throws the whole thing into a realm of ...
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 ...
0
votes
0
answers
70
views
CS50 : Tideman : sort_pairs
sort_pairs is not returning successfully when I check the code. Can anyone help point me in the right direction? I spent quite a while on the previous functions getting them correct as I've been away ...
2
votes
2
answers
81
views
selection sort algorithm time complexity
In selection sort the outer loop time complexity will be O(n) and the inner loop time complexity will be (n(n-1))/2 then why have we added outer loop time complexity with inner loop : n + (n(n-1))/2 ...
0
votes
1
answer
100
views
how can calculate time complexity of selection sort step by step?
enter image description here
I should solve the time Complexity method like this photo but I have a problem solving it for selectio sort.
I solved it in general and not in detail like I wanted going ...
1
vote
1
answer
70
views
Segmentation fault in using recursive selection sort in C language
I have i have wrote a C program. It should use recursive selection sort but segmentation fault occurs for big input (10000 or more). Debugger says that the segfault happens in findim function, but it'...
1
vote
2
answers
55
views
Selection sort for linked list by swapping nodes
The assignment is to use selection sort by swapping nodes, not the values. When sorting algorithm changes the last node, it raises AttributeError, because it seems that first.next in def min_sort()...
0
votes
1
answer
37
views
Recursive Selection Sort Stack Overflow Error
import java.util.Arrays;
public class RecSelect {
public static void Select(int[] ar, int idx, int min, int start) {
if(idx == ar.length) {
return;
}
if(idx &...
0
votes
0
answers
34
views
Why is my sorting algorithm not showing the desired output?
My question is with the counting. In my problem the number of the operations after sorting is not giving the same amount as it should. I am using the general logic for the selection sort, insertion ...
-1
votes
2
answers
68
views
Why Does Using a Variable for the Index Work in This Selection Sort Algorithm in JavaScript?
I'm trying to understand why using a variable to assign the index works fine, instead of directly using the index itself in the following code snippet of the selection sort algorithm using JavaScript.
...
1
vote
0
answers
94
views
Calculating the percentage of a Party List of Members to rounded numbers (Because members cannot be fractions)
If I had a list in a party, say 10 people, and I needed to find 25% of that list of people, you could say the answer is 2.5 people.
However, if I had a list of 1 person (go with it), and I needed to ...
-1
votes
1
answer
60
views
What will be the time complexity of this modified selectionSort code?
void simpleSort(int arr[], int arrSize){
/*initial searchSpace bounds*/
int left = 0;
int right = arrSize-1;
int maxElem, minElem, maxElemIndex, minElemIndex;
while(left <...
-2
votes
1
answer
100
views
+=(relation) the meaning of code for selection process [duplicate]
counter += (a1<=x);
what this code statement says ?
it is used in a problem to get how many numbers is lower than or equal (x) variable,
this should be as comparison between a1 and a2 to get what ...
0
votes
1
answer
95
views
why my selection sort in typescript not working
I learn a simple selection sort algoritm and try using from javascript/typescript.
and this my selection.sort algorithm in SelectionSort class
export default class SelectionSort {
private ...
0
votes
0
answers
38
views
animated selection sort on brightness of pixels of an image
Hi in this code in java I want to sort the pixels of the image through their brightness in java by using inversed selection sort however there is no update in the result image. how can i make it work?
...
2
votes
2
answers
994
views
Why is Rust's default sort function slightly slower than my Selection Sort for small arrays?
I'm quite new to Rust, so I might be missing something simple. I am using Rust 1.70.0-nightly. Here is the necessary code:
fn selection_sort(original_vec: &mut Vec<i32>) -> Vec<i32> ...
0
votes
1
answer
130
views
Use branch prediction with no else statement
I am currently implementing selectionsort. Using the code below and the driver file to test it below. I am currently trying to do micro optimizations to see what speeds it up.
public static void ...
0
votes
1
answer
58
views
Selection Sort by alternate selection
I am solving the following code challenge:
Let N be the size of a list. Implement the Selection Sort algorithm with the following modifications:
In odd iterations, find the element with the lowest ...
-1
votes
3
answers
138
views
Why is my ArrayList of String[]'s not sorting properly?
I am reading data in from a file, and asking the user which category they would like to sort by. The file has 13 columns (starting with country, year, and continent, then a list of double statistics ...
1
vote
2
answers
134
views
Sorting a string array length wise
I am required to sort an array with selection sort. I wanted it to to sort a string array in increasing order of length of its specific string elements.
It doesn't give the required output.
String[] a ...
0
votes
0
answers
1k
views
blazor quickgrid sorting not working for when sencond request clicked or selected or not getting refreshed quickgrid table data on selecting different
<QuickGrid TGridItem="DataRow" @ref ="Grid" Items="@rows.AsQueryable()" Pagination="@pagination">
@foreach (var col in columns)
{
<...
0
votes
2
answers
60
views
Error in implementing selection sort in JavaScript
This code is to implement selection sort in JavaScript. I tried with the array [3,2,1] but it return [1,1,1]; the array [4,5,1,2,7] return [1,1,1,2,7]. I don't know where I went wrong. Please help!
...
1
vote
1
answer
117
views
Selection sort in Golang
I have to make a select sort function by passing it an array and using max element to sort it, with the two functions swap and max.
func Swap(x *int, y *int) {
aux := *x
*x = *y
*y = aux
}
...
0
votes
2
answers
105
views
Can't find anything wrong with my selection sort code in C, but the code won't work
I'm a complete beginner in C, and I'm trying to learn how to do this selection sort algorithm to create an ascending list. But for some reason it doesn't run, and I can't seem to figure out why for an ...
2
votes
2
answers
171
views
Why isn't my C# Selection Sort algorithm outputting the expected result?
So I'm trying to implement selection sort in C# but the output isn't exactly what I'm expecting,
I tried tracing the loops and even brought out the good ol pen and paper but to no avail
using System;
...
1
vote
0
answers
34
views
Dynamic selection widget with fixed row count and an option to expand
I have an issue building the widget in the pic,
I'm trying to build a dynamic selection widget with an option to expand.
Max row is 3 but there is no constrain on how much children the row could have, ...
-2
votes
1
answer
94
views
I implement this sorting program in c . Why this is not working?
#include <stdio.h>
int main() {
int arr[5];
for(int i=0; i<5; i++)
scanf("%d",&arr[i]);
for(int i=0; i<5; i++)
{
int m=arr[i];
...
0
votes
2
answers
612
views
Big O Notation O(n^2) what does it mean?
For example, it says that in 1 sec 3000 number are sorted with selection sort. How can we predict how many numbers are gonna be sorted in 10 sec ?
I checked that selection sort needs O(n^2) but I dont ...
0
votes
1
answer
28
views
why my selection sort program is not working?
public class first {
public static void main(String args[]){
int arr[]={5,4,1,3,2};
for(int i=0; i<arr.length-1;i++){
int smallest=arr[i];
...
0
votes
1
answer
43
views
Getting wrong output while trying to sort information first by age and in case of same age then alphabetically
So I have to sort a list of people's information by their ages. In case there are people of the same ages, I have to sort them by their names alphabetically.
Here's my code:
#include <stdio.h>
#...
0
votes
0
answers
29
views
How to apply selection sort on a csv file data which is read into a struct based on a specific column?
I am reading an excel .csv file data to a struct. I am supposed to apply selection sort algorithm to this data on the basis of number of employees and then saving this sorted data into a new .csv file....
1
vote
0
answers
67
views
If I create a new list to perform sort , is it still valid to call it selection sort?
I am learning selection sort. Suppose I have to sort elements of a list in ascending order.We normally follow these steps -:
1- We divide (hypothetically) the list into two groups : sorted and ...
-2
votes
1
answer
76
views
Can't find where is the error , but showing error in this C program
While compiling the code the error is showing is conflicting type for
a function I have decelerated in this code , but I can't understand
where is the error.. Need help to fins the error , and how to ...
-1
votes
1
answer
24
views
selection sort is not working properly it is not scanning the number which are at last of the array
#include<iostream>
using namespace std;
int main()
{
int arr[] = {40,20,14,20,55,14,22,45,22,447,441,224,421,2,14,1,9};
int size = sizeof(arr) / sizeof(int);
for (int i = 0; i <...
0
votes
0
answers
15
views
selection sort algo in javascript [duplicate]
As we all know that selection sort in DS is done by comparing the elements and then swapping the smallest to the beginning using a temporary variable. I have learnt a new way to swap is by just ...
2
votes
1
answer
105
views
My sorting algorithm doesn't function due to unknown reason
I'm trying to create a sorting algorithm, it contains a nested loop which compares each element of the array to all other elements in the array, and if an element is greater in value than any of its ...
-3
votes
1
answer
97
views
why return value is -1 in this sorted list [2, 3, 12, 100, 200] target value is 100?
I practice some selection sort and given a sorted list found a number with the binary search but is not working. Why output comes index -1.
def selectionsort(lst, target):
first = 0
last ...
0
votes
2
answers
147
views
Implementing Selection Sort in C
I am trying to implement the Selection Sort Algorithm and here is my attempt:
int select(int arr[], int i)
{
int j, minIndex;
minIndex = i;
for (j = i + 1; arr[j]; j++)
{
...
1
vote
0
answers
164
views
Selection Sort displaying each Pass
So my Professor gave us an activity where we input the amount of array and its value. Then Selection sort will be implemented and will display each pass. I manage to do the input part but only managed ...
-3
votes
1
answer
113
views
Which sorting algorithm is efficient? [closed]
Which sorting algorithm work efficient for these two arrays:
Insertion Sort
Selection Sort
Bubble Sort
int arr1={16,22,11,62,45,37,62,45,3,17};
int arr2={3,6,9,12,15,17,20,22,29,35};
0
votes
2
answers
339
views
Problem in sorting array using Selection Sort algorithm
When passing an array in the selection function, I'm getting the required sorted array only for positive real numbers but for the negative numbers it is failing to do the same.
static void ...
-1
votes
1
answer
34
views
why the swap part is executing again after the function hit return statement
the code is working fine till end and i am getting a sorted array, but after sorting it is again executing swap part code , but the issue is getting solved by adding else to the swap method.
if(i==...
0
votes
3
answers
296
views
SelectionSort in c++ not sorting*
I am having a tough time trying to follow the logic here as to why it is not working correctly
expected output :
1 5 6 8
any help is greatly appreciated
Update: I got selection sort and insertion ...
-1
votes
1
answer
79
views
How to implement a benchmarking method for selection sort?
I have tried to measure the execution time for selection sorting an array in my code. The selection sort part is working but the benchmarking method "time" does not even get executed. What ...
0
votes
1
answer
416
views
Selection Sort and Nested For Loop Python
I understand the concept of Selection Sort (I think) but what I'm confused about is trying to code it. From my understanding of Selection Sort, you set the first element as your minimum value and then ...
0
votes
1
answer
48
views
Set value is object
I want to put obj into value ex. <option value={valueSort}>// valueSort = {name: 'ASC'}
for use to sort by name in my project but now the result that is [object Object]. I don't know what is ...
0
votes
1
answer
69
views
What is the time complexity of Stable Selection Sort algorithm?
static void stableSelectionSort(int[] a, int n)
{
for (int i = 0; i < n - 1; i++)
{
int min = i;
for (int j = i + 1; j < n; j++)
if (a[min] > a[j])
...
0
votes
1
answer
68
views
Selection_sort (python)
I came across this code on selection sort algorithm:
ls = [2, 5, 1, -9, 10, 13, 7, 2]
def selection_sort(ls):
for i in range(len(ls)):
imin = min(range(i,len(ls)), key = lambda x: ls[x])...
0
votes
1
answer
142
views
How can I return how many times my list is compared and swapped using selection sort?
I want to return a list where after each iteration, in the list has the number of comparisons and number of swaps.
like an output such as this:
[[3,1], [2,1], [6,1]]
How can I achieve this?
Apart from ...
-1
votes
2
answers
87
views
Selection sorting. not getting the required output
What is wrong with this code? Not getting the right output.
void selectionSort(vector<int>& arr, int n)
{
for(int i = 0; i < n-1; i++ )
{
int min = arr[i];
...