Shellbeehaken

1. Efficiently Search for Number "N" in a Million Integers

// Linear Search Use
#include <iostream>
#include <vector>
#include <algorithm>

bool searchNumber(const std::vector<int>& numbers, int N) {
    // Assume the numbers are not sorted; if they are sorted, use binary_search.
    return std::find(numbers.begin(), numbers.end(), N) != numbers.end();
}

int main() {
    std::vector<int> numbers = { /* a million integers */ };
    int N = 42;
    if (searchNumber(numbers, N)) {
        std::cout << "Number found.\n";
    } else {
        std::cout << "Number not found.\n";
    }
    return 0;
}

2. Sum of All Values in a Tree

3. Print Numbers from N to 0 Using Recursion

4. Power of 2 Base Function without Using + or * (Using Bitwise Operations)

5. Distribute Candies Equally Among All Children (Pseudocode)

6. Array Combinations to Match a Given Number

7. Maximum Height of the Tree

8. What Happens When You Hit Enter After Writing the URL in the Search Bar?

When you hit enter after typing a URL:

  1. DNS Resolution: The browser contacts the DNS server to translate the domain name into an IP address.

  2. TCP Connection: The browser establishes a TCP connection with the server using the IP address (3-way handshake).

  3. HTTP/HTTPS Request: The browser sends an HTTP/HTTPS request to the server.

  4. Server Processing: The server processes the request and generates a response.

  5. HTTP/HTTPS Response: The server sends the response back to the browser.

  6. Rendering: The browser renders the content (HTML, CSS, JavaScript) and displays it to the user.

  7. Additional Requests: The browser may make additional requests for resources like images, stylesheets, and scripts.

9. Indexes in DBMS

Indexes are data structures that improve the speed of data retrieval operations on a database table. They are used to quickly locate data without having to search every row in a table. Indexes are typically created on columns that are frequently used in search conditions or join conditions.

10. Difference Between TRUNCATE and DROP

  • TRUNCATE: Removes all rows from a table without logging individual row deletions. It is faster and uses fewer system and transaction log resources. It does not remove the table structure or its dependencies.

  • DROP: Completely removes the table from the database along with its structure, data, indexes, and dependencies. It is a more destructive operation than TRUNCATE.

Last updated