An array of data structures and algorithms

Array is a simple data structure, which occupies a contiguous memory and stored in the order data, must be specified when creating the data capacity size;

  • Advantages: high time efficiency, i.e. high efficiency look O (1), and can achieve a simple hash table;
  • Disadvantages: the low spatial efficiency, even if only one data store must allocate space for all data, and the insertion and deletion inefficient O (n);

Find a two-dimensional array (interview questions to prove safety offer --- 3)

Title: In a two-dimensional array, each row from left to right in order of ascending sort each column are sorted in ascending order from top to bottom. A complete function, enter such a two-dimensional array and an integer, it is determined whether the array contains the integer.

  • bool Find(int *matrix, int rows, int cols, int number);

Problem-solving ideas:

(1) First, select the top right corner of array numbers (lower-left corner may be), if the number = number, then the search process ends;

(2) if the number> number, then culled the cell columns;

(3) if the number <number, excluding the line where the number;

2 To be continued ~

Guess you like

Origin www.cnblogs.com/bo1990/p/11441961.html