Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSD 201 ENDSEMS 2017, Exercises of Programming Languages

CSD 201 ENDSEMS 2017, High chance of question getting repeated or getting the similar type of questions, C language.

Typology: Exercises

2016/2017

Available from 08/10/2021

meetendra-singh
meetendra-singh 🇮🇳

17 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programme: B.Tech Discipline: Computer Science and Engineering
Exam: End Semester Year: 2016-2017
Course Code: CSD201 Course Title: Data Structures
Date: May 02, 2017 Time: 9:30 AM - 12.30 PM Max. Marks: 90
Ques1. Write True or False against each of the following: (5 Marks)
1. Consider a weighted directed graph G = (V, E, w) and let X be a shortest s-t path for s, t
є V. If we double the weight of every edge in the graph, setting w'(e) = 2w(e) for each e є E, then X
will still be a shortest s-t path in (V, E, w').
2. No node in a binary tree has more than 2 children
3. In a post-order traversal of a tree, root nodes comes at the last.
4. A Linked List takes more memory than an array to store the same number of data elements of the same
type.
5. Postfix expression is just a reverse of prefix expression.
Ques2. What is the result of relaxing the following edges as per Bellman Ford Algorithm: (3 Marks)
(i)
(ii)
(iii)
Ques3. Draw a hash table with open addressing (Linear Probing) with a table size of 9. Use the hash function k
% 9. Insert the keys: 5, 29, 20, 0, 27 and 18 into your table (in that order). (2 Marks)
Ques4. Fill in the blanks: (7 Marks)
1. ___________________ is a collision resolution technique that puts all the elements that hash to the
same slot in a linked list
2. Binary search tree has best case run-time complexity of O(log n). What could be the worst case run-time
complexity?
3. Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is __________
4. A binary search tree is generated by inserting in order the following integers:
50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24
The number of nodes in the left subtree and right subtree of the root respectively is ______ and _____ .
5. A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of
the heap is given below:
10, 8, 5, 3, 2
Two new elements '1' and '7' are inserted in the heap in that order. The level-order traversal of the heap after the
insertion of the elements will be _______________________ .
Ques5. Write down the space and time complexities of Kruskals Algorithm. (2 Marks)
Ques6. What is the Red constraint in a Red-Black Tree? (1 Mark)
4
12
9
7
17
11
3
4
5
pf3
pf4

Partial preview of the text

Download CSD 201 ENDSEMS 2017 and more Exercises Programming Languages in PDF only on Docsity!

Programme: B.Tech Discipline: Computer Science and Engineering Exam : End Semester Year: 2016- Course Code: CSD201 Course Title: Data Structures Date: May 02, 2017 Time: 9:30 AM - 12.30 PM Max. Marks: 90

Ques1. Write True or False against each of the following: (5 Marks)

  1. Consider a weighted directed graph G = (V, E, w) and let X be a shortest s-t path for s, t

є V. If we double the weight of every edge in the graph, setting w'(e) = 2w(e) for each e є E, then X

will still be a shortest s-t path in (V, E, w').

  1. No node in a binary tree has more than 2 children
  2. In a post-order traversal of a tree, root nodes comes at the last.
  3. A Linked List takes more memory than an array to store the same number of data elements of the same type.
  4. Postfix expression is just a reverse of prefix expression.

Ques2. What is the result of relaxing the following edges as per Bellman Ford Algorithm: (3 Marks)

(i)

(ii)

(iii)

Ques3. Draw a hash table with open addressing (Linear Probing) with a table size of 9. Use the hash function “k % 9”. Insert the keys: 5, 29, 20, 0, 27 and 18 into your table (in that order). (2 Marks)

Ques4. Fill in the blanks: (7 Marks)

  1. ___________________ is a collision resolution technique that puts all the elements that hash to the same slot in a linked list
  2. Binary search tree has best case run-time complexity of O(log n). What could be the worst case run-time complexity?
  3. Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is __________
  4. A binary search tree is generated by inserting in order the following integers: 50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24 The number of nodes in the left subtree and right subtree of the root respectively is ______ and _____.
  5. A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is given below: 10, 8, 5, 3, 2 Two new elements '1' and '7' are inserted in the heap in that order. The level-order traversal of the heap after the insertion of the elements will be _______________________.

Ques5. Write down the space and time complexities of Kruskal’s Algorithm. (2 Marks) Ques6. What is the Red constraint in a Red-Black Tree? (1 Mark)

Ques7. Convert the expression ((X + Y) * Z - (P - Q) ^ (R + S)) to equivalent postfix notation. (2 Marks) Ques8. Write down the equation that define the relationship between the parent and child nodes in a ternary tree (degree 3 tree) when using array representation with all array elements representing valid nodes notation, with no gaps for full or complete trees. (2 Marks)

Ques9. Draw the B-Tree of order 3 created by inserting the following data arriving in sequence: 92, 24, 6, 7, 11, 8, 22, 4, 5, 16, 19, 20, 78 (5 Marks)

Ques10. (a) Show the red-black tree that results after each of the integer keys 9, 8, 7, 3, 5 and 2 are inserted, in that order, into an initially empty red-black tree. Clearly show the tree that results after each insertion (indicating the color of each node), and make clear any rotations that must be performed.

(b) Delete 2, 5, 3, 7, 8, 9 in that order from the above tree. (10 Marks)

Ques11. State the order in which the vertices of the below given graph will be traversed when the edges incident on a vertex are traversed by the alphabetic order of the adjacent vertices, and each of the following traversal algorithms is used. Start at node A. (2 Marks)

Depth First Traversal : _______________________________ Breadth First Traversal : _____________________________

Ques12. Consider the following algorithm: (5 Marks) for (i = 1 to 100) { for( k = 1 to n) { j = 1; m = n; while(j < m) { m = (m = j) / 2; }

} } for (i = 1 to 3) { for (j = 1 to n) { k = i + j + n; } } for (i = 1 to 70) { j = 2n + i; }

(a) What is its exact running time with respect to n? (b) What is its big O running time? (c) What is its big Omega running time? (d) What is its big Theta running time?

Ques17. Draw the Binary Search Tree from the given Inorder and Postorder Traversals. ( 3 Marks) Inorder: D, A, H, E, J, F, I, B, G, C Postorder: A, D, E, H, F, B, C, G, I, J

Ques18. Consider this Binary Search Tree: (1 Mark)

Suppose we remove the root, replacing it with something from the left subtree. What will be the new root?

Ques19. Consider the following AVL Tree and perform the instructions given below: (5 Marks)

Consider the original tree for performing every operation and draw the Resultant Tree after every operation.

Ques20. Given the following node structure and field definition for a general tree. The data in each element also contains a pointer to a child node in the tree. (10 Marks)

*typedef struct node { int data; struct node child; }NODE;

Use pseudocode to complete the following function to determine the height of a subtree of a general tree where the root node of the subtree contains the given data value. You may use any data structures and their operations that we have discussed in class.

int heightSubtree(NODE root, int data) return height ( search ( root, data ) ) end heightSubtree

A. Complete the algorithm for search. You may not assume an enumerator exists.

NODE search ( NODE tree, int data )

B. Complete the algorithm for height. You may not assume an enumerator exists. You must program the leaf check yourself.

int height ( NODE tree )

(i) Insert 32 (ii) Remove 50 (iii) Insert 38