Data Structures and Algorithm Analysis Chapter

Chapter III table, stacks and queues

This chapter describes the three basic, most simple data structure, such as a title.
This chapter focuses on:

  • Introduce the concept of abstract data type (ADT) of
  • It explains how to effectively operate the table
  • ADT introduces its application in the realization of recursive
  • Introduction queue ADT and its application in the operating system and algorithm design

Abstract Data Types (abstract data type, ADT) isAchieve storage structure for storing data and basic arithmetic operations

Table 1. ADT

Simple continuous linear structure for storing data, implemented method:

  • Array achieve
  • Pointer realization
  • Cursor achieve

All operations on the table can be used to implement an array, the array is dynamically assigned, and the need to estimate the maximum value of the table, the array can be the subject of certain operations to benefit, such as PrintList and Find operations can be completed in a linear time However, insertion and deletion costs are expensive, need to be inserted after insertion of the elements are shifted one position backwards, is required to remove a forward position, in the worst case complexity of these two operations is O (n ), the array is generally not so simple to achieve this structure

In order to avoid the insertion and deletion of linear cost, we can not allow continuous table stored (in memory), which we use a pointer to implement (the book is very simple, I use the smart pointer + template implemented)
HTTPS: // blog.csdn.net/lancelot0902/article/details/91364882

If a language does not support a pointer, we can use the third method - the cursor method, we set up an array of structures, and data structures comprising next, next index point to the next data in the array, for example, a [1] = 2 illustrates a [1] successor element is a [2], because we use an array, so there is no new and free nature to add or delete nodes, so we maintain a FreeList chain, with CursorAlloc and CursorFree controlling the list, to add elements from FreeList in a take away, if deleting elements, put the deleted node is added to FreeList go
https://blog.csdn.net/lancelot0902/article/details/91413853

Stack ADT

  • List implementation
  • Array achieve

Applications: function call occurs when a function call, to store all important information (activity record, stack frame whatever), you can use a stack to hold this information, then control is transferred to the new functions perform operations new function, after the implementation, this information is then transferred from the control transfer of the original function, so when using recursion, can not forget the baseline scenario, and recursive process can not be too long, both of which can cause a stack overflow, it is sometimes used in place of the recursive loop when good choice

queue

  • List implementation
  • Array achieve

There are two points to achieve circular queue Note:

  • Detecting whether the queue is empty it is important
  • The queue size is implicit by the front and rear calculated

Guess you like

Origin blog.csdn.net/lancelot0902/article/details/91364684