【数据结构】数据结构笔记

java特征

inheritance

the root object class

abstract classes抽象类方法

interfaces接口

genetics泛型

线性数据结构

ps:An abstract data type (ADT) is a set of objects together with a set of operations. Abstract data types are mathematical abstractions; nowhere in an ADT’s defifinition is there any mention of how the set of operations is implemented.

抽象数据类型(ADT):带有操作的数据集合

数组array

In case of a linked list having n elements, we need to travel through every node of the list to add the element at the end of the list. Thus asymptotic time complexity is θ(n).

We know the head node in the given linked list. Insertion and deletion of elements at the front of the linked list completes in O (1) time whereas for insertion and deletion at the last node requires to traverse through every node in the linked list. Suppose there are n elements in a linked list, we need to traverse through each node. Hence time complexity becomes O(n).

栈stack

特点:结构清晰,先进后出。

operations:push、pop(空栈没有,可以来判断是否为空)、top(空栈没有,可以来判断是否为空)

Process of inserting an element in stack is called push.

 In a stack, if a user tries to remove an element from empty stack it is called underflow.Underflow occurs when the user performs a pop operation on an empty stack. Overflow occurs when the stack is full and the user performs a push operation. Garbage Collection is used to recover the memory occupied by objects that are no longer used.

Pushing an element into stack already having five elements and stack size of 5, then stack becomes overflow.

That there is a Sequential entry that is one by one is the meaning of that entries in a stack are “ordered”.In stack data structure, elements are added one by one using push operation. Stack follows LIFO Principle i.e. Last In First Out(LIFO).

Wjen data Transfer between two asynchronous process,you may not use a stack.Data transfer between the two asynchronous process uses the queue data structure for synchronisation. The rest are all stack applications.

In the entire parenthesis balancing method when the incoming token is a left parenthesis it is pushed into stack. A right parenthesis makes pop operation to delete the elements in stack till we get left parenthesis as top most element. 3 elements are there in stack before right parentheses comes. Therefore, maximum number of elements in stack at run time is 3.

用单链表实现栈功能:

对列queue

A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a queue.Linear list of elements in which deletion is done at front side and insertion at rear side is called Queue. In stack we will delete the last entered element first.

The data structure required for Breadth First Traversal on a graph is queue. In Breadth First Search Traversal, BFS, starting vertex is first taken and adjacent vertices which are unvisited are also taken. Again, the first vertex which was added as an unvisited adjacent vertex list will be considered to add further unvisited vertices of the graph. To get first unvisited vertex we need to follows First In First Out principle. Queue uses FIFO principle.

Circular Queue is also known as Ring Buffer.Circular Queue is also called as Ring Buffer. Circular Queue is a linear data structure in which last position is connected back to the first position to make a circle. It forms a ring structure.

When Rear = MAX_SIZE – 1, there will be no space left for the elements to be added in queue. Thus queue becomes full.

用单链表实现队功能:

package chp3.ex03.que32;

public class SingleQueue<AnyType> {
	private Node<AnyType> front, rear;	
	SingleQueue(){	
		front = null;
		rear = null;
	}
	public Node<AnyType> getFront(){
		return front;		
	}
	public Node<AnyType> getRear(){
		return rear;		
	}
	void enqueue(AnyType x) {	
		Node<AnyType> p = new Node<AnyType>(x, null);
		if (rear != null) {
			rear.next = p;
			rear = p;			
		}	
		else {
			front = p;
			rear = p;
		}	
	}
	AnyType dequeue() {	
		AnyType temp = front.data;
		Node<AnyType> p = front;
		if (front.next == null) {// only 1 node
			front = null;
		 	rear = null;
		}
		else
			front = front.next;
		return temp;
	}
	private class Node<AnyType>{
		AnyType data;
		Node<AnyType> next;
		Node(){
			this(null, null); 
		}
		Node(AnyType x){
			this(x, null);
		}
		Node(AnyType x, Node<AnyType> p){		
			data = x;
			next = p;
		}		
	}		
}

链表linked list

The ‘next’ pointer points to null only when the list is empty, otherwise it points to the head of the list. Every node in circular linked list can be a starting point(head).

我们将大小为0的特殊列表称为空列表。

数据链表(array list)

频繁查找用数组链表,频繁插入撤销用单向链表

单向链表(Simple Linked Lists)

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBARGF2aWRfSHp5,size_9,color_FFFFFF,t_70,g_se,x_16

查找数据要挨个执行访问,数据后面只跟一个指针。

双向链表(Doubly Linked Circular Lists)

A doubly linked list has two pointers ‘left’ and ‘right’ which enable it to traverse in either direction. Compared to singly liked list which has only a ‘next’ pointer, doubly linked list requires extra space to store this extra pointer. Every insertion and deletion requires manipulation of two pointers, hence it takes a bit longer time. Implementing doubly linked list involves setting both left and right pointers to correct nodes and takes more time than singly linked list.

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBARGF2aWRfSHp5,size_20,color_FFFFFF,t_70,g_se,x_16

 频繁访问数据时优势明显,一个数据有左右两个指针。

非线性数据结构

哈希表

Binomial Queues二项队列

二项树的集(二项树:There is at most one binomial tree of every height. A binomial tree of height 0 is a one-node tree; a binomial tree, Bk, of height k is formed by attaching a binomial tree, Bk−1, to the root of another binomial tree, Bk−1. )

合并:高度一致的二项树合并

删除1.删除根节点值最小的二项树,剩下二项树集合成为新的二线队列H'

       2.去掉删除的二项树节点,成为H''

       3.合并H'与H''

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

岩塘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值