# Algorithms_in_C++: operations_on_datastructures/trie_multiple_search.cpp File Reference

Loading...
Searching...
No Matches
trie_multiple_search.cpp File Reference

Trie datastructure with search variants More...

`#include <algorithm>`
`#include <cassert>`
`#include <cctype>`
`#include <cstring>`
`#include <iostream>`
`#include <queue>`
Include dependency graph for trie_multiple_search.cpp:

## Classes

class | operations_on_datastructures::trie_operations::Tnode
| Class defining the structure of trie node and containing the methods to perform operations on them. More...

## Namespaces

namespace | operations_on_datastructures
| for std::vector
namespace | trie_operations
| Functions for Trie datastructure implementation.

## Functions

static void | test ()
| Function to test a simple search before and after deleting an entry. And to test out the multiple variants of search. More...
int | main (int argc, char const *argv[])
| Main function. More...

## Detailed Description

Trie datastructure with search variants

This provides multiple variants of search functions on a trie structure utilizing STL. The trie is valid for only English alphabets.

Author
  Ghanashyam

## Function Documentation

## main()

int main | ( | int | argc,
|  | char const * | argv[]
| ) |  |

Main function.

Parameters

  argc | commandline argument count (ignored)
  argv | commandline array of arguments (ignored)

Returns
  0 on exit

{
test(); // run self-test implementations
return 0;
}
test
static void test()
Function to test a simple search before and after deleting an entry. And to test out the multiple var...
Definition: trie_multiple_search.cpp:422
Here is the call graph for this function:

## test()

static void test | ( |  | ) |

static

Function to test a simple search before and after deleting an entry. And to test out the multiple variants of search.

{
auto root = new operations_on_datastructures::trie_operations::Tnode();
std::vector<std::string> inputs = {
"abcde", "sss", "ssss", "ssst", "sssu", "sssv",
"sst", "ssts", "sstt", "sstu", "tutu", "tutuv",
"tutuu", "tutuvs", "tutus", "tvst", "tvsu", "vvvv"};
for (auto &i : inputs) {
root->Insert(i);
}
// Search an existing entry
assert(root->SearchPresence("vvvv"));
std::cout << root->SearchPresence("vvvv") << std::endl;
// Delete it
root->Delete("vvvv");
// Search for the entry again
assert(!root->SearchPresence("vvvv"));
std::cout << root->SearchPresence("vvvv") << std::endl;
std::cout << root->SearchPresence("tutu") << std::endl;
root->SearchSuggestions("tutu");
std::cout << root->SearchPresence("tutu") << std::endl;
root->SearchSuggestions("tutuv");
std::cout << root->SearchPresence("tutuv") << std::endl;
root->SearchSuggestions("tutuvs");
root->SearchFreqSuggestions(
"tu"); // The top 3 frequent entries with prefix tu are tutu, tutuv &
// tutuvs respectively
root->SearchSuggestions(
""); // Empty search to list all the entries in the trie
}
std::cout
operations_on_datastructures::trie_operations::Tnode
Class defining the structure of trie node and containing the methods to perform operations on them.
Definition: trie_multiple_search.cpp:34
std::endl
T endl(T... args)
std::vector
Here is the call graph for this function: