原创 算法作業:證明題(5)-- 8.12

問題摘要: 證明如下問題是NP-完全問題,給定一個無向圖G=(V,E)和整數k,求G中一個規模爲k的團以及一個規模爲k的獨立集 證明: a)對於團,因爲對於V的子集V’,其每一對節點是由邊集一條邊相連,則團爲G完全子圖。又對於一個給定圖

原创 算法作業:證明題(4)-- 8.12

問題陳述: 證明: a)∵給定一個圖G的待定生成樹,遍歷生成樹的每一個節點,檢查每個點的度數是否小於等於k,可判定其是否滿足k-生成樹,判定過程時間複雜度O(V) ∴ k-生成樹問題是一個搜索問題 b) ∵需要找到生成的樹是否符合要求

原创 算法作業HW28:LeetCode 100. Same Tree

Description: Given two binary trees, write a function to check if they are equal or not. Two binary trees are c

原创 算法作業HW27:LeetCode 28. Implement strStr()

Description: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needl

原创 算法作業:證明題(3)-- 8.10

問題描述: 證明: a) b)使g=|V|-1,可得到一個Rudrata路徑 c)讓g表示爲子句的總數可得 d)使a*(a-1)/2 = b,這時候可成最大團問題,因爲這使得a個頂點兩兩之間相互連接 e)要成最大獨立子集問題,只需使b

原创 算法作業HW29:LeetCode 219. Contains Duplicate II

Description: Given an array of integers and an integer k, find out whether there are two distinct indices i and j i

原创 算法作業HW30:LeetCode 235. Lowest Common Ancestor of a Binary Search Tree

Description: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.

原创 算法作業:證明題(2)-- 8.8

問題描述: 證明: ∵ EXACT 4SAT是NP問題,且可通過對於任一個EXACT 3SAT的實例,當其包含了某變量的否定或者肯定,去除該變量;或者當其某一個子句多次包含了某一個文字,將所有包含文字數縮減爲一次 ∴EXACT 3S

原创 算法作業HW25:LeetCode 26. Remove Duplicates from Sorted Array

Description: Given a sorted array, remove the duplicates in place such that each element appear only once and return

原创 算法作業HW22:LeetCode29 Divide Two Integers

Description: Divide two integers without using multiplication, division and mod operator. If it is overflow, r

原创 算法作業HW20 202. Happy Number

Description: Write an algorithm to determine if a number is "happy". A happy number is a number defined by the f

原创 算法作業HW23:LeetCode 31 Next Permutation

Description: Implement next permutation, which rearranges numbers into the lexicographically next greater permuta

原创 算法作業HW21:LeetCode 18 4Sum

Description: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar

原创 算法作業HW26:LeetCode 27. Remove Element

Description: Given an array and a value, remove all instances of that value in place and return the new length. Do

原创 算法作業HW18:LeetCode102 Binary Tree Level Order Traversal

Description:   Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right