computer-science

How to determine the height of a recursion tree from a recurrence relation?

删除回忆录丶 提交于 2019-12-03 17:33:16
问题 How does one go about determining the height of a recursion tree, built when dealing with recurrence run-times? How does it differ from determining the height of a regular tree? alt text http://homepages.ius.edu/rwisman/C455/html/notes/Chapter4/ch4-9.gif edit: sorry, i meant to add how to get the height of the recursion tree from the recurrence relation . 回答1: If recurrence is in the form of T(n) = aT(n/b) + f(n) then the depth of the tree is log base b of n. For example, 2T(n/2) + n

Why Two's Complement?

限于喜欢 提交于 2019-12-03 17:13:40
问题 I'm writing a tutorial to teach kids (ages 9 to 13) about programming. I started with computers themselves, they don't have that much to do with computer science, it's more about the process involved with a solution to a computational problem. With that starting point, I'm guiding them toward an understanding that machines can help us with certain computational problems. People are great at abstract thinking and imagination, but computers are AWESOME at following a well-specified routine.

What's the difference between a boolean literal and a boolean value?

孤街醉人 提交于 2019-12-03 16:47:47
I can't seem to find a clear explanation as to what the difference is between these two. I'd also like to point out that I don't really understand the difference between literals and values either. Do boolean literals use the Boolean object? dtech A literal is a value you literally provide in your script, so they are fixed. A value is "a piece of data". So a literal is a value, but not all values are literals. Example: 1; // 1 is a literal var x = 2; // x takes the value of the literal 2 x = x + 3; // Adds the value of the literal 3 to x. x now has the value 5, but 5 is not a literal. For your

What is a “set” in C++? When are they useful?

做~自己de王妃 提交于 2019-12-03 15:45:36
I'm having a hard time conceptualizing c++ sets, actually sets in general. What are they? How are they useful? Don't feel bad if you have trouble understanding sets in general. Most of a degree in mathematics is spent coming to terms with set theory: http://en.wikipedia.org/wiki/Set_theory Think of a set as a collection of unique, unordered objects. In many ways it looks like a list: { 1, 2, 3, 4 } but order is unimportant: { 4, 3, 2, 1} = { 1, 2, 3, 4} and repetitions are ignored: { 1, 1, 2, 3, 4 } = { 1, 2, 3, 4} A C++ set is an implementation of this mathematical object, with the odd

Does it Make Sense to Map a Graph Data-structure into a Relational Database?

六月ゝ 毕业季﹏ 提交于 2019-12-03 15:05:21
Specifically a Multigraph . Some colleague suggested this and I'm completely baffled. Any insights on this? It's pretty straightforward to store a graph in a database: you have a table for nodes, and a table for edges, which acts as a many-to-many relationship table between the nodes table and itself. Like this: create table node ( id integer primary key ); create table edge ( start_id integer references node, end_id integer references node, primary key (start_id, end_id) ); However, there are a couple of sticky points about storing a graph this way. Firstly, the edges in this scheme are

Minimum Subarray which is larger than a Key

谁都会走 提交于 2019-12-03 14:29:48
I have an array of integers (not necessarily sorted), and I want to find a contiguous subarray which sum of its values are minimum, but larger than a specific value K e.g. : input : array : {1,2,4,9,5} , Key value : 10 output : {4,9} I know it's easy to do this in O(n ^ 2) but I want to do this in O(n) My idea : I couldn't find anyway to this in O(n) but all I could think was of O(n^2) time complexity. Let's assume that it can only have positive values. Then it's easy. The solution is one of the minimal (shortest) contiguous subarrays whose sum is > K . Take two indices, one for the start of

Partition Problems Brute Force Algorithm

…衆ロ難τιáo~ 提交于 2019-12-03 13:03:53
问题 I am trying to do the pseudocode for the partition problem below in bruteforce. a set of integers X and an integer k (k >1). Find k subsets of X such that the numbers in each subset sum to the same amount and no two subsets have an element in common, or conclude that no such k subsets exist. The problem is NP-Complete For example, with X = {2, 5, 4, 9, 1, 7, 6, 8} and k = 3, a possible solution would be: {2, 5, 7}, {4, 9, 1}, {6, 8} because all of them sum up to 14. for exhaustive search I

Binary Search Problems? [duplicate]

霸气de小男生 提交于 2019-12-03 12:23:54
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What are the pitfalls in implementing binary search? I was perusing the wikipedia page for Binary Search and stumbled on a quote by Knuth below: "Although the basic idea of binary search is comparatively straightforward, the details can be surprisingly tricky" I recall implementing several Binary Searches as part of my Computer Science curriculum, but don't remember it being terribly tricky. However, this

Is conditional branching a requirement of Turing-completeness?

自古美人都是妖i 提交于 2019-12-03 12:23:26
问题 I've been searching the web and I'm finding somewhat contradictory answers. Some sources assert that a language/machine/what-have-you is Turing complete if and only if it has both conditional and unconditional branching (which I guess is kind of redundant), some say that only unconditional is required, others that only conditional is required. Reading about the German Z3 and ENIAC, Wikipedia says: The German Z3 (shown working in May 1941) was designed by Konrad Zuse. It was the first general

Is number comparison faster than string comparison?

喜夏-厌秋 提交于 2019-12-03 11:07:13
问题 I heard that hashing (ie converting a string or object to a number) is used for strings and such because it is easier to compare numbers than strings. If true, what is the reason for this ? 回答1: This is not necessarily the case, but probably the case most of the time. Consider the following situation: I want to compare the string "apples" vs. "oranges". If I only want to determine "apples" == "oranges", I need only compare the first character of each string: 'a' != 'o' => "apples" != "oranges