The document discusses arrays in C programming. It defines key concepts like array representation, index starting from 0, memory representation of arrays, and address calculation of array elements. It also covers various array operations like creation, copying, deletion, insertion, sorting, and representation of arrays as abstract data types. Multidimensional arrays and their row-major and column-major representations are explained along with examples.
The document discusses arrays in C programming. It defines arrays as a collection of similar data types stored in contiguous memory locations and accessed using indexes. It describes how to declare, initialize, access, and manipulate single and multi-dimensional arrays. It also covers passing arrays to functions, array addressing and calculations, and merging two sorted arrays.
Two dimensional arrays allow the storage of tables of values arranged in rows and columns. They are declared with the general form type array_name[row_size][column_size]. Elements are accessed using two indices, the first for the row and second for the column. Elements are stored in memory in row-major order, with contiguous blocks for each row. Dynamic allocation of 2D arrays involves allocating an array of pointers, with each pointer storing the address of a dynamically allocated 1D array for that row.
This document discusses arrays in C programming. It defines an array as a collection of variables of the same type that are referenced by a common name. It describes single-dimensional and multi-dimensional arrays. Single-dimensional arrays are comprised of finite, homogeneous elements while multi-dimensional arrays have elements that are themselves arrays. The document provides examples of declaring, initializing, accessing, and implementing arrays in memory for both single and double-dimensional arrays. It includes sample programs demonstrating various array operations.
The document discusses various linear data structures like arrays, strings, stacks, queues, and linked lists. It provides details on representing single and multi-dimensional arrays, including addressing formulas. Operations on ordered lists like lists are defined. Linear lists using arrays are implemented with methods for adding, removing, and changing elements.
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
The document discusses arrays in C programming. Some key points include:
- An array is a collection of variables of the same type referred to by a common name. Each element has an index and arrays use contiguous memory locations.
- Arrays are declared with the type, name, and size. The first element is at index 0.
- One-dimensional arrays can be initialized, accessed, input from and output to the user. Multidimensional arrays like 2D arrays represent tables with rows and columns.
- Arrays can be passed to functions by passing the entire array or individual elements. Operations like searching, sorting and merging can be performed on arrays.
An array is a collection of similar elements that are stored in contiguous memory locations. Arrays in C can have one or more dimensions. One-dimensional arrays are declared with the type of elements, name of the array, and number of elements within brackets (e.g. int marks[30]). Multi-dimensional arrays represent matrices and are declared with the number of rows and columns (e.g. int arr[5][10]). Individual elements within an array are accessed via indices (e.g. arr[2][7]). Pointers in C are related to arrays - the name of an array represents the address of its first element, and pointer arithmetic can be used to access successive elements in an array.
The document discusses linear data structures using sequential organization. It begins by defining sequential access and linear data structures. Linear data structures traverse elements sequentially, with direct access to only one element. Examples given are arrays and linked lists. The document then focuses on arrays, providing definitions and discussing array representation in memory, basic array operations like traversal and searching, and multi-dimensional arrays. Two-dimensional and three-dimensional arrays are explained with examples.
The document discusses arrays in C programming. It defines arrays as a collection of similar data types stored in contiguous memory locations and accessed using indexes. It describes how to declare, initialize, access, and manipulate single and multi-dimensional arrays. It also covers passing arrays to functions, array addressing and calculations, and merging two sorted arrays.
Two dimensional arrays allow the storage of tables of values arranged in rows and columns. They are declared with the general form type array_name[row_size][column_size]. Elements are accessed using two indices, the first for the row and second for the column. Elements are stored in memory in row-major order, with contiguous blocks for each row. Dynamic allocation of 2D arrays involves allocating an array of pointers, with each pointer storing the address of a dynamically allocated 1D array for that row.
This document discusses arrays in C programming. It defines an array as a collection of variables of the same type that are referenced by a common name. It describes single-dimensional and multi-dimensional arrays. Single-dimensional arrays are comprised of finite, homogeneous elements while multi-dimensional arrays have elements that are themselves arrays. The document provides examples of declaring, initializing, accessing, and implementing arrays in memory for both single and double-dimensional arrays. It includes sample programs demonstrating various array operations.
The document discusses various linear data structures like arrays, strings, stacks, queues, and linked lists. It provides details on representing single and multi-dimensional arrays, including addressing formulas. Operations on ordered lists like lists are defined. Linear lists using arrays are implemented with methods for adding, removing, and changing elements.
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
The document discusses arrays in C programming. Some key points include:
- An array is a collection of variables of the same type referred to by a common name. Each element has an index and arrays use contiguous memory locations.
- Arrays are declared with the type, name, and size. The first element is at index 0.
- One-dimensional arrays can be initialized, accessed, input from and output to the user. Multidimensional arrays like 2D arrays represent tables with rows and columns.
- Arrays can be passed to functions by passing the entire array or individual elements. Operations like searching, sorting and merging can be performed on arrays.
An array is a collection of similar elements that are stored in contiguous memory locations. Arrays in C can have one or more dimensions. One-dimensional arrays are declared with the type of elements, name of the array, and number of elements within brackets (e.g. int marks[30]). Multi-dimensional arrays represent matrices and are declared with the number of rows and columns (e.g. int arr[5][10]). Individual elements within an array are accessed via indices (e.g. arr[2][7]). Pointers in C are related to arrays - the name of an array represents the address of its first element, and pointer arithmetic can be used to access successive elements in an array.
The document discusses linear data structures using sequential organization. It begins by defining sequential access and linear data structures. Linear data structures traverse elements sequentially, with direct access to only one element. Examples given are arrays and linked lists. The document then focuses on arrays, providing definitions and discussing array representation in memory, basic array operations like traversal and searching, and multi-dimensional arrays. Two-dimensional and three-dimensional arrays are explained with examples.
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDev Chauhan
Arrays, stacks, queues, and linked lists are common data structures in computer science. Arrays allow direct access to elements but have fixed size, while linked lists can dynamically grow and shrink but require traversing nodes sequentially. Stacks follow LIFO (last in first out) and queues follow FIFO (first in first out) ordering for inserting and removing elements. Linked lists store data in nodes that link to the next node, allowing efficient insertion/removal anywhere in the list. Common operations on these structures include push/pop for stacks, enqueue/dequeue for queues, and insert/delete nodes for linked lists.
computer dataA computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. A computer system is a nominally complete computer that includes the hardware, operating system (main software), and peripheral equipment needed and used for full operation. This term may also refer to a group of computers that are linked and function together, such as a computer network or computer cluster.
A broad range of industrial and consumer products use computers as control systems. Simple special-purpose devices like microwave ovens and remote controls are included, as are factory devices like industrial robots and computer-aided design, as well as general-purpose devices like personal computers and mobile devices like smartphones. Computers power the Internet, which links billions of other computers and users.
Early computers were meant to be used only for calculations. Simple manual instruments like the abacus have aided people in doing calculations since ancient times. Early in the Industrial Revolution, some mechanical devices were built to automate long, tedious tasks, such as guiding patterns for looms. More sophisticated electrical machines did specialized analog calculations in the early 20th century. The first digital electronic calculating machines were developed during World War II. The first semiconductor transistors in the late 1940s were followed by the silicon-based MOSFET (MOS transistor) and monolithic integrated circuit chip technologies in the late 1950s, leading to the microprocessor and the microcomputer revolution in the 1970s. The speed, power and versatility of computers have been increasing dramatically ever since then, with transistor counts increasing at a rapid pace (as predicted by Moore's law), leading to the Digital Revolution during the late 20th to early 21st centuries.
This document discusses 1-dimensional arrays in C. It explains that arrays allow storing multiple values of the same type using a single name. Elements in an array are accessed using an index from 0 to size-1. Arrays can be initialized, read from using a for loop and scanf, printed using printf, and manipulated using operations on individual elements. Examples demonstrate finding the minimum, computing GPA with two parallel arrays, binary search, and selection sort of an array. Character arrays can represent strings by storing characters and terminating with a null character.
An array is a collection of homogeneous data items stored in successive memory locations. It allows storing multiple elements of the same type using a single name. Elements in an array can be accessed using the array name and index number. Common operations on arrays include storing/retrieving elements, searching for a particular element or largest/smallest element, and calculating sum of elements based on certain criteria like even/odd indexing. Arrays can also be modified by inserting or deleting elements.
A one-dimensional array stores elements linearly such that they can be accessed using an index, the document provides an example of finding the address of an element in a 1D array and taking user input to store in an array and display all elements, and abstract data types provide only the interface of a data structure without implementation details.
The document discusses arrays and strings in C programming. It covers key topics like:
- Declaring and initializing arrays and accessing array elements. Arrays have 0 as the first index.
- Difference between initialization and assignment of arrays. Arrays cannot be assigned.
- String arrays which are arrays of characters terminated by a null character.
- Common string functions like strcpy(), strcat(), strlen(), strcmp() etc.
- Two dimensional arrays and how elements are stored in row major order in contiguous memory.
- Examples of declaring, initializing and accessing 2D arrays.
The document discusses arrays in C programming. Some key points:
- An array is a collection of similar data elements that are stored in consecutive memory locations and referenced using an index.
- To declare an array, you specify the data type, name, and maximum size. Arrays allow storing and accessing elements using indexes.
- Common array operations include initializing elements, accessing elements using loops, calculating element addresses, inserting/deleting elements, and performing searches like linear and binary search.
- Multidimensional arrays like 2D arrays use multiple indexes to access elements and can be stored in memory in row-major or column-major order.
A two dimensional array is an array that has two dimensions like rows and columns. The total number of elements in a two dimensional array is calculated by multiplying the number of rows and columns. A two dimensional array can be accessed using two indices like A[i][j] where i represents the row and j represents the column. Common operations on two dimensional arrays include storing and retrieving elements, finding the sum of boundary elements, finding the sum of diagonal elements, adding, subtracting and multiplying two dimensional arrays.
The document provides examples of basic C programs that demonstrate fundamental programming concepts like printing values, arithmetic operations, arrays, functions, conditionals, loops, and matrices. The programs cover topics such as printing and reading integers, adding/multiplying numbers, swapping values, checking vowels/consonants, Armstrong numbers, palindromes, summing matrices, and finding the transpose of a matrix.
The document discusses arrays in C programming language. It defines arrays as fixed-sized sequenced collections of elements of the same data type that share a common name. One-dimensional arrays represent lists, while two-dimensional arrays represent tables with rows and columns. Arrays must be declared before use with the size specified. Elements can be accessed using indices and initialized. Common operations like input, output, sorting and searching of array elements are demonstrated through examples.
The document discusses multidimensional arrays in C, including two-dimensional and three-dimensional arrays. It explains the syntax for declaring multidimensional arrays and how they are logically and physically stored in memory as one-dimensional arrays. The document also covers passing multidimensional arrays to functions, including type conversions, and initializing multidimensional arrays.
The document provides information about arrays, strings, and character handling functions in C language. It discusses:
1. Definitions and properties of arrays, including declaring, initializing, and accessing single and multi-dimensional arrays.
2. Built-in functions for testing and mapping characters from the ctype.h library, including isalnum(), isalpha(), iscntrl(), isdigit(), ispunct(), and isspace().
3. Strings in C being arrays of characters terminated by a null character. It discusses common string handling functions from string.h like strlen(), strrev(), strlwr(), strupr(), strcpy(), strcat(), and strcmp().
Basic of array and data structure, data structure basics, array, address calc...nsitlokeshjain
The document discusses different data structures and algorithms. It defines data structures as ways to store and organize data, mentioning linear structures like arrays and linked lists, and non-linear structures like trees and graphs. It also discusses abstract data types, arrays, sorting algorithms like bubble sort, and searching algorithms like linear and binary search. Key operations and their implementations are provided for each concept through definitions, examples and pseudocode.
Arrays are data structures that store a collection of data values of the same type in consecutive memory locations that can be individually referenced by their numeric index. Different representations of arrays are possible including using a single block of memory or a collection of elements. Common operations on arrays include retrieving or storing elements by their index and traversing the entire array sequentially.
The document provides examples of C++ functions that accept integer arrays as arguments and rearrange or modify the elements in various ways. One function converts a 1D array into a 2D array by assigning elements to rows and columns. Another replaces even elements with half their value and odd elements with double their value. A third swaps elements of even and odd indices. The examples demonstrate functions that rearrange arrays in reverse order or sort structures by a field using bubble sort.
Arrays allow storing and manipulating a collection of related data elements. They can hold groups of integers, characters, or other data types. Declaring individual variables becomes difficult when storing many elements, so arrays provide an efficient solution. Arrays are declared with a datatype and size, and elements can be initialized, accessed, inserted, deleted, and manipulated using their index positions. Common array operations include displaying values, finding maximum/minimum values, calculating sums, and passing arrays to functions. Multi-dimensional arrays extend the concept to store elements in a table structure accessed by row and column indexes.
The document provides solutions to various problems involving 1D arrays in C and Python. It includes programs to:
1. Reverse the elements of an array
2. Determine if an array contains all even, odd, or mixed elements
3. Count the number of even and odd elements in an array
4. Check if two arrays are equal
5. Find the sum of perfect square elements in an array
6. Find the minimum scalar product of two vectors
7. Find the smallest and largest elements in an array
8. Print all distinct elements in an array
9. Check if two arrays are disjoint
For each problem, it provides the algorithm, C and Python solutions, sample input/output,
International Conference on NLP, Artificial Intelligence, Machine Learning an...gerogepatton
International Conference on NLP, Artificial Intelligence, Machine Learning and Applications (NLAIM 2024) offers a premier global platform for exchanging insights and findings in the theory, methodology, and applications of NLP, Artificial Intelligence, Machine Learning, and their applications. The conference seeks substantial contributions across all key domains of NLP, Artificial Intelligence, Machine Learning, and their practical applications, aiming to foster both theoretical advancements and real-world implementations. With a focus on facilitating collaboration between researchers and practitioners from academia and industry, the conference serves as a nexus for sharing the latest developments in the field.
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...University of Maribor
Slides from talk presenting:
Aleš Zamuda: Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapter and Networking.
Presentation at IcETRAN 2024 session:
"Inter-Society Networking Panel GRSS/MTT-S/CIS
Panel Session: Promoting Connection and Cooperation"
IEEE Slovenia GRSS
IEEE Serbia and Montenegro MTT-S
IEEE Slovenia CIS
11TH INTERNATIONAL CONFERENCE ON ELECTRICAL, ELECTRONIC AND COMPUTING ENGINEERING
3-6 June 2024, Niš, Serbia
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDev Chauhan
Arrays, stacks, queues, and linked lists are common data structures in computer science. Arrays allow direct access to elements but have fixed size, while linked lists can dynamically grow and shrink but require traversing nodes sequentially. Stacks follow LIFO (last in first out) and queues follow FIFO (first in first out) ordering for inserting and removing elements. Linked lists store data in nodes that link to the next node, allowing efficient insertion/removal anywhere in the list. Common operations on these structures include push/pop for stacks, enqueue/dequeue for queues, and insert/delete nodes for linked lists.
computer dataA computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. A computer system is a nominally complete computer that includes the hardware, operating system (main software), and peripheral equipment needed and used for full operation. This term may also refer to a group of computers that are linked and function together, such as a computer network or computer cluster.
A broad range of industrial and consumer products use computers as control systems. Simple special-purpose devices like microwave ovens and remote controls are included, as are factory devices like industrial robots and computer-aided design, as well as general-purpose devices like personal computers and mobile devices like smartphones. Computers power the Internet, which links billions of other computers and users.
Early computers were meant to be used only for calculations. Simple manual instruments like the abacus have aided people in doing calculations since ancient times. Early in the Industrial Revolution, some mechanical devices were built to automate long, tedious tasks, such as guiding patterns for looms. More sophisticated electrical machines did specialized analog calculations in the early 20th century. The first digital electronic calculating machines were developed during World War II. The first semiconductor transistors in the late 1940s were followed by the silicon-based MOSFET (MOS transistor) and monolithic integrated circuit chip technologies in the late 1950s, leading to the microprocessor and the microcomputer revolution in the 1970s. The speed, power and versatility of computers have been increasing dramatically ever since then, with transistor counts increasing at a rapid pace (as predicted by Moore's law), leading to the Digital Revolution during the late 20th to early 21st centuries.
This document discusses 1-dimensional arrays in C. It explains that arrays allow storing multiple values of the same type using a single name. Elements in an array are accessed using an index from 0 to size-1. Arrays can be initialized, read from using a for loop and scanf, printed using printf, and manipulated using operations on individual elements. Examples demonstrate finding the minimum, computing GPA with two parallel arrays, binary search, and selection sort of an array. Character arrays can represent strings by storing characters and terminating with a null character.
An array is a collection of homogeneous data items stored in successive memory locations. It allows storing multiple elements of the same type using a single name. Elements in an array can be accessed using the array name and index number. Common operations on arrays include storing/retrieving elements, searching for a particular element or largest/smallest element, and calculating sum of elements based on certain criteria like even/odd indexing. Arrays can also be modified by inserting or deleting elements.
A one-dimensional array stores elements linearly such that they can be accessed using an index, the document provides an example of finding the address of an element in a 1D array and taking user input to store in an array and display all elements, and abstract data types provide only the interface of a data structure without implementation details.
The document discusses arrays and strings in C programming. It covers key topics like:
- Declaring and initializing arrays and accessing array elements. Arrays have 0 as the first index.
- Difference between initialization and assignment of arrays. Arrays cannot be assigned.
- String arrays which are arrays of characters terminated by a null character.
- Common string functions like strcpy(), strcat(), strlen(), strcmp() etc.
- Two dimensional arrays and how elements are stored in row major order in contiguous memory.
- Examples of declaring, initializing and accessing 2D arrays.
The document discusses arrays in C programming. Some key points:
- An array is a collection of similar data elements that are stored in consecutive memory locations and referenced using an index.
- To declare an array, you specify the data type, name, and maximum size. Arrays allow storing and accessing elements using indexes.
- Common array operations include initializing elements, accessing elements using loops, calculating element addresses, inserting/deleting elements, and performing searches like linear and binary search.
- Multidimensional arrays like 2D arrays use multiple indexes to access elements and can be stored in memory in row-major or column-major order.
A two dimensional array is an array that has two dimensions like rows and columns. The total number of elements in a two dimensional array is calculated by multiplying the number of rows and columns. A two dimensional array can be accessed using two indices like A[i][j] where i represents the row and j represents the column. Common operations on two dimensional arrays include storing and retrieving elements, finding the sum of boundary elements, finding the sum of diagonal elements, adding, subtracting and multiplying two dimensional arrays.
The document provides examples of basic C programs that demonstrate fundamental programming concepts like printing values, arithmetic operations, arrays, functions, conditionals, loops, and matrices. The programs cover topics such as printing and reading integers, adding/multiplying numbers, swapping values, checking vowels/consonants, Armstrong numbers, palindromes, summing matrices, and finding the transpose of a matrix.
The document discusses arrays in C programming language. It defines arrays as fixed-sized sequenced collections of elements of the same data type that share a common name. One-dimensional arrays represent lists, while two-dimensional arrays represent tables with rows and columns. Arrays must be declared before use with the size specified. Elements can be accessed using indices and initialized. Common operations like input, output, sorting and searching of array elements are demonstrated through examples.
The document discusses multidimensional arrays in C, including two-dimensional and three-dimensional arrays. It explains the syntax for declaring multidimensional arrays and how they are logically and physically stored in memory as one-dimensional arrays. The document also covers passing multidimensional arrays to functions, including type conversions, and initializing multidimensional arrays.
The document provides information about arrays, strings, and character handling functions in C language. It discusses:
1. Definitions and properties of arrays, including declaring, initializing, and accessing single and multi-dimensional arrays.
2. Built-in functions for testing and mapping characters from the ctype.h library, including isalnum(), isalpha(), iscntrl(), isdigit(), ispunct(), and isspace().
3. Strings in C being arrays of characters terminated by a null character. It discusses common string handling functions from string.h like strlen(), strrev(), strlwr(), strupr(), strcpy(), strcat(), and strcmp().
Basic of array and data structure, data structure basics, array, address calc...nsitlokeshjain
The document discusses different data structures and algorithms. It defines data structures as ways to store and organize data, mentioning linear structures like arrays and linked lists, and non-linear structures like trees and graphs. It also discusses abstract data types, arrays, sorting algorithms like bubble sort, and searching algorithms like linear and binary search. Key operations and their implementations are provided for each concept through definitions, examples and pseudocode.
Arrays are data structures that store a collection of data values of the same type in consecutive memory locations that can be individually referenced by their numeric index. Different representations of arrays are possible including using a single block of memory or a collection of elements. Common operations on arrays include retrieving or storing elements by their index and traversing the entire array sequentially.
The document provides examples of C++ functions that accept integer arrays as arguments and rearrange or modify the elements in various ways. One function converts a 1D array into a 2D array by assigning elements to rows and columns. Another replaces even elements with half their value and odd elements with double their value. A third swaps elements of even and odd indices. The examples demonstrate functions that rearrange arrays in reverse order or sort structures by a field using bubble sort.
Arrays allow storing and manipulating a collection of related data elements. They can hold groups of integers, characters, or other data types. Declaring individual variables becomes difficult when storing many elements, so arrays provide an efficient solution. Arrays are declared with a datatype and size, and elements can be initialized, accessed, inserted, deleted, and manipulated using their index positions. Common array operations include displaying values, finding maximum/minimum values, calculating sums, and passing arrays to functions. Multi-dimensional arrays extend the concept to store elements in a table structure accessed by row and column indexes.
The document provides solutions to various problems involving 1D arrays in C and Python. It includes programs to:
1. Reverse the elements of an array
2. Determine if an array contains all even, odd, or mixed elements
3. Count the number of even and odd elements in an array
4. Check if two arrays are equal
5. Find the sum of perfect square elements in an array
6. Find the minimum scalar product of two vectors
7. Find the smallest and largest elements in an array
8. Print all distinct elements in an array
9. Check if two arrays are disjoint
For each problem, it provides the algorithm, C and Python solutions, sample input/output,
International Conference on NLP, Artificial Intelligence, Machine Learning an...gerogepatton
International Conference on NLP, Artificial Intelligence, Machine Learning and Applications (NLAIM 2024) offers a premier global platform for exchanging insights and findings in the theory, methodology, and applications of NLP, Artificial Intelligence, Machine Learning, and their applications. The conference seeks substantial contributions across all key domains of NLP, Artificial Intelligence, Machine Learning, and their practical applications, aiming to foster both theoretical advancements and real-world implementations. With a focus on facilitating collaboration between researchers and practitioners from academia and industry, the conference serves as a nexus for sharing the latest developments in the field.
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...University of Maribor
Slides from talk presenting:
Aleš Zamuda: Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapter and Networking.
Presentation at IcETRAN 2024 session:
"Inter-Society Networking Panel GRSS/MTT-S/CIS
Panel Session: Promoting Connection and Cooperation"
IEEE Slovenia GRSS
IEEE Serbia and Montenegro MTT-S
IEEE Slovenia CIS
11TH INTERNATIONAL CONFERENCE ON ELECTRICAL, ELECTRONIC AND COMPUTING ENGINEERING
3-6 June 2024, Niš, Serbia
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...IJECEIAES
Medical image analysis has witnessed significant advancements with deep learning techniques. In the domain of brain tumor segmentation, the ability to
precisely delineate tumor boundaries from magnetic resonance imaging (MRI)
scans holds profound implications for diagnosis. This study presents an ensemble convolutional neural network (CNN) with transfer learning, integrating
the state-of-the-art Deeplabv3+ architecture with the ResNet18 backbone. The
model is rigorously trained and evaluated, exhibiting remarkable performance
metrics, including an impressive global accuracy of 99.286%, a high-class accuracy of 82.191%, a mean intersection over union (IoU) of 79.900%, a weighted
IoU of 98.620%, and a Boundary F1 (BF) score of 83.303%. Notably, a detailed comparative analysis with existing methods showcases the superiority of
our proposed model. These findings underscore the model’s competence in precise brain tumor localization, underscoring its potential to revolutionize medical
image analysis and enhance healthcare outcomes. This research paves the way
for future exploration and optimization of advanced CNN models in medical
imaging, emphasizing addressing false positives and resource efficiency.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...IJECEIAES
Climate change's impact on the planet forced the United Nations and governments to promote green energies and electric transportation. The deployments of photovoltaic (PV) and electric vehicle (EV) systems gained stronger momentum due to their numerous advantages over fossil fuel types. The advantages go beyond sustainability to reach financial support and stability. The work in this paper introduces the hybrid system between PV and EV to support industrial and commercial plants. This paper covers the theoretical framework of the proposed hybrid system including the required equation to complete the cost analysis when PV and EV are present. In addition, the proposed design diagram which sets the priorities and requirements of the system is presented. The proposed approach allows setup to advance their power stability, especially during power outages. The presented information supports researchers and plant owners to complete the necessary analysis while promoting the deployment of clean energy. The result of a case study that represents a dairy milk farmer supports the theoretical works and highlights its advanced benefits to existing plants. The short return on investment of the proposed approach supports the paper's novelty approach for the sustainable electrical system. In addition, the proposed system allows for an isolated power setup without the need for a transmission line which enhances the safety of the electrical network
Understanding Inductive Bias in Machine LearningSUTEJAS
This presentation explores the concept of inductive bias in machine learning. It explains how algorithms come with built-in assumptions and preferences that guide the learning process. You'll learn about the different types of inductive bias and how they can impact the performance and generalizability of machine learning models.
The presentation also covers the positive and negative aspects of inductive bias, along with strategies for mitigating potential drawbacks. We'll explore examples of how bias manifests in algorithms like neural networks and decision trees.
By understanding inductive bias, you can gain valuable insights into how machine learning models work and make informed decisions when building and deploying them.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSIJNSA Journal
The smart irrigation system represents an innovative approach to optimize water usage in agricultural and landscaping practices. The integration of cutting-edge technologies, including sensors, actuators, and data analysis, empowers this system to provide accurate monitoring and control of irrigation processes by leveraging real-time environmental conditions. The main objective of a smart irrigation system is to optimize water efficiency, minimize expenses, and foster the adoption of sustainable water management methods. This paper conducts a systematic risk assessment by exploring the key components/assets and their functionalities in the smart irrigation system. The crucial role of sensors in gathering data on soil moisture, weather patterns, and plant well-being is emphasized in this system. These sensors enable intelligent decision-making in irrigation scheduling and water distribution, leading to enhanced water efficiency and sustainable water management practices. Actuators enable automated control of irrigation devices, ensuring precise and targeted water delivery to plants. Additionally, the paper addresses the potential threat and vulnerabilities associated with smart irrigation systems. It discusses limitations of the system, such as power constraints and computational capabilities, and calculates the potential security risks. The paper suggests possible risk treatment methods for effective secure system operation. In conclusion, the paper emphasizes the significant benefits of implementing smart irrigation systems, including improved water conservation, increased crop yield, and reduced environmental impact. Additionally, based on the security analysis conducted, the paper recommends the implementation of countermeasures and security approaches to address vulnerabilities and ensure the integrity and reliability of the system. By incorporating these measures, smart irrigation technology can revolutionize water management practices in agriculture, promoting sustainability, resource efficiency, and safeguarding against potential security threats.
Comparative analysis between traditional aquaponics and reconstructed aquapon...bijceesjournal
The aquaponic system of planting is a method that does not require soil usage. It is a method that only needs water, fish, lava rocks (a substitute for soil), and plants. Aquaponic systems are sustainable and environmentally friendly. Its use not only helps to plant in small spaces but also helps reduce artificial chemical use and minimizes excess water use, as aquaponics consumes 90% less water than soil-based gardening. The study applied a descriptive and experimental design to assess and compare conventional and reconstructed aquaponic methods for reproducing tomatoes. The researchers created an observation checklist to determine the significant factors of the study. The study aims to determine the significant difference between traditional aquaponics and reconstructed aquaponics systems propagating tomatoes in terms of height, weight, girth, and number of fruits. The reconstructed aquaponics system’s higher growth yield results in a much more nourished crop than the traditional aquaponics system. It is superior in its number of fruits, height, weight, and girth measurement. Moreover, the reconstructed aquaponics system is proven to eliminate all the hindrances present in the traditional aquaponics system, which are overcrowding of fish, algae growth, pest problems, contaminated water, and dead fish.
5. ARRAY
5
• Array Representation
• Index starts with 0.
• Array length is 10 which means it can store 10 elements.
• Each element can be accessed via its index. For example, we
can fetch an element at index 6 as 9.
8. The address of the ith element is calculated by the
following formula
(Base address) + (offset of the ith element from base
address)
Here, base address is the address of the first element
where array storage starts.
Address calculation of 1-D array
Address of arr[i]=base address+ i* element_size
Address of percentage[3]
= 3 * sizeof(float)
= 3000+3*4
=3012
ADDRESS CALCULATION
. 8 8
2
9. • CREATE()-produces empty array.
• RETRIVE(array,index)->value
Takes as input array and index and either returns
appropriate value or an error.
• STORE(array,index,value)-array used to enter new index
value pairs.
ADT FOR AN ARRAY
10. Representation and analysis
Type variable_name[size]
Operations with arrays:
Create
Copy
Delete
Insert
Search
Sort
Merging of sorting arrays.
INTRODUCTION TO ARRAYS
11. CREATE OPERATION
#include <stdio.h>
int main()
{
int a[100],b[100]; // declaration of array
int position, c ,n;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d", &a[c]);// accepting an array element
printf("Enter %d elementsn", n);
for( c = 0 ; c < n ; c++ )
printf("%dn", a[c]); // printing an array element
}
12. COPY OPERATION
#include <stdio.h>
int main()
{
int a[100],b[100] position, c n;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d", &a[c]);
printf("Enter %d elementsn", n);
for( c = 0 ; c < n 1 ; c++ )
printf("%dn", a[c]);
//Coping the element of array a to b
for( c = 0 ; c < n ; c++ )
{
b[c]=a[c];
}
printf("Enter %d elementsn", n);
for( c = 0 ; c < n 1 ; c++ )
printf("%dn", b[c]);
}
13. OUTPUT
•
Enter number of elements in array 4
Enter4 elements
1
2
3
4
displaying array a
1
2
3
4
displaying array b
1
2
3
4
•
14. DELETE OPERATION
#include <stdio.h>
int main()
{
int array[100], position, i, n;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for ( i = 0 ; i < n ; i++ )
scanf("%d", &array[i]);
printf("Enter the location where you wish to delete elementn");
scanf("%d", &position);
for ( i = position ; i < n; i++ )
{
array[i] = array[i+1]; // moving one element ahead
}
printf("Resultant array isn");
for( i = 0 ; i < n-1 ; i++ )
printf("%dn", array[i]);
return 0;}
16. #include <stdio.h>
int main()
{
int array[100], position, i, n, value;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for (i= 0;i< n; i++)
scanf("%d", &array[i]);
printf("Enter the location where you wish to insert an elementn");
scanf("%d", &position);
printf("Enter the value to insertn");
scanf("%d", &value);
for (i = n - 1; i >= position ; i--)
array[i+1] = array[i];
array[position] = value;
printf("Resultant array isn");
for (i= 0; i <= n; i++)
printf("%dn", array[i]);
return 0; }
INSERTING AN ELEMENT
19. REVERSE ARRAY
#include <stdio.h>
int main() {
int array[100], n, i, temp, end;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
end = n - 1;
for (i = 0; i < n; i++) {
scanf("%d", &array[i]);
}
for (i= 0; i< n/2; i++)
{
temp = array[i];
array[i] = array[end];
array[end] = temp;
end--;
}
printf("Reversed array elements are:n"); for ( i= 0; i < n;
i++)
{
printf("%dn", array[i]);
}
return 0;
}
22. ROWS
N-NO OF
COLUMNS
Printf(“n Enter the rows and columns”);
Scanf(%d %d”,&m,&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
Printf(“n Enter the value of(%d)(%d)=“,i,j);
Scanf(“%d”,&a[i][j]);
}
}
24. Formally ADT is a collection of domain, operations,and
axioms (orrules)
Fordefining an arrayas an ADT, we have todefine its very
basic operations or functions that can be performed on it
The basic operations of arrays are creation of an array,
storing an element, accessing an element, and traversing
thearray
2
6
ARRAY AS AN ADT
. 26
25. List of operation on Array :-
1. Inserting an element into an array
2. deleting element from array
3. searching an element from array
4. sorting the array element
.
27
30. The address of A[i][j][k] is computedas
Addrof A[i][j][k] = X + i * m2 * m3 + j * m3 + k
By generalizing this we get the address of A[i1][i2][i3] … [ in] in n-
dimensional array A[m1][m2][m3]. ….[ mn]
Consider the address of A [0][0][0]…..[0] is X then the address of A
[i][0][0]….[0] = X + (i1 * m2 * m3 * - - -- - * mn )and
Address of A [i1][i2] …. [0] = X + (i1 * m2 * m3 * - -- - *mn ) + (i2 *
m3 * m4 *--- * mn)
Continuing in a similar way, address of A[i1][i2][i3]- - - -[ in] willbe
Address of A[i1][i2][i3]----[ in] = X + (i1 * m2 * m3 * - - -- - * mn) +
(i2 * m3 * m4 *--- - - * mn )+(i3 * m4 * m5--- * mn + (i4 * m5 * m6--
- - - * mn +…….+ in =
.
32
31. EX-ARRAYS
#include <stdio.h>
int main ()
{
int a[10],i,size;
printf(“nhow many no of elements u want to scan”);
scanf(“%d”,&size);
printf(“nEnter the elements in the array”);
for(i=0;i<size;i++)
{
scanf(“%d”,&a[i]);
} //end for
for(i=0;i<size;i++)
{
printf(“The array is %d”,a[i]); //DisplayingArray
} //end for
return 0;
36. HOW TO INITIALIZE 2-D
ARRAY IN PROGRAM
• Initializing Two-DimensionalArrays
int a[3][4] = { {0, 1, 2, 3} , /* initializers for
{4, 5, 6, 7} ,
{8, 9, 10, 11} /* initializers for row
/* initializers for row indexed by 2 */ };
38. THREE-DIMENSIONAL
ARRAYS IN C
• For example, the following declaration creates a three
dimensional integer array −
• Ex-int threedim[5][10][4];
39. Arrays support various operations such as
traversal, sorting, searching, insertion,
deletion, merging, block movement, etc.
Insertion of an element into an array
Deleting anelement
Memory Representation of Two-DimensionalArrays
.
THE CLASS ARRAY
41
44. The address of the element of the ith row and the jth column for matrix of
size m x n can be calculated as:
Addr(A[i][j]) = Base Address+ Offset = Base Address + (number
of rows placed before ith row * size of row) * (Size of Element) +
(number of elements placed before in jth element in ith row)*
size of element
As row indexing starts from 0, i indicate number of rows before the
ith row hereand similarly for j.
For Element Size = 1 the address is
Address of A[i][j]= Base + (i * n ) +j
.
46
45. In general,
Addr[i][j] = ((i–LB1) * (UB2 – LB2 + 1) * size) + ((j– LB2) * size)
where number of rows placed before ith row = (i –LB1)
where LB1 is the lower bound of the firstdimension.
Size of row = (number of elements in row) * (size of
element)Memory Locations
The number of elements in arow = (UB2 – LB2 + 1)
where UB2 and LB2 are upper and lower bounds of the
second dimension.
.
47
46. COLUMN-MAJOR
REPRESENTATION
48
.
In column-major representation m × n elements of two- dimensional
array A are stored as one single row of columns.
The elements are stored in the memory as a sequence as first the
elements of column 1, then elements of column 2 and so on till elements
of column n
48. The address of A[i][j] is computedas
Addr(A[i][j]) = Base Address+ Offset= Base Address + (number of
columns placed before jth column * size of column) * (Size of
Element) + (number of elements placed before in ith element in ith
row)* size of element
For Element_Size = 1 the addressis
Address of A[i][j] for column major arrangement = Base + (j *
m ) + I
In general, for column-major arrangement; address of the
element of the jth row and the jth column therefore is
Addr (A[i][j] = ((j – LB2) * (UB1 – LB1 + 1) * size) + ((i –LB1) * size)
.
50
49. Example 2.1: Consider an integer array, int A[3][4] inC++. If
the base address is 1050, find the address of the element A[2]
[3] with row-major and column-major representation of the
array.
For C++, lower bound of index is 0 and we have m=3, n=4,
and Base= 1050. Let us compute address of element A [2][3]
using the address computationformula
1. Row-Major Representation:
Address of A [2][3] = Base + (i * n ) +j
= 1050 + (2 * 4) + 3
= 1061
.
51
51. 2. Column-Major Representation:
Address of A [2][3] = Base + (j * m ) +i
= 1050 + (3 * 3) + 2
= 1050 + 11
= 1061
⚫Here the address of the element is same because it is the
last member of last row and lastcolumn.
.
53
52. 1 2 3 4 5 6 7 8 9 10 11 12
(0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2) (0,3) (1,3) (2,3)
Col 1 Col 2 Col 3 Col 4
.
54
Column-Major Representation of 2-D
array
53. S OF ARRAY
55
.
An array is a finite ordered collection of homogeneous data
elements.
In array, successive elements of list are stored at a fixed
distance apart.
Array is defined as set of pairs-( index and value).
Array allows random access to any element
deletion of element in
Inarray, insertion and
between positions
• requires data movement.
static allocation, which means space
once during compile time, can not be
Array provides
allocation done
changed run time.
54. DATA STRUCTURE
56
. 56
Arrayspermit efficient randomaccess in constanttime 0(1).
Arrays are most appropriate for storing a fixed amount of data
and also for high frequency of data retrievals as data can be
accessed directly.
Wherever there is a direct mapping between the elements and
there positions, arraysarethe mostsuitable datastructures.
Ordered lists such as polynomials are most efficiently
handled using arrays.
Arrays are useful to form the basis for several more complex
data structures, such as heaps, and hash tables and can be
used to represent strings, stacks andqueues.
55. STRUCTUR
E
57
. 56
Arrays provide static memory management. Hence during
execution the size can neither be grown nor shrunk.
Array is inefficient when often data is to inserted or deleted
as inserting and deleting an element in array needs a lot of
data movement.
Hence array is inefficient for the applications, which very
often need insert and delete operations in between.
56. APPLICATIONS OF ARRAYS
58
. 56
Although useful in their own right, arrays also form the
basis for several more complex data structures, such as
heaps, hash tables and can be used to represent strings,
stacks and queues.
All these applications benefit from the compactness and
direct access benefits ofarrays.
Two-dimensional data when represented as Matrix and
matrix operations.
57. LIST
59
. 56
Ordered list is the most common and frequently used data
object
Linear elements of an ordered list are related with each
other in a particular order or sequence
Following are some examples of theordered list.
1, 3,5,7,9,11,13,15
January, February, March, April, May,June, July,
August, September,
October, November, December
Red, Blue, Green, Black, Yellow
58. There are many basic operations that can be
performed on the ordered list asfollows:
Finding the length of the list
Traverse the list from left to right or from
right to left
Access the ith element in thelist
.
60
56
the ith
Update (Overwrite) the value of
position
Insert an element at the ith location
Delete an element at the ith position
63. Polynomial as an ADT, the basic operations are as
follows:
Creation of a polynomial
Addition of two polynomials
Subtraction of two polynomials
Multiplication of twopolynomials
Polynomial evaluation
.
65
56
66. Structure is better than array for Polynomial:
.
68
56
Such representation by an array is both time and space efficient when
polynomial is not a sparse one such as polynomial P(x) of degree 3 where
P(x)= 3x3+x2–2x+5.
But when polynomial is sparse such as in worst case a polynomial as
A(x)= x99 + 78 for degree of n =100, then only two locations out of 101
would be used.
In such cases it is better to store polynomial as pairs of coefficient and
exponent. We may go for two different arrays for each or a structure
having two members as two arrays for each of coeff. and Exp or an array
of structure that consists of two data members coefficient and exponent.
68. SPARSE MATRIX
70
most of
In many situations, matrix size is very large but out of it,
the elements are zeros (not necessarily always zeros).
And only a small fraction of the matrix is actually used. A matrix of
such type is called a sparse matrix,
. 56
77. Time complexity will be O (n. T)
= O (n . mn)
= O (mn2)
which is worst than the conventional transpose with time
complexity O (mn)
SIMPLE SPARSE MATRIX
TRANSPOSE
79
. 56
78. FAST SPARSE MATRIX TRANSPOSE
80
. 56
In worst case, i.e. T= m × n (non-zero elements) the magnitude
becomes O (n +mn) = O (mn) which is the same as 2-D
transpose
However the constant factor associated with fast transpose is
quite high
When T is sufficiently small, compared to its maximum of m .
n, fast transpose will workfaster
79. It is usually formed from the character set of the
programming language
The value n is the length of the character string S where n ³
0
If n = 0 then S is called a null string or empty string
STRING MANIPULATION
USING ARRAY
81
. 56
80. Basically a string is stored as a sequence of characters in
one- dimensional character array say A.
char A[10] ="STRING" ;
Each string is terminated by a special character that is null
character ‘0’.
This null character indicates the end or termination of each
string.
.
82
56
81. There are various operations that can be
performed on thestring:
Tofind the length of astring
Toconcatenate two strings
Tocopy astring
Toreverse a string
String compare
Palindrome check
Torecognize a substring
.
83
56
82. 84
REVERSE STRING.
#include<iostream>
#include<string.h>
using namespace std;
int main ()
{
char str[50], temp;
int i, j;
cout << "Enter a string : ";
Cin>>str;
j = strlen(str) - 1;
for (i = 0; i < j; i++,j--)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
cout << "nReverse string : " << str;
return
PR
0O
; F.
}
83. . 85
/* C++ PROGRAM - CONCATENATE
STRING USING INBUILT FUNCTION */
#include<iostream.h>
#include<string.h>
void main()
{
clrscr();
char str1[50], str2[50];
cout<<"Enter first string : ";
Cin>>str1;
cout<<"Enter second string : ";
cin>>str2;
strcat(str1, str2);
cout<<"String after concatenation is "<<str1;
getch();
}
84. . 86
INBUILT FUNCTION */
#include <iostream>
using namespace std;
int main()
{
char str1[100] = "Hi...";
char str2[100] = "How are you";
int i,j;
cout<<"String 1: "<<str1<<endl;
cout<<"String 2: "<<str2<<endl;
for(i = 0; str1[i] != '0'; ++i);
j=0;
while(str2[j] != '0')
{
str1[i] = str2[j];
i++; j++;
}
str1[i] = '0';
cout<<"String after concatenation: "<<str1;
return 0;
}
85. . 87
To get the length of a C-string
string, strlen() function is used.
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[] = "C++ Programming is
awesome";
// you can also use str.length()
cout << "String Length = " <<
strlen(str);
return 0;
}
FIND LENGTH OF STRING WITHOUT
USING STRLEN FUNCTION
#INCLUDE<IOSTRE
AM> USING
NAMESPACE STD;
INT MAIN()
{
char str[] = "Apple";
int count = 0;
while (str[count] != '0')
count++;
cout<<"The string is "<<str<<endl; cout
<<"The length of the string is
"<<count<<endl;
return 0;
}
87. . 89
<STRING.H>
USING
NAMESPACE STD;
INT MAIN()
{
char str1[20], str2[20];
int i, j, len = 0, flag = 0;
cout << "Enter the string : ";
gets(str1);
len = strlen(str1) - 1;
for (i = len, j = 0; i >= 0 ; i--, j++)
str2[j] = str1[i];
if (strcmp(str1, str2))
flag = 1;
if (flag == 1)
cout << str1 << " is not a palindrome";
else
cout << str1 << " is a palindrome";
return 0;
}
String is palindrom or not
88. .
SIMPLE TRANSPOSE OF MATRIX IN C++
#include <iostream>
using namespace std;
int main()
{
int a[10][10], trans[10][10], r, c, i, j;
cout << "Enter rows and columns of matrix: ";
cin >> r >> c;// Storing element of matrix
cout << endl << "Enter elements of matrix: " <<
endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << "Enter elements a" << i + 1 << j + 1 << ":
";
cin >> a[i][j];
} // Displaying the matrix a[][]
cout << endl << "Entered Matrix: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{ cout << " " << a[i][j];
if(j == c - 1)
cout << endl << endl; }
// Finding transpose of matrix a[][] and storing it
infor(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
trans[j][i]=a[i][j];
}
// Displaying the transpose
cout << endl << "Transpose of Matrix: " << endl;
for(i = 0; i < c; ++i)
for(j = 0; j < r; ++j)
{
cout << " " << trans[i][j];
if(j == r - 1)
cout << endl << endl;
}
90
return 0; }
89. . 91
MULTIPLICATION OF TWO
POLYNOMIAL
#include<math.h>
#include<stdio.h>
#include<conio.h>
#define MAX 17
void init(int p[]);
void read(int p[]);
void print(int p[]);
void add(int p1[],int p2[],int p3[]);
void multiply(int p1[],int p2[],int p3[]);
/*Polynomial is stored in an array, p[i] gives coefficient
of x^i .
a polynomial 3x^2 + 12x^4 will be represented as
(0,0,3,0,12,0,0,….)
*/
void main()
{
int p1[MAX],p2[MAX],p3[MAX];
int option;
do
{
printf(“nn1 : create 1’st polynomial”);
printf(“n2 : create 2’nd polynomial”);
printf(“n3 : Add polynomials”);
printf(“n4 : Multiply polynomials”);
printf(“n5 : Quit”);
printf(“nEnter your choice :”);
scanf(“%d”,&option);
switch(option)
{
case 1:read(p1);break;
case 2:read(p2);break;
case 3:add(p1,p2,p3);
printf(“n1’st polynomial -> “);
print(p1);
printf(“n2’nd polynomial -> “);
print(p2);
printf(“n Sum = “);
print(p3);
break;
case 4:multiply(p1,p2,p3);
printf(“n1’st polynomial -> “);
print(p1);
printf(“n2’nd polynomial -> “);
print(p2);
printf(“n Product = “);
print(p3);
break;
}
}while(option!=5);
}
90. 92
MULTIPLICATION OF TWO
POLYNOMIAL
void read(int p[])
{
int n, i, power,coeff;
init(p);
printf(“n Enter number of terms :”);
scanf(“%d”,&n);
/* read n terms */
for (i=0;i<n;i++)
{ printf(“nenter a term(power coeff.)”);
scanf(“%d%d”,&power,&coeff);
p[power]=coeff;
}
}
void print(int p[])
{
int i;
for(i=0;i<MAX;i++)
if(p[i]!=0)
printf(“%dX^%d “,p[i],i);
}
void add(int p1[], int p2[], int p3[])
{
int i;
for(i=0;i<MAX;i++)
p3[i]=p1
P[
R
i]
O
+
F
p
. 2
A[
N
i]
A
;ND GHARU
}
void multiply(int p1[], int p2[], int p3[])
{
int i,j;
init(p3);
for(i=0;i<MAX;i++)
for(j=0;j<MAX;j++)
p3[i+j]=p3[i+j]+p1[i]*p2[j];
}
void init(int p[])
{
int i;
for(i=0;i<MAX;i++)
p[i]=0;
}
*******END******
91. . 93
FIND SIMPLE TRANSPOSE OF
MATRIX
#include <iostream>
using namespace std;
int main()
{
int a[10][10], trans[10][10], r, c, i, j;
cout << "Enter rows and columns of matrix: ";
cin >> r >> c;
//Storing element of matrix enter by user in array a[][].
cout << endl << "Enter elements of matrix: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << "Enter elements a" << i + 1 << j + 1 << ":
";
cin >> a[i][j];
}
// Displaying the matrix a[][]
cout << endl << "Entered Matrix: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << " " << a[i][j];
if(j == c - 1)
cout << endl << endl;
}
// Finding transpose of matrix a[][] and storing it
in array trans[][].
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
trans[j][i]=a[i][j];
}