









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Algorithmic Methodology : Basic Concepts and Notation, Understanding the Problem, Plan the Logic, Code the Program, Pseudocode and Flowchart, Efficiency of Algorithms. Complexity Measures, Basic Time Analysis of an Algorithm, Space Complexity. Conditionals : Control Structures and Program Writing. Looping : Repetitions. Abstract Data Types : Data Abstraction and Basic Data Structures, Data Types, Abstract Data Types. Recursion : Characteristics of Recursive Functions, Mathematical Induction Prop
Typology: Study notes
1 / 16
This page cannot be seen from the preview
Don't miss anything!










Algorithmic Methodology : Basic Concepts and Notation, Understanding the Problem, Plan the Logic, Code the Program, Pseudocode and Flowchart, Efficiency of Algorithms. Complexity Measures, Basic Time Analysis of an Algorithm, Space Complexity. Conditionals : Control Structures and Program Writing. Looping : Repetitions. Abstract Data Types : Data Abstraction and Basic Data Structures, Data Types, Abstract Data Types. Recursion : Characteristics of Recursive Functions, Mathematical Induction Propositional Logic, First Order Predicate Calculus : Introduction to Formal Logic, Propositions, Conditional Propositions, Proofs, Resolution Proofs, Rules of Inference Program Specification : Problem Solving, Variables, Selection, Modules and Repetitions. Arrays : Storage Allocation Functions, Linked Allocation, Hashed Allocation Techniques, Sorting Searching Sequential, Binary and Hashed Searching, Internal and External Sorting Techniques, Bubble Sort, Insertion Sort, Selection Sort, Merge Sort, Radix Sort and Quick Sort Comparisons and String Conversions, Representations of Variable-Length Strings, Examples of Operations on Strings. Data Structures and File Handling : File Organisation, Text and Binary Files, Opening and Closing Files. Advanced Programming Concepts : (Introduction Only) : Recursion, Dynamic Memory Management and Allocation, Operating System Calls, Inner Process Communication, Advanced File Handling and Indexing. Language : C (Examples using C wherever required).
For more detail: - http://www.gurukpo.com Content S.No. Name of Topic Page No.
1. Algorithmic Methodology 7- 13 1.1 Understanding the Problem 1.2 Plan the Logic 1.3 Code the Program 1.4 Pseudocode 1.5 Flowchart 1.6 Time & Space Complexity 2. Conditionals & Looping 14- 16 2.1 Control Structure 2.2 Looping 3. Abstract Data Types & Recursion 17- 18 3.1 Basic Data Structure 3.2 Characteristics of Recursion Functions 4. Searching & Sorting Techniques 19- 27 4.1 Bubble Sort 4.2 Selection Sort 4.3 Insertion Sort 4.4 Merge Sort 4.5 Radix Sort 4.6 Quick Sort 4.7 Binary Sort 4.8 Internal & External Sorting For more detail: - http://www.gurukpo.com 5. Arrays 28- 31 5.1 Storage Allocation Functions 5.2 Hashed Allocation Techniques 5.3 Linked Allocation Techniques 6. String Manipulations 32- 33 6.1 String Manipulations 6.2 Representations of Strings 7. Data Structures & File Handling 34- 36 7.1 Text of Binary Files 7.2 Opening & Closing Files 8. Advanced Programming Concepts 37- 47 8.1 Operating System Cells 8.2 Dynamic Memory Management 8.3 Inner Process Communication 8.4 Indexing 9. First Order Predicate Calculus 48- 62 9.1 Introduction to Formal Logic 9.2 Propositional Logic 9.3 Conditional Propositions
Print "failed"
Document : A printed document or report. Decision : A decision or branching point. Lines representing different decisions emerge from different points of the diamond. Input/Output : Represents material or information entering or leaving the system, such as customer order (input) or a product (output). Connector : Indicates that the flow continues where a matching symbol (containing the same letter) has been placed. Flow Line : Lines indicate the sequence of steps and the direction of flow. Database : Indicates a list of information with a standard structure that allows for searching and sorting. Display : Indicates a step that displays information. Q.4 What are the advantages and disadvantages of using Flowcharts? Ans.: Advantages of using Flowcharts : The benefits of flowcharts are as follows : (1) Communication : Flowcharts are better way of communicating the logic of a system to all concerned. For more detail: - http://www.gurukpo.com (2) Effective Analysis : With the help of flowchart, problem can be analysed in more effective way. (3) Proper Documentation : Program flowcharts serve as a good program documentation, which is needed for various purposes. (4) Efficient Coding : The flowcharts act as a guide or blueprint during the systems analysis and program development phase. (5) Proper Debugging : The flowchart helps in debugging process. (6) Efficient Program Maintenance : The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part Limitations of using Flowcharts : (1) Complex Logic : Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy. (2) Alterations and Modifications : If alterations are required the flowchart may require re-drawing completely. (3) Reproduction : As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem. (4) The essentials of what is done can easily be lost in the technical details of how it is done. Q.5 What is Time Complexity & Space Complexity measures of Algorithm? Ans.: The time complexity of a problem is the number of steps that it takes to solve an instance of the problem as a function of the size of the input (usually measured in bits), using the most efficient algorithm. To understand this intuitively, consider the example of an instance that is n bits long that can be solved in n ² steps. In this example we say the problem has a time complexity of n ². Of course, the exact number of steps will depend on exactly what machine or language is being used. To avoid that problem, the Big O notation is generally used (sometimes described as the "order" of the calculation, as in "on the order of"). If a problem has time complexity O( n ²) on one typical computer, then it will also have
If we want more than a single statement to be executed in case that the condition is true we can specify a block using braces { }: if (x == 100) { cout << "x is "; cout << x; } We can additionally specify what we want to happen if the condition is not fulfilled by using the keyword else. Its form used in conjunction with if is: if (condition) statement1 else statement For example: if (x == 100) cout << "x is 100"; else cout << "x is not 100"; prints on the screen x is 100 if indeed x has a value of 100 , but if it has not - and only if not- it prints out x is not 100. The if + else structures can be concatenated with the intention of verifying a range of values. The following example shows its use telling if the value currently stored in x is positive, negative or none of them (i.e. zero): if (x > 0) cout << "x is positive"; else if (x < 0) cout << "x is negative"; else For more detail: - http://www.gurukpo.com cout << "x is 0"; Q.2 What are the different types of Loops? Ans.: Iteration Structures (Loops) : Loops have as purpose to repeat a statement a certain number of times or while a condition is fulfilled. The while loop Its format is : while (expression) statement and its functionality is simply to repeat statement while the condition set in expression is true. For example, we are going to make a program to countdown using a while-loop: The do-while loop Its format is : do statement while (condition); The for loop Its format is : for (initialization; condition; increase) statement;
For more detail: - http://www.gurukpo.com Abstract Data Types & Recursion Q.1 What is Abstract Data Structure? Give some examples.
Ans.: An abstract data structure is an abstract storage for data defined in terms of the set of operations to be performed on data and computational complexity for performing these operations, regardless of the implementation in a concrete data structure. Selection of an abstract data structure is crucial in the design of efficient algorithms and in estimating their computational complexity, while selection of concrete data structures is important for efficient implementation of algorithms. Abstract data types (ADT) typically implemented in programming languages (or their libraries) include : Complex Number List Priority Queue Queue Stack String Tree Q.2 What is Recursion? Explain with example? Ans.: Recursion , in mathematics and computer science, is a method of defining functions in which the function being defined is applied within its own definition. The term is also used more generally to describe a process of repeating objects in a self-similar way. For instance, when the surfaces of two mirrors are almost parallel with each other the nested images that occur are a form of recursion.
For more detail: - http://www.gurukpo.com It is a way of thinking about and solving problems. It is, in fact, one of the central ideas of computer science. [1] Solving a problem using recursion means the solution depends on solutions to smaller instances of the same problem. [2] Factorial : A classic example of a recursive procedure is the function used to calculate the factorial of an integer. Function Definition : A recurrence relation is an equation that relates later terms in the sequence to earlier terms[6]. Recurrence relation for factorial: bn = n * bn- 1 b 0 = 1 Computing the recurrence relation for n = 4: b 4 = 4 * b 3 = 4 * 3 * b 2 = 4 * 3 * 2 * b 1 = 4 * 3 * 2 * 1 * b 0 = 4 * 3 * 2 * 1 * 1 = 4 * 3 * 2 * 1 = 4 * 3 * 2 = 4 * 6 = 4 * 6 = 24
Q.2 Explain the concept of Selection Sort along with Algorithm. Ans.: The algorithm works as follows : (1) Find the minimum value in the list. (2) Swap it with the value in the first position. (3) Repeat the steps above for remainder of the list (starting at the second position). Effectively, we divide the list into two parts: the sublist of items already sorted, which we build up from left to right and is found at the beginning, and the sublist of items remaining to be sorted, occupying the remainder of the array. Here is an example of this sort algorithm sorting five elements : 64 25 12 22 11 11 25 12 22 64 11 12 25 22 64 11 12 22 25 64 Selection sort can also be used on list structures that make add and remove efficient, such as a linked list. In this case it's more common to remove the minimum element from the remainder of the list, and then insert it at the end of the values sorted so far. For example : For more detail: - http://www.gurukpo.com 64 25 12 22 11 11 64 25 12 22 11 12 64 25 22 11 12 22 64 25 11 12 22 25 64 Pseudo-code : A is the set of elements to sort, n is the number of elements in A (the array starts at index 0) for i ← 0 to n- 2 do min ← i for j ← (i + 1) to n- 1 do if A[j] < A[min] min ← j swap A[i] and A[min] Q.3 Explain the Algorithm of Insertion Sort? Ans.: Insertion sort is a simple sorting algorithm, a comparison sort in which the sorted array (or list) is built one entry at a time. It is much less efficient on large lists than more advanced algorithms such as quick sort, heap sort, or merge sort, but it has various advantages : (1) Simple to implement. (2) Efficient on (quite) small data sets. (3) Efficient on data sets which are already substantially sorted: it runs in O( n
insertionSort( array A) for i = 1 to length[A]- 1 do begin For more detail: - http://www.gurukpo.com value = A[i] j = i- 1 while j >= 0 and A[j] > value do begin A[j + 1] = A[j] j = j- 1 end A[j+1] = value end Q.4 Explain the Merge Sort? Ans.: Conceptually, a Merge Sort works as follows : If the list is of length 0 or 1, then it is sorted. Otherwise; Divide the unsorted list into two sublists of about half the size; Sort each sublist recursively by re-applying merge sort; Merge the two sublists back into one sorted list. In a simple pseudocode form, the algorithm could look something like this: function mergesort(m) var list left, right, result if length(m) ≤ 1 return m var middle = length(m) / 2 for each x in m up to middle add x to left for each x in m after middle add x to right left = mergesort(left) right = mergesort(right) result = merge(left, right) return result For more detail: - http://www.gurukpo.com Q.5 Explain the Radix Sort? Ans.: In computer science, radix sort is a sorting algorithm that sorts integers by processing individual digits. Because integers can represent strings of characters (e.g., names or dates) and specially formatted floating point numbers, radix sort is not limited to integers. Most digital computers internally represent all of their data as electronic representations of binary numbers, so processing the digits of integer representations by groups of binary digit representations is most convenient. Two classifications of radix sorts are least significant digit (LSD) radix sorts and most significant digit (MSD) radix sorts. LSD radix sorts process the integer representations starting from the least significant digit and move towards the most significant digit. MSD radix sorts work the other way around.
factor of two each time, and finds the target value. The algorithm : The most common application of binary search is to find a specific value in a sorted list. To cast this in the frame of the guessing game (see Example below), realize that we are now guessing the index , or numbered place, of the value in the list. This is useful because, given the index, other data structures will contain associated information. Suppose a data structure containing the classic collection of name, address, telephone number and so forth has been accumulated, and an array is prepared containing the names, numbered from one to N. A query might be: what is the telephone number for a given name X. To answer this the array would be searched and the index (if any) corresponding to that name determined, whereupon it would be used to report the associated telephone number and so forth. Appropriate provision must be made for the name not being in the list (typically by returning an index value of zero), indeed the question of interest might be only whether X is in the list or not. low = 0 high = N For more detail: - http://www.gurukpo.com while (low < high) { mid = (low + high)/2; if (A[mid] < value) low = mid + 1; else //can't be high = mid-1: here A[mid] >= value, //so high can't be < mid if A[mid] == value high = mid; } if (low < N) and (A[low] == value) return low else return not_found This algorithm has two other advantages. At the end of the loop, low points to the first entry greater than or equal to value , so a new entry can be inserted if no match is found. Moreover, it only requires one comparison; which could be significant for complex keys in languages which do not allow the result of a comparison to be saved. Q.8 What is Internal & External Sorting techniques? Ans.: An internal sort is any data sorting process that takes place entirely within the main memory of a computer. This is possible whenever the data to be sorted is small enough to all be held in the main memory. For sorting larger datasets, it may be necessary to hold only a chunk of data in memory at a time, since it wont all fit. The rest of the data is normally held on some larger, but slower medium, like a hard-disk. Any reading or writing of data to and from this slower media can slow the sortation process considerably. This issue has implications for different sort algorithms. Consider a Bubblesort, where adjacent records are swapped in order to get them into the right order, so that records appear to 'bubble' up and down through the
dataspace. If this has to be done in chunks, then when we have sorted all the records in chunk 1, we move on to chunk 2, but we find that some of the records in chunk 1 need to 'bubble through' chunk 2, and vice versa (i.e., there are records in chunk 2 that belong in chunk 1, and records in chunk 1 that belong in chunk 2 or later chunks). This will cause the chunks to be read and written back to disk many times as records cross over the boundaries between them, resulting For more detail: - http://www.gurukpo.com in a considerable degradation of performance. If the data can all be held in memory as one large chunk, then this performance hit is avoided. On the other hand, some algorithms handle external sorting rather better. A Merge sort breaks the data up into chunks, sorts the chunks by some other algorithm (maybe bubblesort or Quick sort) and then recombines the chunks two by two so that each recombined chunk is in order. This approach minimises the number or reads and writes of data-chunks from disk, and is a popular external sort method.
For more detail: - http://www.gurukpo.com Arrays Q.1 What are the different functions used for Allocation of Memory? Ans.: Sizeof & Malloc : The sizeof operator returns the size in bytes of its operand. Whether the result of sizeof is unsigned int or unsigned long is implementation defined—which is why the declaration of malloc above ducked the issue by omitting any parameter information; normally you would use the stdlib.h header file to declare malloc correctly. Here is the last example done portably : #include <stdlib.h> /* declares malloc() */ float *fp; fp = (float *)malloc(sizeof(float)); The operand of sizeof only has to be parenthesized if it's a type name, as it was in the example. If you are using the name of a data object instead, then the parentheses can be omitted, but they rarely are. #include <stdlib.h> int *ip, ar[100]; ip = (int *)malloc(sizeof ar); In the last example, the array ar is an array of 100 ints; after the call to malloc (assuming that it was successful), ip will point to a region of store that can also be treated as an array of 100 ints. The fundamental unit of storage in C is the char, and by definition sizeof(char) is equal to 1, so you could allocate space for an array of ten chars with malloc(10) while to allocate room for an array of ten ints, you would have to use malloc(sizeof(int[10])) If malloc can't find enough free space to satisfy a request it returns a null pointer to indicate failure. For historical reasons, the stdio.h header file contains a defined
the following type, placing student ID k in location data[k]: Student data[100]; // array of 100 records The record for student ID k can be retrieved immediately since we know it is in data[k]. What, however, if the student IDs do not form a neat range like 0..99. Suppose that we only know that there will be a hundred or fewer and that they will be distributed in the range 0..9999. We could then use an array with 10, components, but that seems wasteful since only a small fraction of the array will be used. It appears that we have to store the records in an array with 100 elements and to use a serial search through this array whenever we wish to find a particular student ID. If we are clever, we can store the records in a relatively small array and still retrieve students by ID much faster than we could by serial search. To illustrate this, suppose that we know that the student IDs will be: 0, 100, 200, ... , 9800, 9900 In this case, we can store the records in an array called data with only 100 components. We'll store the record with student ID k at location: data[k/100] If we want to retrieve information for student ID 700, we compute 700/100 and obtain the index 7. The record for student ID 700 is stored in array component data[7]. This general technique is called hashing. Each record requires a unique value called its key. In our example the student ID is the key, but other, more complex keys are sometimes used. A function called the hash function , maps keys to array indices. For more detail: - http://www.gurukpo.com Suppose we name our hash function hash. If a record has a key of k , then we will try to store that record at location data[hash(k)]. Using the hash function to compute the correct array index is called hashing the key to an array index. The hash function must be chosen so that its return value is always a valid index for the array. In our example: hash(k) = k / 100 Given this hash function and keys that are multiples of 100, every key produces a different index when it was hashed. Thus, hash is a perfect hash function. Unfortunately, a perfect hash function cannot always be found.
Visit: - www.gurukpo.com For more detail: - http://www.gurukpo.com