Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:07:55+00:00 2026-06-02T15:07:55+00:00

My algorithm is not working, I’m a newbie to all algorithms and javascript and

  • 0

My algorithm is not working, I’m a newbie to all algorithms and javascript and I just can’t seem to work out why it’s not working.

Here’s the Array (23, 19, 35, 12, 30)

Max value = 0

Here’s what I have…

For K= 0 to n – 2 

  MAX = 0

      For j = 0 to n – k - 2

                         If item[j] > item[MAX]
                         MAX = item[j] 

                  end if
          end for 
      swap n - k - 2 with item[MAX] 
   end for
end SelectionSort

Where have I gone wrong? thanks!!!!

Also, if anyone could tell me how to use it in a trace table I would be sooo happy!

Kind regards
Craig

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:07:57+00:00Added an answer on June 2, 2026 at 3:07 pm

    Using max in this expression is causing the problem item[MAX], It would be j. Please give it a consideration and then try again like this, The selection sort Demo

         var arr = new Array (23, 19, 35, 12, 30);         
         temp = 0;
    
         for( k = 0; k < arr.length-1; k++)
         {
    
            for( j = k+1;  j < arr.length; j++)
            {
    
                if (arr [k] > arr [j])
                {
    
                     temp = arr[k];
                     arr[k] = arr[j];
                     arr[j] = temp;
                }
             }
         }
    
    for(k = 0; k < arr.length; k++)
        alert(arr[k]);​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to implement simple ray tracing algorithm, but I can not figure out
I've got a fairly simple pagination algorithm here but it's not working the way
Just started working on a basic grid analysis algorithm in JavaScript but I have
Okay so here's my algorithm for finding a Cut in a graph (I'm not
I'm doing some work with Ukkonen's algorithm for building suffix trees, but I'm not
I'm not sure if I'm completely understanding genetic algorithms and how they work, I'm
I begin a new Fibonacci algorithm, but it's not working. It's very simple: --fiblista
See also: Why is my image rotation algorithm not working? This question isn't language
Two simple questions and my brain's not working. I'm using Floyd's Algorithm and trying
I'm working on a Clojure algorithm to solve the problem posed here: http://spin.atomicobject.com/2011/05/31/use-clojure-to-move-drugs-a-programming-challenge/ and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.