Saturday, December 8, 2012

.::VULMSIT::.eNoxel.com CS410-MID TERM SUBJECTIVE With REFERENCE SOLVED BY UMAIR SAULAT

CS410 – Visual Programming

SOLVED SUBJECTIVE


Qno.1    How can I use the CopyTo method of the Windows Forms controls collection to copy controls into an array? (3)

Answer:-

The CopyTo method will take the current controls collection and copy all the controls into an array. In order to use it, you must specify the array and the starting point. For instance, the following code copies the controls to the MyArrayOfControls array starting at the first element

 

Ref         http://msdn.microsoft.com/en-us/magazine/cc164035.aspx

 

Qno.2    Write a complete syantax of "Getparents" functions? What kind of value it return and when this function is use?

Answer:-

 

Qno.3    Differentiate pen &brush?

Answer:-

PEN

Brush

A pen is a graphics tool that an application for Microsoft Windows uses to draw lines and curves

A brush is a graphics tool that a Windows based application uses to paint the interior of polygons, ellipses, and paths

Pens to draw freehand lines, straight lines, and curves.

brushes use to paint shapes

pens to designate trends in graphs and to outline bar graphs and pie charts

Brushes to paint the sections of pie charts and the bars in bar graphs.

REF :: Handouts Page No.69

 

 

Qno.4    It is sometimes more efficient for an application to draw directly in a window without relying on the WM_PAINT message. How this task can be accomplished (i.e. how can we draw in a window directly without using WM_PAINT message)? (5)

 

Answer:-

The task can be accomplished which is given below:-

 

This can be useful when the user needs immediate feedback, such as when selecting text and dragging or sizing an object. In such cases, the application usually draws while processing keyboard or mouse messages.

To draw in a window without using a WM_PAINT message, the application uses the GetDC or GetDCEx function to retrieve a display device context for the window. With the display device context, the application can draw in the window and avoid intruding into other windows. When the application has finished drawing, it calls the ReleaseDC function to release the display device context for use by other applications. application draws a selection and an intervening WM_PAINT message occurs, the application must ensure that any drawing done during the message does not corrupt the selection. To avoid this, many applications remove the selection, carry out usual drawing operations, and then restore the selection when drawing is complete

REF :: Handouts Page No.167


Qno.5    How Windows keep track of the files? (3)

Answer:-

The system requires instance handles to keep track of all modules. The system assigns a handle to each copy of a running executable or .dll.
REF :: Handouts Page No.78


Qno.6    Can you write a class without specifying namespace? Which namespace does it belong to by default? (2)

Answer:-

Yes, you can, and then the class belongs to global namespace which has no name. For commercial products, naturally, you wouldn't want global namespace.

REF:: http://www.netsqlinterviewquestions.com/-net_interview_questions/580_can-you-write-a-class-without-specifying-namespace-which-namespace-does-it-belong-to-by-default-.aspx?topicid=2



Qno.7    "In the GDI environment there are two working spaces", Name these two. (2)

Answer:-

In the GDI environment there are two working spaces

  1. Logical
  2. Physical

REF :: Handouts Page No.140

 


Qno.8    how many kinds of macros are there?

Answer:-

There are two kinds of macros.

  1. Object-like macros resemble data objects when used,
  2. Function-like macros resemble function calls.

REF :: Handouts Page No.40

 

Qno.9    What are the GDI environment working space names?

Answer:-

In the GDI environment there are two working spaces

  1. Logical
  2. Physical

REF :: Handouts Page No.140

 

Qno.10                 List down three Pre-Defined GDI objects in window

Answer:-

Pre-defined GDI objects in Windows are:

  • Pens
  • Brushes
  • Fonts
  • Palettes

REF :: Handouts Page No.178

 

Qno.11                 what are macros and its types? Explain it with example.

Answer:-

There are two kinds of macros.

1         Object-like macros resemble data objects when used,

2         Function-like macros resemble function calls.

Example:-

Here's a macro that computes the maximum of two numeric values:

                #define min(X, Y) ((X)>(Y) ? (X)LY))

Explain

To define a macro that takes arguments, you use the #define command with a list of parameters in parentheses after the name of the macro. The parameters may be any valid C identifiers separated by commas at the top level (that is, commas that aren't within parentheses) and, optionally, by white-space characters. The left parenthesis must follow the macro name immediately, with no space in between

REF :: Handouts Page No.40

 

  Qno.12 what is a process?

Answer:-

A series of actions or steps taken to achieve an end, a process is a collection of interrelated work tasks initiated in response to an event that achieves a specific result for the customer of the process.

REF:: https://www.google.com/webhp?source=search_app#hl=en&tbo=d&sclient=psy-ab&q=What+is+Process&oq=What+is+Process&gs_l=hp.3..0l4.1060964.1063012.3.1063209.15.14.0.1.1.2.515.2870.0j11j2j5-1.14.0.les%3B..0.0...1c.1.z147022bvT0&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&fp=1cb31f4b3d702abf&bpcl=39650382&biw=1024&bih=624

 

 

Qno.13 briefly defines Modal Loop?

Answer:-

Modal loop is run by Modal dialogs and process message as does application message loop. That's why program execution is transfer to modal loop so the modal loop itself gets messages and dispatch message.

REF :: Handouts Page No.246

 

Qno.14 Write windows Programming control process?

Answer:-

1         Edit Control

2         Static Control

REF :: Handouts Page No.120

 

Qno.15 Explain Pointer to Constant, and constant to Painter?

Answer:-

Constant pointer to variable data:

             char * const ptr = buff.                      // constant pointer to variable data

            *ptr = 'a';

            ptr = buff2;                                          // it will be an error

 

since we have declared ptr as a "constant pointer to variable data", so we can change the contents of the place where ptr is pointing at, i.e. data but being a constant variable, the ptr value i.e. the address it contains cannot be modified.

 

Variable pointer to Constant data:

            const char * ptr = buff.                       //variable pointer to constant data

            *ptr = 'a';                                            // it will be an error

            ptr = buf2;

REF :: Handouts Page No.64

 

 

Qno.16 Write the complete syntax or "get parent function"

Answer:-

GetParent function returns the parent handle of the specified child. This function will be useful when the parent of the child window to use.

Syntax::

 

HWND GetParent

(

HWND hWnd   // handle to child window

);

REF :: Handouts Page No.185

 

 

Qno.17 Types of assertion and name them?

Answer:-

There are three types of assertion:

1         Preconditions

  • Specify conditions at the start of a function.

2         Post conditions

  • Specify conditions at the end of a function.

3         Invariants

  • Specify conditions over a defined region of a program

REF :: Handouts Page No.49

 

Qno.18 Write the characteristics of child windows?

Answer:-

Following are the characteristics of child windows.

  • A child window always appears within the client area of its parent window.
  • Child windows are most often as controls.
  • A child window sends WM_COMMAND notification messages to its parent window.
  • When a child window is created a unique identifier for that window is specified in hMenu parameter of CreateWindow()

REF :: Handouts Page No.183

 

 

Qno.18 what will happen if GetUpdateRect returns zero?

Answer:-

An application should call the GetUpdateRect function to determine whether the window has an update region. If GetUpdateRect returns zero, the application should not call the BeginPaint and EndPaint functions.

REF :: Handouts Page No.164

 

 

Qno.19 Define Client area?

Answer:-

The client area is the part of a window where the application displays output, such as text or graphics. For example, a desktop publishing application displays the current page of a document in the client area. The application must provide a function, called a window procedure, to process input to the window and display output in the client area.

REF :: Handouts Page No.84

 

Qno.20 WIN MAIN describe with detail

Answer:-

WinMain is the starting point in Every Win32 GUI programs. WinMain has four

Parameters these are,

  1. First is instance of the current application.
  2. Second parameter is also an instance of this application which is used for the previous application of the same type that is already running. It is used only in Window 16bit editions or Windows 3.1. Windows 32bit editions do not support this parameter. It is here just for compatibility.
  3. Third parameter is a command line argument of string type which is a type defined as char *.
  4. Fourth parameter is windows style.

REF :: Handouts Page No.73

 

Qno.21 Message queues of each application (2)

Answer:-

An application must remove and process messages posted to the message queues of its threads

REF :: Handouts Page No.104

 

 

 

Qno.22 Paint function usage (3)

Answer:-

Paint function performs following tasks.

  • The BeginPaint() function prepares the specified  window for painting and fills a PAINTSTRUCT structure with information about the painting.
  • BeginPaint() first erases the background of window's client area by sending WM_ERASEBKGND message.
  • If the function succeeds, the return value is the handle to a display device context for the specified window.

REF :: Handouts Page No.160

 

Qno.23 Differentiate Desktop Window and Application Window

Answer:-

Desktop Windows

Application Windows

When you start the system, it automatically creates the desktop window. The desktop window is a system-defined window

When you start an application, the system also associates a taskbar button with the application. The taskbar button contains the program icon and title

uses a bitmap to paint the background of the screen

Most applications also create other windows, either directly or indirectly, to perform tasks related to the main window

A system configuration application, such as a Control Panel item, changes the desktop wallpaper by using the System Parameters Info function

An application window includes elements such as a title bar, a menu bar, the window menu (formerly known as the system menu),

REF :: Handouts Page No.114

 

Qno.24 show the implementation of _cdecl calling convolution with respect to (5)

Answer:-

1: Argument passing order.

2: stack maintenance responsibility.

3: name decoration convention.

REF :: Handouts Page No.54

 

Qno.25 What happened if GetUpdateWn returns zero (3)

Answer:-

If GetUpdateRect returns zero, the application should not call the BeginPaint and EndPaint

functions.

REF :: Handouts Page No.164

 

Qno.26 A window may have more than one windows inside it explain the line(2)

Answer:-

A Window may further contain more windows inside it. For example let's take a calculator; A calculator contains more windows in forms of buttons, radio buttons and check boxes.

  • Every Window has its parent and zero or more siblings.
  • Top level window has desktop as its parent.

REF :: Handouts Page No.113

Qno.27 What is the function of ws_paint in Windows class(3)

Answer:-

DispatchMessage function to a window procedure when the application obtains a WM_PAINT message from message Queue by using the GetMessage or PeekMessage functions.

REF :: Handouts Page No.113

 

Qno.28 Message queuing 2 marks

Answer:-

Message Queue is created when every any GDI function call is made or send message or post

Message function calls are made. Message Queue can be attached to every thread either it is

User interface thread or worker threads. User Interface threads always a message queue

REF :: Handouts Page No.332

 

Qno.29 Kernel tasks 3marks

Answer:-

Kernel is a main module of the operating system. This provides system services for managing threads, memory, and resources.

Kernel has to perform very important responsibilities e.g.

1.       Process Management

2.       File Management

3.       Memory Management (System and Virtual Memory)

REF :: Handouts Page No.68

 

Qno.30 Difference between __stdcall and __cdecl calling convention

Answer:-

cdecl and __stdcall just tells the compiler whether the called function or the calling function

cleans up the stack. In __stdcall calling convention, the called function cleans up the stack when

it is about to return. So if it is called in a bunch of different places, all of those calls do not need

to extra code to clean up the stack after the function call.

 

In __cdecl calling convention, it is the caller function that is responsible for cleaning the stack,

so every function call must also need to include extra code to clean up the stack after the

function call.

REF :: Handouts Page N.54

 

Qno.31 Erase window function explanation 5marks

Answer:-

Erase windows uses the GetClipBox function to retrieve the logical coordinates of the area to erase and passes these coordinates to the FillRect function. Applications that process these messages can use similar techniques. The system supplies a window device context with the WM_ICONERASEBKGND message regardless of whether the corresponding window has a private device context.

REF :: Handouts Page No.154

 

 

 

 

Qno.32 Clipboard Working 3mraks

Answer:-

In Windows, data is shareable among applications. We can use it for copying the data from one file to the other in same format.e.g from notepad to MS Word.. All the text or image data you have previously copied can now be pasted in other application.

REF :: Handouts Page No.72

 

Qno.33 write down complete syntax of "getDC" function?(2)

Answer:-

The system retrieves a device context from the cache whenever an application calls the GetDC

or BeginPaint function; the system returns the DC to the cache when the application subsequently calls the ReleaseDC or EndPaint function.

REF :: Handouts Page No.151

 

Qno.34 infinite recursion (3)

Answer:-

Infinite recursion, a special case of an infinite loop that is caused by recursion. This revised function will only run out of stack space if n is less than 1 or n is too large; error checking would remove the first case. For information on recursive functions which never run out of stack

REF :: http://en.wikipedia.org/wiki/Infinite_loop#Infinite_recursion

 

Qno.35 what is stack? (2)

Answer:-

In computer science, a stack is an area of memory that holds all local variables and parameter used by any function, and remembers the order in which functions are called so that function returns occur correctly.

REF:: http://en.wikipedia.org/wiki/Stack_(abstract_data_type)

 

Qno.36 what is extern storage class?

Answer:-

Extern defines a global variable that is visible to all object modules. When you use 'extern' the variable cannot be initialized as all it does is to point the variable name at a storage location that has been previously defined

REF :: Handouts Page No.60

 

 

Qno.37 An application can set up for itself any logical coordinates system, using API. Write down any two.(3)

Answer:-

There are two types of brushes: logical and physical. A logical brush is one that you define in code as the ideal combination of colors and/or pattern that an application should use to paint shapes. A physical brush is one that a device driver creates, which is based on your logical-brush definition.

REF :: Handouts Page No.70

 

 

 

 

Qno.38 what happened if an application does not process WM_ErasebkGrd massages but pass it defWindowProcs.(5)

Answer:-

If it processes WM_ERASEBKGND, the application should use the message's wParam parameter to draw the background. This parameter contains a handle to the display device context for the window. After drawing the background, the application should return a nonzero value. This ensures that BeginPaint does not erroneously set the fErase member of the PAINTSTRUCT structure to a nonzero value (indicating the background should be erased) when the application processes the subsequent WM_PAINT message.

 

An application can define a class background brush by assigning a brush handle or a system color value to thehbrBackground member of the WNDCLASS structure when registering the class with the RegisterClass function. TheGetStockObject or CreateSolidBrush function can be used to create a brush handle. A system color value can be one of those defined for the SetSysColors function. (The value must be increased by one before it is assigned to the member.)

REF :: Handouts Page No.167

 

Qno.38 Define "Virtual-Key" message -    2 Marks

Answer:-

virtual-key code is a device-independent value defined by the system that identifies the purpose of a key. After translating a scan code, the keyboard layout creates a message that includes the scan code, the virtual-key code, and other information about the keystroke, and then places the message in the system message queue.

REF :: Handouts Page No.192

 

Qno.39 Differentiate between Super Classing and Sub Classing.   3 Marks

Answer:-

SuperClassing

SubClassing

Super-classing defines a class that adds new functionality to a predefined window class,

Subclassing is allowed only within a process.

Button or list box controls.

Win32 processes have separate address spaces

Superclassing involves creating a new class that uses the window procedure of an existing class for basic functionality.

An application cannot subclass a window or class that belongs to another process.

 

REF :: Handouts Page No.132


Qno.40
why the entries in the parent process table and child table?  2

Answer:- It means that the handle value that identifies a kernel object is identical in both the parent and the child processes

REF :: http://www.coolinterview.com/interview/54829/

 

 

 

Qno.41 Define instance Handle? Briefly explain  

Answer:- This member is Application instance handle.

REF :: Handouts Page No.90

 

Qno.42 List down the important distance between subclassing and superclassing?  

Answer:-

SuperClassing

SubClassing

Super-classing defines a class that adds new functionality to a predefined window class,

Subclassing is allowed only within a process.

Button or list box controls.

Win32 processes have separate address spaces

Superclassing involves creating a new class that uses the window procedure of an existing class for basic functionality.

An application cannot subclass a window or class that belongs to another process.

 

REF :: Handouts Page No.132

 

Qno.43 Write down the code c/c++ program that has 2 functions on take 4 integer variable as parameters and return their sum and other take 4 integer as arguments and return their multiplication.

Answer

#include <stdio.h>

 

// prototypes, the parameter names are optional,

// print the menu and obtains a selection

int GetChoice();

// inserts a number in the sorted array.

int AddNum (int num[], int sz);

// removes a number from the array.

int DelNum(int num[], int sz);

// prints out the sorted array

void PrintNums(int num[], int sz);

 

void main()

{

      // the number of elements in array A[]

      int Size = 0,

      // the array that will keep its numbers sorted

      A[20],

      // the selection made from the menu

      Selection;

 

      // keep doing this loop until a 4 or Quit is

      // selected from the menu...

      Selection = GetChoice();

      for( ; Selection != 4; )

      {

            if(Selection == 1)

                  Size = AddNum(A, Size);

            else

                  if(Selection == 2)

                        Size = DelNum(A, Size);

                  else

                        PrintNums(A, Size);

            Selection = GetChoice();

      }

}

 

// assuming that user will enter only a valid int

int GetChoice()

{

      int Choice;

 

      printf("Enter 1 - Insert, 2 - Delete, ");

      printf("3 - List and 4 - Quit:  ");

            scanf_s("%d", &Choice);

            return Choice;

}

 

int AddNum(int Num[ ], int sz)

{

      // local variables...

      int i, j, Number;

      // gets the number to insert

      printf("What number to insert? ");

      scanf_s("%d", &Number);

      // finds the place (i) to put the new number

      for(i = 0; i < sz; ++i)

            if(Number < Num[i])

                  break;

      // shift the rest of the array by moving

      // the numbers up by one slot.

      for(j = sz; j > i; --j)

            Num[j] = Num[j - 1];

      // place the new number

      Num[i] = Number;

      // the array size is incremented

      // and return to the calling function

      return ++sz;

}

 

// assuming that the deleted item exists

int DelNum(int Num[], int sz)

{

      // local variables...

      int i, Number;

      // gets the number to be deleted

      printf("What number are you going to delete? ");

      scanf_s("%d", &Number);

      // find the place in the array to be deleted

      for(i = 0; i < sz; ++i)

            if(Number == Num[i])

                  break;

      // the array size is decremented

      --sz;

      // shift the rest of the array by moving the numbers

      // down by one slot

      for( ; i < sz; ++i)

            Num[i] = Num[i + 1];

      // return sz to the calling function

      return sz;

}

 

void PrintNums(int Num[ ], int sz)

{

      // local variable...

      int i;

 

      for(i = 0; i < sz; ++i)

            printf("Num[%d] = %d\t", i, Num[i]);

      printf("\n");

}

 

Output of this Program

 


REF http://www.tenouk.com/clabworksheet/labworksheet13.html

 

Qno.44 Write two macros that perform the same tasks as these functions perform? 5

Answer:-

A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look like when they are used. Object-like macros resemble data objects when used, function-like macros resemble function calls.

 

You may define any valid identifier as a macro, even if it is a C keyword. The preprocessor does not know anything about keywords. This can be useful if you wish to hide a keyword such as const from an older compiler that does not understand it. However, the preprocessor operator defined can never be defined as a macro, and C++'s named operators cannot be macros when you are compiling C++.

 

To define a macro that takes arguments, you use the #define command with a list of parameters in parentheses after the name of the macro. The parameters may be any valid C identifiers separated by commas at the top level (that is, commas that aren't within parentheses) and, optionally, by white-space characters. The left parenthesis must follow the macro name immediately, with no space in between.

 

For example, here's a macro that computes the maximum of two numeric values:

                #define min(X, Y) ((X)>(Y) ? (X):(Y))

REF :: Handouts Page No.40


Qno.45
Two common controls in window programming

Answer:-

Common controls are of these types.

  1. Date Time Picker Control.
  2. List View Control.

REF :: Handouts Page No.121

 

 

Qno.46 Write at least two tasks performed by BeginPaint () function?   3

Answer:-

1         The BeginPaint() function prepares the specified  window for painting and fills a PAINTSTRUCT structure with information about the painting.

2         BeginPaint() first erases the background of window's client area by sending WM_ERASEBKGND message.

REF :: Handouts Page No.160

 

Qno.47 about _cdecl calling convention? 

Answer:-

The __cdecl is the default calling convention for C programs. In this calling convention, the stack is cleaned up by the caller. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code.

REF :: Handouts Page No.54


--
Zindagi mein 2 Logo ka buhat khayal rahkoooo
Ist woh jiss ney tumhari jeet ke Liye buhat kuch hara hoo
(Father)
2nd woh jiss ko tum ney har dukh me pukaara hoo (Mother)
Regards,
Umair Saulat Mc100403250

--
--
Virtual University of Pakistan*** IT n CS Blog
================================
http://www.eNoxel.com
http://www.enoxelit.tk
http://www.geniusweb.tk
 
and Please do Share this group with your Friends and Class Fellows so that our Circle would expand and can be more useful for other Students.
 
Thanks, n Best of Luck......
 
 
You received this message because you are subscribed to the Google
Groups "vulms" group.
To post to this group, send email to vulmsit@googlegroups.com
To unsubscribe from this group, send email to
vulmsit+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/vulmsit?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "vulms" group.
Visit this group at http://groups.google.com/group/vulmsit?hl=en-GB.
 
 

Friday, December 7, 2012

.::VULMSIT::.eNoxel.com Free Conference Seminar: Your Role as a SAP Consultant on a project - MM WM SD FICO PP CRM HR/HCM BIBW & ASAP methodology - 101ERP

Join us every Monday at 9.30 PM EST. Please find the meeting details at events.101erp.com
This conference seminar will give you a good understanding on what roles you will be playing as an SAP consultant in real projects.
Thanks

--
--
Virtual University of Pakistan*** IT n CS Blog
================================
http://www.eNoxel.com
http://www.enoxelit.tk
http://www.geniusweb.tk
 
and Please do Share this group with your Friends and Class Fellows so that our Circle would expand and can be more useful for other Students.
 
Thanks, n Best of Luck......
 
 
You received this message because you are subscribed to the Google
Groups "vulms" group.
To post to this group, send email to vulmsit@googlegroups.com
To unsubscribe from this group, send email to
vulmsit+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/vulmsit?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "vulms" group.
Visit this group at http://groups.google.com/group/vulmsit?hl=en-GB.
 
 

.::VULMSIT::.eNoxel.com Free Conference Seminar: Your Role as a SAP Consultant on a project - MM WM SD FICO PP CRM HR/HCM BIBW & ASAP methodology - 101ERP

Join us every Monday at 9.30 PM EST. Please find the meeting details at events.101erp.com
This conference seminar will give you a good understanding on what roles you will be playing as an SAP consultant in real projects.
Thanks

--
--
Virtual University of Pakistan*** IT n CS Blog
================================
http://www.eNoxel.com
http://www.enoxelit.tk
http://www.geniusweb.tk
 
and Please do Share this group with your Friends and Class Fellows so that our Circle would expand and can be more useful for other Students.
 
Thanks, n Best of Luck......
 
 
You received this message because you are subscribed to the Google
Groups "vulms" group.
To post to this group, send email to vulmsit@googlegroups.com
To unsubscribe from this group, send email to
vulmsit+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/vulmsit?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "vulms" group.
Visit this group at http://groups.google.com/group/vulmsit?hl=en-GB.
 
 

.::VULMSIT::.eNoxel.com CS502 - SHORT QUESTION ASNWER WITH REFFERENCE

CS502  - Fundamental of Algorithm

Short- Question Answer

 

QNo.1  What is heap and what is heap order? (Mark2)

Answer:-

The heap is the section of computer memory where all the variables created or initialized at runtime are stored.  The heap order property: in a

(min) heap, for every node X, the key in the parent is smaller than or equal to the key in X.

Ref:  Handouts Page no. 40

 

 

QNo.2  Quick sort such that sort the array in to non-increasing order? (Mark2)

Answer:-

 

Quick sorting, an array A[1..n] of n  numbers We are to reorder these elements into increasing (or decreasing) order.  More generally, A is an array of objects and we sort them based on one of the attributes - the key value. The key value need not be a number. It can be any object from a totally ordered domain. Totally ordered domain means that for any two elements of the domain, x and y, either x < y, x = y or x > y.

Ref:  Handouts Page no. 40

 

 

QNo.3  Draw the cost table for chain multiplication problem with initial states(Mark3)

Answer:-

 (A1)(A2A3A4 . . .An)

or (A1A2)(A3A4 . . .An)

or (A1A2A3)(A4 . . .An)

. . . . . .

or (A1A2A3A4 . . .An−1)(An)

Ref:  Handouts Page no. 90

 

QNo.4  we can avoid unnecessary repetitions for recursive calls? (Mark3)

Answer:-

We can avoid these unnecessary repetitions by writing down the results of recursive calls and looking them up again if we need them later. This process is called memorization

Ref:  Handouts Page no. 49

 

Worst case for edit distance algorithm? What is the simple change that can change the worst case time ? 5 marks

Answer:-

Analysis of DP edit distance

There are  entries in the matrix. Each entry E(i,j) takes  time to compute. The total running is  Recursion clearly leads to the same repetitive call pattern that we saw in Fibonnaci sequence. To avoid this, we will  use the DP approach. We will build the solutionb bottom-up. We will use the base case E(0,j) to fill first row and the base case E(I,0) to fill first column. We will fill the remaining E matrix row by row.

 

Ref:  Handouts Page no. 14

 

 

Describe an efficient algorithm to find the median of a set of 106 integers; it is known that there are fewer than 100 distinct integers in the set

 

Solution:-

Step1:Start

Step2:Find the 100 distinct numbers among 10^6 integers.

Step3:Sort the 100 distinct numbers

Step4:Count the distinct numbers

Step5: if count is odd,middle number is the median

Step6:if count is even,add the middle two numbers then divide by 2,the result is the median Step5:End

number.

 

Ref:  Handouts Page no. 34

 

What is the formula for generating Catalan numbers?

Solution

Equation (22) is a recurrence relation.
C_(n+1) = C_n * [2(2n+1)] / (n+2)

we have the values of n in one column and the values of C_n in another, then to put this formula in Excel, on the (n+1)-th row just replace C_n and n with the appropriate cells from the previous row.

Ref:  Handouts Page no. 85

 

What are Catalan numbers? Give the formula.

 

Catalan numbers form a sequence of natural numbers that occur in variouscounting problems, often involving recursively defined objects

Formula is C(n) = 2n Cn / (n+1)

Ref:  Handouts Page no. 85

 

 

 

Q-Write a pseudo code Fibonacci With memorization? -- (3)

Sol
MEMOFIB(n)
1 if (n < 2)
2 then return n
3 if (F[n] is undefined)
4 then F[n] MEMOFIB(n − 1) + MEMOFIB(n − 2)
5 return F[n]

Ref:  Handouts Page no. 12, 74


Q – Write Down the steps of Dynamic programming (5)

Dynamic programming is essentially recursion without repetition. Developing a dynamic programming
algorithm generally involves two separate steps:

 

·         Formulate problem recursively. Write down a formula for the whole problem as a simple
combination of answers to smaller sub problems.

·         Build solution to recurrence from bottom up. Write an algorithm that starts with base cases and works its way up to the final solution.


Dynamic programming algorithms need to store the results of intermediate sub problems. This is often but not always done with some kind of table. We will now cover a number of examples of problems in which the solution is based on dynamic programming strategy.

Ref:  Handouts Page no. 74 – 77

 

 

How we build heap

We build a max heap out of the given array of numbers A[1..n]. We repeatedly extract the maximum item from the heap. Once the max item is removed, we are left with a hole at the root.

Ref:  Handouts Page no. 41

 

Write Pseudo code for KNAPSACK algorithm? 5 marks

Solution:

KNAPSACK (n, W)

1 for w=0,W

2 do V[0,w]ß0

3 for i=0,n

4 do V[i,0]ß0

5   for w=0,W

6   do if(wi w&  +V[i-1,w- ]>V[i-1,w])

7                      then V[I,w]ß +V[i-1,w]


8                      else V[i,w]
ßV[i-1,w]

The time complexity is clearly O(n,W), it must be cautioned that as n and W get large, both time and space complexity become significant.

Ref:  Handouts Page no. 96

 

 

Spelling correction in edit distance? 3 marks

A better way to display this editing process is to place the words above the other:

S  D  I  M  D  M

 M A  -   T  H  S

  A  -   R  T  -  S

THE FIRST WORD HAS AGAP FOR EVERY INSERTION (1)AND THE SECOND WORD HAS A GAP FOR EVERY DELETION (D). MATHES (M) DO NOT COUNT. THE EDIT TRANSCRIPT IS DEFINED AS A STRING OVER THE ALPHABETM,S,I,d THAT DESCRIBES A TRANSFORMATION OF ONE STRING INTO OTHER. FOR EXAMPLE

S D I M D M

1+1+1+0+1+0+=4
Ref:  Handouts Page no. 77


Differentiate b/w Bubble sort, insertion sort and selection sort? 3 marks

 

SOLUTION:

Bubble sort: scan the array. Whenever two consecutive items are found that are out of order, swap them. Repeat until all consecutive items are in order.

Insertion sort: assume that A[1…i-1] have already been sorted. Insert A[i] into its proper position in this sub array. Create this position by shifting all larger elements to the right.

Selection sort:

Assume that A[1..i-1] contain the i-1 smallest elements in sorted order. Find the smallest in A[i….n] swap it with A[i].

Ref:  Handouts Page no. 54

 

Write down the steps of dynamic programming strategy.   (2 marks)

Solution:

Developing a dynamic programming algorithm generally involves two separate steps:

1_formulate problem recursively.

Write down a formula for the whole problem as a simple combination of answers to smaller sub problems.

2_ Build solution to recurrence from bottom up:

Ref:  Handouts Page no. 75

 

Solve the recursion problem. (5marks.)

Solution:

Recursion clearly leads to the same repetitive call pattern that we saw in Fibonnaci sequence. To avoid this, we will  use the DP approach. We will build the solutionb bottom-up. We will use the base case E(0,j) to fill first row and the base case E(I,0) to fill first column. We will fill the remaining E matrix row by row.

If we trace through the recursive calls to MemoFib, we find that array F[] gets filled from bottom up…i.e., first  F[2], then F[3], and so on, upto F[n]. we can replace recursion with a simple for-loop that just fills up the array F[] in that order.

                                                                      
•       We are given an array of n elements of x1 , x2 ,x3 , ,,,,xn,
suggest best sorting algorithm of order On.  (5 marks).

Solution:

The main shortcoming of counting sort is that it is useful for small integers, i.e., 1…k where k is small. If this were a million more, the size of the rank array would also be a million. Radix sort provides a nice work around this limitation by sorting numbers one digit at a time.

 



--
Zindagi mein 2 Logo ka buhat khayal rahkoooo
Ist woh jiss ney tumhari jeet ke Liye buhat kuch hara hoo
(Father)
2nd woh jiss ko tum ney har dukh me pukaara hoo (Mother)
Regards,
Umair Saulat Mc100403250

--
--
Virtual University of Pakistan*** IT n CS Blog
================================
http://www.eNoxel.com
http://www.enoxelit.tk
http://www.geniusweb.tk
 
and Please do Share this group with your Friends and Class Fellows so that our Circle would expand and can be more useful for other Students.
 
Thanks, n Best of Luck......
 
 
You received this message because you are subscribed to the Google
Groups "vulms" group.
To post to this group, send email to vulmsit@googlegroups.com
To unsubscribe from this group, send email to
vulmsit+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/vulmsit?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "vulms" group.
Visit this group at http://groups.google.com/group/vulmsit?hl=en-GB.
 
 

.::VULMSIT::.eNoxel.com Moderator's spam report for vulmsit@googlegroups.com

This message is being sent to you because you are a moderator of the group vulmsit.

The following suspicious messages were sent to your group, but are being held in your moderation queue because they are classified as likely spam messages.

If you take no action, all the messages below will be discarded automatically as spam.

However, if you see any messages that are not spam below, you may approve them individually by going to:

http://groups.google.com/group/vulmsit/pendmsg

Please do not mark this notification as spam; this is a service for group moderators. If you do not wish to receive these notifications in the future, you may change your preferences by going to:

http://groups.google.com/group/vulmsit/manage_post


------- 1 of 18 -------
Subject: Today Online Quran & Online Hadith 05 December 2012 (20th Muharram 1434)
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 05 07:57AM +0500

<http://www.gophoto.it/view.php?i=http://api.ning.com:80/files/qFQO2CCIhZ3nQY6VnIBwX9K9Fm8UCrKMMpjcaVCEcd5tdbp7inJeSIuHyhAdoTcWXOBLu*HMgchqE4UC97y*ug__/image001.jpg>


Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=5777662478681760932

------- 2 of 18 -------
Subject: ECO402 - Microeconomics Online Quiz No.2 Conference At 10:00 am and 07:00 Pm on 05-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 05 09:46AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=3904430159051778950

------- 3 of 18 -------
Subject: ISL201 Islamic Studies Online Quiz No.2 Conference At 12:00 pm and 09:00 Pm on 05-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 05 09:47AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=3764957380187106945

------- 4 of 18 -------
Subject: CS401 Computer Architecture and Assembly Language Programming Online Quiz No.2 Conference At 02:00 pm and 10:00 Pm on 05-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 05 09:48AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=3384067131010546703

------- 5 of 18 -------
Subject: ENG101 English Comprehension Quiz No.2 Conference At 04:00 pm on 05-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 05 10:29AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=5319971249721031575

------- 6 of 18 -------
Subject: ENG201 Business and Technical English Writing Online Quiz No.2 Conference At 03:00 pm on 05-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 05 10:30AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=5551159671657095412

------- 7 of 18 -------
Subject: MGT602 - Entrepreneurship Online Quiz No.2 Conference At 05:00 pm on 05-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 05 11:43AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=1913319944989407566

------- 8 of 18 -------
Subject: CS304 Object Oriented Programming (Rescheduled) Online Quiz No.2 Conference At 06:00 pm on 05-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 05 11:45AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=6650831937264686201

------- 9 of 18 -------
Subject: Take this Online SAP test and see where you stand - 101ERP
From: ARUN P <simp.biz39@gmail.com>
Date: Dec 05 02:10AM -0500

Take this quick test folks - Gives you an idea on what roles a SAP
consultant plays on a project and also gives an insight from interview
point of view for SAP aspirants

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=6334032274760281259

------- 10 of 18 -------
Subject: Today Online Quran & Online Hadith 06 December 2012 (21th Muharram 1434)
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 06 07:41AM +0500

<http://www.gophoto.it/view.php?i=http://api.ning.com:80/files/qFQO2CCIhZ3nQY6VnIBwX9K9Fm8UCrKMMpjcaVCEcd5tdbp7inJeSIuHyhAdoTcWXOBLu*HMgchqE4UC97y*ug__/image001.jpg>


Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=826881059474057208

------- 11 of 18 -------
Subject: MGT502 - Organizational Behavior Online Quiz No.2 Conference At 06:00 pm on 06-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 06 08:17AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=742828588765509984

------- 12 of 18 -------
Subject: ENG201 Business and Technical English Writing Online Quiz No.2 Conference At 04:00 pm and 10:00 pm on 06-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 06 08:22AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=5715780606451679381

------- 13 of 18 -------
Subject: ENG101 English Comprehension Quiz No.2 Conference At 03:00 pm and 11:00 pm on 06-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 06 08:25AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=7492353478031559229

------- 14 of 18 -------
Subject: CS201 Introduction to Programming Online Quiz No.2 Conference At 10:00 am and 07:00 pm on 06-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 06 08:29AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=6828136282828511007

------- 15 of 18 -------
Subject: CS601 Data Communication Online Quiz No.2 Conference At 12:00 pm and 09:00 pm on 06-12-2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 06 08:35AM +0500

Asslam.o.Alaikum

Dear Students

Virtualians Social Network has started Quiz. Conference of VU Online
Quizzes for Virtual University Students.

The main purpose of such quiz conferences is to motivate encourages and
create a class environment

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=8269138157335348725

------- 16 of 18 -------
Subject: All Subjects Midterm Solved Paper, Short Notes, Faqs and Glossary for Midterm Exam Preparation Fall 2012
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 06 09:36PM +0500

*Asslam.o.alaikum*
*
*
*Dear Students All Subjects Midterm Solved Paper, Short Notes, Faqs and
Glossary for Midterm Exam Preparation Fall 2012 has posted *
*
*
*Click here select your to read and download All Midterm Solved Paper,

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=3880658139096530123

------- 17 of 18 -------
Subject: MIT 1st semester ALL MID term paperz in one maga palce, in one Mail ........(eagle_eye)
From: "◄::-:: eagle_eye ::-::►" <fantasy.eagle@gmail.com>
Date: Dec 06 11:55PM +0500

*AOA to all dearz...*

* *

*Welcome all MIT new students in VU
*

*
*

*Dear new students herez' are some paperz that helps you all in mid term
study… *

* *

*Here'z is the all MIT 1st semester MID TERM paperz...

Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=8610370402683701799

------- 18 of 18 -------
Subject: Today Online Quran & Online Hadith 07 December 2012 (22th Muharram 1434)
From: "www.virtualians.pk" <irfankhan0044@gmail.com>
Date: Dec 07 07:15AM +0500

<http://www.gophoto.it/view.php?i=http://api.ning.com:80/files/qFQO2CCIhZ3nQY6VnIBwX9K9Fm8UCrKMMpjcaVCEcd5tdbp7inJeSIuHyhAdoTcWXOBLu*HMgchqE4UC97y*ug__/image001.jpg>


Approve: http://groups.google.com/group/vulmsit/pendmsg?view=full&pending_id=1598856822803479065


For more information about this message, please visit:
https://support.google.com/groups/bin/answer.py?hl=en&answer=47792

--
--
Virtual University of Pakistan*** IT n CS Blog
================================
http://www.eNoxel.com
http://www.enoxelit.tk
http://www.geniusweb.tk

and Please do Share this group with your Friends and Class Fellows so that our Circle would expand and can be more useful for other Students.

Thanks, n Best of Luck......


You received this message because you are subscribed to the Google
Groups "vulms" group.
To post to this group, send email to vulmsit@googlegroups.com
To unsubscribe from this group, send email to
vulmsit+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/vulmsit?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "vulms" group.
Visit this group at http://groups.google.com/group/vulmsit?hl=en-GB.