Arrays, linked lists, jump table

Arrays, linked lists, jump table

Arrays, linked lists, and basically jump table properties

Array (Array)

  • java, c ++: int a [100]; // initialization of the definition of a good capacity to
  • Python: list = [] // define an array directly
  • JavaScript: let x=[1,2,3]

time complexity

method the complexity
prepend O (n)
append O (1)
lookup O (1)
insert O (n)
delete O (n)

Member function

  • Element access
    • access at specified element at the same time bounds checking
    • operator [] to access the specified element
    • front access to the first element
    • back to access the last element
    • It returns a pointer to the first data point in the array in memory element
  • Iterator
    • begin the first element returns an iterator container
    • It returns a pointer to the tail end of the container end iterator
    • Returns a pointer to the last element of the container rbegin reverse iterator
    • Returns a pointer to the distal end rend reverse iterator
  • capacity
    • Check whether the empty container is empty
    • Returns the size to accommodate the number of elements
    • max_size Returns the maximum number of elements that can be accommodated
  • operating
    • fill the container filled with the specified value
    • swap exchange content

List

class Node {
    int data;
    Node next;
}
class LinkedList {
    Node head; /
    Node (int d) { data = d;}
}

time complexity

method the complexity
prepend O (1)
append O (1)
lookup O (n)
insert O (1)
delete O (1)

Member function

  • Element access
    • front access to the first element
    • back to access the last element
  • Iterator
    • Returns a pointer to the first element of the container begin iterator
    • It returns a pointer to the tail end of the container end iterator
    • Returns a pointer to the tail end of the container rbegin iterator
    • Returns a pointer to the distal end rend reverse iterator
  • capacity
    • Check whether the empty container is empty
    • size Returns the number of receiving elements
    • max_size Returns the maximum number of elements that can be accommodated
  • modifier
    • clear Clear content
    • insert insert elements
    • emplace situ construction elements
    • erase Erase element
    • push_back adding elements to the end of the container
    • emplace_back place at the end of the container construction element
    • pop_back end elements removed
    • the starting element is inserted into the container push_front
    • emplace_front container construction element head situ
    • pop_front remove the first element
    • resize can change the number of elements stored in the container
    • swap exchange content
  • operating
    • merge merge two sorted list
    • splice elements move in list from another
    • remove / remove_if remove elements that meet specified criteria
    • The reverse order of all elements in the inverted list
    • unique erases consecutive duplicate elements
    • sort sorts the elements

Jump table

time complexity

  • 跳表查询的时间复杂度分析:
    n/2、n/4、n/8、第k级索引结点的个数就是n/(2^k) 假设索引有h级,最高级的索引有2个结点。
    n/(2^h) = 2,从而求得 h = log2(n) - 1

  • 时间复杂度 O(logn)
    • 优化
      • 升维 :空间换时间
    • 应用
      • LRU Cache - Linked list: LRU 缓存机制
      • Redis - Skip LIst

        1.Stack:先入后出;添加、删除皆为O(1)
        2.查询为 O(n)

        时间复杂度

        方法 复杂度
        Access O(n)
        Search O(n)
        Insertion O(1)
        Deletion O(1)

        成员函数

  • 元素访问
    • top 访问栈顶元素
  • 容量
    • empty 检查底层的容器是否为空
    • size 返回容纳的元素数
  • 修改器
    • push 向栈顶插入元素
    • emplace 于顶原位构造元素
    • pop 删除栈顶元素
    • swap 交换内容

队列

1.Queue:先入先出;添加、删除皆为O(1)
2.查询为 O(n)

时间复杂度

方法 复杂度
Access O(n)
Search O(n)
Insertion O(1)
Deletion O(1)

成员函数

  • 元素访问
    • front 访问第一个元素
    • back 访问最后一个元素
  • 容量
    • empty 检查底层的容器是否为空
    • size 返回容纳的元素数
  • 修改器
    • push 像队列尾部插入元素
    • emplace 于尾部原位构造元素
    • pop 删除栈顶元素
    • swap 交换内容

      扩展

  • 双端队列
    • 简单理解:两端可以进出的
    • 插入和删除都是O(1)操作
    • QueueDeque - double ended queue
  • 优先队列
    • 插入操作:O(1)
    • 取出操作:O(logN) - 按照元素的优先级取出
    • 底层具体实现的数据结构较为多样和复杂:heap、bst(二叉搜索树)、treap

Guess you like

Origin www.cnblogs.com/liugangjiayou/p/12369998.html