Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to design and analysis of algorithms.
2
votes
Accepted
Linear Search Algorithm - Why allow a user to input a start and end index to LS?
Surely, it is not about correctness. It is only a slightly general version of linear search. This technique is not uncommon. Obviously the more general the procedure is, the more applicable it is.
Li …
1
vote
Accepted
Perform an operation on an array in O(n)
Yes, you can perform this operation in $O(n)$ using a stack $\mathbb{S}$.
Before presenting the algorithm directly, I would like to give you an illustration using your example. It is not difficult f …
0
votes
Accepted
Finding undirected cycles in linear time (triangulating graphs while minimizing degree)
Which algorithm does "Eulers technique to find an Eulerian cycle" refer to?
It probably refers to the Hierholzer algorithm (wiki) which takes linear time.
The algorithm below is from the wiki a …
4
votes
Solution verification: solving $T(n) = T(n-1) + 2/n$
Although the final result is correct, your solution is not.
The recurrences of the form $T(n) = T(n-1) + 2/n$ is often called "decrease and conquer"; while the ones of the form $T(n) = T(n/2) + O(1)$ …
3
votes
Accepted
Find the minimum range
Below I try to prove that the greedy algorithm ($\mathcal{A}$) given by @norbertpy (and @Bergi) is correct. Please check it.
Problem Definition:
The algorithm $\mathcal{A}$ of @norbertpy is for a …
1
vote
k-center algorithm in one-dimensional space
[1] Efficient Algorithms for the One-Dimensional $k$-Center Problem. arXiv, 2014. …
1
vote
Accepted
Integer Knapsack Problem - No duplicates Allowed
You are right about "independence" between subproblems. Therefore, you use the new subproblems (wiki) by introducing another variable $i$, meaning using the items up to $i$:
Define $V[i,s]$ to be …
2
votes
Selecting k-1 items that divide a sorted array to k equal parts
I assume that $k = 2^m$ ($m \in \mathbb{N}$) and $k \le n$.
Here is a recursive (divide-and-conquer) algorithm:
Select the median of the array $A$ and use it to partition the array into $A_l$ and $ …
1
vote
2
answers
6k
views
Check whether an undirected graph contains a simple cycle of length four using the "Squares"...
The following problem is exercise 4.3 of the book "Algorithms" by S. Dasgupta, C. Papadimitriou, and U. Vazirani.
Squares. …
2
votes
Accepted
What are some real world examples of nearly sorted lists
What about log files described in AWStats logfile analyzer 7.5 Documentation?
An error log file is not always completely sorted but only "nearly" sorted because of cache and writing log engines us …
0
votes
How to find the median of 5 elements by rote and its time complexity is O(n)
Becuase $5$ is a constant, you can use (almost) any naive method to find the median of $5$ elements in constant time.
However, it is known that $6$ comparisons are sufficient (and necessary) to find …
3
votes
Accepted
Given n distinct numbers show that the second smallest element can be found in n + lg n - 2 ...
The algorithm with $n + \lceil \lg n \rceil -2$ comparisons uses "tournament" (lecture note from utdallas).
To form a tournament tree: Compare $A[2i−1]$ with $A[2i]$ for $i = 1$
to $n$. We compare t …
7
votes
Determine whether a point lies in a convex hull of points in O(logn)
The proofs of these two theorems contain the algorithms you are looking for. …
2
votes
0
answers
145
views
Are there some popular science videos on computer algorithms to recommend?
I am seeking for some popular science videos on computer algorithms for my last lecture delivered in this term. … The topic of the videos includes but are limited to algorithm design, algorithm analysis, computational complexity, the application of algorithms, the history of algorithms (even computer science), the …
20
votes
log(n) complexity. Difficulty understanding example
Do you know the Harmonic series (wiki)?
$$1 + \frac{1}{2} + \cdots + \frac{1}{n} = 1 + \sum_{i=2}^{n} \frac{1}{i} \le 1 + \int_{1}^{n} \frac{1}{x} \text{d}x = 1 + \ln n = \Theta(\log n).$$
Similarly …