deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so, you mean i should fake it

It doesn't matter, do what you want.

but i must be ready for explaining anything related to my answer ?

Always.

if i dont know the answer or say i dnt have any idea related to that, then should i make vague guesses or just say them "sir, i have no idea!"

If you don't know the answer, try to figure it out. Or say you don't know and explain how you might go about finding the answer. Guessing won't make you look good in the eyes of the interviewer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Perhaps we use different notations.

It seems we do. Mine is correct. ;)

I class O(n) and O(mn) and indeed O(any multiple of n at all) as all being O(n).

What happens when the growth of m reaches or exceeds the growth of n? You're assuming that m is insignificant, which isn't a safe assumption. It's not unreasonable for O(mn) to be equivalent to O(n*n), which as I'm sure you're aware equates to O(n^2). It could be even worse than that, and saying that the complexity is O(n) for such cases would be woefully inaccurate.

In complexity analysis you're allowed to discard constants from the equation, not independent variables that have their own asymptotic growth.

@james sir, what is that solution u talking about ? is that trie related or what ?

The O(mn) solution I was thinking of was a simple frequency table or map. One pass through the URL collection to build the table and another pass to look for frequencies equal to 1. The m part of the equation accounts for comparing URL strings when building the table.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

should i fake it that i dont know OR should i say him that i know the answer already OR do what ?

Interview questions generally adhere to one of two goals:

  1. Determine if the candidate is a good cultural fit for the company.
  2. Determine if the candidate is capable of doing the job.

In interviews I don't really care if you know the answer or not; I'm more interested in seeing how you reach an answer than what the answer is. So I'd suggest following the "show your work" rule. If you want to rattle off an answer, that's fine, but expect to be asked to explain any answer you give.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

some O(n) is acheivable, but not getting how can it be O(n)

I can immediately think of an O(mn) solution where m represents the length of these strings, but strictly O(n) kind of ignores the fact that you're dealing with collections of characters or assumes that some constant form of identity for each URL already exists. Otherwise you have to calculate the identity of a URL and that factors into the time complexity.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

no

No what? Just because it's an interview question doesn't change the answer. Without more information about the structure of the list, you cannot assume that the problem is solvable in a realistic way. Thus you're left with three options:

  1. Accept equally unrealistic restrictions on the solution.
  2. Ensure the structure of the list such that it's conducive to a realistic solution.
  3. Use a double linked list.

i was curious to know whetther his answer was correct or not

His answer was more incorrect than correct. The correct "answer" in an interview is to get more information. For example, "does this list use a sentinel tail node?". I'd probably also reject someone who jumped to the conclusion that it was impossible without trying to fully understand the problem. However, in some cases it is indeed impossible, but without being sure that you're looking at such a case, it's wrong to reach that conclusion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The System.Windows.Media libraries make this so easy as to be trivial:

public static class ImageProcessing
{
    /// <summary>
    /// Encodes the provided TIFF file with new compression and pixel format.
    /// </summary>
    /// <param name="path">The source TIFF image file.</param>
    /// <param name="compression">Desired TIFF compression.</param>
    /// <param name="format">Desired pixel format.</param>
    /// <remarks>
    /// The original file is overwritten with the result.
    /// </remarks>
    public static void Encode(string path, TiffCompressOption compression, PixelFormat format)
    {
        var decoder = TiffBitmapDecoder.Create(
            new Uri(path),
            BitmapCreateOptions.PreservePixelFormat,
            BitmapCacheOption.OnLoad);
        var encoder = new TiffBitmapEncoder();

        encoder.Compression = compression;
        encoder.Frames.Add(BitmapFrame.Create(SetPixelFormat(decoder.Frames[0], format)));

        using (var stream = new FileStream(path, FileMode.Truncate, FileAccess.Write))
        {
            encoder.Save(stream);
        }
    }

    /// <summary>
    /// Sets the pixel format for an image.
    /// </summary>
    /// <param name="image">The original image.</param>
    /// <param name="pixelFormat">The desired pixel format.</param>
    /// <returns>The image converted ot the desired pixel format.</returns>
    private static BitmapSource SetPixelFormat(BitmapSource image, PixelFormat format)
    {
        var formatted = new FormatConvertedBitmap();

        formatted.BeginInit();
        formatted.Source = image;
        formatted.DestinationFormat = format;
        formatted.EndInit();

        return formatted;
    }
}

Just call that function like this:

ImageProcessing.Encode("myfile.tif", TiffCompressOption.Ccitt4, PixelFormats.BlackWhite);

Easy peasy. :) Some things are hard with that library, but dicking around with the compression and pixel format of a TIFF is a no brainer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

1) When you compare a range such do you use && or do you use the or statement to compare them?

You can use either, but typically the result is reversed between then:

// Compare range [lbound, ubound) using &&
if (x >= lbound && x < ubound)
{
    // In range
}
else
{
    // Out of range
}

// Compare range [lbound, ubound) using ||
if (!(x < lbound || x >= ubound))
{
    // In range
}
else
{
    // Out of range
}

2) In c++ you can use the word "and" or the && do these have the same effect?

As a matter of fact, you can and they do. C++ supports alternative keywords for several operators that are problematic internationally. However, note that some compilers won't enable them by default and you need to include the <ciso646> header.

3) When you are useing nested if-then-else such as these do you nest the parenthese such as in the first if statement?

I'm not entirely sure what you're asking, but it sounds like a style question. Do whatever you find to be most readable, but there are a few common bracing styles.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but problem arises when the node given to us is last node in the linked list. then ?

That falls under my "you often have no choice but to enforce unreasonable limitations" clause. If your list doesn't have a sentinel tail node, you're SOL. Too bad, so sad, use a double linked list next time.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you aren't already familiar with the material or what will be on the exam to guide people providing examples, then I strongly doubt random examples will help you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Swap the data with the next node and then delete that node. This trick is obviously incomplete and its suitability depends on the design of the list, but if you're working with unreasonable requirements, you often have no choice but to enforce unreasonable limitations on the solution.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't see SqlDbType.Int in any of your parameters. If the error is complaining about converting varchar to int, then it seems one of your columns is defined as an integer and you need to treat the parameter accordingly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sounds like a glitch. Has it happened on any other threads or just that one?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's possible, although I have yet to see one that works well.

Technically it's not possible due to how compilation works (even for .NET languages). However, in some cases (.NET languages for example) a decent facsimile is possible by disassembling the executable and then interpreting the disassembly to the desired language. You'll never get a result that matches the original source code, and depending on how aggressively the compiler optimized the result, what you get may be so awful that the disassembly itself is more useful.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We may be checking for the wrong MIME type. I'll see what I can see when I get a chance to run some tests. Our company (my day job, not Daniweb) just got sold, so this week may be hectic for me.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The code didn't make it through.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Given the choice between making the experience for new members worse, and asking mods to move a few threads every now and then from a well defined and consistent drop location, I'd favor the latter. The Community Center is a good spot too, because regardless of our individual favorite forums, I think most (if not all) moderators frequent the Community Center and will see these rogue threads.

pritaeas commented: Exactly. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Basically any cookie that is not required for the site to work needs confirmation first

Technically any cookie that the site uses is required for the site to "work", because lack of the cookie would be removing a "feature" of the site that would otherwise be provided. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Ah, the joys of CSS. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I do not understand why did you make 3 for loops?

The real question would be why did the OP not format his code in an understandable way. Reread the original code, it doesn't have three nested loops.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Just make a sum variable and accumulate the results into it:

int sum = 0;

for (int i = 0; i < size; i++)
{
    sum += (test[i] - test[0]);
}

cout << "Sum of differences: " << sum << '\n';
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure I understand exactly what you're asking, but initialization lists can be nested:

int foo[2][2][3] =
{
    {
        {1, 2, 3},
        {1, 2, 3}
    },
    {
        {1, 2, 3},
        {1, 2, 3}
    }
};

If the values of the array aren't known at compile time then you're stuck with some variation of looping through every element and initializing it at runtime.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So it kinda sounds like you update each time a new version is released?

There's no "kinda" about it, I do upgrade each time a new version is released, if only for testing purposes.

I wasn't sure if the changes to VS were that big that it warranted updating each time

There's usually at least one significant improvement or new feature that justifies the upgrade. Of course, if you're paying for a full version out of your pocket each time that changes things. As a Microsoft Certified Partner I get licenses as part of the benefits package. The Express versions are also convenient when cost is an issue.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how often have you upgraded your Visual Studio version?

I upgrade to the latest version shortly after it's released (since VC6), but for testing purposes rather than business use. For business use, I tend to wait until the first service pack or major update so that any bugs and irritants are shaken out.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are the different high level languages translated into the same MSIL language?

Yes. All of the CLI languages ultimately get translated down into CIL (previously known as MSIL). That C stands for "common", after all. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You should let your coworkers work how they wish as long as they get the job done.

It doesn't work that way. Your statement tells me that either you've never worked on a team before or the only teams you've worked on have been exceptionally bad. But whatever floats your boat. I'm confident you'll never be in a position to join any of my teams (because you wouldn't be hired), so your poor choices really don't affect me at all.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's an example of how to inspect the first character of a "word" and respond to it's type (either a digit or not). Note that this program doesn't do what your requirements state, but it can be used as a template. So don't complain that I didn't solve your exact problem, thanks.

#include <ctype.h>
#include <stdio.h>

int main(void)
{
    FILE *in = fopen("test.txt", "r");

    if (in)
    {
        char lead, header = '\0';
        int value, n = 0;

        while (true)
        {
            int rc = fscanf(in, " %c", &lead);

            if (rc != 1 || !isdigit(lead))
            {
                if (n != 0)
                {
                    printf("Found %d values on '%c' line\n", n, header);
                }

                // End-of-file was reached, but we still wanted to print the last line result
                if (rc != 1)
                {
                    break;
                }

                header = lead; // Save the lead for later display
                n = 0;         // Reset the value count for a new line
            }
            else
            {
                // Return the lead character because it's part of a value
                ungetc(lead, in);

                // Extract the whole value, but discard it
                if (fscanf(in, "%d", &value) == 1)
                {
                    ++n;
                }
            }
        }

        fclose(in);
    }

    return 0;
}

The reason I posted this code is because there's a little bit of trickiness in three cases:

  1. Making sure not to print bogus values on the first line.
  2. Being able to locate the start of a new line.
  3. Not having the last line get lost.

See if you can figure out what I did to handle …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

pls,can you explain in detail?

You can't ask a vague question and expect a detailed answer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Could you summarize the many solutions you've tried unsuccessfully so that we can avoid wasting your time recommending solutions you've attempted?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'll give it a test when I get home tonight, since I have Windows 8 there but not here at work. I'm using Windows 7 and Chrome presently.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I just tried with a test account that has slightly lower privileges than you and those steps still worked fine. Try clearing your cache; something might have gotten mucked up with your browser's copy of the client side scripts.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I just want to double check the reproduction steps, because the following worked as expected for me:

  1. Click on the up arrow to add a positive vote.
  2. Refresh and verify that the vote applied.
  3. Click on the up arrow again to reverse the positive vote.
  4. Refresh and verify that the reversal applied.
  5. Hover over the up arrow, add a comment, and click on the Up-Vote & Comment button to add rep.
  6. Refresh and verify that the vote and comment both applied.
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The only C++isms you've got are in main and revolve around string I/O. Basically just replace getline() with fgets() and modify the rest of the code to match.

SerenityG commented: Thanks, I'll give that a go. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i am trying to google too but i cannot find any info on this.

You may have better luck if you search for "strdup implementation". Your copyString() function already has a de facto name of strdup. The implementation is dead easy, but you'll need to remember to call free() on the returned pointer when using that function.

Also note that strdup is not a good name as it invades the compiler's reserved name space.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I've seen these as well, and it's somewhat frustrating given the point of tags. I'll look into a programmatic solution, but in the meantime, please report those posts so that a mod can fix the tags.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Having done software development however I'm not sure if it satisfies me on a personal level.

Find a job you can tolerate and which doesn't eat up all of your time. When you see a better opportunity, take it. Don't forget that a job is nothing more than how you acquire money to live an enjoyable life. If you're one of those lucky people who can find a job that's rewarding, more power to you, but beware unrealistic expectations.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I change it to x=x+y and x=x+1 the way it is suppose to be expressed.

It seems you have an extremely low opinion of your peers. Your arrogance and condescension of others is palpable; I'm truly grateful that you're not one of my coworkers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So my question is will i ever understand recursion

That's entirely up to you.

how did you understand it

I worked through recursive problems, traced recursion, converted between recursive and stack based approaches, converted between recursive and non-stack based iterative approaches, and learned programming languages that naturally tend toward recursion (eg. LISP).

how long did it take to fully understand

I picked up the concept quickly, but understanding a concept and being able to put it into practice are two different things. I don't want to put a number of months or years onto it, since my learning process is more about piling on experience than focused training. However, I will say that I haven't had any issues with recursion in many years.

PS. I know that tracing recursion is a bad idea.

I disagree. Tracing recursion is a great way to get a feel for how it flows. It's also easier to see performance problems by tracing a recursion tree (a good example is the Fibonacci program). Obviously you should only trace a subset of the problem rather than the whole thing, just enough to see the flow and structure.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Did they break down what exactly was smoked or is it just any kind of burning tobacco constitutes a smoker?

[rant]
I've seen an unfortunate trend in smoking studies to lump pipe and cigar smokers in with cigarette smokers. There's a significant difference between the chemical components of cigarettes and cigars or pipe tobacco. The latter are essentially pure aged tobacco (noting that I'm talking about premium cigars and pipe tobacco), the former have a laundry list of non-tobacco components and extraneous chemicals.

For example, a cigarette has ~100ppb of arsenic while a cigar has ~0.3ppb. Put in perspective, cigarettes have ten times the amount of arsenic allowed in drinking water (10ppb) and cigars have less than 1/10th. CO (carbon monoxide), C6H6 (benzene), C20H12 (benzo[a]pyrene) and NH3 (ammonia) are in both cigarettes and cigars, but their danger is primarily from inhalation.

Cigar and pipe smoke isn't inhaled; cigarette smoke is inhaled. While that means greater risk in terms of mouth, throat, and sinus issues, removing the lungs from the equation is a pretty big deal in smoking related disease risk (which includes heart problems).

Nicotine delivery is completely different as well. Cigarette smoke is more acidic, which makes it difficult to absorb by the mouth and easy to absorb in the lungs without the lungs being overly irritated. Cigars are the opposite: alkaline with strong irritation of the lungs if inhaled and easy absorption by the mouth. Note that inhaled nicotine reaches the brain faster. That might seem like …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

free() is a macro which is used to deallocate memory.

free() is not a macro, it's a function.

When we need more memory realoc() reallocate memory according to given size.

While not technically wrong, there's so much missing that this answer borders on useless. It's essentually a tautology. You're saying that realloc() reallocates memory, which is obvious, redundant, and essentially defines realloc() in terms of itself.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I didn't say your reply was wrong, just outdated.

What part of "hypothetical" and "made up example" is not clear? Do I have to use the most modern terms possible in a fake example to highlight an abstract concept? Here, let me fix it to get you out of your MS-DOS mindset:

"while an introspective memory model could be the forward facing configuration on a platform, the compiler may choose to use empirical pointers under the hood unless the address is transcendental. If an empirical pointer is used, it'll take up a lot less memory than an intuitive pointer."

Of course, now I'd have to define my terms whereas before I used terms that were actually used in the real world in a similar context as my example. In my opinion this makes the example far more transparent.

Do you get it now? I'm not talking about MS-DOS or any "real" platform, therefore it cannot be outdated. You're tilting at windmills here, dude.

I understand the standards don't say they have to be, but in practice I think they are all the same size.

And yet your post named at least one system where they're not and implied several more. You've contradicted yourself in two sentences.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Always change that as well.
n=n+1;

I hope you're not changing code that someone else wrote just to suit your own aesthetic preferences. That's an excellent way to introduce bugs.

I'd also argue that your preference is unconventional and will cause programmers to stumble over your code not because they don't understand it, but because they don't trust that you understand it. When a language supports x += y or x++ for example, any use of x = x + y will be viewed with suspicion; this is justified, in my opinion, because bad programmers are the ones that use such constructs without good reason.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's the format of the packet?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The example is 100% hypothetical and uses what I felt would be helpful terms for nailing down the concept of pointers not being required to all have the same size.

In hindsight, I wish I had bet someone that the first reply after mine would be some pedant nitpicking that my made up example was wrong. :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

"8a" is two characters, but you actually typed three. Count each key you press when running this test, and the remaining character will become clear. That character is pulled by the second read() call and due to this that call will not block for further input.

This is a variation of the classic newline bug, where a newline in the stream mucks up unsuspecting code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yup, my fingers were on autopilot. Thanks for the correction, I've edited my post.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The simple solution is to ask visitors what timezone they're in and calculate the date from the offset. A less simple solution is to use Javascript/AJAX to acquire the date-time from the client side and pass it to the server for processing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Normally I'd say not to micromanage piddling stuff like this. However, C++ has gotten more quirky over the years in that seemingly piddling things can have a nontrivial effect on performance. In this case though I would be quite shocked to see any justification for either of those options other than syntactic convenience.

Profile all you want, but don't be surprised if there's little to no difference.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Using the common sense we expect 32 bits platforms to have

Common sense doesn't really apply when there are many equally good expectations. For example, common sense might also say:

  • 4 bytes per pointer
  • 4 bytes per int
  • 8 bytes per long

Pointer types are also not required to all be the same size and representation. I'll use hopefully familiar nomenclature to highlight the point: while a flat memory model could be the forward facing configuration on a platform, the compiler may choose to use near pointers under the hood unless the address crosses segments. If a near pointer is used, it'll take up a lot less memory than a far pointer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the dfference between realloc() and free()?

free() performs a task that is a subset of realloc(). Here's what realloc() does:

  • realloc(p, n): Changes the size of the block pointed to by p and returns p. If the size of that block cannot be changed, allocates a new block of n bytes, copies the contents of p, and then returns that new block.
  • realloc(NULL, n): Allocates a new block of n bytes and returns it. Functionally identical to malloc(n).
  • realloc(p, 0): Releases the memory allocated by p and returns NULL. Functionally identical to free(p).

If you're really interested, here's a sample implementation of realloc() and free(). That's a working implementation of stdlib.h, so you can also look at malloc() and the system-specific back end of each.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the easiest way to declare and initialize 2d dynamic array in class in C++ ??

By far the easiest way is to use the vector class:

vector<vector<int>> foo; // 2D vector of int

Given that std::vector is essentially required to be implemented as a dynamic array, this technically meets your requirements. ;)

If you actually want to do the grunt work yourself, dynamic arrays are nothing more than pointers to sufficient memory. Since Schol-R-LEA introduced a class-based approach, here's the most common C-like (ie. low level) approach that uses nothing but pointers (which can be wrapped in a class for convenience if needed):

/*
    Allocate memory for an NxM table
*/
int **p = new int*[N];

for (int i = 0; i < N; i++) {
    p[i] = new int[M];
}

/*
    Test it out by filling it with values and displaying them
*/
for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
        p[i][j] = i * j;
    }
}

for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
        cout << p[i][j] << ' ';
    }

    cout << '\n';
}

/*
    Don't forget to release the memory when you're done.
    Just reverse the process of allocation using delete.
*/
for (int i = 0; i < N; i++) {
    delete[] p[i];
}

delete[] p;