Tagged Questions
An algorithm is a sequence of instructions, to solve a problem.
2
votes
2answers
88 views
Check if a binary tree is a subtree of another tree
I am doing a refresher on algorithms.
I tried to solve the problem of determining if you have 2 trees (T1 and T2), one is a subtree of the other.
I came up with the following:
public boolean ...
2
votes
2answers
73 views
Quicksort review
Reviewed quicksort today, here is the implementation I ended up with. Please post your feedback!
#include <cstdio>
#include <cstdlib>
#include <iostream>
inline void swap(int * ...
2
votes
6answers
120 views
N*N queen algorithm
I was just playing around with N queen problems means accommodating N queens on N*N chees board such that no one can kill each other. I tried a simple algorithm which uses backtracking.The program is ...
2
votes
1answer
62 views
How can I improve this JavaScript DOM-manipulation data-structure/algorithm?
(this is a crosspost from StackOverflow, it was suggested I asked here)
Goal
I've got a DOM with about 70 elements on it (divs with some content) . I need to move and toggle the display of those ...
2
votes
3answers
140 views
Longest words in dictionary that can be constructed from a list of letters — is this C++ code idiomatic?
As the title suggests, the problem is this: find the longest words in a dictionary of legal words that can be constructed from a given list of letters.
For example:
$ ./scrabble dictionary.txt i g h ...
-5
votes
0answers
35 views
How do you find the Big-O of the Rabin-Karp, Knuth-Morris-Pratt, and the Boyer-Moore string matching algorithms? [closed]
I still find the Big-O concept kind of abstract and hard to grasp. We've been going over it in class this past week, but unfortunately my professor isn't in town this week to help me understand the ...
1
vote
5answers
119 views
Sieve of Eratosthenes: making it quicker
I was thinking about doing problem 23 of Project Euler. It includes the difficulty where you have to factorize primes. I had already done that in problems I solved earlier, but it was only necessary ...
0
votes
0answers
20 views
why this won't work for only some testcases stated [migrated]
http://pastebin.com/XBMdfp2j
here's the link which shows the java class and also the problem statement.this doesn't work for some testcases, for example (3) in problem_statement in given link
Is ...
2
votes
1answer
107 views
Binary tree traversal algorithms
I recently started learning binary tree. Following is the code for a typical node for a tree (no code review required for that):
typedef unsigned int uint;
template<typename T>
class ...
-3
votes
0answers
47 views
Alogrithm with 0 input [closed]
the starting of alogirthms says that an algorithm may have ZERO INPUT and atleast ONE OUTPUT
in terms of output it is correct .please give example when it have ZERO input(neither internal(self) nor ...
3
votes
1answer
79 views
Date Time - Seconds Difference
For trivial reasons, I decided to have a go at differentiating dates. Low and behold having no idea how much of a non-trivial task it was to become.
It was originally a small sidetrack from a project ...
1
vote
2answers
85 views
Generic binary search
I have the following code for binary search
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
namespace ...
2
votes
1answer
63 views
Preparing for coding competition, need your feedback
After checking some incoming coding competitions, I feel I may want to develop a little bit more on my coding skills and style using some basic algorithms/data structures.
The following two pieces of ...
4
votes
2answers
154 views
Is it possible to optimize my sort method?
I just made this sort method. It runs fine and the code looks okay in my eyes.
Is is possible to opimize it so it runs faster? I mean like if it's O(n^3) now, it would be interessting changing it to ...
5
votes
2answers
140 views
Please comment on this heapsort code
For the time being I am not interested in any recursive solution,and also the code is not modularized,the whole body is inside the main function.
#include<iostream.h>
#include<stdlib.h>
...