TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of Saddleback Algorithm for 2D arrays. More...
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | search |
for std::assert | |
namespace | saddleback |
Function for implementing Saddleback Algorithm. | |
Functions | |
std::pair< uint32_t, uint32_t > | search::saddleback::saddleback (std::vector< std::vector< int32_t > > matrix, int32_t element) |
static void | test () |
Test implementations. | |
int | main () |
Main function. | |
Implementation of Saddleback Algorithm for 2D arrays.
Saddleback Algorithm is an algorithm that searches 2D array in linear time, i.e, O(m + n), where m is number of rows and n is number of columns of 2D array. Also, each row and column of the matrix should be sorted beforehand for this algorithm to work.
Definition in file saddleback_search.cpp.
int main | ( | void | ) |
Main function.
Definition at line 112 of file saddleback_search.cpp.
std::pair< uint32_t, uint32_t > search::saddleback::saddleback | ( | std::vector< std::vector< int32_t > > | matrix, |
int32_t | element ) |
This function implements Saddleback Algorithm, on a sorted 2D array, and finds the location of the element needed to search
matrix | 2D matrix which is sorted on the basis of rows and columns |
element | element to be searched |
Definition at line 39 of file saddleback_search.cpp.
|
static |
Test implementations.
Definition at line 78 of file saddleback_search.cpp.