Cheating paper for Data Structure

本文深入探讨了算法复杂度、排序算法、递归、动态规划等核心概念,解析了冒泡排序、归并排序、快速排序等经典排序方法,并讨论了堆、栈、队列、树等数据结构的应用与实现细节。
  1. Time Complexity (Lecture 2)
    1.1. Definition: given input size N, find running time of the algorithm.
    1.2. Notation:
    1.2.1. |X|: the size of X
    1.2.2. o(N) little-o notation: limit of function at given value

e.g.
1.2.3. O(N) big-o notation: worst case

1.2.4. big omega notation: best case

1.2.5. big theta notation:

1.2.6. but not the way around
e.g.
1.3. Property 1:
Property 2:
1.4. Facts: proof by L’Hôspital’s rule
1.5. Input size: 1 byte = 8 bits =
1.6. Common sense: if the algorithm ends in many rounds, the time complexity is

  1. Recursion
    2.1. Common form: recursion with boundary conditions, e.g. F(x)=F(x-1)+1, F(0)=2
    2.2. Order/Time-complexity of recursion: solve asymptotically

2.2.1.
2.2.2.
2.2.3.
2.3. Solve problems in recursive way: cut problem into sub-problems

  1. Sorting
    3.1. Abstract data type (ADT): array
    3.2. Sorting method
    3.2.1. Bubble sort (naïve sorting):
    Pseudocode:
    while (A is not in ascending order) do {
    for each j in {0,1 … n - 2} do
    if A[j] > A[j + 1] then
    switch A[j] and A[j + 1]} //switch two adjacent numbers
    Time complexity:
    Worst case:
    Average case:
    3.2.2. Merge sort/In-place merge sort:
    Pseudocode:
    (a) Divide into sub-array
    (b) Compare and merge
    Function:
    Time complexity:
    Worst case:
    Average case:
    3.2.3. Quick sort/In-place quick sort:
    Pseudocode:
    qsort(A, h, t) {
    if (h < t)
    q = partition(A, h, t) //select number, put smaller on left, put larger on right
    qsort(A, h, q - 1) //then recursion on the left
    qsort(A, q + 1, t) //then recursion on the right
    }
    Function:
    Partition algorithm:
    Two-pass algorithm: goes from head/tail, compared number is at the middle and switch
    One-pass algorithm: goes from head/tail, compared number is at the head and switch
    Time complexity:
    Average case:
    Worst case: Ω
    3.2.4. Radix sorting (linear sort, non-comparison):
    Sort by digit (个\十\百…)
    3.3. Average case: use expectation (summation or integral)

3.4. Summary:
Algorithms Worst case Best case Average case
Naïve sort
Bubble sort
Merge sort
Quick sort
Where , the lower bound issue.

  1. Stack
    4.1. Method: push, pop, top
    4.2. Time complexity: N operations are of for push() and pop()
    4.3. Related problems: prefix/infix expression evaluation, call stack.

  2. Queue
    5.1. Method: enqueue, dequeue, front
    5.2. Time complexity: 1 operation is of for dequeue, and 1 operation is of for enqueue (moving all element back for 1 position).
    5.3. Cyclic array: reduced enqueue time complexity to : record head and tail position, update position after enqueue.
    5.4. Queue implementation with 2 stacks.

  3. Divide and conquer algorithm
    6.1. E.g. sorting algorithm above
    6.2. E.g. linear time k-th largest number algorithm: split array A (size N) into M groups, choose pivot - the median within medians of each group, use the pivot to split A into 2 sub-array, and choose array with k-th position number, and recursion…
    Here, we are sure that numbers of N is less than pivot. Then the function is:

Algorithm improved.
6.3. E.g. Optimization problem – backpack packing problem
Description: Given weights and values of items, find max value given weight bound.
7. Dynamic programming
7.1. E.g. greedy algorithm, like Huffman encoding problem

  1. 2 basic algorithms
    Algorithm Divide-and-conquer Dynamic programming
    Define Solve sub-probs and divide into smaller sub-probs and solve subs, finally combine sub-sols Divide first, find solution, go to larger sub-problem, combine solution, find solution

  2. Abstract data type (ADT)
    9.1. Set
    9.2. Cartesian product: all combination of two sets
    9.3. Relationship set: union, intersection
    9.4. Linked list (insert, delete, find):
    9.4.1. Find k-th element: 2 pointers at head, one goes twice faster than the other one.
    9.4.2. Doubly linked list
    9.5. Tree
    9.5.1. T = (r, V, E), r is root, V is a set of nodes, E is a set of edges between nodes
    9.5.2. Tree is recursive ADT, with ancestors and successors
    9.5.3. Special case – binary tree
    9.5.3.1. If tree is at height , then there are nodes, leaves, and internal nodes
    9.5.3.2. Problems: infix/prefix calculation
    9.5.4. Binary search tree (BST)
    9.5.4.1. Def: left node is smaller, right node is larger
    9.5.4.2. Creating algorithms:
    Naïve algorithm (brute force)
    9.5.4.3. Problems: Huffman encoding, finding longest path in tree.
    9.5.5. Special case – balanced tree (at height )
    9.5.5.1. Time complexity: insert, delete, find at worst case
    9.5.6. Special case – red-black tree, AVL tree
    9.5.7. Special case – heap

  3. Priority queue
    10.1. It is similar to min-heap or max-heap, where root value is min or max in tree
    10.2. Methods
    10.2.1. Insertion: put new number at last position and bubble it up, by comparing with the value of its parents, at
    10.2.2. Pop: pop head, and put last element at head, then bubble down, update time
    10.3. Problem – streaming algorithms, keep only top 10 numbers no matter the input
    10.3.1. Solution: selection tree (tournament tree), build at , update at
    10.3.1.1. winner tree, leaves are numbers, node is the larger ones of two children
    10.3.1.2. loser tree, node is smaller one of two children, where the largest value can also be recorded during the comparison.
    10.3.2. Usage: merge M sorted array. Each time, we update winner (loser) and move to the next value.
    10.3.3. Good: tournament tree save time on (1) looking up data is expensive (2) looking up leaves is expensive

  4. Graph
    11.1. Definition: G = (V, E), E is edge between two nodes, V is vertex (node)
    11.2. Classification:

11.3. Example: tree is a special graph without cycle. Cycle. Weight Graph, G = (V, E, W), W is weight.
11.4. Concepts:
Degree of node, D(x): the number of edges attached to node x
Out-degree: in directed graph, the number of edges leaving node x
In-degree: in directed graph, the number of edges pointing towards node x
Regular graph: the D(x) is same for any node x in graph, x边形
Sub-graph: vertices are sub-vertices
Induced sub-graph: vertices are sub-vertices, AND edges have endpoints in U
Connected graph: for any pair of nodes (x, y), there must be a path between x and y in graph. Connected components of undirected graph is a partition of vertices such that within each subset, vertices are mutually reachable.
11.5. Representation:
11.5.1. NxN adjacent matrix, 1 represents existing edge between two vertices (column and row are vertices).
11.5.2. Array of linked list.
11.6. Methods to enumerate graph:
11.6.1. Breadth first search (BFS): explore neighbor first, by marking attached edges available and the vertex unavailable, then next neighbor vertex
11.6.2. Depth first search (DFS): explore neighbors until no unvisited node attached, go back, do recursion. If none, restart DFS on a new vertex. Do recursion inside for loop. In connected undirected graph, it must visit all vertices.
Time complexity:
, linear in edge, if use linked list. Because each position in the adjacency linked list is visited once and there are |V| vertices and |E| edges.
, if use adjacent matrix. Because each position in the matrix is visited once.
11.7. Related problems: shortest paths, INDEPENDENT SETS, COVER SETS, minimum cut, min spanning tree, Euler tour, travelling salesman problem.
11.7.1. Longest path in tree. Start from root to leave, or leave to root, both ok.
11.7.2. Spanning tree. Tree that contains all vertices in graph, e.g. DFS tree, BFS tree.
11.7.3. Minimum spanning tree (MST): connect all vertices with minimum weight edges.
11.7.3.1. Solution: greedy algorithm. Always choose min weight edges, and then move to next vertices, until all vertices are visited.
If use heap and linked list, it takes .
(1) Choose a minimum weighted edge (a, b) from V-S to S, add a to S
(2) Repeat (1) until S = V
If use adjacency matrix, it takes
(1) Each time we choose a smallest value from D, add vertex to S
(2) Update value in D
(3) Repeat (1) and (2) until S = V
D 1 2(linked to 1) 3(linked to 1) 4(linked to 1) 5 6(linked to 1) 7
Start at 1 Inf 2 10 5 Inf 1 Inf

D 1 2(linked to 1) 3(linked to 1) 4(linked to 6) 5 6(linked to 6) 7
Start at 1 Inf 2 10 2 Inf Inf Inf
Correctness (Claim and proof) prove minimality in different situation
11.7.3.2. Union find set (UF) for MST
Union method: by rank, or by tree size. F is a set of value, UF unite values together to form a larger union in F.
11.7.3.3. Kruskal’s algorithm for MST
F is a union of verti:ces, T is paired vertices (less weight), S is edges with weight in ascending order. Pop min weight edge and linked vertices in S, store them in T, union pairs from T to F, if the number is visited in F, then not store them in T. Finally, T is pairs of vertices, then add weights between these vertices together to form a MST.
11.7.4. Bipartite graph: if there is a way to split undirected graph G into 2 sets A, B, s.t. all edges are between A and B.
11.7.5. Matching: find a set of edges, that no endpoint of any found edge in the set is overlapping.
11.7.6. Shortest path between two nodes in graph – Dijkstra’s algorithm
11.7.6.1. Pseudocode
init
S = {s}, current = s
dist = [inf, inf, inf, inf, inf, …], dist[s] = 0, // distance to s at current stage

()
For each (current, u) in E, u not in S
if dist[u] > dist[current] + w[current, u] update the dist[u]
Put current in S
Let current = min_j { dist[ j ] } for all j not in S
Repeat (
) until t is in S.
11.7.6.2. If we continue until all vertices included, then we can calculate shortest path from the source to all vertices.
11.7.6.3. Correctness:
11.7.6.4. Time complexity:
11.7.7. Detect negative cycle and negative weight in graph G – Bellman-ford algorithm. After many runs, if the d[k] is still changing, there is a negative cycle.
11.8. Directed graph.
11.8.1. Dijkstra’s shortest path algorithms also works on directed graph without negative weight.
11.8.2. Classification and concepts:
Acyclic: no circle in graph
Sinks/minima: out-degree 0 vertices
Sources/maxima: in-degree 0 vertices
11.8.3. Topological sorting, for acyclic undirected graph. Method is, “find source, remove source vertex and attached edges”, then again recursion.

11.8.3.1. Implementation based on linked list graph.
B is stack stores unexplored vertices, and D is current in-degree of vertices in the remaining graph.
11.8.3.2. Prove correctness on claim if all vertices have non-zero in degree, then there is a cycle in the graph.
11.9. Edges
11.9.1. Type: tree edges, backward edges (point to ancestor), forward edges (point to descendant), cross edges (else in directed graph)
11.10. Strongly connected components (SCC): (a, b) where a can reach b, and b can reach a in directed G, such relation R is equivalent relation. A class of R is called SCC.
11.10.1. To find all linked SCC in graph, topologically sort can make sure the starting vertex is not trapped in a SCC, and can go to other SCC. SCC(u) < SCC(v) means there is a path from v to u in G, but not the way around.
11.10.2. Implementation on finding the lowest SCC.
(1) Reverse graph, , where edges are reversed in directed graph G.
(2) Do DFS on , starting with any vertex, and restart for several rounds later. Then get several DFS trees. Finally, find the source.
(3) From source, do DFS on G.
Time complexity is

  1. Elementary P, NP, NP-hardness
    12.1. Sample HARD/NP problems.
    12.1.1. 3-SAT problems: N union of variables, each variable is of three Boolean symbols. Determine this N union is true or false.
    12.1.2. Independent set problem. Set S is any pair of vertices in S, no edge in between.
    12.1.3. Vertex cover problem. Cover set S is a subset of V, such that all edges in G can be reached through these vertices.
    Find largest independent set in graph <=> find smallest vertex cover set in graph.
    12.1.4. Clique problem.
    12.1.5. Hitting set problem. given a set O of objects and a collection C of subsets of O. Whether there is a set of K objects from O such that for each c in C, there is one element from K in c. E.g. O = {1,2,3,4,5}, C = {{1,2,5},{3,4}}, K=2, then the hitting set can be {1,3,5}
    12.1.6. Set cover problem: given a set S of objects and a collection C of subsets of O. Whether there is a subset D of C whose size is K and such that = 𝑆.
    12.1.7. Backpack packing problem.
    12.2. Classifications.
    12.2.1. Easy problems: can be solved in polynomial time algorithm
    12.2.2. Hard problems: cannot be solved in polynomial time algorithm.
    12.2.3. P: deterministic polynomial time solvable
    12.2.4. NP: non-deterministic polynomial time solvable
    12.2.5. Hardness: defined by whether the problem can be reduced. E.g. a problem is NP hard if other NP problem can be reduced to this problem.
    12.2.6. NP complete: if the problem is NP and NP hard
    12.3. Prove a problem is HARD.
    12.4. Reduction: in polynomial time, the algorithm can transfer input from problem A, to suit input of problem B. then problem A can be reduced in polynomial time to problem B. , want to find a final reduced problem x that can be solved in polynomial time.
    12.4.1. E.g. clique problem can be reduced to independent set.
    An independent set is a group of nodes where for any pair of nodes in the set, there is not an edge between those nodes. A clique is a group of nodes where for any pair of nodes in the set, there is an edge between those nodes. Therefore, an independent set in a graph G is a clique in the complement of G and vice-versa.
    Given this, a simple transformation would be given G and k to produce (the complement of G) and k. Then, G has an independent set of size k if and only if has a clique of size k.
    12.4.2. E.g. clique problem can be reduced to vertex cover. E.g. vertex cover to hitting set. E.g. vertex cover to set cover.

  2. Dynamic programming
    13.1. Problem: longest non-decreasing sequence, longest common subsequence
    Solution: define subproblems, write recursion, write pseudocode, prove correctness, find time complexity.

内容概要:文章以“智能网页数据标注工具”为例,深入探讨了谷歌浏览器扩展在毕业设计中的实战应用。通过开发具备实体识别、情感分类等功能的浏览器扩展,学生能够融合前端开发、自然语言处理(NLP)、本地存储与模型推理等技术,实现高效的网页数据标注系统。文中详细解析了扩展的技术架构,涵盖Manifest V3配置、内容脚本与Service Worker协作、TensorFlow.js模型在浏览器端的轻量化部署与推理流程,并提供了核心代码实现,包括文本选择、标注工具栏动态生成、高亮显示及模型预测功能。同时展望了多模态标注、主动学习与边缘计算协同等未来发展方向。; 适合人群:具备前端开发基础、熟悉JavaScript和浏览器机制,有一定AI模型应用经验的计算机相关专业本科生或研究生,尤其适合将浏览器扩展与人工智能结合进行毕业设计的学生。; 使用场景及目标:①掌握浏览器扩展开发全流程,理解内容脚本、Service Worker与弹出页的通信机制;②实现在浏览器端运行轻量级AI模型(如NER、情感分析)的技术方案;③构建可用于真实场景的数据标注工具,提升标注效率并探索主动学习、协同标注等智能化功能。; 阅读建议:建议结合代码实例搭建开发环境,逐步实现标注功能并集成本地模型推理。重点关注模型轻量化、内存管理与DOM操作的稳定性,在实践中理解浏览器扩展的安全机制与性能优化策略。
基于Gin+GORM+Casbin+Vue.js的权限管理系统是一个采用前后端分离架构的企业级权限管理解决方案,专为软件工程和计算机科学专业的毕业设计项目开发。该系统基于Go语言构建后端服务,结合Vue.js前端框架,实现了完整的权限控制和管理功能,适用于各类需要精细化权限管理的应用场景。 系统后端采用Gin作为Web框架,提供高性能的HTTP服务;使用GORM作为ORM框架,简化数据库操作;集成Casbin实现灵活的权限控制模型。前端基于vue-element-admin模板开发,提供现代化的用户界面和交互体验。系统采用分层架构和模块化设计,确保代码的可维护性和可扩展性。 主要功能包括用户管理、角色管理、权限管理、菜单管理、操作日志等核心模块。用户管理模块支持用户信息的增删改查和状态管理;角色管理模块允许定义不同角色并分配相应权限;权限管理模块基于Casbin实现细粒度的访问控制;菜单管理模块动态生成前端导航菜单;操作日志模块记录系统关键操作,便于审计和追踪。 技术栈方面,后端使用Go语言开发,结合Gin、GORM、Casbin等成熟框架;前端使用Vue.js、Element UI等现代前端技术;数据库支持MySQL、PostgreSQL等主流关系型数据库;采用RESTful API设计规范,确保前后端通信的标准化。系统还应用了单例模式、工厂模式、依赖注入等设计模式,提升代码质量和可测试性。 该权限管理系统适用于企业管理系统、内部办公平台、多租户SaaS应用等需要复杂权限控制的场景。作为毕业设计项目,它提供了完整的源码和论文文档,帮助学生深入理解前后端分离架构、权限控制原理、现代Web开发技术等关键知识点。系统设计规范,代码结构清晰,注释完整,非常适合作为计算机相关专业的毕业设计参考或实际项目开发的基础框架。 资源包含完整的系统源码、数据库设计文档、部署说明和毕
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值