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

  • Home
  • SEARCH
  • 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 8052255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:30:07+00:00 2026-06-05T07:30:07+00:00

I was recently asked to create a program to find best matches in text

  • 0

I was recently asked to create a program to find best matches in text fragment. I have successfully written this program but I do have a question about its time complexity.

Problem is defined as following.

given a query, find occurrences of the query words in document and highlight the best tokens.

The time that my program takes

O(m + n + p)

here

m = length of the document in characters

n = length of the query in characters

p = number of total matches in the document

In this case the biggest term is always going to be "m" because in most cases documents are going to be larger then the query itself.

Can I safely deduce that time complexity of my program is O(m)?

  • 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-05T07:30:08+00:00Added an answer on June 5, 2026 at 7:30 am

    No, you can’t. According to the Big-O notation your function m is an upper bound on the actual time your algorithm takes to run, if there’s a constant M such as the real time will always be less or equals to M*m. Take a case where the document has size zero (an empty document) but someone queries it with a positive number of characters. The upper bound in this case will be 0 (plus a constant), but the actual time the program will take to run might be greater than that. So your program can not be said to be O(m).

    In other words, “most cases” isn’t enough: you must prove that your algorithm will perform within that upper bound in all cases.

    Update: The same can be said for p: common sense says p is always smaller than m, but that’s only true if the search terms don’t overlap. Take for instance the document aaaaaa (m=6) and the search terms a, aa and aaa (n=3). In this case, there are 6 occurences of a, 5 of aa and 4 of aaa, so p = 15. Even though it’s a very unlikely scenario (same for the empty document) it’s still required that you take p into account in your complexity analysis. So your program must really be described as O(m + n + p) as you originally stated.

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

Sidebar

Related Questions

Recently I have asked a question about what I should use to create self-contained
I just recently asked this question: https://stackoverflow.com/questions/6359367/running-a-bash-program-every-day-at-the-same-time The solution of using crontab -e to
Ok I had asked a question recently based on this. But I need to
i recently asked this question on how to have a container div width set
I recently asked this question in the pyglet-users group, but got response, so I'm
Recently I asked this question: Find Common Values in several arrays, or lists VB.NET
I recently asked this question: MS SQL share identity seed amongst tables (Many people
Please forgive if this question has been asked numerous times. I recently installed Eclipse
I've recently asked a question regarding best ways of separating business logic from data
I recently asked this question: Expose XML or Objects - thanks all for the

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.