Columns A[0] A[0][0] = 20 A[0][1] = 30

Size: px
Start display at page:

Download "Columns A[0] A[0][0] = 20 A[0][1] = 30"

Transcription

1 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 start from 0 It is represented using [ ] square brackets. Write a program to find sum of array elements. int i, n,sum, a[0]; printf( enter how many numbers ); printf( enter numbers one by one: ); for( i=0; i<n; i++) sum = sum + a[i]; printf( answer = %d, sum); Enter how many numbers Enter numbers one by one List out any six string handling functions. Strcat() to concatenate a string (join) Strupr() to change to Upper case (Capital letters) Strlwr() to change to Lower case ( Small letters) Strlen() to find length of string Strrev() to reverse a string Strcmp() to compare two strings Strcpy() to copy one string to another string. What is a two-dimensional array? It is an array in which rows and columns are the two dimensions Two square brackets are used for rows and columns More number of elements can be stored Ex:- Int a[][] = 0,0, 0,0 ;- Rows / A[0] A[] Columns A[0] A[0][0] = 0 A[0][] = 0 A[] A[][0] = 0 A[][] = 0. What is a string? A string is a one dimensional array to store characters It is represented inside double quotes It is also called as sequence of characters Array is used to store the string. Ex:- char a[0] = Mechanical ; M e c h a n i c a l A[0] A[] A[] A[] A[] A[] A[] A[] A[] A[]

2 Part B ( and mark questions). Write a C program to arrange numbers in ascending order and descending order. Ascending order:- int i, j, temp; int a[0] =,,,,,,,,, 0 ; for( i=0; i<0; i++) for(j=i+; j<0; j++) if ( a[i] > a[j] ) temp = a[i]; a[i] = a[j]; a[j] = temp; printf( answer= ); for( i=0; i<0; i++) printf( %d, a[i]); Descending order:- int i, j, temp; int a[0] =,,,,,,,,, 0 ; for( i=0; i<0; i++) for(j=i+; j<0; j++) if ( a[i] < a[j] ) temp = a[i]; a[i] = a[j]; a[j] = temp; printf( answer= ); for( i=0; i<0; i++) printf( %d, a[i]); 0 0. Write a C program for addition of two matrices int i, j; int a[][], b[][], c[][]; printf( enter matrix a in x ); for( i=0; i<; i++) for(j=0; j<; j++) printf( enter matrix b in x ); for( i=0; i<; i++) for(j=0; j<; j++) scanf( %d,&b[i][j]); for( i=0; i<; i++) for(j=0; j<; j++) c[i][j] = a[i][j] + b[i][j]; printf( answer = ); for( i=0; i<; i++) for(j=0; j<; j++) printf( %d,c[i][j]); A in X B in X 0

3 . Write a C program for subtraction of two matrices int i, j; int a[][], b[][], c[][]; printf( enter matrix a in x ); for( i=0; i<; i++) for(j=0; j<; j++) printf( enter matrix b in x ); for( i=0; i<; i++) for(j=0; j<; j++) scanf( %d,&b[i][j]); for( i=0; i<; i++) for(j=0; j<; j++) c[i][j] = a[i][j] - b[i][j]; printf( answer = ); for( i=0; i<; i++) for(j=0; j<; j++) printf( %d,c[i][j]); A in X 0 B in X.Write a program for multiplication of two matrices int i, j, k; int a[][], b[][], c[][]; printf( enter matrix a in x ); for( i=0; i<; i++) for(j=0; j<; j++) printf( enter matrix b in x ); for( i=0; i<; i++) for(j=0; j<; j++) for(k=0; k<=; k++) c[i][j] = c[i][j] + a[i][j] * b[i][j]; for( i=0; i<; i++) for(j=0; j<; j++) c[i][j] = a[i][j] - b[i][j]; printf( answer = ); for( i=0; i<; i++) for(j=0; j<; j++) printf( %d,c[i][j]); A in X B in X 0 0 0

4 . Write a C program for transpose of a matrix int i, j; int a[][]; printf( enter matrix A in x ); for( i=0; i<; i++) for(j=0; j<; j++) printf( answer = ); for( j=0; j<; i++) for(i=0; i<; j++) printf( %d,a[i][j]); in X. Write a program to find sum of diagonal elements of a matrix int i, j, sum; int a[][]; printf( enter matrix in x ); for( i=0; i<; i++) for(j=0; j<; j++) for( i=0; i<; i++) for(j=0; j<; j++) if(i==j) sum = sum + a[i][j]; printf( answer = %d, sum); in X. Write a C program to find determinant of a matrix int i, j, det; int a[][]; printf( enter matrix in x ); for( i=0; i<; i++) for(j=0; j<; j++) det = a[0][0] * a[][] - a[][0] * a[0][]; printf( answer = %d, det); Enter x matrix

5 .Explain some string handling functions with example C programs. Strcat() to concatenate two strings (join) mechengg char s[0] = mech ; char s[0] = engg ; strcat(s,s); printf( %s,s); Strlen() to find length of a string 0 int a; char s[0]= mechanical ; a=strlen(a); printf( %d,a); Strcpy() to copy one string to another string mechanical char s[0]= mechanical ; char s[0]= ; strcpy(s,s); printf( %s,s); strrev() to reverse a string lacinahcem char s[0]= mechanical ; printf( %s,strrev(s) ); strupr() to change letters to upper case (Captials) MECHANICAL char s[0]= mechanical ; printf( %s,strupr(s) ); strlwr() to change letters to lower case (small letter) mechanical char s[0]= MECHANICAL ; printf( %s,strlwr(s) ); strset() to change letters to some other letters zzzzzzzzzz char s[0]= mechanical ; strset(s,z); printf( %s,s );. Explain binary search with an example. It follows divide and conquer technique. Key means, search element. Key is compared with middle element. If key > middle, ignore first half of elements If key < middle, ignore second half of elements This process is repeated recursively. Until the element is found. Input: sorted array of elements Output: element found (or) not found. Sorted array Key Steps:- Find middle element of array Compare it with key Binary search Element Found Element not found If middle < key, repeat steps and for st half of array If middle > key, repeat steps and for nd half of array if middle == key, element is found.

6 Sorted array: 0, 0, 0, 0, 0, 0 Key : 0 Here, left = 0, right = 0, mid = (0 + 0) / = Therefore, mid = 0 or 0. We take mid = 0 0 = 0? (false). 0 < 0? (true) So, take second half of elements: 0, 0, 0 Sorted array: 0, 0, 0 Key : 0 Here, left = 0, right = 0, mid = (0 + 0) / = 0 0 = 0? (true) Therefore, element found at th position. Program:- int a[0], i, n, key, c, left, right, mid; printf( enter the sorted array elements ); printf( enter the key ); scanf( %d,&key); right = n-; while(left<=right) mid = (left+right)/; if(key==a[mid] c=; else if(key < a[mid]) right = mid -; else left = mid +; if ( c ==0 ) printf( element not found ); else printf( element found ); Enter number of elements Enter sorted array Enter key 0 Element found Advantages Efficient and faster Uses divide and conquer Suitable for large elements Disadvantages Not suitable for unsorted array Not suitable for dynamically changing data 0. Explain linear search with an example. The process of finding the key from the collection. Compare all the elements one by one. No technique is used Input: unsorted array of elements Output: element found (or) not found unsorted array key linear search element found element not found Steps:- Read the first element Compare with key If true, element is found. If not true, compare next element. Continue step,, and till the last element. Unsorted array:,,,,,, 0 Key : 0? (false). Go to next 0? (false). Go to next 0? (false). Go to next 0? (false). Go to next 0? (true) element found Program:- int a[0], key, c, i; printf( enter the sorted array elements ); printf( enter the key ); scanf( %d,&key);

7 if(a[i] = = key) c = ; break; if( c ==0) printf( element not found ); else printf( element found ); Enter number of elements Enter sorted array 0 Enter key Element found Advantages Easy and faster Array can be unsorted Suitable for small number of elements Disadvantages Not suitable for large number of elements Slower method Very basic technique. Explain bubble sort with an example It the oldest and easiest sorting. In this sorting, the elements are arranged in some technique. Take first element, compare it with next element. If first > second, swap the elements. Then, again compare st element with next element Continue this process until, each element is compared with every other element. Unsorted array Bubble sort Sorted array Program:- int n, temp, i, j, a[0]; printf( enter the elements ); for(i=0; i<n, i++) for(i=n-; i>0; i--) for(j=0; j<=i; j++) if(a[j]>a[j+]) temp = a[j]; a[j] = a[j+]; a[j+]= temp; printf( answer= ); printf( %d,a[i]); Enter number of elements Enter elements Advantages Easy technique simple Suitable for small number of elements Disadvantages Not suitable for large number of elements Not efficient Very basic technique

8 . Explain insertion sort with example Insertion sort is the process of taking elements from the list one by one and inserting them at correct position in the array. It is the simplest sorting. Unsorted array Sorted array Steps:- Take first element in the list Then take nd element in the list Check if it is less than st Insert at correct position Then take next element, insert at correct position Repeat this process till all elements are sorted Program:- int n, temp, i, j, a[0]; printf( enter the elements ); for(i=0; i<n, i++) For(i=0; i<s; i++) Temp = a[i]; J = i=; While( ( temp < a[j] ) && (j>=0) ) A[j+] = a[j]; J= j-; A[j+]=temp; printf( answer= ); printf( %d,a[i]); Insertion sort Enter number of elements Enter elements Answer= Advantages Disadvantages Easy technique Not suitable for large number of elements Simple and stable method expensive Suitable for small number of elements. Explain selection sort with example It is one of the basic sorting technique. It is used to sort the elements in ascending order It is based on comparison and swapping. Take the first element and compare it with all the other elements. The elements are swapped if first one is greater than the other element. Unsorted array Steps:- selection sort sorted array Take first element Compare it with next element If st < nd, compare st element with rd element If st > nd element, swap them. Continue this process till all the elements are in ascending order.

9 Program:- int n, temp, i, j, a[0]; printf( enter the elements ); for(i=0; i<n, i++) for(j=i+; j<n; j++) if(a[i] > a[j]) temp = a[i]; a[i]=a[j]; a[j]=temp; printf( answer= ); printf( %d,a[i]); Advantages Easy technique Simple method Suitable for small number of elements Disadvantages Not suitable for large number of elements Slow process. Explain merge sort with example It uses divide and conquer technique Any number of elements can be sorted The unsorted array is divided into smaller pieces. Divided until single element. Then it is merged (joined) in the increasing order. Both dividing and merging is done recursively. Unsorted array Enter number of elements Enter elements Merge sort Answer= Sorted array Program:- Refer book page number:.. Differentiate entry checked and exit checked conditional constructs with an example. (or) Differentiale WHILE loop and Do..WHILE loop constructs with an example. WHILE loop Entry checked loop Top-tested loop Condition is checked at the entry Loop will not execute if condition is FALSE Execute loop until condition is satisfied While(condition) Body of the loop int a=0; while(a<) printf( %d,a); a++; 0

10 Do..While loop:- Exit checked loop Bottom tested loop Condition is checked at the end If condition is false, loop will execute one time Execute the loop until the condition is true. Do Body of the loop; while(condition); Example program:- int a=0; do printf( %d,a); a++; while(a<);. Write a C program to generate Fibbonacci series int n, fib, f, f, i; for(i=; i<=n;i++) fib = f + f; printf( %d,fib); f = f; f = fib; 0 Enter number of elements 0

GE6151 COMPUTER PROGRAMMING REG.2013 NOTES

GE6151 COMPUTER PROGRAMMING REG.2013 NOTES Q January May January 5 May 5. Adv - 5 th generation (0000) = (?)8 What is Flow chart? What is super computer? computers. What is pseudo code? Flowchart for biggest of number Define algorithm Define pseudo

More information

Lecture 6 Sorting and Searching

Lecture 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 information

Saini Technologies ADVANCED C PROGRAMMING WITH SAINI TECHNOLOGIES. Sushil Kumar Saini Mo.

Saini Technologies ADVANCED C PROGRAMMING WITH SAINI TECHNOLOGIES. Sushil Kumar Saini   Mo. Saini Technologies ADVANCED C PROGRAMMING WITH SAINI TECHNOLOGIES Sushil Kumar Saini Email: Sushilsaini04@gmail.com Mo. 9896470047 Integer Array int a[]=12,34,54,45,34,34; printf("%d",a[0]); printf(" %d",a[1]);

More information

UNIT 7. SEARCH, SORT AND MERGE

UNIT 7. SEARCH, SORT AND MERGE UNIT 7. SEARCH, SORT AND MERGE ALGORITHMS Year 2017-2018 Industrial Technology Engineering Paula de Toledo CONTENTS 7.1. SEARCH 7.2. SORT 7.3. MERGE 2 SEARCH Search, sort and merge algorithms Search (search

More information

Introduction to Arrays

Introduction 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 information

Sorting & Searching. Hours: 10. Marks: 16

Sorting & 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 information

Questions Bank. 14) State any four advantages of using flow-chart

Questions Bank. 14) State any four advantages of using flow-chart Questions Bank Sub:PIC(22228) Course Code:-EJ-2I ----------------------------------------------------------------------------------------------- Chapter:-1 (Overview of C Programming)(10 Marks) 1) State

More information

Types of Data Structures

Types 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 information

International Journal Of Engineering Research & Management Technology

International Journal Of Engineering Research & Management Technology International Journal Of Engineering Research & Management Technology A Study on Different Types of Sorting Techniques ISSN: 2348-4039 Priyanka Gera Department of Information and Technology Dronacharya

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan 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 information

To store the total marks of 100 students an array will be declared as follows,

To store the total marks of 100 students an array will be declared as follows, Chapter 4 ARRAYS LEARNING OBJECTIVES After going through this chapter the reader will be able to declare and use one-dimensional and two-dimensional arrays initialize arrays use subscripts to access individual

More information

Write a C program using arrays and structure

Write a C program using arrays and structure 03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string

More information

Long Questions. 7. How does union help in storing the values? How it differs from structure?

Long Questions. 7. How does union help in storing the values? How it differs from structure? Long Questions April/May - 2010 Marks 1. Explain arithmetic operators and their precedence in C. 2. Explain the term structured programming with help of example 3. Write a program to read 10 numbers and

More information

Arrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array

Arrays. 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 information

Subject: Computer Science

Subject: 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 information

Unit 3 Decision making, Looping and Arrays

Unit 3 Decision making, Looping and Arrays Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.

More information

Sorting Algorithms. Array Data is being arranged in ascending order using the bubble sort algorithm. #1 #2 #3 #4 #5 #6 #7

Sorting 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 information

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Computer 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 information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

F.E. Sem. II. Structured Programming Approach

F.E. Sem. II. Structured Programming Approach F.E. Sem. II Structured Programming Approach Time : 3 Hrs.] Mumbai University Examination Paper Solution - May 14 [Marks : 80 Q.1(a) What do you mean by algorithm? Which points you should consider [4]

More information

Problem: Read 10 numbers from the keyboard and store them

Problem: Read 10 numbers from the keyboard and store them Arrays Problem: Read 10 numbers from the keyboard and store them Problem: Read 10 numbers from the keyboard and store them // solution #1 int a0, a1, a2, a3, a4, a5, a6, a7, a8, a9; printf( Enter a number:

More information

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.

Chapter4: 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 information

EENG 212 Lab 2. Recursive Functions

EENG 212 Lab 2. Recursive Functions EENG 212 Lab 2 Outline - Recursive Functions - Arrays Recursive Functions As it was said before modules in C are called functions. One of the types of functions is a recursive function. A recursive function

More information

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04

Department 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 information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Objectives of This Chapter

Objectives of This Chapter Chapter 6 C Arrays Objectives of This Chapter Array data structures to represent the set of values. Defining and initializing arrays. Defining symbolic constant in a program. Using arrays to store, list,

More information

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, Strings Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, decimal digits, special characters and escape

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART

More information

Arrays, Vectors Searching, Sorting

Arrays, Vectors Searching, Sorting Arrays, Vectors Searching, Sorting Arrays char s[200]; //array of 200 characters different type than class string can be accessed as s[0], s[1],..., s[199] s[0]= H ; s[1]= e ; s[2]= l ; s[3]= l ; s[4]=

More information

Structured programming

Structured programming Exercises 6 Version 1.0, 25 October, 2016 Table of Contents 1. Arrays []................................................................... 1 1.1. Declaring arrays.........................................................

More information

Principles of Programming. Chapter 6: Arrays

Principles of Programming. Chapter 6: Arrays Chapter 6: Arrays In this chapter, you will learn about Introduction to Array Array declaration Array initialization Assigning values to array elements Reading values from array elements Simple Searching

More information

Government Polytechnic Muzaffarpur.

Government Polytechnic Muzaffarpur. Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: 1625408 Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking

More information

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array? 1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The

More information

Sorting. Task Description. Selection Sort. Should we worry about speed?

Sorting. Task Description. Selection Sort. Should we worry about speed? Sorting Should we worry about speed? Task Description We have an array of n values in any order We need to have the array sorted in ascending or descending order of values 2 Selection Sort Select the smallest

More information

Quick Sort. CSE Data Structures May 15, 2002

Quick Sort. CSE Data Structures May 15, 2002 Quick Sort CSE 373 - Data Structures May 15, 2002 Readings and References Reading Section 7.7, Data Structures and Algorithm Analysis in C, Weiss Other References C LR 15-May-02 CSE 373 - Data Structures

More information

UNIT 3: ANALYSIS OF SIMPLE ALGORITHMS

UNIT 3: ANALYSIS OF SIMPLE ALGORITHMS UNIT 3: ANALYSIS OF SIMPLE ALGORITHMS Analysis of simple Algorithms Structure Page Nos. 3.0 Introduction 85 3.1 Objective 85 3.2 Euclid Algorithm for GCD 86 3.3 Horner s Rule for Polynomial Evaluation

More information

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function

More information

8.1. Chapter 8: Introduction to Search Algorithms. Linear Search. Linear Search. Linear Search - Example 8/23/2014. Introduction to Search Algorithms

8.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 information

(i) Describe in detail about the classification of computers with their features and limitations(10)

(i) Describe in detail about the classification of computers with their features and limitations(10) UNIT I - INTRODUCTION Generation and Classification of Computers- Basic Organization of a Computer Number System Binary Decimal Conversion Problems. Need for logical analysis and thinking Algorithm Pseudo

More information

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size] (November 10, 2009 2.1 ) Arrays An array is a collection of several elements of the same type. An array variable is declared as type array name[size] I The elements are numbered as 0, 1, 2... size-1 I

More information

Question Bank (SPA SEM II)

Question Bank (SPA SEM II) Question Bank (SPA SEM II) 1. Storage classes in C (Refer notes Page No 52) 2. Difference between function declaration and function definition (This question is solved in the note book). But solution is

More information

Initialisation of an array is the process of assigning initial values. Typically declaration and initialisation are combined.

Initialisation 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 information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer 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 information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 17 EXAMINATION Subject Name: Data Structure Using C Model Answer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as

More information

UNIT III ARRAYS AND STRINGS

UNIT III ARRAYS AND STRINGS UNIT III ARRAYS AND STRINGS Arrays Initialization Declaration One dimensional and Two dimensional arrays. String- String operations String Arrays. Simple programs- sorting- searching matrix operations.

More information

Sorting. There exist sorting algorithms which have shown to be more efficient in practice.

Sorting. There exist sorting algorithms which have shown to be more efficient in practice. Sorting Next to storing and retrieving data, sorting of data is one of the more common algorithmic tasks, with many different ways to perform it. Whenever we perform a web search and/or view statistics

More information

'C' Programming Language

'C' Programming Language F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax

More information

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms Analysis of Algorithms Unit 4 - Analysis of well known Algorithms 1 Analysis of well known Algorithms Brute Force Algorithms Greedy Algorithms Divide and Conquer Algorithms Decrease and Conquer Algorithms

More information

List of Practical for Class XII Computer Science

List of Practical for Class XII Computer Science List of Practical for Class XII Computer Science P.01. Write a complete C++ program to define class Garment with following description: Private members: Code - type string Type - type string Size - type

More information

UNIT-2. Problem of size n. Sub-problem 1 size n/2. Sub-problem 2 size n/2. Solution to the original problem

UNIT-2. Problem of size n. Sub-problem 1 size n/2. Sub-problem 2 size n/2. Solution to the original problem Divide-and-conquer method: Divide-and-conquer is probably the best known general algorithm design technique. The principle behind the Divide-and-conquer algorithm design technique is that it is easier

More information

Algorithm Complexity Analysis: Big-O Notation (Chapter 10.4) Dr. Yingwu Zhu

Algorithm Complexity Analysis: Big-O Notation (Chapter 10.4) Dr. Yingwu Zhu Algorithm Complexity Analysis: Big-O Notation (Chapter 10.4) Dr. Yingwu Zhu Measure Algorithm Efficiency Space utilization: amount of memory required Time efficiency: amount of time required to accomplish

More information

One Dimension Arrays 1

One Dimension Arrays 1 One Dimension Arrays 1 Array n Many applications require multiple data items that have common characteristics In mathematics, we often express such groups of data items in indexed form: n x 1, x 2, x 3,,

More information

Matrices. Jordi Cortadella Department of Computer Science

Matrices. Jordi Cortadella Department of Computer Science Matrices Jordi Cortadella Department of Computer Science Matrices A matrix can be considered a two-dimensional vector, i.e. a vector of vectors. my_matrix: 3 8 1 0 5 0 6 3 7 2 9 4 // Declaration of a matrix

More information

Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013

Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013 Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013 One Dimensional Q1: Write a program that declares two arrays of integers and fills them from the user. Then exchanges their values and display the

More information

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR 603 203 FIRST SEMESTER B.E / B.Tech., (Common to all Branches) QUESTION BANK - GE 6151 COMPUTER PROGRAMMING UNIT I - INTRODUCTION Generation and

More information

ARRAYS(II Unit Part II)

ARRAYS(II Unit Part II) ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful

More information

8/2/10. Looking for something COMP 10 EXPLORING COMPUTER SCIENCE. Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE

8/2/10. Looking for something COMP 10 EXPLORING COMPUTER SCIENCE. Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE Looking for something COMP 10 EXPLORING COMPUTER SCIENCE Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE Searching algorithms Linear search Complexity Sorting algorithms

More information

Attendance (2) Performance (3) Oral (5) Total (10) Dated Sign of Subject Teacher

Attendance (2) Performance (3) Oral (5) Total (10) Dated Sign of Subject Teacher Attendance (2) Performance (3) Oral (5) Total (10) Dated Sign of Subject Teacher Date of Performance:... Actual Date of Completion:... Expected Date of Completion:... ----------------------------------------------------------------------------------------------------------------

More information

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays Prof. Amr Goneid, AUC 1 Arrays Prof. Amr Goneid, AUC 2 1-D Arrays Data Structures The Array Data Type How to Declare

More information

Programming for Engineers Arrays

Programming for Engineers Arrays Programming for Engineers Arrays ICEN 200 Spring 2018 Prof. Dola Saha 1 Array Ø Arrays are data structures consisting of related data items of the same type. Ø A group of contiguous memory locations that

More information

Functions. Arash Rafiey. September 26, 2017

Functions. 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 information

Data Structures and Algorithms for Engineers

Data Structures and Algorithms for Engineers 0-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University

More information

Sorting. Bubble Sort. Pseudo Code for Bubble Sorting: Sorting is ordering a list of elements.

Sorting. Bubble Sort. Pseudo Code for Bubble Sorting: Sorting is ordering a list of elements. Sorting Sorting is ordering a list of elements. Types of sorting: There are many types of algorithms exist based on the following criteria: Based on Complexity Based on Memory usage (Internal & External

More information

g(n) time to computer answer directly from small inputs. f(n) time for dividing P and combining solution to sub problems

g(n) time to computer answer directly from small inputs. f(n) time for dividing P and combining solution to sub problems .2. Divide and Conquer Divide and conquer (D&C) is an important algorithm design paradigm. It works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until

More information

CS11001/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 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 information

UNIT I : OVERVIEW OF COMPUTERS AND C-PROGRAMMING

UNIT I : OVERVIEW OF COMPUTERS AND C-PROGRAMMING SIDDARTHA INSTITUTE OF SCIENCE AND TECHNOLOGY:: PUTTUR Siddharth Nagar, Narayanavanam Road 517583 QUESTION BANK (DESCRIPTIVE) Subject with Code : PROGRAMMING FOR PROBLEM SOLVING (18CS0501) Course & Branch

More information

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal MA 511: Computer Programming Lecture 3: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Last

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

PERFORMANCE OF VARIOUS SORTING AND SEARCHING ALGORITHMS Aarushi Madan Aarusi Tuteja Bharti

PERFORMANCE OF VARIOUS SORTING AND SEARCHING ALGORITHMS Aarushi Madan Aarusi Tuteja Bharti PERFORMANCE OF VARIOUS SORTING AND SEARCHING ALGORITHMS Aarushi Madan Aarusi Tuteja Bharti memory. So for the better performance of an algorithm, time complexity and space complexity has been considered.

More information

Unit-2 Divide and conquer 2016

Unit-2 Divide and conquer 2016 2 Divide and conquer Overview, Structure of divide-and-conquer algorithms, binary search, quick sort, Strassen multiplication. 13% 05 Divide-and- conquer The Divide and Conquer Paradigm, is a method of

More information

Downloaded from

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

F.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 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 information

Logical Coding, algorithms and Data Structures

Logical Coding, algorithms and Data Structures Logical Coding, algorithms and Data Structures Display Pattern. * * * * * 2. 2 3 3 4 4 4 4 4 5 5 5 5 5 3. 4 5 4 5 4 5 4 5 4 5 4. B BBBB C CCCC D DDDD E EEEE 5. B C D E B C D E B C D E B C D E B C D E 6.

More information

Algorithms. Chapter 8. Objectives After studying this chapter, students should be able to:

Algorithms. Chapter 8. Objectives After studying this chapter, students should be able to: Objectives After studying this chapter, students should be able to: Chapter 8 Algorithms Define an algorithm and relate it to problem solving. Define three construct and describe their use in algorithms.

More information

Arrays and Applications

Arrays and Applications Arrays and Applications 60-141: Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2014 Instructor: Dr. Asish Mukhopadhyay What s an array Let a 0, a 1,, a n-1 be a sequence

More information

Sorting. Bringing Order to the World

Sorting. Bringing Order to the World Lecture 10 Sorting Bringing Order to the World Lecture Outline Iterative sorting algorithms (comparison based) Selection Sort Bubble Sort Insertion Sort Recursive sorting algorithms (comparison based)

More information

Q 1. Attempt any TEN of the following:

Q 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

Cpt S 122 Data Structures. Sorting

Cpt S 122 Data Structures. Sorting Cpt S 122 Data Structures Sorting Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Sorting Process of re-arranging data in ascending or descending order Given

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 10: Arrays Readings: Chapter 9 Introduction Group of same type of variables that have same

More information

Chapter 3:- Divide and Conquer. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Chapter 3:- Divide and Conquer. Compiled By:- Sanjay Patel Assistant Professor, SVBIT. Chapter 3:- Divide and Conquer Compiled By:- Assistant Professor, SVBIT. Outline Introduction Multiplying large Integers Problem Problem Solving using divide and conquer algorithm - Binary Search Sorting

More information

O(n): printing a list of n items to the screen, looking at each item once.

O(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 information

CS256 Applied Theory of Computation

CS256 Applied Theory of Computation CS256 Applied Theory of Computation Parallel Computation II John E Savage Overview Mesh-based architectures Hypercubes Embedding meshes in hypercubes Normal algorithms on hypercubes Summing and broadcasting

More information

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

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 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 information

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of

More information

Administrivia. HW on recursive lists due on Wednesday. Reading for Wednesday: Chapter 9 thru Quicksort (pp )

Administrivia. HW on recursive lists due on Wednesday. Reading for Wednesday: Chapter 9 thru Quicksort (pp ) Sorting 4/23/18 Administrivia HW on recursive lists due on Wednesday Reading for Wednesday: Chapter 9 thru Quicksort (pp. 271-284) A common problem: Sorting Have collection of objects (numbers, strings,

More information

Chapter 10 - Notes Applications of Arrays

Chapter 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 information

Code No: R Set No. 1

Code No: R Set No. 1 Code No: R05010106 Set No. 1 1. (a) Draw a Flowchart for the following The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional

More information

PDS Class Test 2. Room Sections No of students

PDS Class Test 2. Room Sections No of students PDS Class Test 2 Date: October 27, 2016 Time: 7pm to 8pm Marks: 20 (Weightage 50%) Room Sections No of students V1 Section 8 (All) Section 9 (AE,AG,BT,CE, CH,CS,CY,EC,EE,EX) V2 Section 9 (Rest, if not

More information

LECTURE 08 SEARCHING AND SORTING ARRAYS

LECTURE 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 information

Maltepe 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 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 information

Introduction to string

Introduction to string 1 Introduction to string String is a sequence of characters enclosed in double quotes. Normally, it is used for storing data like name, address, city etc. ASCII code is internally used to represent string

More information

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types

More information

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos.

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos. UNIT 2 ARRAYS Arrays Structure Page Nos. 2.0 Introduction 23 2.1 Objectives 24 2.2 Arrays and Pointers 24 2.3 Sparse Matrices 25 2.4 Polynomials 28 2.5 Representation of Arrays 30 2.5.1 Row Major Representation

More information

Computers Programming Course 11. Iulian Năstac

Computers Programming Course 11. Iulian Năstac Computers Programming Course 11 Iulian Năstac Recap from previous course Cap. Matrices (Arrays) Matrix representation is a method used by a computer language to store matrices of different dimension in

More information

Searching 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 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 information

String can be represented as a single-dimensional character type array. Declaration of strings

String can be represented as a single-dimensional character type array. Declaration of strings String String is the collection of characters. An array of characters. String can be represented as a single-dimensional character type array. Declaration of strings char string-name[size]; char address[25];

More information

CS 261 Data Structures. Big-Oh Analysis: A Review

CS 261 Data Structures. Big-Oh Analysis: A Review CS 261 Data Structures Big-Oh Analysis: A Review Big-Oh: Purpose How can we characterize the runtime or space usage of an algorithm? We want a method that: doesn t depend upon hardware used (e.g., PC,

More information

Arrays. Dr. Madhumita Sengupta. Assistant Professor IIIT Kalyani

Arrays. Dr. Madhumita Sengupta. Assistant Professor IIIT Kalyani Arrays Dr. Madhumita Sengupta Assistant Professor IIIT Kalyani INTRODUCTION An array is a collection of similar data s / data types. The s of the array are stored in consecutive memory locations and are

More information

Computer Science 4U Unit 1. Programming Concepts and Skills Algorithms

Computer Science 4U Unit 1. Programming Concepts and Skills Algorithms Computer Science 4U Unit 1 Programming Concepts and Skills Algorithms Algorithm In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation,

More information

CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings

CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Pointer Arithmetic and Element

More information