0% found this document useful (0 votes)
5 views

DrDSLecture11-Revision

The document outlines various data structures and algorithms, including operations on doubly linked lists, binary search trees, hash tables, heaps, and sorting algorithms. It includes tasks such as inserting elements, drawing trees, sorting lists, and performing depth-first search on graphs. Additionally, it contains multiple-choice questions and fill-in-the-blank exercises related to data structures and sorting algorithms.

Uploaded by

Mohammed Adel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

DrDSLecture11-Revision

The document outlines various data structures and algorithms, including operations on doubly linked lists, binary search trees, hash tables, heaps, and sorting algorithms. It includes tasks such as inserting elements, drawing trees, sorting lists, and performing depth-first search on graphs. Additionally, it contains multiple-choice questions and fill-in-the-blank exercises related to data structures and sorting algorithms.

Uploaded by

Mohammed Adel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lecture 11 – Revision II

Linked List
1. Given a doubly Linked-list with head(front) and rear(tail) references. Write an
insert function that Insert element x at second last position.

void insert (int x )


Binary Search Tree
2. Draw the BST that results when you insert items
14 12 90 3 7 40 51 19 4 20
in that order into an initially empty tree.

Draw the tree after deleting node 14


Hash
3. Given the following hash table, use hash function h(k) = k mod 10 and handle
collisions using Quadratic Probing.

In which slot should the record with key value 159 be inserted?

4. Given the following hash table, use hash function h(k) = k mod 11 and handle
collisions using Double Hashing with h2(k) = 1 + (k % 10).

In which slot should the record with key value 832 be inserted?

h1(832) = 7.

h2(832) = 3.
Heap

5. Sort the following list 11,2,9,13,57 in ascending order using the heap sort
algorithm
Draw the list changes step by step indicating the sorted and unsorted list in each step.
Sorting
6. Here is an array of 7 integers
5 3 8 9 1 7 0
Draw this array after each iteration of the large loop in
i. Selection sort
ii. Insertion sort
iii. Bubble sort
Sorting
7. Here is an array of 7 integers
5 3 8 9 1 7 0
Develop each partition of array using quick sort when pivot is the first element of the
array
Graph

8. Consider the following graph


Provide three DFS trees starting at node M
9. Given a Directed Acyclic Graph (DAG) with V vertices and E edges, find any
possible Topological Sorting of that Graph starting at node 5.
10.Choose the correct answer
1. The worst time complexity to insert element at begin of doubly linked list is?
a. O(1)
b. O(n)
c. O(n^2)
d. O(n logn)

2. Which of the following sorting algorithms in its typical implementation gives best performance
when applied on an array which is sorted or almost sorted (maximum 1 or two elements are
misplaced).
a. Quick Sort
b. Merge sort
c. Heap sort
d. Insertion sort

3. In what time can a binary heap be built?


a. O(N)
b. O(N log N)
c. O(log N)
d. O(N^2)

4. What is the time taken to perform a delete min operation in heap sort?
a. O(N)
b. O(N log N)
c. O(log N)
d. O(N^2)

5. What is the worst-case complexity of quick sort?


a. O(N)
b. O(N log N)
c. O(log N)
d. O(N^2)

6. What is the best-case complexity of quick sort?


a. O(N)
b. O(N log N)
c. O(log N)
d. O(N^2)
11.Complete the missing parts with the suitable data structure

1. …………………is a collection of related things linked to the previous or/and next data items.

2. …………………is a collection of values that are all have the same type.

3. …………………is a data structure which is used for fast retrievals.

4. …………………is a data structure which is commonly used with modifiable data.

5. …………………is a data structure which is commonly used in String reversal, Parenthesis

checking and backtracking

6. …………………is a data structure which is commonly used in task scheduling and sometimes it

is called buffer

7. …………………tree is a self-balancing binary search tree.

8. …………………is a data structure where the value of the root node is greater than or equal to either of

its child nodes.

12.Complete the missing parts with the suitable sorting algorithm

1. ………………… algorithm is generally considered the fastest sorting algorithm because it has the best

performance for most inputs.

2. ………………… , ………………….algorithms are following the divide and conquer paradigm.

3. ………………… algorithm may have the worst-case time complexity when the array is sorted.

4. …………………,…………... algorithms give best performance when applied on a sorted array.

5. …………………,…………... algorithms will take least time when all elements of input array are

identical.

6. ………………… algorithm has the highest best-case runtime complexity.

7. ………………… algorithm is generally considered not In-place algorithm.

You might also like