Download ds_lab_viva_ques

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Linked list wikipedia , lookup

Transcript
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURE LAB VIVA QUESTIONS
1. What is a pointer on pointer?
It’s a pointer variable which can hold the address of another pointer variable. It de-refers twice
to point to the data held by the designated pointer variable.
Eg:int x =5,*p=&x,**q=&p;
Therefore ‘x’ can be accessed by **q.
2. Distinguish between malloc() & calloc() memory allocation.
Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated
What is a constant pointer?
A pointer which is not allowed to be altered to hold another address after it is holding
one.
3. What is a static variable?
A static local variables retains its value between the function call and the default value is 0. The
following function will print 1 2 3 if called thrice.
4. What is a NULL pointer?
A pointer pointing to nothing is called so. Eg: char *p=NULL;
What is the purpose of extern storage specifier?
Used to resolve the scope of global symbol.
Eg:
main(){
externint i;
Printf(“%d”,i);
}
int i =20;
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
5. Explain the purpose of the function sprintf().
Prints the formatted output onto the character array.
6. What is the meaning of base address of the array?
The starting address of the array is called as the base address of the array.
7. When should we use the register storage specifier?
If a variable is used most frequently then it should be declared using register storage specifier,
then possibly the compiler gives CPU register for its storage to speed up the look up of the
variable.
8. What is a dangling pointer?
A pointer initially holding valid address, but later the held address is released or freed. Then
such a pointer is called as dangling pointer.
9. What is the purpose of the keyword typedef?
It is used to alias the existing type. Also used to simplify the complex declaration of the type.
10. What is the difference between actual and formal parameters?
The parameters sent to the function at calling end are called as actual parameters while at the
receiving of the function definition called as formal parameters.
11. Can a program be compiled without main() function?
Yes, it can be but cannot be executed, as the execution requires main() function definition.
12. What is the advantage of declaring void pointers?
When we do not know what type of the memory address the pointer variable is going to hold,
then we declare a void pointer for such.
13. Where an automatic variable is stored?
Every local variable by default being an auto variable is stored in stack memory.
14. What is a nested structure?
A structure containing an element of another structure as its member is referred so.
15. What is the difference between variable declaration and variable definition?
Declaration associates type to the variable whereas definition gives the value to the variable.
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
16. What is a self-referential structure?
A structure containing the same structure pointer variable as its element is called as selfreferential structure.
17. Does a built-in header file contain built-in function definition?
No, the header file only declares function. The definition is in library which is linked by the
linker.
18. Explain modular programming.
Dividing the program in to sub programs (modules/function) to achieve the given task is
modular approach. More generic functions definition gives the ability to re-use the functions,
such as built-in library functions.
19. What is a token?
A C program consists of various tokens and a token is either a keyword, an identifier, a
constant, a string literal, or a symbol.
20. What is a constant pointer?
A pointer which is not allowed to be altered to hold another address after it is holding
one.
21. Describe stack operation.
Stack is a data structure that follows Last in First out strategy.
Stack Operations:Push – Pushes (inserts) the element in the stack. The location is specified by the pointer.
Pop – Pulls (removes) the element out of the stack. The location is specified by the pointer
Swap: - the two top most elements of the stack can be swapped
Peek: - Returns the top element on the stack but does not remove it from the stack
Rotate:- the topmost (n) items can be moved on the stack in a rotating fashion
A stack has a fixed location in the memory. When a data element is pushed in the stack, the
pointer points to the current element.
22. Discuss how to implement queue using stack.
A queue can be implemented by using 2 stacks:1. An element is inserted in the queue by pushing it into stack 1
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
2. An element is extracted from the queue by popping it from the stack 2
3. If the stack 2 is empty then all elements currently in stack 1 are transferred to stack 2 but in the
reverse order
4. If the stack 2 is not empty just pop the value from stack 2.
23. What is data structure?
Data structures refers to the way data is organized and manipulated. It seeks to find ways to
make data access more efficient. When dealing with data structure, we not only focus on one
piece of data, but rather different set of data and how they can relate to one another in an
organized manner.
24. What is a queue?
A queue is a data structures that can simulates a list or stream of data. In this structure, new
elements are inserted at one end and existing elements are removed from the other end.
25. What are binary trees?
A binary tree is one type of data structure that has two nodes, a left node and a right node. In
programming, binary trees are actually an extension of the linked list structures.
26. Which data structures is applied when dealing with a recursive function?
Recursion, which is basically a function that calls itself based on a terminating condition, makes
use of the stack. Using LIFO, a call to a recursive function saves the return address so that it
knows how to return to the calling function after the call terminates.
27. What is a stack?
A stack is a data structure in which only the top element can be accessed. As data is stored in the
stack, each data is pushed downward, leaving the most recently added data on top.
28. Explain Binary Search Tree
A binary search tree stores data in such a way that they can be retrieved very efficiently. The left
subtree contains nodes whose keys are less than the node’s key value, while the right subtree
contains nodes whose keys are greater than or equal to the node’s key value. Moreover, both
subtrees are also binary search trees.
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
29. What are doubly linked lists?
Doubly linked lists are a special type of linked list wherein traversal across the data elements can
be done in both directions. This is made possible by having two links in every node, one that
links to the next node and other one that links to the previous node.
30. What is Huffman’s algorithm?
Huffman’s algorithm is associated in creating extended binary trees that has minimum weighted
path lengths from the given weights. It makes use of a table that contains frequency of
occurrence for each data element.
31. What is Fibonacci search?
Fibonacci search is a search algorithm that applies to a sorted array. It makes use of a divide-andconquer approach that can greatly reduce the time needed in order to reach the target element.
32. Briefly explain recursive algorithm.
Recursive algorithm targets a problem by dividing it into smaller, manageable sub-problems. The
output of one recursion after processing one sub-problem becomes the input to the next recursive
process.
33. What is the minimum number of queues needed to implement the priority queue?
Two. One queue is used for the actual storing of data, and the other one is used for storing the
priorities.
34. Which data structure is used to perform recursion?
The answer is Stack. Stack has the LIFO (Last In First Out) property; it remembers it's ‘caller’.
Therefore, it knows to whom it should return when the function has to return. On the other hand,
recursion makes use of the system stack for storing the return addresses of the function calls.
Every recursive function has its equivalent iterative (non-recursive) function. Even when such
equivalent iterative procedures are written explicit, stack is to be used.
35. What are some of the applications for the tree data structure?
1- Manipulation of the arithmetic expressions.
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
2- Symbol table construction.
3- Syntax analysis.
36. How does dynamic memory allocation help in managing data?
Aside from being able to store simple structured data types, dynamic memory allocation can
combine separately allocated structured blocks to form composite structures that expand and
contract as needed.
37. What is FIFO?
FIFO is short for First-in, First-out, and is used to represent how data is accessed in a queue.
Data has been inserted into the queue list the longest is the one that is removed first.
38. What is an ordered list?
An ordered list is a list in which each node’s position in the list is determined by the value of its
key component, so that the key values form an increasing sequence, as the list is traversed.
39. What is merge sort?
Merge sort takes a divide-and-conquer approach to sorting data. In a sequence of data, adjacent
ones are merged and sorted to create bigger sorted lists. These sorted lists are then merged again
to form an even bigger sorted list, which continuous until you have one single sorted list.
40. What is the difference between a PUSH and a POP?
Pushing and popping applies to the way data is stored and retrieved in a stack. A push denotes
data being added to it, meaning data is being “pushed” into the stack. On the other hand, a pop
denotes data retrieval, and in particular refers to the topmost data being accessed.
41. What is a linear search?
A linear search refers to the way a target key is being searched in a sequential data structure.
Using this method, each element in the list is checked and compared against the target key, and
is repeated until found or if the end of the list has been reached.
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
42. How does variable declaration affect memory allocation?
The amount of memory to be allocated or reserved would depend on the data type of the variable
being declared. For example, if a variable is declared to be of integer type, then 32 bits of
memory storage will be reserved for that variable.
43. What is the advantage of the heap over a stack?
Basically, the heap is more flexible than the stack. That’s because memory space for the heap
can be dynamically allocated and de-allocated as needed. However, memory of the heap can at
times be slower when compared to that stack.
44. What is a postfix expression?
A postfix expression is an expression in which each operator follows its operands. The advantage
of this form is that there is no need to group sub-expressions in parentheses or to consider
operator precedence.
45. What is data structure?
Data structures refers to the way data is organized and manipulated. It seeks to find ways to
make data access more efficient. When dealing with data structure, we not only focus on one
piece of data, but rather different set of data and how they can relate to one another in an
organized manner.
46. Differentiate file structure from storage structure.
Basically, the key difference is the memory area that is being accessed. When dealing with the
structure that resides the main memory of the computer system, this is referred to as storage
structure. When dealing with an auxiliary structure, we refer to it as file structures.w they can
relate to one another in an organized manner.
47. What is a linked list?
A linked list is a sequence of nodes in which each node is connected to the node following it.
This forms a chain-like link of data storage.
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
48. How do you reference all the elements in a one-dimension array?
To do this, an indexed loop is used, such that the counter runs from 0 to the array size minus one.
In this manner, we are able to reference all the elements in sequence by using the loop counter as
the array subscript.
49. In what areas do data structures applied?
Data structures is important in almost every aspect where data is involved. In general, algorithms
that involve efficient data structure is applied in the following areas: numerical analysis,
operating system, A.I., compiler design, database management, graphics, and statistical analysis,
to name a few.
50. What is LIFO?
LIFO is short for Last In First Out, and refers to how data is accessed, stored and retrieved.
Using this scheme, data that was stored last , should be the one to be extracted first. This also
means that in order to gain access to the first data, all the other data that was stored before this
first data must first be retrieved and extracted.
51. What is a queue?
A queue is a data structures that can simulates a list or stream of data. In this structure, new
elements are inserted at one end and existing elements are removed from the other end.
52. What are binary trees?
A binary tree is one type of data structure that has two nodes, a left node and a right node. In
programming, binary trees are actually an extension of the linked list structures.
53. Which data structures is applied when dealing with a recursive function?
Recursion, which is basically a function that calls itself based on a terminating condition, makes
use of the stack. Using LIFO, a call to a recursive function saves the return address so that it
knows how to return to the calling function after the call terminates.
54. What is a stack?
A stack is a data structure in which only the top element can be accessed. As data is stored in the
stack, each data is pushed downward, leaving the most recently added data on top.
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
55. What are multidimensional arrays?
Multidimensional arrays make use of multiple indexes to store data. It is useful when storing data
that cannot be represented using a single dimensional indexing, such as data representation in a
board game, tables with data stored in more than one column.
56. Are linked lists considered linear or non-linear data structures?
It actually depends on where you intend to apply linked lists. If you based it on storage, a linked
list is considered non-linear. On the other hand, if you based it on access strategies, then a linked
list is considered linear.
57. How does dynamic memory allocation help in managing data?
Aside from being able to store simple structured data types, dynamic memory allocation can
combine separately allocated structured blocks to form composite structures that expand and
contract as needed.
58. What is FIFO?
FIFO is short for First-in, First-out, and is used to represent how data is accessed in a queue.
Data has been inserted into the queue list the longest is the one that is removed first.
59. What is the primary advantage of a linked list?
A linked list is a very ideal data structure because it can be modified easily. This means that
modifying a linked list works regardless of how many elements are in the list.
60. What is the difference between a PUSH and a POP?
Pushing and popping applies to the way data is stored and retrieved in a stack. A push denotes
data being added to it, meaning data is being “pushed” into the stack. On the other hand, a pop
denotes data retrieval, and in particular refers to the topmost data being accessed.
61. What is a linear search?
A linear search refers to the way a target key is being searched in a sequential data structure.
Using this method, each element in the list is checked and compared against the target key, and
is repeated until found or if the end of the list has been reached.
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
62. How does variable declaration affect memory allocation?
The amount of memory to be allocated or reserved would depend on the data type of the variable
being declared. For example, if a variable is declared to be of integer type, then 32 bits of
memory storage will be reserved for that variable.
63. What is the advantage of the heap over a stack?
Basically, the heap is more flexible than the stack. That’s because memory space for the heap
can be dynamically allocated and de-allocated as needed. However, memory of the heap can at
times be slower when compared to that stack.
64. What is a postfix expression?
A postfix expression is an expression in which each operator follows its operands. The advantage
of this form is that there is no need to group sub-expressions in parentheses or to consider
operator precedence.
65. What are dynamic data structures?
Dynamic data structures are structures that expand and contract as a program runs. It provides a
flexible means of manipulating data because it can adjust according to the size of the data.
66. In what data structures are pointers applied?
Pointers that are used in linked list have various applications in data structure. Data structures
that make use of this concept include the Stack, Queue, Linked List and Binary Tree.
67. What are ARRAYs?
When dealing with arrays, data is stored and retrieved using an index that actually refers to the
element number in the data sequence. This means that data can be accessed in any order. In
programming, an array is declared as a variable having a number of indexed elements.
68. Differentiate STACK from ARRAY.
Data that is stored in a stack follows a LIFO pattern. This means that data access follows a
sequence wherein the last data to be stored will the first one to be extracted. Arrays, on the other
hand, does not follow a particular order and instead can be accessed by referring to the indexed
element within the array.
Dept. of. CSE
B. L. D. E. Association’s
V. P. Dr. P. G. Halakatti College of Engineering and Technology, Vijayapur-586103
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
69. Differentiate linear from non linear data structure.
Linear data structure is a structure wherein data elements are adjacent to each other. Examples of
linear data structure include arrays, linked lists, stacks and queues. On the other hand, non-linear
data structure is a structure wherein each data element can connect to more than two adjacent
data elements. Examples of non linear data structure include trees and graphs.
Dept. of. CSE