ARRAY FUNCTIONS (1D ARRAY)
|
|
- Geoffrey Leonard
- 5 years ago
- Views:
Transcription
1 ARRAY FUNCTIONS (1D ARRAY) EACH QUESTIONS CARRY 2 OR 3 MARKS Q.1 Write a function void ChangeOver(int P[ ], int N) in C++, which re-positions all the elements of the array by shifting each of them to the next position and by shifting the last element to the first position. Example: If the content of array P is 12, 15, 17, 13, 21 The content of array P should become 21, 12, 15, 17, 13 void ChangeOver(int P[ ],int N) int temp=p[n-1]; for(int i=n-2; i>=0; i--) P[i+1]=P[i]; P[0]=temp; Q.2 Write a function SWAP2BEST(int ARR[], int Size) in C++ to modify the content of the array in such a way that the elements, which are multiples of 10 swap with the value present in the very next position in the array. Example: If the content of array ARR is 90, 56, 45, 20, 34, 54 The content of array ARR should become 56, 90, 45, 34, 20, 54 void SWAP2BEST(int ARR[ ],int Size) int i, temp; for(i=0; i<size;) if(arr[i]%10==0) temp=arr[i+1]; ARR[i+1]=ARR[i]; ARR[i]=temp; i+=2; i++; Q.3 Write a Get2From1( ) function in C++ to transfer the content from one array ALL[ ] to two different arrays Odd[ ] and Even[ ]. The Odd[ ] array should contain the values from odd positions (1,3,5,..) of ALL[ ] and Even[ ] array should contain the values from even positions (0,2,4, ) of ALL[ ]. Example If the ALL[ ] array contains 12, 34, 56, 67, 89, 90. The Odd[ ] array should contain 34, 67, 90 And the Even[ ] array should contain 12, 56, 89 void Get2From1( int ALL[],int N) int Odd[ ], Even[ ], j=0, k=0; for(int i=0;i<n;i++) if (i%2==0) Even[j]=ALL[i]; j++;
2 Odd[k]=ALL[i]; k++; Q.4 Write a function REASSIGN( ) in C++, which accepts an array of integers and its size as arguments and divide all those array elements by 5 which are divisible by 5 and multiply other array elements by 2. - void REASSIGN (int A[ ], int n) for(int i=0;i<n;i++) if(a[i]%5= =0) A[i]= A[i]/5; A[i]= A[i]*2; Q.5 Write a function SORTPOINTS( ) in C++ to sort an array of structure Game in descending order of Points using bubble sort: struct Game long Pno; // Player no. char Pname[20]; long Points; ; void SORTPOINTS(Game G[ ], int n) Game temp; for(int i=0;i<n;++i) for(int j=0;j<(n-1) ;j++) if(g[j].points<g[j+1].points) temp=g[j]; G[j]=G[j+1]; G[j+1]=temp; Q.6 Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in reverse. Example:If an array of nine elements initially contains the elements as 4, 2, 5, 1, 6, 7, 8, 12, 10 Then the function should rearrange the array as 10, 12, 8, 7, 6, 1, 5, 2, 4 void reversearray(int A[ ], int size) int i, j, temp; for(i=0, j=size-1; i<=j; i++, j--) temp=a[i]; A[i]=A[j]; A[j]=temp;
3 Q.7 Write a function in C++, which accepts an integer array and its size as arguments and swap the elements of every even location with its following odd location. Example: If an array of nine elements initially contains the elements as 2, 4, 1, 6, 5, 7, 9, 23, 10 then the function should rearrange the array as 4, 2, 6, 1, 7, 5, 23, 9, 10 void SwapArray(int A[ ], int N) int i, j, temp; if(n%2==0) j=n; j= N-1; for(i=0; i<j; i+=2) temp=a[i]; A[i]=A[i+1]; A[i+1]=temp; Q.8 Write function in C++ which accepts an integer array and size as arguments and replaces elements having odd values with thrice its value and elements having even values with twice its value. Example : if an array of five elements initially contains elements as 3, 4, 25, 16, 9 The function should rearrange the content of the array as 9, 8, 75, 32, 27 void manipulate (int a[ ],int size) for (int i=0;i<size;i++) if (a[i]%2= =0) a[i]=a[i]*2; a[i]=a[i]*3; cout<<a[i]<<, ; Q.9 Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having even values with its half and elements having odd values with twice its value. Example : If an array of five elements initially contains the elements as 3, 4, 5, 16, 9 then the function should rearrange content of the array as 6, 2, 10, 8, 18 void changearray(int a[ ],int size) for (int i=0;i<size;i++) if (a[i]%2= =0) a[i]=a[i]/2; a[i]=a[i]*2; cout<<a[i]<<, ; Q.10 Write a function in C++ which accepts an integer array and its size as arguments and exchanges the values of first half side elements with the second half side elements of the array. Example : If an array of 8 elements initial content as 2, 4, 1, 6, 7, 9, 23, 10 The function should rearrange array as 7, 9, 23, 10, 2, 4, 1, 6 void change(int a[ ],int size) int i,j,temp; for(i=0,j=size/2; j<size; i++,j++)
4 temp=a[i]; a[i]=a[j]; a[j]=temp; Q.11 Define the function SwapArray(int[ ], int),that would expect a 1D integer array NUMBERS and its size N. the function should rearrange the array in such a way that the values of that locations of the array are exchanged. (Assume the size of the array to be even). Example : If the array initially contains 2, 5, 9, 14, 17, 8, 19, 16 Then after rearrangement the array should contain 5, 2, 14, 9, 8, 17, 16, 19 void SwapArray(int ARR[ ],int Size) int i, temp; for(i=0; i<size;i++) temp=arr[i+1]; ARR[i+1]=ARR[i]; ARR[i]=temp; Q.12 Assume a array E containing elements of structure Employee is required to be arranged in descending order of Salary. Write a C++ function to arrange same with the help of bubble sort, the array and its size is required to be passed as parameters to the function. Definition of structure Employee is as follows: struct Employee int Eno; char name[25]; float Salary; ; void bubble(employee E[ ],int n) int i,j; Employee temp; for(i=0;i<n;++i) for(j=0; j<(n-1) ;j++) if(e[j].salary<e[j+1].salary) temp=e[j]; E[j]=E[j+1]; E[j+1]= temp; cout<<"the details of the employee in descending order of salary "; for(i=0;i<n;i++) cout<<e[i].eno<<'\t'<<e[i].name<< \t<<e[i].salary<<endl; Q.13 Suppose A, B, C are arrays of integers of size M, N and M+N respectively. The numbers in array A appear in ascending order while numbers in array B in descending order. Write user defined function in C++ to produce third array C by merging array A by B in ascending order. Use A, B and C as arguments in the function. void Merge(int A[ ],int M,int B[ ],int N,int C[ ]) int a=0,b= N-1,c=0; while (a<m && b>=0) if(a[a]<=b[b]) C[c++]=A[a++]; C[c++]=B[b--];
5 if(a<m) while(a<m) C[c++]=A[a++]; while(b>=0) C[c++]=B[b--]; ( ½ Mark for function header with desired parameter s) ( ½ Mark initialising counters) (1 Mark for correct formation of loop) (1 Mark for correct comparison of elements) (1 Mark for transferring remaining elements in resultant array) Q.14 Suppose a 1D array AR containing integers is arranged in ascending order. Write a user defined function in C++ to search for one integer from AR with the help of binary search method, to show presence of the number in the array. The function should have three parameters: (1) an array AR (2) the number to be searched and (3) the number of elements N in the array. void BinSearch(int AR[ ], int item, int N) int beg=0, last= N-1,mid, flag=0; while(beg<=last) mid=(beg + last)/2; if (item= = AR[mid]) flag=1; break; if (item<ar[mid]) last=mid-1; beg=mid+1; if( flag = = 0) cout<< \nthe Search Element <<item<< is not available ; cout<< \nthe Search Element <<item<< is available ; Q.15 Suppose an array P containing float is arranged in ascending order. Write a user defined function in C++ to search for one float from P with the help of binary search method. The function should return an integer 0 to show absence of the number in the array. The function should have the parameters as (1) an array P (2) the number DATA to be searched (3) number of elements N. int BinSearch(float P[ ],float DATA, int N) int beg=0, last= N-1, mid; while(beg<=last) mid=(beg + last)/2; if (DATA= = P[mid]) return 1; if (DATA<P[mid]) last=mid-1; beg=mid+1; return 0; Q.16 Write a function in C++ to combine the contents of two equi-sized arrays A and B by computing their corresponding elements with the formula 2*A[i]+3*B[i]; where value i varies from 0 to N-1 and transfer the resultant content in the third same sized array.
6 void AddNSave(int A[],int B[],int C[],int N) for (int i=0;i<n;i++) C[i]=2*A[i]+3*B[i]; Q.17 Q.19
7 Q.20 Write a function to sort any array of n elements using insertion sort. Array should be passed as argument to the function. void insertsort( int a[],int n) int p,ptr; //Assuming a[0]=int_min i.e. smallest integer for(p=1;p<=n;p++) temp=a[p]; ptr=p-1; while(temp<a[ptr]) a[ptr+1]=a[ptr]; // Move Element Forward ptr--; a[ptr+1]=temp; // Insert Element in Proper Place Q.21 Write function oddeven(int S [ ], int N) in C++, to add 5 in all the odd values and 10 in all the even values of the array S. Example : if the original content of the array S is 50, 11, 19, 24, 28 The modified content will be: 60, 16, 24, 34, 38 void oddeven (int S[ ],int N) for (int i=0;i<n;i++) if (a[i]%2= =0) a[i]=a[i]+10; a[i]=a[i]+5; cout<<a[i]<<, ;
8 Q.22 Write a function TRANSFER(int A[], int B[], int Size) in C++ to copy the elements of array A into array B in such a way that all the negative elements of A appear in the beginning of B, followed by all the positive elements, followed by all the zeroes maintaining their respective orders in array A. (3) For example: If the contents of array A are: 7, -23, 3, 0, -8,-3,4, 0 The contents of array B should be -23, -8, -3, 7, 3, 4, 0, 0 #include<iostream.h> #include<conio.h> void transfer(int a[],int b[],int size); void main() int a[]= 7, -23, 3, 0, -8,-3,4, 0,b[8]; transfer(a,b,8); for(int i=0;i<8;i++) cout<<b[i]<<'\t'; getch(); void transfer(int a[],int b[],int size) int k=0; for(int i=0;i<size;i++) if(a[i]<0) b[k]=a[i]; k++; for(int i=0;i<size;i++) if(a[i]>0) b[k]=a[i]; k++; for(int i=0;i<size;i++) if(a[i]==0) b[k]=a[i]; k++; Q.23 Write the definition of function named Array_Swap() that will accept an integer array & its size as arguments and the function will interchange/swap elements in such a way that the first element is swapped with the last element, second element is swapped with the second last element and so on, only if anyone or both the elements are odd. E.g. if initially array of seven elements is: 5, 16, 4, 7, 19, 8, 2 After execution of the above function, the contents of the array will be: 2,16, 19, 7, 4, 8, 5
Downloaded from
Unit-II Data Structure Arrays, Stacks, Queues And Linked List Chapter: 06 In Computer Science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.
More information:: Computer Science C++ Important Questions ::
:: Computer Science C++ Important Questions :: 1 Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in descending order. Example: If an array of
More informationIntroduction to Arrays
Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an
More informationKENDRIYA VIDYALYA CLRI CHENNAI AUTUMN BREAK HOLIDAY HW MARKS QUESTIONS : DATA STRUCTURE
KENDRIYA VIDYALYA CLRI CHENNAI AUTUMN BREAK HOLIDAY HW 8 MARKS QUESTIONS : DATA STRUCTURE. Write a function in C++ which accepts an integer array and its size as arguments and change all the even number
More informationSubject: Computer Science
Subject: Computer Science Topic: Data Types, Variables & Operators 1 Write a program to print HELLO WORLD on screen. 2 Write a program to display output using a single cout statement. 3 Write a program
More informationVARIABLE, OPERATOR AND EXPRESSION [SET 1]
VARIABLE, OPERATOR AND EXPRESSION Question 1 Write a program to print HELLO WORLD on screen. Write a program to display the following output using a single cout statement. Subject Marks Mathematics 90
More informationArrays. Elementary Data Representation Different Data Structure Operation on Data Structure Arrays
Arrays Elementary Data Representation Different Data Structure Operation on Data Structure Arrays Elementary Data Representation Data can be in the form of raw data, data items and data structure. Raw
More information1. Write step by step code to delete element from existing Doubly Linked List. Suppose that all declarations are done
1. Write step by step code to delete element from existing Doubly Linked List. Suppose that all declarations are done. first NULL 42 A A 13 A A 6 NULL Write code here first NULL 42 A A 13 A A 6 NULL p
More informationCSE101-lec#19. Array searching and sorting techniques. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming
CSE101-lec#19 Array searching and sorting techniques Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Introduction Linear search Binary search Bubble sort Introduction The process of finding
More informationA two-dimensional array is an array in which each element is itself a 1-D array. There is no rows and columns in one-dimensional array.
CHAPTER-9 ARRAYS VERY SHORT/SHORT ANSWER QUESTIONS 1. Define the term data structure and state its significance. Ans. A data structure is a named group of data of different data types which can be processed
More information// array initialization. void main() { cout<<b[4]<<endl; cout<<b[5]<<endl; } Output is 9
UNIT-2 DATA STRUCTURES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. The data structure can be classified into following two types:
More informationUnit 2: Data Structures
Unit 2: Data Structures 2.1: Arrays ARRAYS Introduction to data structure, Arrays, One Dimensional Array, Basic operations on 1-D array: traversal, Searching- linear, binary search, insertion, deletion,
More informationSearching an Array: Linear and Binary Search. 21 July 2009 Programming and Data Structure 1
Searching an Array: Linear and Binary Search 21 July 2009 Programming and Data Structure 1 Searching Check if a given element (key) occurs in the array. Two methods to be discussed: If the array elements
More informationChapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.
Chapter4: s Data: It is a collection of raw facts that has implicit meaning. Data may be single valued like ID, or multi valued like address. Information: It is the processed data having explicit meaning.
More informationSubject: Fundamental of Computer Programming 2068
Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find
More informationColumns A[0] A[0][0] = 20 A[0][1] = 30
UNIT Arrays and Strings Part A (mark questions). What is an array? (or) Define array. An array is a collection of same data type elements All elements are stored in continuous locations Array index always
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays 1 What are Arrays? Arrays are our first example of structured data. Think of a book with pages numbered 1,2,...,400.
More informationAn array is a collection of similar elements that is all the elements in an array should have same data type. This means that an array can store
An array is a collection of similar elements that is all the elements in an array should have same data type. This means that an array can store either all integers, all floating point numbers, all characters,
More informationCSE202- Lec#6. (Operations on CSE202 C++ Programming
Arrays CSE202- Lec#6 (Operations on Arrays) Outline To declare an array To initialize an array Operations on array Introduction Arrays Collection of related data items of same data type. Static entity
More informationTypes of Data Structures
DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data
More informationSolution: A pointer is a variable that holds the address of another object (data item) rather than a value.
1. What is a pointer? A pointer is a variable that holds the address of another object (data item) rather than a value. 2. What is base address? The address of the nth element can be represented as (a+n-1)
More informationArrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection
Morteza Noferesti Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful
More information3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)
Structures Programming in C++ Sequential Branching Repeating Loops (Repetition) 2 1 Loops Repetition is referred to the ability of repeating a statement or a set of statements as many times this is necessary.
More informationSearching Elements in an Array: Linear and Binary Search. Spring Semester 2007 Programming and Data Structure 1
Searching Elements in an Array: Linear and Binary Search Spring Semester 2007 Programming and Data Structure 1 Searching Check if a given element (called key) occurs in the array. Example: array of student
More informationSBOA SCHOOL & JUNIOR COLLEGE, CHENNAI 101 COMPUTER SCIENCE CLASS: XI HALF YEARLY EXAMINATION MAX MARKS:70 CODE - A DURATION : 3 Hours
SBOA SCHOOL & JUNIOR COLLEGE, CHENNAI 101 COMPUTER SCIENCE CLASS: XI HALF YEARLY EXAMINATION 2016 MAX MARKS:70 CODE - A DURATION : 3 Hours All questions are compulsory. Do not change the order of the questions
More informationArrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array
Arrays Array is a collection of similar data types sharing same name or Array is a collection of related data items. Array is a derived data type. Char, float, int etc are fundamental data types used in
More informationInitialisation of an array is the process of assigning initial values. Typically declaration and initialisation are combined.
EENG212 Algorithms & Data Structures Fall 08/09 Lecture Notes # 2 OUTLINE Review of Arrays in C Declaration and Initialization of Arrays Sorting: Bubble Sort Searching: Linear and Binary Search ARRAYS
More informationComputers in Engineering COMP 208. Where s Waldo? Linear Search. Searching and Sorting Michael A. Hawker
Computers in Engineering COMP 208 Searching and Sorting Michael A. Hawker Where s Waldo? A common use for computers is to search for the whereabouts of a specific item in a list The most straightforward
More informationChapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:
Chapter-11 POINTERS Introduction: Pointers are a powerful concept in C++ and have the following advantages. i. It is possible to write efficient programs. ii. Memory is utilized properly. iii. Dynamically
More informationFunctions. Introduction :
Functions Introduction : To develop a large program effectively, it is divided into smaller pieces or modules called as functions. A function is defined by one or more statements to perform a task. In
More informationSorting Algorithms. Array Data is being arranged in ascending order using the bubble sort algorithm. #1 #2 #3 #4 #5 #6 #7
Sorting Algorithms One of the fundamental problems of computer science is ordering a list of items. There s a plethora of solutions to this problem, known as sorting algorithms. Some sorting algorithms
More informationO(n): printing a list of n items to the screen, looking at each item once.
UNIT IV Sorting: O notation efficiency of sorting bubble sort quick sort selection sort heap sort insertion sort shell sort merge sort radix sort. O NOTATION BIG OH (O) NOTATION Big oh : the function f(n)=o(g(n))
More informationSorting & Searching. Hours: 10. Marks: 16
Sorting & Searching CONTENTS 2.1 Sorting Techniques 1. Introduction 2. Selection sort 3. Insertion sort 4. Bubble sort 5. Merge sort 6. Radix sort ( Only algorithm ) 7. Shell sort ( Only algorithm ) 8.
More information115 cs Algorithms and Data Structures-1. Sorting: To arrange the elements into ascending or descending order.
cs Algorithms and Data Structures- Sorting Chapter-6 Sorting: To arrange the elements into ascending or descending order. sort ( ) : It is a method found in "java.util.arrays" package. it is a static method
More informationQ2: Write an algorithm to merge two sorted arrays into a third array? (10 Marks) Ans Q4:
Model Answer Benha University 1 st Term (2013/2014) Final Exam Class: 2 nd Year Students Subject: Data Structures Faculty of Computers & Informatics Date: 26/12/2013 Time: 3 hours Examiner: Dr. Essam Halim
More information#include<iostream.h> { for(int L=1;L<=N;L++) cout<<m*l; cout<<endl; } void main()
CHAPTER-3 Function Overloading SHORT ANSWER QUESTIONS 1. How does the compiler interpret more than one definitions having same name? What steps does it follow to distinguish these? Ans. The compiler will
More information(a) Differentiate between a call by value and call by reference method.
ATOMIC ENERGY CENTRAL SCHOOL NO- RAWATBHATA Half Yearly Examination 05 Model Paper Class XII Subject Computer Science Time Allowed: hours Maximum Marks: 70 Note. (i) All questions are compulsory. (ii)
More informationSorting. Bubble Sort. Selection Sort
Sorting In this class we will consider three sorting algorithms, that is, algorithms that will take as input an array of items, and then rearrange (sort) those items in increasing order within the array.
More informationProgramming in C++ (Educational Support)
Programming in C++ (Educational Support) http:// 1. WRITE A PROGRAM TO TRAVERSING OF AN ARRAY. #include # include void main () int a [10], lb = 1, ub, k, I; cout
More information1. Basics 1. Write a program to add any two-given integer. Algorithm Code 2. Write a program to calculate the volume of a given sphere Formula Code
1. Basics 1. Write a program to add any two-given integer. Algorithm - 1. Start 2. Prompt user for two integer values 3. Accept the two values a & b 4. Calculate c = a + b 5. Display c 6. Stop int a, b,
More informationLECTURE 17. Array Searching and Sorting
LECTURE 17 Array Searching and Sorting ARRAY SEARCHING AND SORTING Today we ll be covering some of the more common ways for searching through an array to find an item, as well as some common ways to sort
More informationMake sure the version number is marked on your scantron sheet. This is Version 1
Last Name First Name McGill ID Make sure the version number is marked on your scantron sheet. This is Version 1 McGill University COMP 208 -- Computers in Engineering Mid-Term Examination Tuesday, March
More information8.1. Chapter 8: Introduction to Search Algorithms. Linear Search. Linear Search. Linear Search - Example 8/23/2014. Introduction to Search Algorithms
Chapter 8: Searching and Sorting Arrays 8.1 Introduction to Search Algorithms Introduction to Search Algorithms Search: locate an item in a list of information Two algorithms we will examine: Linear search
More informationIf the numbers are 5 and 2,
Chapter : 4 Functions Examples 1. An example for functions.[pg-94] int fact(int num) int factorial = 1; for(inta=1;a
More informationmywbut.com Sorting Techniques
6 Sorting Techniques The operation of sorting is the most common task performed by computers today. Sorting is used to arrange names and numbers in meaningful ways. For example; it is easy to look in the
More informationPointers. Introduction
Pointers Spring Semester 2007 Programming and Data Structure 1 Introduction A pointer is a variable that represents the location (rather than the value) of a data item. They have a number of useful applications.
More informationSorting is ordering a list of objects. Here are some sorting algorithms
Sorting Sorting is ordering a list of objects. Here are some sorting algorithms Bubble sort Insertion sort Selection sort Mergesort Question: What is the lower bound for all sorting algorithms? Algorithms
More informationAryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9
Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths
More informationFunctions. Arash Rafiey. September 26, 2017
September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic
More informationLecture 6 Sorting and Searching
Lecture 6 Sorting and Searching Sorting takes an unordered collection and makes it an ordered one. 1 2 3 4 5 6 77 42 35 12 101 5 1 2 3 4 5 6 5 12 35 42 77 101 There are many algorithms for sorting a list
More informationAC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 2014
AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 214 Q.2 a. Design an algorithm for computing gcd (m,n) using Euclid s algorithm. Apply the algorithm to find gcd (31415, 14142). ALGORITHM Euclid(m, n) //Computes
More informationPROGRAMMING IN C AND C++:
PROGRAMMING IN C AND C++: Week 1 1. Introductions 2. Using Dos commands, make a directory: C:\users\YearOfJoining\Sectionx\USERNAME\CS101 3. Getting started with Visual C++. 4. Write a program to print
More informationm) sin() n) endl o) getch() p) cout
SAMPLE PAPER 1. a) Name the header file for the following built-in functions: a) log() b) exp() c) getch() d) isalnum() e) fabs() f) isalpha() g) toupper() h) cos() i) random() j) gets() k) abs() l) tolower()
More informationLinear Search. Sorting Algorithms. linear search code. Sorting in Ascending Order Selection Sort. Selection sort algorithm
Linear Search Additional CPSC1620 topics Searching, Sorting, Big(O) template functions, classes The idea of a linear search is to walk through the entire list until the value is found. The list does not
More informationReview Questions for Final Exam
CS 102 / ECE 206 Spring 11 Review Questions for Final Exam The following review questions are similar to the kinds of questions you will be expected to answer on the Final Exam, which will cover LCR, chs.
More informationClassification s of Data Structures
Linear Data Structures using Sequential organization Classification s of Data Structures Types of Data Structures Arrays Declaration of arrays type arrayname [ arraysize ]; Ex-double balance[10]; Arrays
More informationOutput of sample program: Size of a short is 2 Size of a int is 4 Size of a double is 8
Pointers Variables vs. Pointers: A variable in a program is something with a name and a value that can vary. The way the compiler and linker handles this is that it assigns a specific block of memory within
More informationQ 1. Attempt any TEN of the following:
Subject Code: 17212 Model Answer Page No: 1 / 26 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The
More information! Search: find a given item in a list, return the. ! Sort: rearrange the items in a list into some. ! list could be: array, linked list, string, etc.
Searching & Sorting Week 11 Gaddis: 8, 19.6,19.8 (8th ed) Gaddis: 8, 20.6,20.8 (9th ed) CS 5301 Fall 2018 Jill Seaman!1 Definitions of Search and Sort! Search: find a given item in a list, return the position
More informationKENDRIYA VIDYALAYA SANGATHAN GUWAHATI REGION क य व लय स गठन, ग व ह ट स भ ग I-PRE BOARD EXAMINATION ( -ब ड पर )
KENDRIYA VIDYALAYA SANGATHAN GUWAHATI REGION क य व लय स गठन, ग व ह ट स भ ग I-PRE BOARD EXAMINATION 203-4( -ब ड पर 203-4) Class: XII Time: 3 Hrs. Computer Science Max. Marks: 70 Answer Key Q a) Typedef
More informationLECTURE NOTES ON DATA STRUCTURES THROUGH C
LECTURE NOTES ON DATA STRUCTURES THROUGH C Revision 4 July 2013 L. V. NARASIMHA PRASAD Professor and Head E. KRISHNARAO PATRO Associate Professor Department of Computer Science and Engineering Shamshabad,Hyderabad
More informationCS101 Computer Programming Quiz for Wednesday Batch 8 October 2014
CS101 Computer Programming Quiz for Wednesday Batch 8 October 2014 Q1. Consider the following variation of Merge Sort to sort the array in descending order. In the version of Merge Sort discussed in class,
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationI SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.
I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK 70. a) What is the difference between Hardware and Software? Give one example for each. b) Give two differences between primary and secondary memory.
More informationCSC138: STRUCTURED PROGRAMMING CHAP 1 ONE DIMENSIONAL ARRAY (1D) LEARNING OBJECTIVES. Introduction to array. Array declaration and initialization
CSC138: STRUCTURED PROGRAMMING CHAP 1 ONE DIMENSIONAL ARRAY (1D) LEARNING OBJECTIVES Introduction to array Array declaration and initialization Input / Output values into array Accessing elements of an
More informationMaltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers
Maltepe University Computer Engineering Department BİL 133 Algoritma ve Programlama Chapter 8: Arrays and pointers Basics int * ptr1, * ptr2; int a[10]; ptr1 = &a[2]; ptr2 = a; // equivalent to ptr2 =
More informationSorting Pearson Education, Inc. All rights reserved.
1 19 Sorting 2 19.1 Introduction (Cont.) Sorting data Place data in order Typically ascending or descending Based on one or more sort keys Algorithms Insertion sort Selection sort Merge sort More efficient,
More informationDownloaded from
Unit I Chapter -1 PROGRAMMING IN C++ Review: C++ covered in C++ Q1. What are the limitations of Procedural Programming? Ans. Limitation of Procedural Programming Paradigm 1. Emphasis on algorithm rather
More informationComputer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];
Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data
More informationData Structures. Chapter 04. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU
Data Structures Chapter 04 1 Linear Array A linear array is a list of finite number N of homogeneous data elements such that: The elements of the array are referenced respectively by an index set consisting
More informationProgramming in OOP/C++
Introduction Lecture 3-2 Programming in OOP/C++ Arrays Part (2) By Assistant Professor Dr. Ali Kattan 1 Arrays Examples Solutions for previous assignments Write a program to enter and store your name and
More informationSample Paper Class XII SUBJECT : COMPUTER SCIENCE
Sample Paper - 2013 Class XII SUBJECT : COMPUTER SCIENCE FIRST SEMESTER EXAMINATION Instructions: (i) All questions are compulsory. (ii) (ii) Programming Language : C++ 1. (a) Name the header files that
More information(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.
CS 7A - Fall 2016 - Midterm 1 10/20/16 Write responses to questions 1 and 2 on this paper or attach additional sheets, as necessary For all subsequent problems, use separate paper Do not use a computer
More informationAlgorithm Analysis. Algorithm Analysis 1
Algorithm Analysis 1 Algorithm Analysis Example: Sequential Search. Given an array of n elements, determine if a given number val is in the array. If so, set loc to be the index of the first occurrence
More informationComputer Science & Engineering 150A Problem Solving Using Computers
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using
More informationStructured programming
Exercises 9 Version 1.0, 13 December, 2016 Table of Contents 1. Remainders from lectures.................................................... 1 1.1. What is a pointer?.......................................................
More informationIndian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination
Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn 2017-18: Mid-Semester Examination Time: 2 Hours Full Marks: 60 INSTRUCTIONS 1. Answer ALL questions 2. Please write
More informationCS101 Computer Programming and Utilization
CS101 Computer Programming and Utilization Milind Sohoni June 13, 2006 Milind Sohoni () CS101 Computer Programming and Utilization June 13, 2006 1 / 25 1 So far 2 What is sorting 3 Bubble Sort 4 Other
More information8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );
- 50 - Control Structures: 8. Functions (II) Arguments passed by value and by reference. Until now, in all the functions we have seen, the arguments passed to the functions have been passed by value. This
More informationCSCE 206: Structured Programming in C++
CSCE 206: Structured Programming in C++ 2017 Spring Exam 3 Monday, April 17, 2017 Total - 100 Points B Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,
More informationCSCE 206: Structured Programming in C++
CSCE 206: Structured Programming in C++ 2017 Spring Exam 3 Monday, April 17, 2017 Total - 100 Points A Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,
More informationSorting and Searching. Sudeshna Sarkar 7 th Feb 2017
Sorting and Searching Sudeshna Sarkar 7 th Feb 2017 Searching an Array: Linear and Binary Search Spring 2012 Programming and Data Structure 2 Searching Check if a given element (key) occurs in the array.
More informationData type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:
Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before
More informationCSE 143. Two important problems. Searching and Sorting. Review: Linear Search. Review: Binary Search. Example. How Efficient Is Linear Search?
Searching and Sorting [Chapter 9, pp. 402-432] Two important problems Search: finding something in a set of data Sorting: putting a set of data in order Both very common, very useful operations Both can
More informationCS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015
CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in
More informationDepartment of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04
Department of Computer Science & Engineering Indian Institute of Technology Kharagpur Topic: Arrays and Strings Practice Sheet #04 Date: 24-01-2017 Instructions: For the questions consisting code segments,
More information1. FIBONACCI SERIES. Write a C++ program to generate the Fibonacci for n terms. To write a C++ program to generate the Fibonacci for n terms.
PROBLEM: 1. FIBONACCI SERIES Write a C++ program to generate the Fibonacci for n terms. AIM: To write a C++ program to generate the Fibonacci for n terms. PROGRAM CODING: #include #include
More informationProgramming and Data Structures Mid-Semester - Solutions to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring
Programming and Data Structures Mid-Semester - s to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring 2015-16 February 15, 2016 1. Tick the correct options. (a) Consider the following
More information8/5/10 TODAY'S OUTLINE. Recursion COMP 10 EXPLORING COMPUTER SCIENCE. Revisit search and sorting using recursion. Recursion WHAT DOES THIS CODE DO?
8/5/10 TODAY'S OUTLINE Recursion COMP 10 EXPLORING COMPUTER SCIENCE Revisit search and sorting using recursion Binary search Merge sort Lecture 8 Recursion WHAT DOES THIS CODE DO? A function is recursive
More informationCSc 110, Spring 2017 Lecture 39: searching
CSc 110, Spring 2017 Lecture 39: searching 1 Sequential search sequential search: Locates a target value in a list (may not be sorted) by examining each element from start to finish. Also known as linear
More informationSample Paper 2013 SUB: COMPUTER SCIENCE GRADE XII TIME: 3 Hrs Marks: 70
Sample Paper 2013 SUB: COMPUTER SCIENCE GRADE XII TIME: 3 Hrs Marks: 70 INSTRUCTIONS: All the questions are compulsory. i. Presentation of answers should be neat and to the point. iii. Write down the serial
More informationDEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK UNIT-III. SUB NAME: DESIGN AND ANALYSIS OF ALGORITHMS SEM/YEAR: III/ II PART A (2 Marks)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK UNIT-III SUB CODE: CS2251 DEPT: CSE SUB NAME: DESIGN AND ANALYSIS OF ALGORITHMS SEM/YEAR: III/ II PART A (2 Marks) 1. Write any four examples
More informationPOINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory
More informationF.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C
F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1 (a) List any four relational operators.
More informationSECOND JUNIOR BALKAN OLYMPIAD IN INFORMATICS
SECOND JUNIOR BALKAN OLYMPIAD IN INFORMATICS July 8 13, 2008 Shumen, Bulgaria TASKS AND SOLUTIONS Day 1 Task 1. TOWERS OF COINS Statement Asen and Boyan are playing the following game. They choose two
More informationChapter 10 - Notes Applications of Arrays
Chapter - Notes Applications of Arrays I. List Processing A. Definition: List - A set of values of the same data type. B. Lists and Arrays 1. A convenient way to store a list is in an array, probably a
More informationLECTURE 08 SEARCHING AND SORTING ARRAYS
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 08 SEARCHING AND
More informationArrays and functions Multidimensional arrays Sorting and algorithm efficiency
Introduction Fundamentals Declaring arrays Indexing arrays Initializing arrays Arrays and functions Multidimensional arrays Sorting and algorithm efficiency An array is a sequence of values of the same
More informationCHAPTER 4 FUNCTIONS. 4.1 Introduction
CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main
More information