Download Introduction To Programming - GH Raisoni College Of Engineering

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

UniPro protocol stack wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Transcript
G. H. Raisoni College of Engineering
Third Semester B.E. (Computer Science & Engineering)
Question Bank
Theoretical
1. Draw the block diagram of computer? Explain in brief.
2. Describe the various generations of computers.
3. What is an algorithm? Write down the steps involved in writing a program.
4. Give the structure for writing a Pascal Program.
5. What is an Identifier?
6. State the rules for define an Identifier.
7. List out all data types available in Pascal.
8. What is an algorithm? State its Characteristics.
9. What is Bottom-Up/Top-Down approach used in programming?
10. What do you mean by Boolean expression?
11. How Boolean expression can be used in program for decision-making.
12. Write down the various types of error occurs during programming?
13. What is subprogram? Explain them in brief.
14. What are the various arguments passing techniques?
15. What do you mean by scope of variable? Explain with Example.
16. What is recursion? What are the various parts of recursion?
17. Explain briefly difference between Testing & Verifying the program.
18. Explain the algorithm for Divide & Conquer Technique.
19. What is an Array?
20. How multidimensional array can be stored in memory using Row Major and
Column Major representation?
21. What is Data Structure? Explain Array & String Data type in detail.
22. Write down the complexity of each sorting algorithm.
23. What is a sparse matrix?
24. Explain the representation of a sparse matrix in memory.
25. How a sparse matrix is converted in Three Tuple Form.
26. Give the Differences between





Volatile and Non Volatile Memory.
Compiler and Interpreter.
Function and Procedure.
Enumerated and Sub range Data types.
FOR loop WHILE loop & REPEAT UNTIL loop.
Programming
1) Write a Pascal program to generate every integer between 1 & n divisible by m.
2) Write a Pascal program generate divisors of an integers.
3) Write a Pascal program to sum the sequence
X=1-1/2+1/3-1/4+1/5----
4) Write a Pascal program to sum the sequence Q=2/9 – 5/13 + 8/17 – 11/21 --5) Write a program to find the sum of series
E=1+1/1! +1/2! +1/3! +-------
6) Write a program to find the sum of series. S=1-1/2 + 1/3 – 1/4 + ------------7)
Write a program to find the sum of series D=1+X+X2+X3+------------Xn
8)
Write a program to find the sum of series Z=X+X3/3! +X5/5! +--------XN/N!
9) Write a Pascal program to find if an integer is ODD, EVEN or PRIME number.
10) Write a Pascal program to reverse and sum the digits of a number.
11) Write a Pascal program to find out the roots of Quadratic Equation.
12) Write a Pascal program to delete duplicates in a vector.
13) Write a Pascal program to find Least Common Divisor of two integers.
14) Write a Pascal program to perform arithmetic operation on two Arrays.
15) Write a Pascal program to perform complex arithmetic operations.
16) Write a Pascal program to find sum the +ve and -ve elements of vector.
17) Write a Pascal program to find Largest ODD and EVEN integers.
18) Write a Pascal program to reverse a vector without using a temporary variable.
19) Write a Pascal program to insert into and delete an element from vector.
20) Write a Pascal program to find Largest and Smallest difference in an array.
21) Write a Pascal program to print lower and upper triangular Matrices.
22) Write a Pascal program to convert binary number to decimal number.
23) Write a Pascal program to swap two values with out using a third variable.
24) Write a program to reverse any digit number. And check whether the number
is palindrome or not.
25) Write a program to generate a fibonacci series up to n terms using recursion.
26) Write a menu driven program to implement the following options
Sum of N digit numbers. Even or Odd.
27) Write a program to enter any 10 numbers and print the prime numbers only.
28) Write a program to print Fibonacci series up to n terms using recursion.
29) Write a program to print the following series.
5 6 7 8
6 7 8
7
8
30) Write a program to multiply two matrices of size 3X3.
31) Write a program to find transpose of MATRIX.
32) Write a program to implement Bubble sort method.
33) Write a program to implement Selection sort method.
34) Write a program to implement Insertion sort method.
35) Write a program to implement Merge sort method.
36) Write a program to implement Quick sort method.
37) Write a program to implement Binary search method.
38) Write a program to implement Linear search method.
39) Write a menu driven program to implement the following options Without
using standard library functions
a) Reverse a string b) Find the length of a string
c) Check whether the string is palindrome or not.
40) Write a program to find the LCM and GCD of two numbers without using
standard library function.
41) Write a program to sort the elements of an ARRAY in an ascending order using
any sorting method.
42) Write a program to display the Name of Day, depending upon the number,
which is entered by the Keyboard using If-Else structure.
43) Write a menu driven program to implement the following options
Addition, Subtraction and Multiplication of two matrices.
44) Write a program to find the Three Tuple form of entered Sparse MATRIX.
45) Write a program to find decimal equivalent of given an octal number.
46) Write a program to find binary equivalent of given a decimal number.
47) Given values for a, b, c and d set of values for the variable X, evaluate
the function defined by the
f (x) = aX2+bX+c
if X < d
f (x) = 0
if X = d
f (x)= aX2+bX-c
if X > d
48) Write a program to find the sum of squares of elements on the diagonal of the
square MATRIX.
49) Write a program to find the square MATRIX is symmetric or not.
50) Write a Procedure to find the trace of a MATRIX. The trace is defined as the
sum of the diagonal elements of the MATRIX.
51) Write a Procedure to find the Norm of a MATRIX. The norm is defined as the
square root of the sum of the squares of all elements in the MATRIX.
52) Write a program to validate the elements of square MATRIX, the rules are
All diagonal elements should be +ve , Non-diagonal elements should be –ve or 0.
53) Write a program to delete all vowels from a sentence.
54) Write a program to count the number of words not characters in a sentence.
55) Write a program to find the Row Sum & Column Sum of entered MATRIX.
56) Write a program to find the saddle point of MATRIX.
57) Write a program to find the entered MATRIX is square MATRIX or not.
58) Write a program to find the entered MATRIX is Magic Square or not.
59) Write a program, using procedures, which accept value parameters, to
implement the calculator program
60) Write a program to find the sum of upper and lower triangular elements of
MATRIX.
61) Write a program using Procedure to concatenate two strings, Find the length
of String, & Print the Surname only if one entered Name & Surname.
62) An election contested by 5 candidates. The candidates are number 1 to 5 and
marking the candidate number on the ballot paper does voting. Write a program to read the ballot & count the vote cast for each candidate using array
variable COUNT. In case number read is outside the range 1 to 5 the ballot
should be read as spoilt ballot. Program should read the ballot number also
declarer the winner.
Objectives
1. Consider the following consecutive configurations of a list while it it being sorted: (4, 5, 3, 1) (4, 5, 3, 1) (4, 3, 5, 1) (4, 3, 1, 5)
What sorting algorithm is being used?
(A) Quick Sort (B) Insertion Sort (C) Bubble Sort (D) Merge Sort
2. What is the best case running time of Bubble Sort?
(A) O(n2)
(B) O(1)
(C) O(n)
(D) O(logn)
3. Why is log(n) often a term in the efficiency expressions for divide and conquer
algorithms?
(A) Because such algorithms divide up the problems they are given, and it takes
log(n) steps to divide a list of n elements into n lists of one element.
(B) Because such algorithms don't need to look at every element in the list.
(C) Because such algorithms use a faster comparison function.
(D) Because such algorithms can only be implemented on quantum computers.
4. What sort might you use if you know that your data will be pretty much in order to begin with and why would you use that sort?
(A) Selection sort; because its efficiency is independent of the data being sorted.
(B) Bubble sort; because it can "short circuit" its operation when it detects that
the list is in order.
(C) Quick sort; because divide and conquer algorithms work well on nearly sorted
data.
(D) Insertion sort; because inserting into a nearly ordered list is highly efficient.
5. Imagine that we run quick sort on an already ordered list, picking the pivot by
taking the first element. What problem do we run into?
(A) The sort fails because quick sort cannot realize that it has an already sorted
list.
(B) The sort runs in O(n) time because quick sort detects that the list is ordered
after one pass.
(C) The sort runs in O(log(n)) time because quick sort is a divide and conquer algorithm.
(D) The sort runs inefficiently because the pivots always divide the lists into an
empty list and a large list.
6. Why are merge sort and quick sort known as "divide and conquer" algorithms?
(A) Because they don't sort the entire list they're given.
(B) Because they sort the entire list at once.
(C) Because they divide the list they're given into smaller lists and then sort those
smaller lists.
(D) Because they use arithmetic division to speed the sorting process.
7. Why might it seem counterintuitive that heap sort can run so efficiently?
(A) Because a heap cannot be easily represented as an array.
(B) Because re-heaping often increases the number of inversions (out of order elements) in the array.
(C) Because it takes O(n2) time to re-heap after removing the root node.
(D) Because heaps are not random access when implemented as arrays.
8. Merge sort is O(nlog(n)). Where does the n term come from?
(A) From the dividing of the list.
(B) From the initial pass through the list to see if it's sorted.
(C) From the merging of the sorted sub lists.
(D) From the costly pre computation merge sort does.
9. Which of the following is a proper heap?
(A) (1, 2, 3, 4, 5) (B) (5, 3, 4, 1, 2) (C) (5, 1, 2, 3, 4) (D) (5, 3, 2, 4, 1)
10. For merge sort to merge the following two arrays: (1, 4, 5, 8) and (3, 7, 9, 13),
what comparisons have to take place?
(A) 1 and 4, 5 and 8, 3 and 7, 9 and 13
(B) 1 and 3, 4 and 7, 5 and 9, 8 and 13
(C) 1 and 9, 13 and 7, 4 and 5, 8 and 5, 3 and 1, 7 and 4, 9 and 13
(D) 1 and 3, 3 and 4, 4 and 7, 5 and 7, 7 and 8, 8 and 9
11. Consider a sorting algorithm that checks all possible configurations of a list
until it finds one that is in order. This algorithm will sort a list correctly, but is
very inefficient. What is its big-O notation?
(A) O(n2) (B) O(n3) (C) O(n5log(n)) (D) O(n!)
12. In what case is the algorithm described above as efficient as bubble sort?
(A) When the data is in nearly sorted order.
(B) When the data is in reverse sorted order.
(C) When the data is in random order.
(D) When the data is already in sorted order.
13. In what case is the algorithm described above more efficient than selection
sort?
(A) When the data is already in sorted order.
(B) When the data is randomly distributed.
(C) When the data is in reverse sorted order.
(D) When the data is in reverse sorted order.
14. Consider the intermediate configurations of an array being sorted below. What
sort is being used? (4, 5, 2, 1, 7) (1, 5, 2, 4, 7) (1, 2, 5, 4, 7)
(A) Selection sort (B) Merge sort. (C) Quick sort (D) Not enough information
15. What sorting algorithm might you choose for the following list? Why?
(1, 2, 3, 6, 5, 9)
(A) Quick sort, because its efficiency is O(nlog(n)).
(B) Merge sort, because divide and conquer sorts are always faster.
(C) Bubble sort, because the list is in nearly sorted order.
(D) Heap sort, because the data is already in a heap.
16.Merge sort & quick sort can only be used on lists whose length is a power of 2.
(A) TRUE (B) FALSE
17. How many comparisons would it take merge sort to merge the following lists:
(1, 2, 3, 4, 5) and (6, 7, 8, 9, 10)?
(A) 5 (B) 10 (C) 20 (D) 7
18. Selection sort can sometimes run as fast as O (n).
(A) TRUE (B) FALSE
19. The intermediate configurations below are characteristic of which sorting algorithm? (5, 1, 4, 8, 2) (1, 5, 4, 8, 2) (1, 4, 5, 8, 2) (1, 4, 5, 2, 8)
(A) Selection sort. (B) Insertion sort. (C) Bubble sort. (D) Heap sort.
20. Why would it be a bad idea to implement heap sort using a heap data structure that didn't support random access?
(A) A data structure without random access can't be re-heaped.
(B) Accessing elements in the heap would take O(n) time, making the sort less efficient.
(C) Non random access data structures will always cause memory violations, even
when used properly.
(D) Non-random access data structures cannot hold the same data elements as
arrays.
21. Imagine the following strategy for picking a pivot in quick sort: scan through
half the data set, & use the median value as the pivot. Why is this a bad strategy?
(A) Because it will often pick out a bad pivot.
(B) Because this makes choosing a pivot O(n); quick sort's efficiency relies on being able to choose a pivot in constant time.
(C) Picking a good pivot is not necessary for the efficient operation of quick sort.
22. Imagine the following specification of a comparison function. If the two numbers passed in have an equal number of digits, they are equal. Otherwise, the one
with the larger number of digits is greater. Which of the following lists are sorted
with respect to this comparison function?
(A) (1, 3, 44, 55, 128)
(B) (5, 1, 4, 2, 111, 2005)
(C) (9, 8, 7, 6, 5, 4, 99, 15, 33, 512, 100, 2028) (D) All of the above.
23. Why are we so concerned with the efficiencies of sorting algorithms?
(A) Since sorting is a very common operation in computer science it is important
that it be performed in an efficient manner; many processes rely on sorting.
(B) It is not particularly important but is an interesting intellectual exercise and a
good demonstration of big-O notation.
24. Imagine a comparison function for complicated objects. Why might efficiency
calculations for a sort using this comparison function be misleading?
(A) They won't be misleading; they're just as accurate as always.
(B) Because sorting doesn't work for things other than numbers.
(C) Efficiency calculations generally consider one comparison to be one step, but
a complicated comparison function might take numerous steps.
(D) Efficiency calculations are usually misleading.
25. Consider the following intermediate configurations of a list being sorted. What
sorting algorithm is being used? (5, 2, 8, 1, 9) (1, 5, 2, 8, 9) (1, 2, 5, 8, 9)
(A) Merge sort (B) Bubble sort (C) Selection sort (D) Insertion sort
26. What is the first swap insertion sort would make on the following list?
(5, 3, 4, 9, 1)
(A) 1 and 5 (B) 5 and 3 (C) 4 and 9
(D) None of the above;
27. What is the first swap selection sort would make on the following list? (5, 3, 4,
9, 1)
(A) 5 and 1 (B) 5 and 3 (C) 4 and 9
(D) None of the above; selection sort doesn't make swaps.
28. What kind of data structure would make insertion sort particularly inefficient?
(A) A memory intensive data structure.
(B) A linear data structure.
(C) A data structure for which shifts are inefficient.
29. Imagine a situation where most of the data to be sorted starts in roughly reverse order. Why would this not be a good situation to use bubble sort?
(A) If the data is in roughly reverse order then bubble sort will almost always be
O(n2).
(B) Bubble sort is always an inefficient algorithm.
(C) It's not a bad idea to use bubble sort in this case; this is when it performs
best.
(D) Because comparisons take longer in situations like this.
30. What simple modification could be made to bubble sort to make it efficient in
the situation described above?
(A) Have it look ahead two elements before making each comparison.
(B) Start at the end of the list and bubble the small elements down.
(C) Reverse the list before applying bubble sort to it.
(D) There is no way to make bubble sort more efficient in this case.
31. Why would bubble sort be more efficient on the list (1, 2, 3, 4, 5, 6, 7) than
selection sort?
(A) Bubble sort will detect that the list is in order after one pass, while selection
sort always takes O(n) steps to sort a list.
(B) Selection sort can't sort in-order lists.
(C) Bubble sort is always more efficient than selection sort.
(D) Bubble sort can sort ordered lists in constant time.
32. When using quick sort, why is it common to switch to another sort when the
lists being sorted are small?
(A) This is a common error made by programmers, which does not make the code
run any faster.
(B) Quick sort's efficiency is very bad, so the sooner we switch to a different algorithm, the faster the data will be sorted.
(C) Quick sort is often implemented recursively and when the lists being sorted
become small the overhead of making a recursive function call outweighs quick
sort's efficiency.
(D) Quick sort's big-O notation becomes worse for small lists.
33. In what situation might heap sort be useful?
(A) In a situation where most of the data were already in sorted order.
(B) In a situation where ease of implementation was key.
(C) In a situation where it was crucial not to use any extra memory other than
the array of elements being sorted.
(D) In a situation where memory was not a concern.
34. What makes heap sort attractive as opposed to quick sort?
(A) Heap sort's average case is better.
(B) Heap sort always sorts a list in O(nlog(n))
(C) Heap sort can detect in order lists in O(n) time.
(D) Heap sort is never better than quick sort.
35. Why is quick sort's name misleading?
(A) Quick sort's big-O notation is no better than merge sort's or heap sort's, and
can even be worse if bad pivots are chosen.
(B) Because it is actually a very slow sort.
(C) Because it gains speed by sorting the data incompletely.
(D) Because it's big-O notation is O(n3).
36. Bubble sort gains efficiency by splitting the data in half.
(A) FALSE (B) TRUE
37. Why is sorting important to the process of searching?
(A) Because the two are often performed in parallel.
(B) Because a data set must be sorted after it is searched.
(C) Because it is much faster to search a sorted data set.
(D) Because algorithms for sorting can be used for searching without modification.
38. For some data sets, quick sort will be slower than bubble sort.
(A) TRUE (B) FALSE
39. How long does re-heaping take?
(A) O(n) (B) O(log(n)) (C) O(1) (D) O(n2)
40. Selection sort's efficiency is independent of the data being sorted.
(A) TRUE (B) FALSE
41.Program Writing (Input and Output);
[A] TRUE (B) FALSE
42.Read (a, b and c);
[A] TRUE (B) FALSE
43.Read (a, a, a);
[A] TRUE (B) FALSE
44.Writeln (‘a’: 85);
[A] TRUE (B) FALSE
45.Writeln (‘a’: -5);
[A] TRUE (B) FALSE
46.Writeln (Screen, ’Hello World’);
[A] TRUE (B) FALSE
47.Writeln( eof );
[A] TRUE (B) FALSE
48.Program Reading (Only Input);
[A] TRUE (B) FALSE
49. Function fib (n: integer): integer;
[A] TRUE (B) FALSE
50. Var a: array [1..20] Of char;
[A] TRUE (B) FALSE