0% found this document useful (0 votes)
79 views12 pages

Regno: Name: Cse 102 - Data Structures and Algorithms - D1 & D2

This document contains questions and answers related to data structures and algorithms. It discusses recursion time complexity, differences between data types and structures, pointer assignments, deletion in sorted and unsorted lists, adding integers to float pointers, linear data structures, recursion without stop conditions, pointer arrays, character pointers, function pointers, 2D array pointers, recursive function execution order, structures with unions, when pointers are needed, recursion for decimal to binary conversion, pointer drawbacks, insertion in sorted and unsorted lists, self-referential structures, pointer types, data structures used for recursion.

Uploaded by

mansur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views12 pages

Regno: Name: Cse 102 - Data Structures and Algorithms - D1 & D2

This document contains questions and answers related to data structures and algorithms. It discusses recursion time complexity, differences between data types and structures, pointer assignments, deletion in sorted and unsorted lists, adding integers to float pointers, linear data structures, recursion without stop conditions, pointer arrays, character pointers, function pointers, 2D array pointers, recursive function execution order, structures with unions, when pointers are needed, recursion for decimal to binary conversion, pointer drawbacks, insertion in sorted and unsorted lists, self-referential structures, pointer types, data structures used for recursion.

Uploaded by

mansur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

1. State the drawback of recursion in terms of time complexity.

- Time required to make push and pop function calls for stack

2. In what way data type and data structure are different.

- Data type specifies domain and range of data. Data structure represents the
structured way of storing and retrieving data.

3. What happens if one structure pointer is assigned to the other?

- Both points to a same variable

4. In what way the deletion procedure differs for unsorted and sorted list?

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

- In sorted list, deleting an element can be done by swapping the element to be


deleted with last element of list and decrement the total number of items. Whereas in
sorted list deleting an element is achieved by overwriting that element with the
subsequent element and shifting all other elements above.

5. What happens if you add an integer to a float pointer?

- The float pointer points to integer* 4bytes

B
6. What the term Linear refers to in Linear Data Structure.

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

Linear refers to the sequential relationship among elements

7. What will happen if the stop condition is not given in recursion? Or will a recursive
call stops when the stop condition is not given?

- Yes the function stops after the system gets exhausted by allocation memory
required for the variables in each call

8 Char *p[3]; what this declaration means and what for p can be used?

- A pointer array that holds address of three characters

9 char *p=welcome; what happens if u print *p+3. Justify your answer.

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

- *p retrieves w whereas *p+3 adds three to the alphabet w and prints z

10. What exactly a function pointer is?

- A pointer that pointer to the starting address of memory where the function is
stored

C
11. Differentiate pointer to an entire 2D array, pointer to the row and pointer to the
element with the example int *s, a[20][20]; s=a;

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

s pointer to the entire array

*(s+i) pointer to the ith row

*(*(s+i)+j) pointer to ith row jth element

12. In what order the statements are executed in recursive function call.

- The statements before function call executes in sequence and statements after
the call executes out of sequence

13. What will happen here. Struct { int a; union{float b; char c;}, long d}*s1;

- a structure variable will get created where the memory will be allocated for
integer, float and long variables.

14. When exactly pointers are needed? Justify the answer.

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

- Pointers are needed when memory has to created without names.

15. Why recursion can be a suitable choice to do decimal to binary conversion?

- If the statement to find the remainder of dividing the number by 2 is printed after
the recursive call, it will get printed in the reverse thereby printing the binary equivalent
of the decimal number.

D
16. State a drawback you feel with pointers.

-The pointers can be manipulated to access the memory beyond the scope of user
memory intended to be accessed thereby breaching the data security.

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

17. In what way the code for inserting an item in sorted and unsorted list differs.

- In sorted list, element to be inserted must be placed in the proper position such
that the resultant list must be in order. This is done by identifying the position and
pushing all the elements down. By doing so, a space gets created for the element to be
inserted. Whereas in unsorted list the element is inserted at the last position of the list.

18. What happens if a structure is created as follows struct stud{ int a; float b; struct stud
*p;}s1;

- The memory gets created for integer, float variable along with the pointer to the
same structure.

19. Is there a need that the pointer should be of the same type as that of variable it is
pointing to? Why?

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

- Yes, only then when the pointer is manipulated it can be shifted to appropriate
number of bytes depending on the type.

20. What data structure is used during recursion? why?

-Stalk DS is used in recursion because in recursion, the last call made must get
executed first. Since stack follows LIFO principle, stack is the correct choice for
recursion.
Quiz II
A
21 How will you handle the overflow condition of a linked stack through code?
Overflow need not be handles in linked stack of if a pointer to the new
node is null then overflow.

22 Which data structure is used to handle function calls and why?


Stack, because function calls must be handled in LIFO order

23 Draw a Doubly LL, assume some pointers for the nodes and explain how the
pointers are adjusted to insert a node "B" between "A" and "C" in a doubly linked
list.
Start curr and prev pointers and traverse the DLL such that curr points c
and Prev points A, then make newnode-> right= prev->right, prev>right=newnode, newnode->left= prev, curr->left=newnode. free(curr),
free(prev).

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

24 Why insertion sort is called so?


Because every time an element from the unsorted array is picked and
inserted into the proper position of sorted array

25 How to create a memory without a name during the execution of the program?
Using dynamic memory allocation functions like malloc()

Quiz II
B
26 How to perform priority dequeue in a queue?
Search for highest priority element and swap it with element at front and
then increment front.

27.Use a stack and convert the given expression into its postfix form (a+(b-c)*d).
Use stack and obtain the result : abc-d*+

28
How to traverse singly linked list in the reverse without using arrays?
Make it as a circular list and traverse till the end and print the last value.
Again go the beginning and traverse last but one and print its value so on
till the entire list is printed.

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

29 Write the set of statements for dequeing the last node of a linked queue.
Make the front to point front link. if front is null make rear also as null

30 Justify the time complexity of Selection sort.


Nested for loops nXn times so O(n2).

Quiz II
C
31 What happens in a shell sort?
Different shell sizes are selected and insertion sort is performed.

32 How will you print the contents of a doubly linked list in reverse?
Traverse and reach the last node using the right pointers and start from the
last node, traverse using the left pointers and print the contents

33 Evaluate the given expression (4*(120/(24-4)+5) using stack.


Convert to postfix using stack to get: 4 120 24 4 - / 5 + *
Evaluate the postfix using stack to get: 44

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2

34 In what way indexed sequential search is advantageous over linear search?


Searching through the index saves time than searching all the elements.

35 What will be the complexity of quicksort when the pivot element is the least of
all?
Every time it may yield 2 arrays one with one element and other with all the
remaining elements. This results in extracting element by element out of the array
which will get complexity O(n2).

Quiz II
D
36 What is the return type of malloc function? Justify the answer.
void * to accept pointer to any type of memory created.

37 What is the precondition for binary search? Justify.


The array should be in sorted order.

38 Write the set of statements for creating the first node of a linked queue.
create a newnode at rear. Make front also to point the new node.

39 How to perform priority enqueue in a queue?

RegNo:

Name:
CSE 102 Data Structures and Algorithms D1 & D2
Take the elements and insert them into queue based on their priority.

40 Which sorting technique is better? merge sort or quick sort? Why?


Merge sort. It always gets O(nlog n). Reason: Quick sort depends on pivot where
as merge sort divides the array exactly into halves.

You might also like