windows could not start the DHCP client on Local Computer.


"windows could not start the DHCP client on Local Computer.

error 1079: the account specified for this service is different from the account specified for other services running on the same process""

Solution:

1. start services.msc
2. open DHCP Client
3. Select Log On Tab, and select "This account" Radio button
4. Click on Browse and select Advanced button
5. Click on Find Now button and select Local Service
6. Press Ok and Start the DHCP Client service


The operation failed as no adapter is in the state permissible for this operation (IPconfig /renew)

I would suggest you to follow these steps and check if it works.




a. Click Start, click Run, type cmd, and then press ENTER.



b. At the command prompt, type netsh int ip reset resetlog.txt, and then press ENTER to reset the TCP/IP network protocol.



c. At the command prompt, type ipconfig /renew, and then press ENTER and check whether you see the error.



Bitwise Operations

1. AND ( &)
2. OR ( | )
3. COMPLEMENT ( ~ )
4.  X-OR (  ^ )
5. LEFT SHIFT ( <<  )
6. RIGHT SHIFT ( >> )

Bits are 0 or 1.

1. AND ( & )

if and only two bits are 1's then result is 1 else 0
  0 & 0 = 0
  0 & 1 = 0
  1 & 0 = 0
  1 & 1 = 1

Ex: a = 0010 , b = 1010
0010
1010  
------
0010   a & b 
------
   
1. OR ( | )

if and only two bits are 0's then result is 0 else 1
  0 | 0 = 0
  0 | 1 = 1
  1 | 0 = 1
  1 | 1 = 1

Ex: a = 0010 , b = 1010
0010
1010  
------
1010   a | b 
------

3. COMPLEMENT ( ~ )

It flips the bits. 

  ~ 0  = 1
  ~ 1  = 0

Ex: a = 0010 
0010
------
1101  ~a  
------

4. X-OR ( ^ )

if and only two bits are same 1's  or 0's then result is 0 else 1. This is used for flip the bits i.e. value ^ 1.
  0 ^ 0 = 0
  0 ^ 1 = 1
  1 ^ 0 = 1
  1 ^ 1 = 0

Ex: a = 0010 , b = 1010
0010
1010  
------
1000   a ^ b 
------

5. LEFT SHIFT ( <<  )

shifts the number bit position to right. acts as multiplication of 2
  
  1010 << 1 = 10100

Ex: a = 0010 ,

a << 2 = 1000

5. LEFT SHIFT ( <<  )

shifts the number bit position to left. acts as division of 2
  
  1010 >> 1 = 0101

Ex: a = 1000 ,

a  >> 2 = 0010

How To Be Successful In Any Job Interview

1. What are your Strengths?
Ans: I'm well motivated. when you need me to step up to the plate, I'm there, I'm always ready and willing to learn new skills.

2. What are your Weaknesses?
Ans: When I become aware of a weakness, I see it as there;s a golden opportunity in me to further develop skills and knowledge. I do this through training or from my colleagues. Some people say, I'm too persistent.

Program Memory



The computer program memory is organized into the following:

Data Segment (Data + BSS + Heap)
Stack
Code segment


Data

The data area contains global and static variables used by the program that are explicitly initialized with a value. This segment can be further classified into a read-only area and read-write area. For instance, the string defined by char s[] = "hello world" in C and a C statement like int debug=1 outside the "main" would be stored in initialized read-write area. And a C statement likeconst char* string = "hello world" makes the string literal "hello world" to be stored in initialized read-only area and the character pointer variable string in initialized read-write area. Ex: static int i = 10 will be stored in the data segment and global int i = 10 will be stored in the data segment.

BSS

The BSS segment, also known as uninitialized data, starts at the end of the data segment and contains all global variables and static variables that are initialized to zero or do not have explicit initialization in source code. For instance a variable declared static int i; would be contained in the BSS segment.


Heap
The heap area begins at the end of the BSS segment and grows to larger addresses from there. The heap area is managed by malloc, realloc, and free, which may use the brk and sbrk system calls to adjust its size (note that the use of brk/sbrk and a single "heap area" is not required to fulfill the contract of malloc/realloc/free; they may also be implemented using mmap to reserve potentially non-contiguous regions of virtual memory into the process' virtual address space). The heap area is shared by all shared libraries and dynamically loaded modules in a process.

Stack

The stack area traditionally adjoined the heap area and grew the opposite direction; when the stack pointer met the heap pointer, free memory was exhausted. (With modern large address spaces and virtual memory techniques they may be placed almost anywhere, but they still typically grow in opposite directions.)

The stack area contains the program stack, a LIFO structure, typically located in the higher parts of memory. On the standard PC x86 computer architecture it grows toward address zero; on some other architectures it grows the opposite direction. A "stack pointer" register tracks the top of the stack; it is adjusted each time a value is "pushed" onto the stack. The set of values pushed for one function call is termed a "stack frame"; A stack frame consists at minimum of a return address.

Virtual function and vtable in C++

If a class declares a function as virtual then compiler constructs the vtable or Virtual Table for that class which stores addresses if virtual funcrions.
If any other classes derives from that class then they creates their own vtable.
The compiler also adds a hidden vptr variable in all such classes.
If a virtual function is not overridden in derived class then vtable stores address of its parent class function.

  • vtable stores static array of virtual functions, so that different instances of the same class can share that vtable. 
  • Since, static members are stored in the data section (.data), the vtable is also stored in the data section of the executable.
  • vtable is used to resolve the address of the function when virtual function is called at run-time.
  • Dynamic binding in C++ is achieved through vtable.

If derived class object is assigned to base object pointer, the vptr variable is points to vtable of the derived class. This ensures that derived virtual functions get called.

Example:

class Base
{
    public:
     virtual void display()
     {
         std::cout << "Base:: display()";
     }
};


class Derived : publid Base
{
   public:
   void display()
   {
       std::cout << "Derived::display()";
   }
};


void main()
{
   Base *b = new Base;
   b->display();

  Derived *d = new Derived();
  d->display();

  Base  *b1 = new Derived();
   b1->display();
}


Output:

Base::display()
Derived::display()
Derived::display()

Queues


Queue uses FIFO(first-in first-out) ordering.

class Queue {
    Node *first, *last;
 
public:
    void enqueue(Node *item)
    {
        if (first == NULL)
        {
            last = new Node(item);
            first = last;
        }
        else {
            last->next = new Node(item);
            last = last->next;
        }
    }
 
    int dequeue(Node *n)
    {
        if (first != 0)
        {
            Node *item = first;
            first = first->next;
            int val = item->value;
            delete item;
            return val;
        }
    }
};

Stacks

Stack uses the LIFO(last-in first-out) ordering. like a stack of dinner plates.


class Node
{
public:
    Node(Node *item)
    {
        value = item->value;
        next = item ->next;
    }
    int value;
    Node* next;
};
 
class Stack {
    Node* top;
 
public:
    int Pop() {
        if (top != 0) {
            Node* item = top;
            top = top->next;
            int val = item->value;
            delete item;
            return val;
        }
    }
 
    void Push(Node *item) {
        Node* t = new Node(item);
        t->next = top;
        top = t;
    }
 
    int peek() {
        return top->value;
    }
}


Good Coding Practice


  1. Correct: The code should operate correctly on all expected and unexpected results
  2. Efficient: In terms of time and space.
  3. Simple: if you can do 10 lines instead of 100.
  4. Readable: A different developer should be able to read.
  5. Maintainable: Code should be reasonably adaptable to changes during the life cycle of a product and should be easy to maintain by other developers


Data structrures brain storm

Linked list: linked lists tend not to do very well with accessing and sorting numbers

Array: fast accessing, but sorting is expensive
Binary  tree: binary trees do failry well with ordering.
Heap:  a heap is reallt good at basic ordering nad keeping track of max and mins.


HSBC calculators

Activating ActiveX Controls in HTMl













<!-- HTML File -->

<html>

<head>

<script src="external_script.js" language="JScript"></script>

</head>



<body>

<div id="EXAMPLE_DIV_ID">

This text will be replaced by the control

</div>

<script language="JScript">

CreateControl( "EXAMPLE_DIV_ID",

"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6",

"EXAMPLE_OBJECT_ID", "600", "400", "example.wmv",

"-1")

</script>

</body>

</html>








// external_script.js

function CreateControl(DivID, CLSID, ObjectID,

WIDTH, HEIGHT, URL, AUTOSTART)

{

var d = document.getElementById(DivID);

d.innerHTML =

'<object classid=' + CLSID + ' id=' + ObjectID +

' width=' + WIDTH + ' height=' + HEIGHT +'>

<param name="URL" value=' + URL + '>

<param name="autoStart" value=' + AUTOSTART + '/>';

}





write code to remove the duplicate characters in a string


public static void removeDuplicates(char[] str) {
if (str == null) return;
int len = str.length;
if (len < 2) return;

int tail = 1;

for (int i = 1; i < len; ++i) {
int j;
for (j = 0; j < tail; ++j) {
if (str[i] == str[j]) break;
}
if (j == tail) {
str[tail] = str[i];
++tail;
}
}
str[tail] = 0;
}

reverse a C-Style String



void reverse(char *str)
 {
char * end = str;
char tmp;
if (str)
{
while (*end) {
++end;
}
--end;

while (str < end) {
tmp = *str;
*str++ = *end;
*end-- = tmp;
}
}
 }

Implement an algorithm to determine if a string has all unique characters.


Solution1:

bool isUniqueChars2(string str) {
 bool[] char_set = new bool[256];
 for (int i = 0; i < str.length(); i++) {
 int val = str[i];
 if (char_set[val]) return false;
 char_set[val] = true;
 }
 return true;
 }

Time complexity is O(n), where n is the length of the string, and space complexity is O(n).

Solution 2:

public static boolean isUniqueChars(String str) {
int checker = 0;
 for (int i = 0; i < str.length(); ++i) {
 int val = str.charAt(i) - ‘a’;
 if ((checker & (1 << val)) > 0) return false;
 checker |= (1 << val);
 }
 return true;
}

Financial Calculators

InOrder Iterative tree traversal


inOrderTraversalIterative(BinaryTree *root)
{
    stack s;

    cursor = root;                    //set cursor to root of binary tree
    done = false;

   while (!done)
   {
     if(cursor != NULL)
     {
        s.push(cursor);             //place pointer to node on the stack
                                    //before traversing the node's left subtree
        cursor = cursor->left();    //traverse the left subtree
     }
     else                        //backtrack from the empty subtree and
                                 //visit the node at the top of the stack;
                                 //however, if the stack is empty, you are
                                 //done
     {
        if (!s.empty())
        {
            cursor = s.top();
            s.pop();
            cout << cursor->data();
            cursor = cursor->right();
        }
     }
  }
}

Diameter of a Tree


int Diameter(TreeNode t, int* height)
{
    int lh = 0, rh = 0;
    int leftD = 0, rightD = 0;

    if(t == NULL)
    {
        *height = 0;
        return 0; /* diameter is also 0 */
    }

    leftD =  Diameter (root->left, &lh);
    rightD =  Diameter (root->right,&rh);

    /* Height of current node is max of heights of left and
    right subtrees plus 1*/
    *height = max(lh, rh) + 1;

    return max(lh + rh + 1, leftD, rightD);
}

C,C++