DSA 6: Algorithm Implementation

Ace your homework & exams now with Quizwiz!

high = mid - 1

*Binary search a sorted array* Given an array T[1..n] sorted in ascending order and a value x, the BINARY_SEARCH(T,x) procedure performs a binary search on the array and return the index of x in the array or NIL is x is not in the array. Identify the missing piece of code.

mid = floor((low + high) / 2)

*Binary search a sorted array* Given an array T[1..n] sorted in ascending order and a value x, the BINARY_SEARCH(T,x) procedure performs a binary search on the array and return the index of x in the array or NIL is x is not in the array. Identify the missing piece of code.

ENQUEUE(Q,T.root)

*Breadth-first search a tree* Given a tree T and a key k, the BFS(T,k) procedure performs a breadth-first search on the tree and returns the node with key == k if such a node exists in T, otherwise it returns NIL. This procedure uses a FIFO queue Q to store discovered, but unexplored nodes. Identify the missing piece of code.

Q.size > 0

*Breadth-first search a tree* Given a tree T and a key k, the BFS(T,k) procedure performs a breadth-first search on the tree and returns the node with key == k if such a node exists in T, otherwise it returns NIL. This procedure uses a FIFO queue Q to store discovered, but unexplored nodes. Identify the missing piece of code.

A.length

*Bubble sort an array* Given an unsorted array A[1..n], the BUBBLE_SORT(A) procedure sorts the contents of the array in ascending order. Identify the missing piece of code.

A[j]

*Bubble sort an array* Given an unsorted array A[1..n], the BUBBLE_SORT(A) procedure sorts the contents of the array in ascending order. Identify the missing piece of code.

-∞

*Depth-first search a binary tree* Given a root node z in a binary tree, the MAX_DFS(z) procedure performs a depth-first search on the tree and returns the maximum key value in the tree. This procedure is recursive. Identify the missing piece of code.

if z.right ≠ NIL

*Depth-first search a binary tree* Given a root node z in a binary tree, the MAX_DFS(z) procedure performs a depth-first search on the tree and returns the maximum key value in the tree. This procedure is recursive. Identify the missing piece of code.

i = i - 1

*Insertion sort an array* Given an unsorted array A[1..n], the INSERTION_SORT(A) procedure sorts the contents of the array in ascending order. Identify the missing piece of code.

i = j - 1

*Insertion sort an array* Given an unsorted array A[1..n], the INSERTION_SORT(A) procedure sorts the contents of the array in ascending order. Identify the missing piece of code.

MERGE(A,p,q,r)

*Merge sort an array* Given an unsorted array A[p..r] and a MERGE(A,p,q,r) procedure that will merge two sub-arrays (A[p..q] and A[q+1..r]), the MERGE_SORT(A,p,r) procedure sorts the contents of the array in ascending order. This procedural is recursive. Identify the missing piece of code.

MERGE_SORT(A,q+1,r)

*Merge sort an array* Given an unsorted array A[p..r] and a MERGE(A,p,q,r) procedure that will merge two sub-arrays (A[p..q] and A[q+1..r]), the MERGE_SORT(A,p,r) procedure sorts the contents of the array in ascending order. This procedural is recursive. Identify the missing piece of code.

min_index = i

*Selection sort an array* Given an unsorted array A[1..n], the SELECTION_SORT(A) procedure sorts the contents of the array in ascending order. Identify the missing piece of code.

A[j]

*Quicksort an array* Given an unsorted array A[p..r], the QUICK_SORT(A,p,r) procedure sorts the contents of the array in ascending order. This procedural is recursive. Identify the missing piece of code.

A[r]

*Quicksort an array* Given an unsorted array A[p..r], the QUICK_SORT(A,p,r) procedure sorts the contents of the array in ascending order. This procedural is recursive. Identify the missing piece of code.


Related study sets

Micro-Economy | TestBank [2] Chapter 1

View Set

CH.55 Prep U's- Management of Patients With Urinary Disorders

View Set

Derivatives of Logarithmic and Exponential Functions

View Set

Linux+ Study Guide Chapter 1: Review Questions

View Set