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

Problem Solving Techniques

The document discusses various algorithms and techniques related to problem solving and data structures. It provides algorithms for computing factorials, Fibonacci numbers, square roots, sorting arrays, finding common divisors, and more. It also discusses concepts like pattern searching, hashing, histograms, and text editing.

Uploaded by

go4nagaraju
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
371 views

Problem Solving Techniques

The document discusses various algorithms and techniques related to problem solving and data structures. It provides algorithms for computing factorials, Fibonacci numbers, square roots, sorting arrays, finding common divisors, and more. It also discusses concepts like pattern searching, hashing, histograms, and text editing.

Uploaded by

go4nagaraju
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

PROBLEM SOLVING TECHNIQUES 1) State any two factors involved in designing efficient algorithm. 1) Avoiding Redundant Computations.

2) Using necessary storage. 2) Design an algorithm that makes the exchanges a b. 1) Input two variables a and b. 2) Duplicate the a value into t. 3) Overwrite the contents of a with that of b. 4) Move the contents of t into b. 3) Develop an algorithm to compute n!. 1) Input n, whose factorial is required. 2) Set up a variable called factor and set it to 1. 3) Set up an index i to keep track of the number of iteration in a loop set i =1. 4) Evaluate factor = factor * i. 5) Update i value i=i+1. 6) Repeat steps 4 and 5 until i =n. 7) Output the factorial value. 4) Convert the decimal number 275 to its corresponding octal representation.

5) State any two methods for computing the square root of any positive number. 1) g1 = m ,g2=(g1+m/g1)/2 2) x i+1=((n-1)x i+ m/xi(n-1))/n where x n = m 6) Find the complete set of divisors of the integer 36. Smaller Factor Bigger Factor 2 is linked with 18 (ie,36/2=18) 3 is linked with 12 4 is linked with 9 6 is linked with 6 Therefore, the complete set of divisors are {2,3,4,6,9,12,18} 7) Find the greatest common divisor of two integers 18 and 30. r:=30 mod 18=12 step(1) r:=18 mod 12=6 step(2) r:=12 mod 6=0 step(3) Therefore, The Greatest Common Divisor gcd(18,30)=6

8) Write a recursive relation for calculating the nth Fibonacci number. The Fibonacci sequence f n is defined recursively as follows: f 1= 0 f 2=1 f n= f n-1+f n-2 for n>2 9) How many pairs of exchanges are required for even array size in the array reversal algorithm. The pairs of exchanges to reverse the order of an array is r that is an integer less than or equal half the array magnitude n. 10) State any two applications of removal of duplicates from an ordered array. 1) Data Compression. 2) Text Processing Problems. 11) What do you mean by partitioning an array. Partitioning an array is the partition of the elements into two subsets such that elements x are in one subset and elements >x are in the other subset. 12) How many comparisons are required to find the kth smallest element in the set of n elements. At least (n+1) comparisons are required to find the kth smallest among n elements. This occurs when the kth smallest element has been chosen as the initial partitioning value. Where the search is made for the median m(ie,m=[n+1]/2) and the problem space is reduced by 1 with each pass then (n/2+1)(n/2+2)/2=(n+2)(n+4)/8 comparisons are required. 13) State any two methods of sorting of large data sets. Sorting by Partitioning Binary Search 14) Write the algorithm to sort the data by using the selection sort. 1) Establish a[n] and read n values. 2) While unsorted portion of a[n] has elements, find min as a[i] and exchange min with a[i],which is the first element of unsorted part. 15) Define binary search algorithm. Binary Search algorithm is the algorithm which divides the data sets into two parts based on middle value and examination of middle value of remaining data and on the basis of comparison eliminate half of the remaining data set until the value is found or it is established that it is not present. 16) Define hash searching algorithm. Hash searching algorithm is only has to look at one, two or three items before terminating successfully. It is much faster than binary search algorithm. 17) What is the use of text line length adjustment. When a set of lines of text is arbitrary length, reformat the text so that no lines of more than n characters are printed. In each output line the maximum number of words that occupy less than or n characters, should be

printed and no word should extend across two lines. Paragraphs should also remain indented. 18) How do you search a keyword in Text. Searching of keyword in text can be made by comparison of the current text character with the current word character. The number of times this test made is equal to the number of characters in the text being searched. 19) Define a pattern searching algorithm. Pattern search algorithm is an algorithm that is linearly dependent on the length of the string or text being searched. 20) State any two applications of sub linear pattern searching. Text editors. Pattern matching. Keyword searching. 21) Mention any two requirements for solving problems by Computer. The requirements for solving problems by computer are as follows: 1) Depth understanding of problem. 2) Data Organization. 22) Why is documentation of program important? Program documentation provides the information that the program presents to the user during the execution phase. The program must specify during execution exactly what responses and their format it requires from the user. 23) Distinguish between program testing and debugging. Program Testing Program testing checks whether the program solves the smallest possible problem, whether it handles the case when all data values are the same and so on. Debugging Debugging is the task of detecting logical errors through a set of statements that will printout information in the strategic points of computation. These additional information to the desired output can be made conditionally executable.

24) Write an algorithm for computation of sine series. 1) Input the value x in radians given in degree x = /180*. 2) Set up a variable called sin to contain the result. 3) Evolve a general expression to represent the second term onwards. The General Expression may be: (-1) t+1 x n / n! Term 1 2 3 4 5 n 1 3 5 7 9 sin x -x3/3! +x5/5! -x7/7! +x9/9!

4) This general form can be put in an iterative loop for the number of terms and n values. 5) Output the sin value. 25) What do you mean by pseudo random sequence. A sequence of random numbers should exhibit the following behavior: 1) The sequence should appear as though each number had occurred by chance. 2) Each number should have a specified probability of falling within a given range. These sequences are predictable in advance and for this reason they are referred to as Pseudo-random sequences. 26) Write an algorithm for generating Fibonacci sequence. 1) Set up the two variables called A and B. 2) Initialize as follows: A=0, B=1. 3) Input N the number of Fibonacci terms to generate. 4) Iteratively compute A=A+B, B=A+B until N terms. 5) Output N terms of the Fibonacci series. 27) State some applications of mod function. The mod function can be used to get the remainder. Some of the applications which uses mod function are as follows: 1) Reversing the digits of an integer. 2) Base Conversion problem. 3) Greatest common divisor of 2 integers. 28) What do you mean by Histogramming? In counting the array of marks, the value of particular mark leads us directly to the particular slot that must be updated .The actual marks value can be used to reference the array location that is to be updated . The number of counts are stored in corresponding mark (array) position. This one-step procedure for each mark is known as Histogramming. 29) How many possible configurations that can apply when two partitions are about to meet in an array? The two partitions that have to meet in an array depends upon the number of elements of an array. The partitioning process is done in the following manner: Left Partition (Growing to the Right) Right Partition (Growing to the Left)

30) Write a simple method for evaluation to compute the value of x. 1) Input the value x in radians given in degree x = /180*. 2) Set up a variable called sin to contain the result. 3) Evolve a general expression to represent the second term onwards. The General Expression may be: (-1) t+1 x n / n! 4) This general form can be put in an iterative loop for the number of terms and n values. 5) Output the sin value. 31) Write an algorithm that counts the number of distinctions in a class.

1) Set variable mark, count. 2) count =0. 3) Read one students mark. 4) If mark>=50 then count=count+1. 5) Repeat steps 3 to 5 until all available marks read. 6) Output count which gives number students who pass. 32) How does redundant computation decrease efficiency? The effects of redundant computation are most serious when they are embedded within a loop that must be executed many times .The most common mistake using loops is to repeatedly recalculate part of an expression that remains constant throughout the entire execution phase of the loop. 33) Define monotone subsequence. A monotone subsequence is a subset of numbers which are strictly increasing from left to right. 34) What is hashing? Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. 35) What are the applications of sorting? Sorting and merging are done so as to organize information for easy retrieval. Sorting is also applied to type of data other than strings or numerical to arrange them according to a predefined relation. 36) How many passes are needed to sort n elements using two way merge sort? For two input arrays of sizes m and n , the number of passes vary from 2 to (n+m+1) to complete the task of two way merge sort. 37) Why text line editing is essential? Text line editing is needed to replace one string by another occurs very frequently in program and documentation preparation. That is, to replace all occurrences on a line of particular pattern by another pattern. 38) Distinguish between linear pattern search and sublinear pattern search. Linear Pattern Search 1)Linear Pattern Search algorithms performance is linearly dependent on the length of the string or text being searched. 2) For a string of length n there can be at most n shifts forward made either by the pattern or in the string , then 2n comparisons could be made. Sublinear Pattern Search 1)Sublinear pattern search will efficiently search a given text for a particular keyword or pattern . 2) When none of the characters in the pattern of length m are in the text of length n, then n/m character comparisons are made.

39) What do you mean by skip in pattern matching algorithm? In Pattern Matching algorithm, the given word is compared with the given text. If a text character is encountered that is not in the keyword we are seeking then we can jump a number of characters equal to the word length before again looking for the last character. This jump is called skip.

40) What do you mean by text line length adjustment? Text line length adjustment means putting a word that has been read, on the next line when a word does not completely fit on a current line.

You might also like