Algorithm na Bincike mai ƙarfi (Dynamic Search) a cikin C++- Bayani, Misali da Lambobi

Algorithm ɗin bincike mai ƙarfi, wanda kuma aka sani da “search-as-you-type” algorithm, yawanci ana amfani dashi don aiwatar da fasali kamar cikawa ta atomatik a sandunan bincike. Wannan algorithm yana ba da shawarwari na ainihin-lokaci dangane da shigar mai amfani da bayanan da ake da su.

Yadda Ake Aiki

  1. Fara da saitin bayanai mai ɗauke da jerin abubuwa(misali, kalmomi, sunaye ko samfura).
  2. Yayin da mai amfani ke rubuta kowane hali, sabunta tambayar nema.
  3. Tace saitin bayanai bisa tambayar neman na yanzu.
  4. Nuna sakamakon da aka tace ga mai amfani a ainihin-lokaci.

Misali

Yi la'akari da tsarin bayanan shirye-shirye: ["C", "C++", " Java ," Python ","," JavaScript "," Ruby "," Swift "."

  1. Nau'in mai amfani "C". Sakamakon da aka tace: ["C", "C++"].
  2. Nau'in mai amfani "C++". Sakamakon da aka tace: ["C++"].
  3. Nau'in mai amfani " Java ". Sakamakon da aka tace: [" Java "," JavaScript "].
  4. Nau'in mai amfani "Py". Sakamakon da aka tace: [" Python "].
  5. Nau'in mai amfani "Jav". Sakamakon da aka tace: [" Java "," JavaScript "].

Misali Code a C++

#include <iostream>  
#include <vector>  
#include <string>  
  
std::vector<std::string> dynamicSearch(const std::vector<std::string>& dataset, const std::string& query) {  
    std::vector<std::string> results;  
  
    for(const std::string& item: dataset) {  
        if(item.find(query) != std::string::npos) {  
            results.push_back(item);  
        }  
    }  
  
    return results;  
}  
  
int main() {  
    std::vector<std::string> programmingLanguages = {"C", "C++", "Java", "Python", "JavaScript", "Ruby", "Swift"};  
    std::string userQuery = "Jav";  
  
    std::vector<std::string> suggestions = dynamicSearch(programmingLanguages, userQuery);  
  
    std::cout << "Suggestions for query '" << userQuery << "': ";  
    for(const std::string& suggestion: suggestions) {  
        std::cout << suggestion << ";  
    }  
    std::cout << std::endl;  
  
    return 0;  
}  

A cikin wannan misali, dynamicSearch aikin yana ɗaukar bayanan bayanan shirye-shirye na harsunan shirye-shirye da kuma tambayar mai amfani azaman abubuwan shigarwa. Yana mayar da shawarwari dangane da tambayar yanzu. Kamar yadda mai amfani ke rubuta haruffa, algorithm yana tace saitin bayanai kuma yana nuna shawarwari na lokaci-lokaci.

Lura: Haƙiƙanin aiwatar da bincike mai ƙarfi na iya zama mai sarƙaƙƙiya, wanda ya haɗa da dabaru kamar tsarin gwaji ko ingantacciyar ƙididdiga don manyan bayanan bayanai.