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 643665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:18:28+00:00 2026-05-13T21:18:28+00:00

I’ve been practicing for an upcoming programming competition and I have stumbled across a

  • 0

I’ve been practicing for an upcoming programming competition and I have stumbled across a question that I am just completely bewildered at. However, I feel as though it’s a concept I should learn now rather than cross my fingers that it never comes up.

Basically, it deals with a knight piece on a chess board. You are given two inputs: starting location and ending location. The goal is to then calculate and print the shortest path that the knight can take to get to the target location.

I’ve never dealt with shortest-path-esque things, and I don’t even know where to start. What logic do I employ to go about tackling this?

P.S. If it’s of any relevance, they want you to supplement the knight’s normal moves by also allowing it to move to the four corners of the square formed by the (potentially) eight moves a knight can make, given that the center of the square is the knight’s location.

  • 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-05-13T21:18:28+00:00Added an answer on May 13, 2026 at 9:18 pm

    You have a graph here, where all available moves are connected (value=1), and unavailable moves are disconnected (value=0), the sparse matrix would be like:

    (a1,b3)=1,
    (a1,c2)=1,
      .....
    

    And the shortest path of two points in a graph can be found using http://en.wikipedia.org/wiki/Dijkstra's_algorithm

    Pseudo-code from wikipedia-page:

    function Dijkstra(Graph, source):
       for each vertex v in Graph:           // Initializations
           dist[v] := infinity               // Unknown distance function from source to v
           previous[v] := undefined          // Previous node in optimal path from source
       dist[source] := 0                     // Distance from source to source
       Q := the set of all nodes in Graph
       // All nodes in the graph are unoptimized - thus are in Q
       while Q is not empty:                 // The main loop
           u := vertex in Q with smallest dist[]
           if dist[u] = infinity:
              break                         // all remaining vertices are inaccessible from source
           remove u from Q
           for each neighbor v of u:         // where v has not yet been removed from Q.
               alt := dist[u] + dist_between(u, v) 
               if alt < dist[v]:             // Relax (u,v,a)
                   dist[v] := alt
                   previous[v] := u
       return dist[]
    

    EDIT:

    1. as moron, said using the
      http://en.wikipedia.org/wiki/A*_algorithm
      can be faster.
    2. the fastest way, is
      to pre-calculate all the distances
      and save it to a 8×8 full matrix.
      well, I would call that cheating,
      and works only because the problem
      is small. But sometimes competitions
      will check how fast your program
      runs.
    3. The main point is that if you are preparing
      for a programming competition, you must know
      common algorithms including Dijkstra’s.
      A good starting point is reading
      Introduction to Algorithms ISBN 0-262-03384-4.
      Or you could try wikipedia, http://en.wikipedia.org/wiki/List_of_algorithms
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.