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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:48:53+00:00 2026-05-22T02:48:53+00:00

Given a sequence of operations: a*b*a*b*a*a*b*a*b is there a way to get the optimal

  • 0

Given a sequence of operations:

a*b*a*b*a*a*b*a*b

is there a way to get the optimal subdivision to enable reusage of substring.

making

a*b*a*b*a*a*b*a*b => c*a*c, where c = a*b*a*b

and then seeing that

a*b*a*b => d*d, where d = a*b

all in all reducing the 8 initial operations into the 4 described here?

(c = (d = a*b)*d)*a*c

The goal of course is to minimize the number of operations

I’m considering a suffixtree of sorts.

I’m especially interested in linear time heuristics or solutions.
The ‘*’ operations are actually matrix multiplications.

  • 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-22T02:48:53+00:00Added an answer on May 22, 2026 at 2:48 am

    This whole problem is known as “Common Subexpression Elimination” or CSE. It is a slightly smaller version of the problem called “Graph Reduction” faced by the implementer of compilers for functional programming languages. Googling “Common Subexpression elimination algorithm” gives lots of solutions, though none that I can see especially for the constraints given by matrix multiplication.

    The pages linked to give a lot of references.

    My old answer is below. However, having researched a bit more, the solution is simply building a suffix tree. This can be done in O(N) time (lots of references on the wikipedia page). Having done this, the sub-expressions (c, d etc. in your question) are just nodes in the suffix tree – just pull them out.


    However, I think MarcoS is on to something with the suggestion of Longest repeating Substring, as graph reduction precedence might not allow optimisations that can be allowed here.

    sketch of algorithm:

    optimise(s):
        let sub = longestRepeatingSubstring(s).
        optimisedSub = optimise(sub)
        return s with sub replaced by optimisedSub
    

    Each run of longest repeating substring takes time N. You can probably re-use the suffix tree you build to solve the whole thing in time N.

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

Sidebar

Related Questions

Given an input sequence, what is the best way to find the longest (not
I'm looking for an algorithm that given two permutations of a sequence (e.g. [2,
Given two sequences of identifier, how to find the smallest operation sequence that will
I need a parallel algorithm (cost optimal) to check if a given sequence of
Given a sequence of data (it may have duplicates), a fixed-sized moving window, move
I would like to know if anyone sees a pattern in the sequence given
Given the following sequence: normal %(b)BOLD% normal I want to transform this into the
Given a unsorted sequence of a[1,...,n] of integers, give an O(nlogn) runtime algorithm to
Given the following model, I want to index the fields (sequence,stock) class QuoteModel(models.Model): quotedate
I need to generate a controlled sequence of pseudo-random numbers, given an initial integer

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.