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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:43:28+00:00 2026-06-01T20:43:28+00:00

I’m trying to come up with fast algorithm to find result of operation, where

  • 0

I’m trying to come up with fast algorithm to find result of AtLA operation, where

  • L – is symmetric n x n matrix with real numbers.
  • A – is sparse n x m matrix, m < n. Each row has one and only one non-zero element, and it’s equal to 1. It’s also guaranteed that every column has at most two non-zero elements.

I come up with one algorithm, but I feel like there should be something faster than this.

Let’s represent every column of A as pair of row numbers with non-zero elements. If a column has only one non-zero element, its row number listed twice. E.g. for the following matrix

Sparse matrix example

Such representation would be

column 0: [0, 2]; column 1: [1, 3]; column 2: [4, 4]

Or we can list it as a single array: A = [0, 2, 1, 3, 4, 4]; Now, L' = LA can be calculated as:

for (i = 0; i < A.length; i += 2):
  if A[i] != A[i + 1]:
     # sum of two column vectors, i/2-th column of L'
     L'[i/2] = L[A[i]] + L[A[i + 1]] 
  else:
     L'[i/2] = L[A[i]]

To calculate L''=AtL' we do it one more time:

for (i = 0; i < A.length; i += 2):
  if A[i] != A[i + 1]:
    # sum of two row vectors, i/2-th row of L''
    L''[i/2] = L'[A[i]] + L'[A[i + 1]]
  else:
    L''[i/2] = L'[A[i]]

The time complexity of such approach is O(mn + mn), and space complexity (to get final AtLA result) is O(nn). I’m wondering if it’s possible to improve it to O(mm) in terms of space and/or performance?

  • 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-01T20:43:30+00:00Added an answer on June 1, 2026 at 8:43 pm

    The second loop combines at most 2m rows of L’, so if m is much smaller than n there will be several rows of L’ that are never used.

    One way to avoid calculating and storing these unused entries is to change your first loop into a function and only calculate the individual elements of L’ as they are needed.

    def L'(row,col):
      i=col*2
      if A[i] != A[i + 1]:
        # sum of two column vectors, i/2-th column of L'
        return L[row][A[i]] + L[row][A[i + 1]] 
      else:
        return L[row][A[i]]
    
    for (i = 0; i < A.length; i += 2):
      if A[i] != A[i + 1]:
        for (k=0;k<m;k++):
          L''[i/2][k] = L'(A[i],k) + L'(A[i + 1],k)
      else:
        for (k=0;k<m;k++):
          L''[i/2][k] = L'(A[i],k)
    

    This should then have space and complexity O(m*m)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.