Running Time of Sorting Algorithm

Determine the asymptotic running time of the sorting algorithm maxSort. Algorithm maxSort(A) Input: An integer array A Output: Array A sorted in non-decreasing order 1. for j <- n-1 down to 1 do 2. m <- 0 3. for i = 1 to j do 4. if A[i] > A[m] then m <- i 5. … Read more

Are all hypothetical machine models for calculating runing time of an alogrithm same?

Im learning about time complexity analysis, and cant seem to figure out why do we consider a hypothetical machine that takes 1 unit of time for arithemitic and logical instructions and 1 unit of time to for assignment and return statements. Q) why does it have to be 1 unit of time? Q) Also is … Read more

Time and space complexity of a recursive problem (code included)

I am having trouble finding out the time and space complexity for this recursive solution. I have to create a list of words in order of word length. Each word, must be one character insertion off from the previous word. All permutations. Here is example: For the set “a, b, at, bat, cat, bait”. The … Read more

Recursion Time Complexity (Half n’ Half)

This is my solution for Leetcode 395, and I’m wondering how I can come up with its time complexity: Input: string s=s1,…,sn, integer k Go over all symbols s1,…,sn, one by one For each symbol si, check whether it appears less than k times in s If all symbols appeared at least k times, return … Read more

Time Complexity of a Naive Solution to Merge K Sorted Arrays

There is a leetcode question about merging k sorted arrays. I would like to be able to explain the time complexity of the following naive solution: function mergexsSortedArrays(xs) { if (xs === null || xs.length === 0) { return []; } let l1 = xs[0]; for (let i = 1; i < xs.length; i++) { … Read more

How to find the asymptotic bit cost

I know from a general point of view what big O notation is. I have taken an algorithms class before that was all implementations and did well. I am now in an algorithms class that is mostly theory and I cannot answer a basic question… Assume that the cost of multiplying two numbers is M(n)=O(n2), … Read more

Is using Fibonacci Heaps in Huffman Code, better than a regular Min-heap?

When using Huffman Code, to generate prefix-code trees for a sequence of letters, CLRS choose to use a normal Min-heap data structure. Using Fibonacci-heaps instead, are we not able to achieve a better bound on the running time, knowing that especially the INSERT operation of Fibonacci-heaps are constant time amortized, compared to worst-case θ(logn) in … Read more