数据结构和算法

DSA - 主页 DSA - 概述 DSA - 环境设置 DSA - 算法基础 DSA - 渐近分析

数据结构

DSA - 数据结构基础 DSA - 数据结构和类型 DSA - 数组数据结构

链接列表

DSA - 链接列表数据结构 DSA - 双向链接列表数据结构 DSA - 循环链表数据结构

堆栈 &队列

DSA - 堆栈数据结构 DSA - 表达式解析 DSA - 队列数据结构

搜索算法

DSA - 搜索算法 DSA - 线性搜索算法 DSA - 二分搜索算法 DSA - 插值搜索 DSA - 跳跃搜索算法 DSA - 指数搜索 DSA - 斐波那契搜索 DSA - 子列表搜索 DSA - 哈希表

排序算法

DSA - 排序算法 DSA - 冒泡排序算法 DSA - 插入排序算法 DSA - 选择排序算法 DSA - 归并排序算法 DSA - 希尔排序算法 DSA - 堆排序 DSA - 桶排序算法 DSA - 计数排序算法 DSA - 基数排序算法 DSA - 快速排序算法

图形数据结构

DSA - 图形数据结构 DSA - 深度优先遍历 DSA - 广度优先遍历 DSA - 生成树

树数据结构

DSA - 树数据结构 DSA - 树遍历 DSA - 二叉搜索树 DSA - AVL 树 DSA - 红黑树 DSA - B树 DSA - B+ 树 DSA - 伸展树 DSA - 尝试 DSA - 堆数据结构

递归

DSA - 递归算法 DSA - 使用递归的汉诺塔 DSA - 使用递归的斐波那契数列

分而治之

DSA - 分而治之 DSA - 最大最小问题 DSA - 施特拉森矩阵乘法 DSA - Karatsuba 算法

贪婪算法

DSA - 贪婪算法 DSA - 旅行商问题(贪婪方法) DSA - Prim 最小生成树 DSA - Kruskal 最小生成树 DSA - Dijkstra 最短路径算法 DSA - 地图着色算法 DSA - 分数背包问题 DSA - 作业排序截止日期 DSA - 最佳合并模式算法

动态规划

DSA - 动态规划 DSA - 矩阵链乘法 DSA - Floyd Warshall 算法 DSA - 0-1 背包问题 DSA - 最长公共子序列算法 DSA - 旅行商问题(动态方法)

近似算法

DSA - 近似算法 DSA - 顶点覆盖算法 DSA - 集合覆盖问题 DSA - 旅行商问题(近似方法)

随机算法

DSA - 随机算法 DSA - 随机快速排序算法 DSA - Karger 最小割算法 DSA - Fisher-Yates 洗牌算法

DSA 有用资源

DSA - 问答 DSA - 快速指南 DSA - 有用资源 DSA - 讨论


Data Structures Algorithms Mock Test

This section presents you various set of Mock Tests related to Data Structures Algorithms. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

Data Structures Algorithms Mock Test IV

Answer : B

Explanation

Recursion uses stack but the main reason is, every recursive call needs to be stored separately in the memory.

Answer : A

Explanation

Heap maintains itself to meet all the requirements of complete binary tree.

Answer : C

Explanation

In a min heap, parent nodes store lesser values than child nodes. The minimum value of the entire heap is stored at root.

Answer : D

Explanation

Regardless of being min heap or max heap, root is always replaced by last element of the last level.

Answer : A

Explanation

All possible spanning trees of graph G, have same number of edges and vertices.

Q 6 - From a complete graph, by removing maximum _______________ edges, we can construct a spanning tree.

A - e-n+1

B - n-e+1

C - n+e-1

D - e-n-1

Answer : A

Explanation

We can remove maximum e-n+1 edges to get a spanning tree from complete graph. Any more deletion of edges will lead the graph to be disconnected.

Q 7 - If we choose Prim's Algorithm for uniquely weighted spanning tree instead of Kruskal's Algorithm, then

A - we'll get a different spanning tree.

B - we'll get the same spanning tree.

C - spanning will have less edges.

D - spanning will not cover all vertices.

Answer : B

Explanation

Regardless of which algorithm is used, in a graph with unique weight, resulting spanning tree will be same.

Q 8 - Re-balancing of AVL tree costs

A - Ο(1)

B - Ο(log n)

C - Ο(n)

D - Ο(n2)

Answer : B

Explanation

AVL rotations have complexity of Ο(log n)

Answer : D

Explanation

The balance factor (BalanceFactor = height(left-sutree) − height(right-sutree)) is used to check if the tree is balanced or unbalanced.

Answer : A

Explanation

BST does not care about complete binary tree properties.

Q 11 - The following sorting algorithms maintain two sub-lists, one sorted and one to be sorted −

A - Selection Sort

B - Insertion Sort

C - Merge Sort

D - both A &am; B

Answer : D

Explanation

Both selection sort and insertion sort maintains two sublists and then checks unsorted list for next sorted element.

Q 12 - If locality is a concern, you can use _______ to traverse the graph.

A - Breadth First Search

B - Depth First Search

C - Either BFS or DFS

D - None of the above!

Answer : B

Explanation

DFS is a better choice when locality-wise items are concerned.

Q 13 - Access time of a binary search tree may go worse in terms of time complexity upto

A - Ο(n2)

B - Ο(n log n)

C - Ο(n)

D - Ο(1)

Answer : C

Explanation

At maximum, BST may need to search all n values in the tree in order to access an element, hence, Ο(n).

Answer : A

Explanation

Shell sort uses insertion sort when interval value is 1.

Q 15 - A pivot element to partition unsorted list is used in

A - Merge Sort

B - Quick Sort

C - Insertion Sort

D - Selection Sort

Answer : B

Explanation

The quick sort partitions an array using pivot element and then calls itself recursively twice to sort the resulting two subarray.

Answer : C

Explanation

A stable sorting algorithm like bubble sort, does not change the sequence of appearance of similar element in the sorted list.

Answer : B

Explanation

A sorting algorithm is said to be adaptive, if it takes advantage of already 'sorted' elements in the list that is to be sorted.

Answer : A

Explanation

For this algorithm to work properly the data collection should be in sorted form and equally distributed.

Q 19 - If the data collection is in sorted form and equally distributed then the run time complexity of interpolation search is −

A - Ο(n)

B - Ο(1)

C - Ο(log n)

D - Ο(log (log n))

Answer : D

Explanation

Runtime complexity of interpolation search algorithm is Ο(log (log n)) as compared to Ο(log n) of BST in favourable situations.

Q 20 - Which of the following algorithm does not divide the list −

A - linear search

B - binary search

C - merge sort

D - quick sort

Answer : A

Explanation

Linear search, seaches the desired element in the target list in a sequential manner, without breaking it in any way.

Q 21 - The worst case complexity of binary search matches with −

A - interpolation search

B - linear search

C - merge sort

D - none of the above

Answer : B

Explanation

In the worst case a binary search needs to access all elements of the target list, same as linear search.

Answer : B

Explanation

Efficiency of algorithm is measured by assuming that all other factors e.g. processor speed, are constant and have no effect on implementation.

Answer : B

Explanation

In this analysis, actual statistics like running time and space required, are collected.

Answer : B

Explanation

Project scheduling is an exmaple of dynamic programming.

Q 25 - In conversion from prefix to postfix using stack data-structure, if operators and operands are pushed and popped exactly once, then the run-time complexity is −

A - Ο(1)

B - Ο(n)

C - Ο(log n)

D - Ο(n2)

Answer : B

Explanation

Infix to postfix conversion using stack will have run time complexity of Ο(n).

Answer Sheet

Question Number Answer Key
1 B
2 A
3 C
4 D
5 A
6 A
7 B
8 B
9 D
10 A
11 D
12 B
13 C
14 A
15 B
16 C
17 B
18 A
19 D
20 A
21 B
22 B
23 B
24 B
25 B
data_structures_algorithms_questions_answers.htm