Thursday, May 14, 2020

Questions and answers in Data Structures and Algorithms 04

TRUE/FALSE Quiz Questions with Answers in Data Structures and Algorithms, Data Structures interview questions



Data Structures and Algorithms TRUE / FALSE Questions – Set 04




1. The time complexity of adding 5 to each element of a array of N numbers is O(N).

(a) TRUE                                                   (b) FALSE


View Answer

Answer: TRUE
The time complexity will be O(N) because each element will be accessed only once to add number 5.

2. Let us suppose that there is a variable declaration int x = 50, *ptr. Then, the statement *ptr = &x is a valid statement in main() function.
(a) TRUE                                                   (b) FALSE


View Answer

Answer: FALSE
*ptr is a pointer, &x is the address of x.
The correct way to assign the address to the pointer variable is, ptr = &x.

3. Minimum and maximum height of a binary heap with N keys will be log2N.

(a) TRUE                                                   (b) FALSE


View Answer

Answer: TRUE
The height of binary heap with N keys will be floor(log2N).

Binary heap

A binary heap is a heap data structure that takes the form of a binary tree. They are useful in the implementation of priority queues. The properties of binary heap are;

  • All child nodes must be less (or greater) than its parent node for a max (or min) heap.
  • The leaves must either fill the h or h-1 node where h is the height of the tree; it means it must be a complete binary tree.
Properties of binary heap


4. Inserting an element to the beginning of an array (that is A[0] element) is more difficult than inserting an element to the beginning of a linked list.

(a) TRUE                                                   (b) FALSE


View Answer

Answer: TRUE
Inserting an element at the beginning of an array is easy only if array is empty. Otherwise, we need to move all the other elements that are stored in that array to create space. Hence, it is difficult to insert an element at the beginning of an array.

To insert an element at the beginning of a linked list is comparatively easy. We need to create a node and link the node to the head node.


5. The largest value in a binary search tree is always stored at the root of the tree.

(a) TRUE                                                   (b) FALSE


View Answer

Answer: FALSE
An important reason that BSTs are widely used is that they allow us to keep the keys in order.
A binary search tree is a binary tree with the following properties:
  • The data stored at each node has a distinguished key which is unique in the tree and belongs to a total order. (That is, for any two non-equal keys, x,y either x < y or y < x.)
  • The key of any node is greater than all keys occurring in its left subtree and less than all keys occurring in its right subtree.

***********

Interview questions and answers in data structure and algorithms

DSA quiz questions with answers explained

Solved true or false questions in DSA

Practice questions in data structures

TRUE  or FALSE questions in data structures and algorithms 

List the properties of binary search tree

list the properties of binary heap

No comments:

Post a Comment

Featured Content

Multiple choice questions in Natural Language Processing Home

MCQ in Natural Language Processing, Quiz questions with answers in NLP, Top interview questions in NLP with answers Multiple Choice Que...

All time most popular contents

data recovery