## 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

## Euclidean algorithm and well define ness on the underlying set

Euclidean algorithm is given below: gcd(a,b):   if a=0, return b   otherwise, return gcd(bmod, a) Let us first argue that the algorithm terminates. The reason is that each time the number is decreasing, and there is a well-ordering defined on the set from which number a and b are defined. Question: What if the … 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

## Convex hull partition of a set of points

Given a set S of n points in R2, denote by convb(S) the boundary of the convex hull of S. Let S1=convb(S)Si+1=convb(S∖i⋃j=1Sj). Now S1,… forms a partition of S. Is there an O(nlogn) time algorithm for computing this partition? Answer AttributionSource : Link , Question Author : Mert Sağlam , Answer Author : Community

## 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

## Why is the run time with a loop of this structure considered O(log n)

I used the search function and a good amount of google searches, but wasn’t able to get a straight answer on how a loop of the form below, is translated to a proper summation where the function derived from the summation is: O(logn). Example of the for loop: int j = 0; for (int i … 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; 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