NCRE Common Foundation-Data Structure

data structure

  • To sort a linear table of length n, in the worst case, the sorting method whose number of comparisons is not n(n-1)/2 is heap sort .
    • Direct insertion sort, quick sort, and bubble sort are all.
    • In the worst case of heap sort, the number of comparisons is n*log2n.
  • Stack, first in last out, last in first out.
    • You can only insert and delete data at the top end of the stack .
  • The space complexity of an algorithm refers to the storage space required to execute the algorithm , including the space occupied by the algorithm program, the space occupied by the input initial data, and the additional space (including temporary work units) required during the execution of the algorithm.
  • An important property of a binary tree: a node with a degree of 0 is always one more node than a node with a degree of 2.
    • If there are 5 nodes with a degree of two, there are six leaf nodes (with a degree of zero).
  • The finiteness of the algorithm means that the running time of the algorithm program is limited.
    • Infinity means that the algorithm must end in a limited number of steps. The difference between an algorithm and a program is that the program can fall into an "endless loop", and the algorithm must end within a finite time. However, the limited amount of data and the limited length cannot guarantee the end of the program. For example, the infinite loop "continuously output one on the screen" only has one statement and one data, it will also fall into an infinite loop and cannot be ended.
  • The complexity of the algorithm includes time complexity and space complexity. Time complexity is the number of basic operations required during the execution of an algorithm, and space complexity is the storage space required to execute the program.
  • The tree has obvious hierarchical characteristics, is a one-to-many relationship, and belongs to a non-linear structure .
    • Binary tree is a type of tree.
  • Stacks and queues are linear structures.
    • A chained stack is a stack stored in a linked list.
    • The chained queue is a queue stored in a linked list, and a circular queue is a queue stored in an array and the space is connected end to end, allowing the first space to be used after the last space is used. It is a sequential storage of the queue structure. Need to reflect the status of the queue through the rear and front pointers. After the circular queue is running, the current number of elements in the circular queue is obtained by rear-front. If the result is negative, add the total capacity of the array.
      • The number of elements in the circular queue is determined by the team head pointer and the team tail pointer.
  • Sequential storage (array) and chain storage (linked list) are two storage methods of data structure. Regardless of linear structure or non-linear structure, both can be used for array storage or linked list storage .
    • For example, the binary tree is a non-linear structure, if it is a complete binary tree, it can also be stored in an array.
    • Since the storage of the sequential structure is an array, each space can only be continuous ; the storage space of the chain structure can be continuous or discontinuous .
    • Both sequential structure and chain structure can store ordered lists (that is, sorted data).
    • In addition to saving data, the chain structure also needs to save pointers; while the sequential structure only saves data, so the sequential structure saves more storage space .

Set of questions

  • Worst case time complexity: bubble sort, selection sort, insertion sort, and quick sort are the same, which is n(n-1)/2.
    • Hill sorting is nr (n<2, so less than n2), and heap sorting is n*log2n.
  • The fastest sorting speed in the worst case is Hill sorting .
  • In order to find a few elements, you need to find several times. In the worst case, the number of comparisons is n.
    • Search in an ordered list of length n. In the worst case, the number of comparisons is n.
  • If the pre-order sequence of the binary tree is the same as the middle-order sequence, it means that each node of the binary tree (except the leaf nodes) has only a right branch and no left branch .
    • The preorder sequence ABCDEF, the root node is A, and the successive branches are B, C, D, E, and F are leaf nodes, then the subsequent sequence is FEDCBA.
  • Number of nodes in the number = degree of all nodes + 1.
    • A tree has a degree of 3, and the number of nodes with a degree of 3 is 5, the number of nodes with a degree of 2 is 4, and there is no node with a degree of 1. Suppose the number of leaf nodes is x, then 5+4+0+x=3 times 5+2 times 4+1 times 0+0 times x+1, so x=15.
  • The data flow diagram is a tool for requirement analysis, expressing the flow and processing of data in the software, and reflecting the functions of the software.
  • Tools for detailed software design:
    • PAD diagram
    • Program flow chart
    • NS diagram
  • Tools for overall design:
    • System structure diagram
  • In object-oriented programming, any object is regarded as composed of two parts: attributes (data) + methods (operations).
    • A class is an abstraction of an object, and an object is an instance of a class.
    • Communication between objects is based on message passing.
    • The characteristics of classes and objects are:
      • Unique identification: the object is distinguishable, and it is distinguished by the inner essence of the object, not by description;
      • Classification: Objects with the same or similar properties and methods can be abstracted into classes (templates). Classes are abstractions of objects, and objects are instances of classes;
      • Encapsulation:
      • Inheritance:
      • Polymorphism:
      • Module independence is good.
    • The class contains operations (methods) on the data.
    • The class contains data (attributes) and methods (or operations).
    • The class is abstract.
  • The conceptual design does not involve specific database management systems, let alone specific database files. It can be simply considered that conceptual design is to abstract the data in the real world to be managed as an ER model and draw an ER diagram.
    • The conceptual model is a part of the data model of the database, facing the objective world and users, and has nothing to do with the database management system.
  • Connection between database fields:
    • 1:N
    • 1:1
    • M:N
    • N:1
  • It is not a combination of multiple columns and satisfies 2NF.
  • There is a transitive dependency, and 3NF is not satisfied.

file

  • The file pointer is a pointer variable defined by FILE in the program.
    • The file pointer is not a file location pointer, and does not indicate the location of the current read and write data.
    • Pass the file to the fscanf function, you can write any character into the text file. 【wrong】
    • The file pointer points to the storage location of the file in the computer. 【wrong】
  • The function call form for reading a binary file is:
    • fread(buffer,size,count,fp);
      • The first address of a memory block in buffer represents the address where the data is stored.
      • size The number of bytes in a memory block
      • count is an integer variable that represents the number of bytes of data to be read
      • fp a file pointer, pointing to the file to be read
  • "R" and "w" can only be written but not read, "wb+"
  • The fwrite function is used to output data to a file in binary form
  • The getchar function is used
  • The gets function is used to read a string from the terminal
  • The fputs function is used to output a string to a file
  • *pf?
  • What is the meaning of the parameters of the fwrite function? Four? (Output string, number, number, pointer position)
  • The rewind function (pointer name) returns the file pointer to the beginning of the file.
  • The file is composed of a data sequence , which can constitute a binary file or a text file.
  • EOF is a symbolic constant defined in the library function file.
    • The value is not zero.
    • When the fgets function reads the last character, the return value is not EOF. !
    • Both text files and binary files can use EOF as an end-of-file mark. 【wrong】
      • EOF can only be used as the end of a text file, and its value is -1.
      • Cannot be used as the end of a binary file.
  • fp one is defined as a pointer to a file, and the end of the file is not read, the function return value of the C language function feof (fp) is 0; the return value is non-zero when the end is read.
  • The function of the standard library function fgets(s,n,f) is to read a string with a length not exceeding n-1 from the file f and store it into the memory pointed to by the pointer s .
  • Call the fopen function in C language to link the files to be read and written in the program with the actual data files on the disk.
    • The parameter of the fopen function is the pointer name!
    • Assign the return value of the fopen function to?
    • When the return value of the fopen function is null?
  • fread is a library function for inputting files (reading files in binary mode).
    • fwrite, fprintf, and fputc can output files and are library functions.
  • The file pointer is a pointer type variable.
    • Call the scamf function to write to a text file?
    • File pointers cannot point to different files at the same time.
    • Is the value of the file pointer file?

Prepared on 2021/3/22.

Guess you like

Origin blog.csdn.net/weixin_52777510/article/details/115255005