非ovarlapping子问题递归解的时间复杂度分析

时间:2016-05-12 10:05:56

标签: python recursion time-complexity big-o asymptotic-complexity

这里我只是放了python代码。

  Rec(Arr,N,K,X) :
     if(X==0 and K==0):
         return 1
     elif(X<=0 or K<=0 or N<0):
        return 0
     else :
         return Rec(Arr,N-1,K,X)+Rec(Arr,N,K-1,X-Arr[N])

如果Arr的所有元素都是不同的,那么这个结论是所有子问题都是非重叠的(只是一个小例子,手动完成)

请按N,K,X评估时间复杂度。 感谢您阅读此问题......

1 个答案:

答案 0 :(得分:0)

基本上,此问题被视为深度优先搜索高度受Undefined symbols for architecture x86_64: "std::get_terminate()", referenced from: _CLSExceptionCheckHandlers in Crashlytics(CLSException.o) "std::set_terminate(void (*)())", referenced from: _CLSExceptionInitialize in Crashlytics(CLSException.o) CLSTerminateHandler() in Crashlytics(CLSException.o) "std::terminate()", referenced from: ___clang_call_terminate in Crashlytics(CLSException.o) "typeinfo for char const*", referenced from: _CLSExceptionRaiseTestCppException in Crashlytics(CLSException.o) GCC_except_table1 in Crashlytics(CLSException.o) "typeinfo for std::exception", referenced from: GCC_except_table1 in Crashlytics(CLSException.o) typeinfo for std::exception const* in Crashlytics(CLSException.o) "vtable for __cxxabiv1::__class_type_info", referenced from: typeinfo for std::__1::__basic_string_common<true> in Crashlytics(CLSException.o) NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. "vtable for __cxxabiv1::__pointer_type_info", referenced from: typeinfo for std::exception const* in Crashlytics(CLSException.o) NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. "vtable for __cxxabiv1::__vmi_class_type_info", referenced from: typeinfo for std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > in Crashlytics(CLSException.o) NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. "___cxa_allocate_exception", referenced from: _CLSExceptionRaiseTestCppException in Crashlytics(CLSException.o) "___cxa_begin_catch", referenced from: CLSTerminateHandler() in Crashlytics(CLSException.o) ___clang_call_terminate in Crashlytics(CLSException.o) "___cxa_current_exception_type", referenced from: CLSTerminateHandler() in Crashlytics(CLSException.o) "___cxa_demangle", referenced from: +[CLSDemangleOperation demangleCppSymbol:] in Crashlytics(CLSDemangleOperation.o) "___cxa_end_catch", referenced from: CLSTerminateHandler() in Crashlytics(CLSException.o) "___cxa_rethrow", referenced from: CLSTerminateHandler() in Crashlytics(CLSException.o) "___cxa_throw", referenced from: _CLSExceptionRaiseTestCppException in Crashlytics(CLSException.o) "___gxx_personality_v0", referenced from: +[CLSDemangleOperation demangleBlockInvokeCppSymbol:] in Crashlytics(CLSDemangleOperation.o) +[CLSDemangleOperation demangleSwiftSymbol:] in Crashlytics(CLSDemangleOperation.o) -[CLSDemangleOperation main] in Crashlytics(CLSDemangleOperation.o) ___28-[CLSDemangleOperation main]_block_invoke in Crashlytics(CLSDemangleOperation.o) Dwarf Exception Unwind Info (__eh_frame) in Crashlytics(CLSDemangleOperation.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 限制的二叉树。因此,时间复杂度的顺序受max(N,K)的限制。然后2^max(N,K)X可能会降低时间复杂度。但目前尚不清楚,因为它取决于ArrArr的值。 (例如,如果Arr = [inf,...,inf],时间复杂度将为X。)