32. (6 points) Trace the Text Search Algorithm for the input t"0101001' and p "001 Input: p( indexed from 1 to m),m, t (indexed from 1 to n),n Output: i text search(p,m,t,n) f For i=...
If the algorithm finds a site that contains the string (that is, Lenovo X200), assume that it then stores all data or all the text on that particular site into a storage area. To understand this problem fully, answer the following questions: 1. What is data mining? 2. What is a character string? 3. What is the worst case run time of this algorithm in terms of p, m, t, n (that is, what is O)? 4. How long do...
Search for 4 in the sequence {3,5,7,8,9,12,21,25}, by working through each step of the algorithm given below. Specify the values of i, j, m and am in each step. procedure binary search (x: integer, a1,a2,...,an: increasing integers) i := 1 {i is left endpoint of search interval } j := n {j is right endpoint of search interval } while i < j m := b(i + j)/2c if x > am then i := m + 1 else j...
Given the following algorithm:
Algorithnm Input: a1, a2,...,an, a sequence of numbers n, the length of the sequence x, a number Output: ?? i:- 1 While (x2 # a, and i < n) i+1 End-while If (x- - a) Return(i) Return(-1) 3, -1, 2,9, 36,-7, 6,4 a) What is the correct output of the Algorithm with the following input: a1, a2,..an b) What is the asymptotic worst-case time complexity of the Algorithm?
Algorithnm Input: a1, a2,...,an, a sequence of numbers...
Algorithm ComparisonCountingSorting(A[0..n-1], S[0..n-1] ) //Input: Array A[0..n-1] of orderable values //Output: Array S[0..n-1] of A's values in ascending order for i ← 0 to n – 1 do Count[i] ← 0 for i ← 0 to n – 2 do for j ← i + 1 to n – 1 do if A[i] < A[j] Count[j] ← Count[j] + 1 // increment counter of larger else Count[i] ← Count[i] + 1 for i ← 0 to n –...
4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...
Algorithm MyAlgorithm (A,B) Input: Arrays A and B each storing n >= 1 integers. Output: What is the output? (Refer to part b below) Start: count = 0 C = 10 for i = 0 to C do { sum = 0 for j = 0 to n-1 do { sum = sum + A[0] for k = 1 to j do sum = sum + A[k] } if B[i] == sum then count = count + 1 } return...
3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int recurseFunc(int n) If n 0, return 1. If n 1, return 1 while i< n do while j <n do print("hi") j 1 end while i i 1 end while int a recurse Func(n/9); int b recurse Func (n/9) int c recurse Func (n/9) return a b c (1) Set up a runtime recurrence for the runtime T n) of this algorithm. (2) Solve...
Analyze the running time of the following algorithms asymptotically. (a) Algorithm for-loop(n): P = 1 for i = 1 to 5n^2 do p = p times i return p (b) Algorithm for-loop(n): s = 0 for i = 1 to n do for j = I to n do s = s + i return s (c) Algorithm WhileLoop(n): x = 0; j = 2; while (j = n){x = x+ 1; j =j times 2;}
(V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a list of n integers) for i = 2 to n do c= j=i-1 while (j > 0) do if ra; then break end if 4j+1 = a; j= j-1 end while j+1 = 1 end for 14: return 0.02. 1, 15: end procedure Answer the following questions: (1) Run the algorithm with input (41, 02, 03, 04) = (3, 0, 1,6). Record the values...
Suppose you have an array S indexed from 1 to n which contains n numbers, not in any particular order, and you wish to count how many times a given number x occurs in S. Consider the recursive algorithm below for this which finds the number of occurrences of x in the index range i...j in S. Of course, solving the problem would involve an initial call to the algorithm for the range 1.n: int CountOccur (int i,j) { int...