An array is a collection of elements of the same data type - fundamental or user-defined. When an array is declared we have to specify the size of the array and accordingly space is allocated in memory. Subsequently, array elements are accessed using the index number.
A linked list is always declared using a user defined data type, like structure. Linked lists are used when the size is not known, so memory is reserved for each node of the list at run time. Nodes are accessed through the pointer.
Self referential structures are used to create linked lists. This type of structure has a member that refers to the structure itself.
Example -
struct Emp{
int code;
char name[20];
Emp *next; // pointer to type Emp
};
Here, structure Emp is a self referential structure. It has a member, next, which stores the address of Emp type.
A linked list is a series of nodes. Each node is divided into two parts – one containing data and the other containing a pointer that contains the address of the next node. Linked lists are used when the number of elements to be stored is not known. Memory is allocated at run time as the need arises. In a singly linked list, each node has one pointer pointing to the next node while in a doubly linked list, each node has two pointers, one pointing to the next node and the other to the previous node.
Input expression : A * ( B + C ) / E – F – (D + G) / H
|
|
Element |
Stack |
Expression Y in Postfix |
|
1 |
A |
( |
A |
|
2 |
* |
(* |
A |
|
3 |
( |
(*( |
A |
|
4 |
B |
(*( |
AB |
|
5 |
+ |
(*(+ |
AB |
|
6 |
C |
(*(+ |
ABC |
|
7 |
) |
(* |
ABC+ |
|
8 |
/ |
(/ |
ABC+* |
|
9 |
E |
(/ |
ABC+*E |
|
10 |
- |
(- |
ABC+*E/ |
|
11 |
F |
(- |
ABC+*E/F |
|
12 |
- |
(- |
ABC+*E/F- |
|
13 |
( |
(-( |
ABC+*E/F- |
|
14 |
D |
(-( |
ABC+*E/F-D |
|
15 |
+ |
(-(+ |
ABC+*E/F-D |
|
16 |
G |
(-(+ |
ABC+*E/F-DG |
|
17 |
) |
(- |
ABC+*E/F-DG+ |
|
18 |
/ |
(-/ |
ABC+*E/F-DG+ |
|
19 |
H |
(-/ |
ABC+*E/F-DG+H |
|
20 |
) |
|
ABC+*E/F-DG+H/- |
Stack is a LIFO (Last In First Out) structure. This means that the element that comes in last is the first to remove. It can be visualized as a stack of trays where a fresh tray is put on top of the existing stack and the one picked up is the tray on top. Thus, insert and delete operations are from the same side. This is called the ‘top’ of the stack. Inserting into a stack is called ‘push’ operation and deleting from a stack is called ‘pop’ operation. A stack can be implemented as an array or as a linked list.
void stack::PUSHIN( ){
Node *X;
X = new Node;
if(X == NULL){
cout<<"n Could not create node.";
getch( );
}
else {
cout<< "n Enter data for node ";
cin>>X->info ;
X->next = NULL;
}
if(top==NULL)
top = X;
else
{ X->next = top;
top = X;
}
}
void stack:: POPOUT( ){
Node *X;
if(top == NULL)
cout<<"n Underflow error";
else
{
cout<<"nvalue popped = "<< top->info;
X = top;
top = top->next;
delete X;
}
}
Algorithm to convert Infix form to Postfix Form
A stack is used in which operators and left parentheses are pushed and popped, X is the infix expression and the output is built up in the form of Y.
1. INPUT X // the arithmetic expression in infix form
2. PUSH '(' into stack and add ')' at the end of X
3. REPEAT STEPS 4 TO 7 for each element of X from left to right, until the stack is empty
4. IF IT IS AN Operand, THEN add to Y
5. IF IT IS '(', THEN Push into stack
6. IF IT IS AN Operator THEN
{
Pop FROM stack and add to Y, each operator with equal or higher precedence.
Push operator into stack.
}
7. IF IT IS ')' THEN
{
Pop FROM stack and add to Y, until ‘(‘ is encountered
Pop '(' from stack
}
Polish String is an application of STACK which is used in the conversion of arithmetic expressions in high-level programming languages into machine readable form. It refers to the notation in which the operator is placed either before its operands (prefix notation) or after its operands (postfix notation) in contrast to usual form where operator is placed in between the operands (infix notation) .
|
Expression in Infix form |
Expression in Prefix form |
Expression in Postfix form |
|
A + B |
+ A B |
A B + |
|
(A – B) * C |
*- A B C |
A B - C * |
|
(A – B) / (C – D) |
/ - A B - C D |
A B - C D - / |
A. Late binding
B. Static binding
C. Dynamic binding
D. Runtime binding
Name binding is association of values with identifiers. The binding of names before the program is run is called static binding.
A. Module
B. Segment
C. Code
D. Procedure
A group of functions together forms a larger identity called module.
A. Difficult to solve
B. Complex
C. Easier to find
D. Errors
Ambiguous statements are errors and programs containing ambiguity will not be compiled.
A. Function overriding
B. Function overloading
C. Operator overloading
D. Complex overloading
If we need to perform a complex mathematical operation then function overloading is the easiest form to solve the problem. With function overloading, the programmer is relieved from the burden of choosing the right function for a given set of values.
A. The second function is treated as a re-declaration of the first.
B. The two functions are considered to be overloaded.
C. The two functions are considered to be overridden.
D. The two functions are considered to be complex.
When a function name is declared more than once in a program and if the signatures of the two functions differ in either the number or type of their arguments then the two functions are considered to be overloaded.
A. Early binding and static binding
B. Late binding and dynamic binding
C. Early binding and late binding
D. Early binding and moderate binding
The two types of binding are early binding and late binding. Early binding is also known as static binding. In early binding, the binding of identifiers is done at the compile time. Late binding is also known as dynamic binding. In late binding, the binding is done at the run time (during program execution).
A. Early binding
B. Dynamic binding
C. Function binding
D. Late binding
Dynamic binding refers to the case, where compiler is not able to resolve the call at compile time and the binding is done at run time only.
A. Late binding
B. Early binding
C. Dynamic binding
D. Function binding
When a system determines how to implement an action at compile time, this is called early binding or static binding.
A. The second is treated as an erroneous re-declaration of first.
B. It is a compile time error.
C. It is a runtime error.
D. The second is treated as a different function.
When a function name is declared more than once in a program and if the signature of the two functions matches exactly but the return types differ, then the second declaration is treated as an erroneous re-declaration of the first and flags error.
A. The second is treated as an erroneous re-declaration of first.
B. It is a compile time error.
C. It is a run time error.
D. The second is treated as a different function.
The second function declaration is treated as an erroneous re-declaration of the first function and is flagged at compile time as an error.
A. Function’s parameters
B. Function’s members
C. Function’s structures
D. Function’s signature
The signature of a function is roughly equivalent to its prototype definition.
A. Virtual function
B. Overloaded function
C. Overloaded operator
D. Polymorphism
Overloaded function has one name and different arguments.
A. Data abstraction
B. Polymorphism
C. Overloading
D. Inheritance
Polymorphism is the ability for a message or data to be processed in more than one form.
A. Run time
B. Compile time
C. Anytime
D. Real time
In late binding, the binding is done at the run time (during program execution) whereas in early binding, the binding of identifiers is done at the compile time.
A. Run time
B. Compile time
C. Anytime
D. Real time
In early binding, the binding of identifiers is done at the compile time whereas in late binding, the binding is done at the run time (during program execution).
A. Static
B. Constant
C. Const
D. Void
Constant arguments prevent temporary modification of the argument. The keyword const added in the beginning of an argument declaration, to prevent the argument from being modified within the body of the called function.
A. C++ tries to find a match through standard conversion.
B. C++ tries to find a match through user-defined conversion.
C. C++ tries to find a match through promotion.
D. C++ tries to find a match through both promotion and conversion.
a. First, C++ tries to find an exact match. This is the case where the actual argument exactly matches the parameter type of one of the overloaded functions. b. If no exact match is found, C++ tries to find a match through promotion. c. If no promotion is found, C++ tries to find a match through standard conversion. d. Finally, C++ tries to find a match through user-defined conversion.
A. C++ tries to find a match through standard conversion.
B. C++ tries to find a match through user-defined conversion.
C. C++ tries to find a match through promotion.
D. C++ tries to find a match through both promotion and conversion.
A. Worst possible
B. Best possible
C. Any
D. Both worst and best
The compiler tries to find the best possible match of the arguments for the function called. The argument matching involves comparing the actual arguments of the function call with the formal arguments of each declared instance of the function.
A. Overridden function
B. Overloaded function
C. Method
D. Static method
When an overloaded function is called, compiler looks for a match between the arguments used to call the method and the method's parameters. Making a call to an overloaded function results in one of three possible outcomes:
A. Late binding
B. Early binding
C. Linking
D. Polymorphism
In early binding, the binding of identifiers is done at the compile time. As static methods are class methods, they can be accessed using the class name itself. Therefore, access of static method is done at compile time.
A. Binding
B. Late binding
C. Early binding
D. Static binding
Binding refers to the linking of a procedure call to the code to be executed in response to that call. Binding is of two types – early binding and late binding.
A. Early binding
B. Static binding
C. Polymorphism
D. Dynamic binding
Binding refers to the linking of a procedure call to the code to be executed in response to that call. When binding is done at the run-time, it is known as dynamic binding (late binding). It is associated with polymorphism.
A. Very long functions that can hardly run
B. One function containing one or more functions inside it
C. Two or more functions with the same name but different number of parameters or type
D. Functions that can easily run
Overloaded functions have same name but different signatures.
A. List
B. Signature
C. Method
D. Parameter
The function’s argument list is known as the function’s signature. If two functions are having same number and types of arguments in the same order, they are said to have the same signature. The signature can differ in number of arguments or in the type of arguments, or both.
Polymorphism is the ability of an object to behave differently in different circumstances. It can be implemented in programming through function overloading.
Arguments are the values of variables that are passed to the function during function call.
Polymorphism is implemented through overloaded operators, overloaded functions and virtual functions.
In the call statement, a variable that accepts the return value from a function should be as per the return type of the function.
Polymorphism
The function’s argument list is known as the function’s signature.
To overload a function name, you need to declare and define all the functions with the same name but with different signatures, separately.
Some of the advantages of default arguments are given below:
In early binding, the binding of identifiers is done at the compile time. As static methods are class methods, they can be accessed using the class name itself. Therefore, access of static method is done at compile time.
Default argument is the value given in the function declaration that compiler automatically inserts, if no value is provided for that argument during function call.
The function pow(x,n) computes and return xn.
This means that if the programmer calls pow(x), then the compiler will replace that call with pow(x,2), returning x2.
Function overloading is used to enhance the readability of the program. It also reduces the number of comparisons in a program and thereby makes the program run faster.
The functions signature is its argument list. This includes the type and number of each argument.
Consider two functions:
void fadd(int a, int b); and
int fadd(int x, int y);
As their argument lists are the same, they have the same signature, even when return type is different.
Two or more functions can share the same name as long as their parameter declarations are different.
This could include:
In static binding, the binding of identifiers is done at the compile time.
In dynamic binding, the binding is done at the run time (during program execution).
A function cannot be overloaded only by its return type because the overloading functions with argument lists of same types, based on return type alone, is an error.
There are two ways to overload the method in C++:
The steps involved in finding the best match are as follows:
When an overloaded function is called, compiler looks for a match between the arguments used to call the method and the method's parameters.
Making a call to an overloaded function results in one of three possible outcomes:
A function name having several definitions in the same scope that are differentiable by the number or types of their arguments is said to be an overloaded function.
The process of creating overloaded functions is called function overloading.
Example:
void read(int a)
{
//statements
}
void read(int a, int b)
{
//statements
}
A. polish notation.
B. reverse polish notation.
C. prefix expression.
D. pushing.
Postfix expression(Also called reverse polish notation of an expression). It is an expression where operators are placed after the operands.
A. circular queues.
B. dequeue.
C. linked queues.
D. simple queues.
These are two variations of dequeue. Input restricted queue allows insertions at only one end but allows deletions at both ends of the list. Output restricted queue allows deletions at only one end but allows insertions at both the ends of the list.
A. only the topmost element.
B. any random element.
C. the last element.
D. a middle element.
Pop operation is always performed on the top element of the stack. If we want to pop the middle element of the stack, then first we have to pop all the elements above it.
A. homogeneous data structure.
B. non-homogeneous data structure.
C. static data structure.
D. dynamic data structure.
A static data structure is a data structure created for an input data set, which is not supposed to change within the scope of the problem.
A. null
B. 10,20,30,40,60,50.
C. 60,50,40,30,20,10.
D. 10,40,20,50,30,60.
Stack is a LIFO data structure, i.e., last in first out. Last element pushed is 60 and it is also the first element to be popped out.
A. static memory allocation.
B. dynamic memory allocation.
C. fixed memory allocation.
D. compile memory allocation.
In computer science, dynamic memory allocation is the allocation of memory storage for use in a computer program during the runtime of that program.
A. static memory allocation.
B. dynamic memory allocation.
C. fixed memory allocation.
D. run time memory allocation.
Static memory allocation refers to the process of allocating memory at compile-time before the associated program is executed.
A. input queue.
B. input restricted queue.
C. output queue.
D. output restricted queue.
An input-restricted queue is one where deletion can be made from both ends, but input can only be made at one end.
A. input queue.
B. input restricted queue.
C. output queue.
D. output restricted queue.
An output-restricted queue is one where input can be made at both ends, but output can be made from one end only.
A. front + rear.
B. 1 + front + rear.
C. front-rear +1.
D. rear+ front - 1.
The formula to count the number of elements in a
queue = front-rear +1.
A. queues.
B. stacks.
C. arrays.
D. dequeue.
In linked list, the number of elements need not be predetermined, more memory can be allocated and released during the processing as and when required but with arrays we cannot do such things because the number of elements are predetermined.
A. postfix notation.
B. prefix notation.
C. infix notation.
D. increment notation.
The word pre means before, so in prefix notation the operator symbol is placed before the operand.
A. an array.
B. a linked list.
C. arrays and linked lists.
D. trees.
When stack is implemented as an array, it inherits all the properties of an array, whereas if it is implemented as a linked list, all characteristics of a linked list are possessed by it.
A. Flow
B. Underflow
C. Overflow
D. Excessflow
Overflow is the condition in data structure when there is no space available and even then you are trying to insert new nodes.
A. a stack implemented as an array.
B. a stack implemented as a linked list.
C. a double ended queue.
D. a queue implemented as an array.
If a stack is implemented as a linked list overflow condition does not occur. As it is a dynamic data structure where space requirements need not be predetermined.
A. linked lists and trees.
B. only linked lists.
C. arrays.
D. stacks.
Both linked lists and trees are used to allocate memory dynamically .It facilitates allocation of memory during the program execution itself, as and when required.
A. link lists.
B. arrays.
C. queues.
D. stacks.
An array is a systematic arrangement of objects, usually in rows and columns.It is one of the simple data structure which stores data sequentially.
A. postfix notation.
B. prefix notation.
C. infix notation.
D. increment notation.
Post means after. Postfix notation is the notation in which operator symbol is placed after its operands. It is a way of writing algebraic notations and is also called as "reverse polish notation".
A. attempt to pop from an empty stack.
B. attempt to insert into an empty queue.
C. attempt to push into an empty stack.
D. attempt to push into a full stack.
If we try to use push operation on a stack, which is already full, it leads to overflow condition.
A. stacks.
B. arrays.
C. trees.
D. queues.
The complex arithmetic operations can be converted into polish string using stacks, which then can be executed in two operands and a operator form.
A. DML.
B. DDL.
C. DCL.
D. TCL.
DML stands for data manipulation language. It provides commands to insert, delete and modify tuples in the database.
A. cartesian product.
B. normalization.
C. projection.
D. cardinality.
Normalization is a basic concept used in analyzing data. This process, in turn, reduces the redundancy in the system.
A. relational data model.
B. hierarchical data model.
C. internal data model.
D. external data model.
A relational data model organizes the data into rows and columns, that form tables.
A. degree.
B. rank.
C. key.
D. cardinality.
The degree of a relationship is the number of entities associated with the relationship.
A. Ω.
B. β.
C. σ.
D. ω.
The selection operation extracts tuple from a relation depending upon a condition and is denoted by σ (sigma).
A. ∏.
B. Ω.
C. β.
D. ω.
The projection extracts column from a relation and is represented by ∏.
A. data abstraction.
B. data integrity.
C. data redundancy.
D. data independence.
The abstract data type implements the concept of data independence as it hides implementation details from the users.
A. view level.
B. physical level.
C. internal level.
D. user level.
View level is concerned with the way in which data is viewed by individual user. It is also known as external level.
A. data.
B. database.
C. information.
D. metadata.
A database is a collection of interrelated data stored together to serve multiple applications.
A. chain.
B. network.
C. hierarchical
D. relational.
Structure in the form of chains is not allowed in database systems. Network, hierarchical and relational data structure are the standard ways to represent data in database systems.
A. domain.
B. tuple.
C. attribute.
D. degree.
In Relational Model, the columns of a table are referred to as attributes and rows are generally referred to as tuples.
A. relational data model.
B. hierarchical data model.
C. network data model.
D. database model.
A hierarchical data model represents data by records, organized in the form of trees and relationships among data are represented by links.
A. relational data model.
B. hierarchical data model.
C. network data model.
D. conceptual data model.
A network data model represents data by collection of records. Relationships among data are represented by links (pointers).
A. select.
B. join.
C. cartesian product.
D. tuple.
Tuple refers to the rows of tables. The various operations of relation algebra are select, project, cartesian product, union, set difference, set intersection, join and division.
A. relational algebra.
B. set difference.
C. natural join.
D. set intersection.
The relational algebra is a collection of operations on relations. Each operation takes one or more relations as its operands and produces another relation as its result.
A. parent table.
B. view.
C. child table.
D. base table.
A view consists of a stored query accessible as a virtual table, composed of the result set of a query. Unlike ordinary tables (base tables) in a relational database, a view does not form part of the physical schema: it is a dynamic, virtual table computed or collated from data in the database.
A. relational data model.
B. network data model.
C. tree data model.
D. hierarchical data model.
A tree has a root and different child nodes. All the other models except tree model are used for managing the database system.
A. row in a table.
B. column in a table.
C. table in a database.
D. key number.
In database, relation refers to tables which is the combination of rows and columns.
A. alternate key.
B. primary key.
C. secondary key.
D. candidate key.
The columns of tables or relations are generally referred as an attribute. Primary key refers to that set of attributes that identifies a tuple uniquely within a relation.
A. database management system.
B. digital based mapping system.
C. database manipulation software.
D. database mapping system.
DBMS is an application software, which consists of interrelated databases and operations to manage databases.
A. data inconsistency.
B. data sharing.
C. data security.
D. data redundancy.
Data sharing is individual pieces of data shared among different users. Data security is the protection of data against unauthorised access and data inconsistency means incorrect data.
A. Definition Data Language.
B. Data Definition Language.
C. Data Degree Language.
D. Database Degree Language.
Data Definition Language (DDL) describes the portion of SQL that allows you to create, alter, and destroy database objects. These database objects include schemas, tables, views, sequences, catalogs, indexes and aliases.
A. reduction of data dependency.
B. addition of node.
C. complexity.
D. machine performance.
The main advantage of the hierarchical data model is that, we can easily attach any child node to any parent node directly.
A. primary key.
B. composite key.
C. alternate key.
D. foreign key.
In the context of relational databases, an alternate key (or secondary key) is any candidate key which is not selected to be the primary key (PK).
A. attribute.
B. tuple.
C. cardinality.
D. entity.
A factor of an object or other kind of entity is known as attribute. It is also known as field.
A. reduced redundancy.
B. non-sharing of data.
C. inconsistency.
D. non-standardized data.
In database management system, it is possible to share the data among multiple tables where redundancy is get reduced.
A. four.
B. five.
C. six.
D. seven.