Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
34 views
Module 1
DSA notes for beginners
Uploaded by
Amit Motaphale
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Module-1 For Later
Download
Save
Save Module-1 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
34 views
Module 1
DSA notes for beginners
Uploaded by
Amit Motaphale
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Module-1 For Later
Carousel Previous
Carousel Next
Save
Save Module-1 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 45
Search
Fullscreen
Lecture Notes Data Structures and Applications [21CS35] 1, Introduction Data Structures are the models for organizing the data so that ac sing becomes easy. They deal with the study of how data is organized in memory, how it can be manipulated, how efficiently it can be retrieved, and the possible ways in which different data items are ally related. 1.1 Data Structures Classification Dr-MaheshG Dr-Harish G Assoc. Prof. Assoc. Prof. esr aM DEAT The different types of data structures are ¥ Primitive Data Structures Data structures which can be manipulated directly by machine instructions are called primitive data structures. EX: int, float, char ete. ¥ Non-Primitive Data Structures Data structures which cannot be manipulated directly by machine instructions are called non-primitive data structures. ‘The different types of non-primitive data structures are - Linear Data Structures: The elements here exhibit either physical adjacency or logical adjacency between them. Here the data is arranged in a linear fashion although the way they are stored in memory need not be sequential. EX: Arrays are physically adjacent i.e. elements are stored in consecutive memory locations, Linked Lists are logically adjacent i.e. they are linked by pointers. - Non-Linear Data Structures: They do not exhibit any adjacency between elements but are logically related. Here data is not arranged in a sequential way. EX: Trees, Graphs ete, 1.2 Data Structures Operations ‘The following are the operations that can be performed on data structures 1. Create - This operation is used to create a data structure. In most of the programming languages this is usually done using a simple declarations statement. For example, the declaration "int a;" allocates memory for the integer ‘a’ during compilation of the declaration statement. 2. Insertion - Insertion means adding new details or new node into the data structure. 3. Deletion - Deletion means removing the existing details or a node from the data structure. Module 1Lecture Notes Data Structures and Apj lications [21CS35] Update - Update means changing the existing details or contents of a node in the data structure, ‘Traversal - Traversing means accessing each node exactly once so that the nodes of a data structure can be processed. Traversing is also called as visiting, Searching - Searching means finding the location of node for a given key value, Sorting - Sorting means arranging the nodes in a particular order. Me ing - Merging means combining the nodes from two lists into a single list. Example: An organization contains a membership file for every department in the organization wherein each record contains the following data for a given member. Name | Address | Phone Number | Email | Age | DOB ‘Suppose a new person joins the organization, then one would insert his or her record to the file. 2. Suppose a person resigns from the organization, then one would delete his or her record from the file. 3. Suppose a member has moved to a new loc: would update his or her record in the file. 4, Suppose the organization wants to organize a meeting though mailing, then one would traverse the file to obtain the name and email of each member. 5. Suppose one wants to find the address for a given name, then one would search the file for the record containing the name. 6. Suppose one wants the list of members in increasing order of their age, then one would sort the file based on age. 7. Suppose one wants a consolidated list of members from 2 different departments, then one would merge the files of 2 different departments into a single file, Dr.Mahesh G Dr-Harish G ‘Assoc. Prof. ASSOC. Prof. 1.3 Data Structures Representation asi 8 br alt Any data structure can be represented using one of the following two ways. Sequential Representation - A sequential representation maintains the data in continuous memory locations which takes less time to retrieve the data but leads to time complexity during insertion and deletion operations. Because of sequential nature, the elements of the list must be freed, when we want to insert a new element or new data at a particular position of the list. To acquire free space in the list, one must shift the data of the list towards the right side from the position where the data Module 1Lecture Notes Data Structures and Apj has to be inserted. Thus, the time taken by CPU to shift the data will be much higher than the insertion operation and will lead to complexity in the algorithm, Similarly, while deleting an item from the list, one must shift the data items towards the left side of the list, which may waste CPU time. 2. Linked Representation - Linked representation maintains the list by means of a link between the adjacent elements which need not be stored in continuous memory locations. During insertion and deletion operations, links will be created or removed between which takes less time when compared to the corresponding operations of sequential representation Dr.Mahesh G Dr.Harish G Assoc. Prof. ASSOC. Prof. eMsiT aM De ATT 1.4 Algorithm Specification Definition: An algorithm is a finite set of instructions that accomplishes a particular task. ‘The criteria’s that must be satisfied are 1. Input: Zero or more quantities are externally supplied. 2. Output: At least one quantity is produced. 3. Definiteness: Each instruction must be clear and unambiguous. 4. Finiteness: The algorithm always terminates after a finite number of steps and uses finite sources. 5, Effectiveness: Every instruction must be basic enough to be carried out. Methods of specifying an algorithm 1. Using a natural language: a clear description of algorithm because of the inherent ambiguity associated with any natural language. 2. Flowchart: is a method of expressing an algorithm by a collection of geometric shapes containing descriptions of the algorithm’s steps. They work well only if the algorithm is small and simple, 3. Pseudo code: is a mixture of a natural language and programming language like constructs(C) giving a semi-formal description of each step to be carried out by the computer, Module 1 lications [21CS35] surprisingly difficultLecture Notes Data Structures and Applications [21CS35] 2. Pointers (Revision — not in syllabus) 2.1 Memory Organization Memory is organized as a sequence of byte sized locations (1 byte = 8bits). Bach byte in memory is associated with a unique address. Addresses are positive integer values that range from zero to some positive integer constant corresponding to last location in the memory. Every object (data or program code) that is loaded into memory is associated with a valid range of addresses, i.e. each variable and each function in a program starts at a particular location, and spans across consecutive addresses from that point onwards depending on the size of the data item. Cor jder the statement int a = 10; This tells the compiler to 1. Reserve space in memory to hold a integer value. 2. Associate the name ‘a’ with this memory location. 3, Store the value 10 at this location, Dr.Mahesh G Dr.Harish G This is as shown in the following memory map. ae eae Msi & M OAT a = ———+ Location Name 10 |» Value at Location 1004 ____ Location No. or Address 2.2 The Address Operator ( & ) This operator when used as a prefix to a variable name gives the address of that variable. EX: Program to print the address of a variable along with its value. #include
void main( ) { inta; a=10; printf(“The address of a is You\n”, &a); printi(“The value of a is %d\n”, a); } Here %u is used for printing address values, because memory addresses are unsigned integers Module 1Lecture Notes Data Structures and Applications [21CS35] Consider the declaration, char a; int b; Assuming char requires 1 byte and int requires 4 bytes, memory space may be reserved in the following way. Fora 2000 2001 a 2002 For ‘b oa 2004 Dr.MaheshG Dr.Harish G ‘Assoc. Prof. Assoc. Prof. aMSIT & M rar i.e. a variables address is the first byte occupied by the variable 2.3 The Indirection Operator ( * ) ‘This operator when used as a prefix to the address of a variable gives the value of that variable (contents at that address). EX: Program to print the address of a variable and then print its value using * operator. #include
void main( ) { printi(“The address of a is %u\n”, &a); printf(~The value of a is %d\n”, *(&a)); } Note: The address and indirection operators are complimentary i.e. when both are applied on a variable, the variable is got back. [ *(&a ] 2.4 Pointer Variables or Pointers ‘The address operator (&) returns the address of a variable. This address can be collected or stored in another variable. EX: b = &a; Here the compiler must also reserve space for the variable “b°, The memory map for this is as shown, - i 10 1004 Module 1 1004 2000Lecture Notes Data Structures and Applications [21CS35] Note that “b’ is not a ordinary variable. It is a variable which contains the address of another variable ‘a’, Such type of variable is called a pointer variable, Definition: A pointer is a variable that contains the address of another variable. 2.5 Pointer Declaration ‘The syntax for declaring a pointer variable is datatype * Name_of_the_Pointer_Variable: Here datatype can be ¥ Primitive datatypes such as int, float char, ete Y User defined datatypes Name_of_the_Pointer_Variable is any valid variable name. Note: The datatype of a pointer variable must be same as the type of the variable that it points to. Y int *P means P is a pointer to an integer ie. it can hold the address of a integer variable . ¥ float *P means P is a pointer to a float i.e. it can hold the address of a floating point variable. v char *P means P is a pointer to a character i.e. it can hold the address of a character variable. EX: Valid in *C’ | Invalid in °C” int *P; int a= 10; P= &a; 2.6 Accessing a Variable through its Pointer We know that by using a pointer variable, we can obtain the address of another = Dr Mahesh G Dr Harish G EX: ‘Assoc. Prof. Assoc. Prof. Toe ouSITEM Dear int *1 /f Assume ‘a’ is stored at address 1000 P=&a; —_// Pwill contain address of i.e. 1000 We know that the value stored at any address can be obtained using the indirection operator (*).. EX: The value stored at address 1000 can be obtained by *P [same as *(&a)]. Here P means the address 1000 and #P means the contents at address 1000 which is 10. Module 1Lecture Notes Data Structures and Applications [21CS35] EX: Program to illustrate the use of indirection operator “*” to access the value pointed by a pointer. #include
void main( ) { b=*P; print{(“Sed\n’ printf(“ed\n”, b); a); printi(“Zed\n”, *P); a DrMahesh @ DrHarish G cone Assoc. Prof. Assoc. Prof. " MSIT& De. AIT 10 2.7 Initialization of Pointer Variables Consider the following variable declaration, where the variable is uninitialized. inta; This declaration tells the compiler to reserve space in memory and associate name ‘a’ to that location. Because it is uninitialized, the value at this location is unknown or some garbage value. This is as shown, a@ ———+ Location Name r+ Unknown Value The same thing applies to pointer variables also. Uninitialized pointers will have unknown memory addresses or unknown values that will be interpreted as memory locations. int *P; P + Location Name Pointer to an Unknown Location P44 Uninitialized pointers cause errors which are very difficult to debug. Hence it is always good practice to assign a valid memory address or NULL value to a pointer. EX: int a; int *P = &a; int *Q= NULL; Module 1Lecture Notes Data Structures and Applications [21CS35] Note: NULL is a pointer value which when assigned to a pointer variable indicates that the pointer does not point to any part of the memory. 2.8 Pointers and Functions EX: Program to swap two numbers #includesstdio.h> void main( ) { int a, b, temp; print{(“Enter 2 numbers\n"); seanf(“Sd%d™, &a, &b): print{(-BEFORE SWAPPING\n”); printf(‘“Value of a = Sed \n”.a); printf(“Value of b = %d \n”.b); temp =a; printi(“AFTER SWAPPING\n”); printf(“Value of a = %ed \n”.a); printi(“Value of b = %d \n",b); } EX: Program to swap two numbers using Functions #include
void swap( int *c, int *d) { int temp; temp = *e; Fo= td; Dr.MaheshG Dr.Harish G d= temp; ‘Assoc. Prof. Assoc. Prof. ) MsmT& OF A void main( ) { int a, b, temp; print{(“Enter 2 numbers\n"); scanf(“%d%d™, &a, &b); printi(“BEFORE SWAPPING\n");, printf(“Value of a = Sed \n”.a); printf(“Value of b = %d \n”,b); swap(é&a, &b); printf(“AFTER SWAPPING\n”); printf(“Value of a= ed \n".a); print{(“Value of b = %d \n",b); } Note: Y If ‘a’ and ‘b’ are passed by value, then the effect of swapping will not be seen in the main function. The variables ‘a’ and ‘b’ will retain their values. Y When only one value needs to be sent from the called function to the calling function, wwe can use the ‘return’ statement. ¥ When more than one value needs to be sent from the called function to the calling function, we have to use call by reference. Module 1Lecture Notes Data Structures and Applications [21CS35] 2.9 Functions returning Pointers EX: Program to find bigger of two numbers #include
int* bigger(int *c, int *d ) { if(*c > *d) return ¢; else return d; } void main( ) { printf(“Enter 2 numbers\n"); seanf“%d%d”, &a, &b); big = bigger(&a, &b); printi(“Bigger of two numbers is “ed \n”, *big); } 2.10 Pointer to a Function EX: Program to add two numbers #include
int add(int c, int d ) { int res; res=c+d; return res; } void main( ) { int a, b, res; int ptr)(int, in); // declaring pointer to a function pir= add; // storing the address of a function in pointer to a function printf(“Enter 2 numbers\n”); scant(“%d%d”, &a, &b); res =(*ptr)(a, b); 7 calling the function using pointer printf(“Result of addition is %d \n”, res); a Module 1Lecture Notes Data Structures and Applications [21CS35] 2.11 Pointer to a Pe Just as we have pointers to int, float or char, we can also have pointers to pointers. This is, because, a pointer is also a variable. Hence, we can always have another variable (pointer) which can contain the address of the pointer variable. EX: inta=10; — //integer variable int *p: / pointer to an integer int**q; _// pointer to a pointer to an integer p=&a, a= 8p; Dr.Mahesh G DrHarish G Assoc. Prof. Assoc. Prof. This is pictorially as shown below. aMsiT aM De. AT q P a 3000 >| 2000 on x 4000 oN 3000 2000 ion, however, there is no limit as to how many levels of ‘The above shows a 2-level in indirection we can use. Here, ¥ pis the address of ‘a’ (2000) ¥ pis the contents or value at address 2000 i.e. 10 Y qis the address of p (3000) Yq is the contents or value at address 3000 (2000) ¥ *¥q is the contents or value at address 2000 (10) ¥ a=*p=™q Module 1 10Lecture Notes Data Structures and Apj I is a process where in the memory space is allocated during the compilation time, Here the allocated memory space cannot be expanded or reduced to accommodate more or less data, ie. the size of the allocated memory space is fixed and it cannot be altered during execution. lications [21CS35] EX: Consider the declaration int af 10]; During compilation, the compiler will allocate 10 memory locations for the variable ‘a’ and once defined cannot be changed. During execution we cannot have more than 10 data items, and if we use 3 locations, another 7 locations are wasted. Assoc. Prof. ASSOC. Prof. eMsiT & M Or. ArT Disadvantages: In this type of memory allocation, the data structures require a fixed amount of storage. Since the amount of storage is fixed, # If the data structure in use, uses only a small amount of memory, rest of the memory is wasted. If the data structure in use, tries to use more memory than actually allocated for it results in an overflow. Because of these limitations, this type of memory allocation can be used in applications where the data size is fixed and known before processing. It is the process of allocating memory space during run time. This type of memory allocation can be used in applications where the storage requirement is unpredictable. The following are the functions using which additional memory space can be allocated or unwanted space can be deleted, thereby optimizing the use of storage space 1._malloe Description: This function allocates and reserves a block of memory, spe and returns a pointer (o the first byte of the allocated space. Syntax: ptr = (datatype *) malloc (size); Where - ptris a pointer of type datatype - datatype can be any of the basic data type or user defined data type. - size is the number of bytes required. Example: pir = (int * ) malloc ( sizeof (int ) ) On successful execution of this statement, a memory space equivalent to size of int is reserved and the address of the first byte of the memory allocated is assigned to the pointer ptr of type int. Return Value ~ On success, it returns a pointer of type void to the newly allocated block of memory. On failure i.e. if the specified size of memory is not available, it returns NULL. Module 1 ulLecture Notes Data Structures and Applications [21CS35] calloc Description — This function allocates multiple blocks of same size, initializes all locations to zero and returns a pointer to the first byte of allocated space. Syntax: ptr = (datatype *) calloc (n, size); Where = ptris apointer of type datatype - datatype can be any of the basic data type or user defined data type. - size is the number of bytes required. - nis the number of blocks to be allocated of size bytes. Example: pir = (int * ) calloc (200, sizeof ( int ) ) On successful execution of this statement, a memory space equivalent to size of 200 int (array of 200 integers) is reserved and the address of the first byte of the memory allocated is assigned to the pointer ptr of type int. Return Value — On success, it returns a pointer of type void to the newly allocated block of memory. On failure i.e. if the specified size of memory is not available, it returns NULL. realloc Description — This function is used to alter the size of the previously allocated space which is allocated either by using malloc or calloc function. Syntax: ptr = (datatype *) realloc (ptr, size); Where _ - ptris the starting address of allocated memory obtained previously by calling malloc, calloc, or realloc functions, - size is the number of bytes required for reallocation. The size specified may be larger or smaller than the previously allocated memory. Example: Ifthe original allocation is done by the statement Dr.Mahesh G Dr.Harish G ptr = malloc(size); ‘Assoc. Prof. ‘Assoc. Prof. Then reallocation of space may be done by the statement MST EM Or AT pir = realloc(ptr, newsize) On successful execution of this statement, realloc allocates a new memory space of size newsize to the pointer variable ptr and returns a pointer to the first byte of the new memory block. Return Value — On success, it returns a pointer to the newly allocated block of memory. On failure ice. if the specified size of memory is not available, it retums NULL. Note: * The storage space allocated dynamically has no name and therefore its contents can be accessed only through a pointer. * It is the responsibility of a programmer to de-allocate memory whenever it is, not required by the application, + _In-case of realloc( ), the contents of the old block will be copied into the newly allocated space and so, this function guarantees that the earlier contents are not lost. Module 1 2Lecture Notes Data Structures and Applications [21CS35] free Description — This function de-allocates (frees) the allocated block of memory which is allocated by using the functions malloc ), ealloc( ) o realloct ). free(ptr); Where ptr is a pointer to a memory block which has already been created by invoking one of the 3 functions malloc( ), calloc( ) or realloc( ). Return Value — None. 3.3 Problems with Dynamic Memory Allocation 1. Memory Leakage This is a problem where in a part of the memory is reserved but is not accessible to any of the applications. Example: Consider the following program segment, main () { int *a; int *)malloc(sizeof (int) ); Dr.Mahesh G Dr.Harish G 105, ‘Assoc. Prof. _-ASs0C. Prof ‘int *)malloc(sizeof (int) ); ee cu *a=20; } Here, memory for the variable ‘a’ is allocated twice. However, “a” contains the address of most recently allocated memory, thereby making the earlier allocated memory inaccessible i.e. the memory location where the value 10 is stored is inaccessible to any of the application and is not possible to free so that it can be reused. 2. Dangling Pointer Any pointer pointing to a destroyed object or which does not contain a valid address is called a dangling pointer. Example: Consider the following program segment main () { int *a; int *)malloc(sizeof(int)); free(a); } Here, if we de-allocate the memory for the variable ‘a’ using free(a), the memory location pointing to by it is returned to the free pool. Now the pointer vz the contents pointed by that cannot be used, because the po contain a valid address now and is called a dangling pointer. Module 1Lecture Notes Data Structures and Applications [21CS35] SI _ Malloc () ‘Syntax: pir = (datatype*) malloc ( size ) 1. | (Takes only one argument which is the size of the block) ‘Syntax: pir = (datatype*) calloc (a, size ) (Takes 2 arguments, first is number of blocks to be allocated and second is the size of each block) not available contiguously but available at different locations, 2 | Allocates a block of memory oF | Allocates multiple blocks of memory, each specified size. block with same size. 3 | Allocated space will not be initialized. [Each byte of the allocated space is 1d t0 zero. ‘Since no initialization takes place, time | calloc( ) is computationally more expensive 4 | efficiency is higher than calloc( ) because of zero filling but, occasionally, more convenient than malloc) This function can allocate the required | This function can allocate the required 5, | size of memory even if the memory is | number of blocks contiguously. If the required memory cannot be allocated contiguously, it retums NULL. time. o "Static Memory Allocation | Dynamic Memory Allocation no. 1 | Memory is allocated during compilation | Memory is allocated during run time, execution, The size of the allocated memory space is 2 | fixed and it cannot be altered during The size of the allocated memory space is not fixed and it can be altered (increased / decreased) during execution, This type of memory allocation can be This type of memory allocation can be 3. | used in applications where the data size is | used in applications where the storage fixed and known before processing. requirement is unpredietable. Execution is faster because memory is | Execution is slower because memory is 4 | already allocated and only data | has to be allocated and only then data manipulation is done. manipulation is done. 3g | Part of memory allocated i stack memory | Part of memory allocated is heap memory | or global/static memory. 6 _| Ex: arrays Ex: Dynamic arrays, linked lists Dr.Mahesh GG Dr.Harish G Assoc. Pro Msi aM |ASS0C. Prof. r. AIT Module 1 4Lecture Notes Data Structures and Applications [21CS35] 4. Arrays Arrays is a collection of items of similar data type. All elements of an array share a common name and each element in the array is identified by using the subscript/index. 4.1 Representation ‘The elements of an array are stored in consecutive memory locations. For example, consider the array declaration (with initialization), int a[5] = (10, 20, 30, 40, 50}; When the compiler encounters this statement, it allocates 5 consecutive memory locations, each large enough to hold a single integer and assigns the values 10, 20, ete to appropriate locations. The memory map of this is as shown below. af] [10 | 1000 aft] [20] 1004 a(2] [30] 1008 a(3] [40] 1012 a4] [50] 1016 Dr.Mahesh G Dr.Harish G ‘Assoc. Prof, Assoc. Prof. MST & M rar UB represents the upper bound and is the largest index in the array (for above UB = 4) and LB represents the lower bound and is the smallest index in the array (for above LB = 0). In general the number of elements or the length of the array can be obtained using the formula, Length = UB - LB +1 Example: 4-0 +1 One way of obtaining the address of each element of an array is by using the “&’ operator. For example, &a[0] gives the address of the first element, &a[1] gives the address of the second element and so on. However, the address of the first element (also called as the base address) is stored in the name of the array i.e. a = &a[0]. Hence the name of the array ‘a’ can be considered as a pointer, pointing to the first element of the array. A second way of obtaining the address of each element of an array is by using the name of the array which is basically a pointer. For example, “a’ gives the address of the first element, Module 1 15Lecture Notes Data Structures and Applications [21CS35] ‘atl’ gives the address of the second element, ‘a+2° gives the address of the third element and so on, Meaning ‘a’ is same as &a[0], “a+1” is same as &a[1] and so on, Note: Adding an integer ‘n° to a pointer, makes the pointer to point to a value ‘n’ elements away i.e. if ‘a’ is a pointer and ‘n’ is a integer, a+ n = a + n* (sizeof(one element)).. EX: In the above memory map ‘a’ = 1000, a+3 =a +3 * sizeof(one element); Here a= 1000, assuming integer takes 4 bytes, sizeof{one element) = 4 and hence, 43 = 1000 +3 * 4 = 1000 + 12 = 1012 = Address of a[3] ie &al3] In general, the address of ali] can be obtained as &ali] or ‘a+i and the value of afi] can be obtained as afi] or *a+i). Program to print the elements of an array along with their address using pointers #include
void main() { int n, i, al20] ; printf(“Enter the number of elements\n”); seanf(“"ed”, &n); printf(“Enter the elements\n”); Dr.MaheshG Dr.Harish G fo i=Oi
void main( ) { [20], sum 5 Enter the number of elements\n”); &n); printf(“Enter the elements\n”); for(i=O;i
The element afi][j] is found by first accessing the pointer in afi). This gives the address of the zeroth element of row “i” of the array. Then by adding ‘j’ to this pointer the address of the j"" element of row ‘i is found This means, ¥ The expression *(a + i) + j points to the j"" element in the i" row ie. (a +i) + j= Salilfi] Y The expression *( *(a + i) +] ) gives the value of the element in i'" row and j"" column ie. *(a4i) +) ) =alilil Program to read and print an array of ‘m X n° matrix using pointers #include
lahes| r.Harist void main() Assoc. Prof, Assoc. Prof. { eMsiT &M Dr. AIT int m, n, i, j, af20] [20]; printi(~ seanf(“%d”, &m Enter the number of rows in the matrix\n”); Module 1 7Lecture Notes Data Structures and Applications [21CS35] printi(“Enter the number of columns in the matrix\n”); seanf“%d”, &n); printf(“Enter the matrix elements\n”); for i=0;i
n || pos <0) { print{("“Invalid position \n"); return ; } for(i = n-1; i >= pos { ali¢1] =alils } Dr.Mahesh G larish G alpos] = item; Assoc. Prof. ASSOC. Prof oust & or aT n=n+l; } 4.2.4 Delete void delete_array(int pos) { int is Module 1 9Lecture Notes Data Structures and Applications [21CS35] if(a==0) { printi("No elements in the array, Cannot delete\n"); return; i if(pos >= nl pos < 0) { printf("Invalid position \n"); return ; } printi("Item deleted = %d \n",a[pos]); for(i = pos+1; isn; i++) { ali-l] =ali); } nem; } 4.2.5 Update void update_array( int iter { int pos) if(n==0) { printf("No elements in the array, cannot update\n"); return; } if(pos > n || pos <0) { printi("Invalid position \n"); return ; } alpos] = item; printi("Updated Successfully \n"); } Lab Program Design, Develop and Implement a menu driven Program in C for the following Array operations a. Creating an Array of N Integer Elements b. Display of Array Elements with Suitable Headings ¢. Inserting an Element at a given valid Position d. Deleting an Element at a given valid Position Dr.MaheshG Dr.Harish G e. Exit. Assoc. Prof. Assoc. Prof. BST a M Dealt #include
int *a, arraysize, n = 0; Module 1 20Lecture Notes void main() { int item, pos, choice; Data Structures and Applications [21CS35] printf(“To Create an Array\n”); printf(“Enter the maximum ye of array\n”); scanf(“%d", &arraysize); printi(“Enter the number of elements to be read initially \n"); seanft“%d", &n); create_array(); for(:s) { printf(“1 Display 2.Insert 3.Delete 4.Exit\n”); printi(“Enter your choice\n”); scanf(“%d”, &choice); switch(choice) ( case 1: case 2: case 3: case 4: lay_array( brea printi(“Enter the item (o insert\n"); scanf(“%d”, &item); printi(“Enter the index position to insert\n”); scanf(“%d", &pos); i array(item, pos); printf(“Enter the index position to delete\n”); seanfl'“%ed”, &pos); delete_array(pos); break; free(a); exit(0); Dr.MaheshG Dr.Harish G Assoc. Prof. Assoc. Prof. aMsiT eM Dear Write a °C” program to search for a given “key” element in an array of ‘n’ elements using linear search technique #include
void main() { int n, i, a[20], key ; printf(“Enter the number of elements\n”); scanf(“%d”, &n); Module 1 2Lecture Notes Data Structures and Applications [21CS35] printf(“Enter the elements\n”); for(i=0;i
void main() { int n, af20], key, low, high, mid ; for(i=O;i
a[mid]) low = mid +1; } printf(“UNSUCCESSFUL SEARCH\n” ); Larson Write a ‘C’ program to sort “n’ elements of an array using bubble sort technique #include
void main( ) { int n, i, a[20}, j, temp + print{(“Enter the number of elements\n”); scanf(“%d”, &n); printf(“Enter the elements\n”); for(i=O;i
= afi+1)]) { temp = ali); [i+]; } printi(“The sorted array elements are\n”); for(i=0;i
void main() { int nl, n2, i, j,k, af20], b[20], c[40]; printf(“Enter the number of elements for array I\n”); seanfl“%d", &n1); printf(“Enter the elements in sorted order\n”); for(i=O;i
void main() { intn, i, printi(“Enter the number of elements\n”); seanf(“%ed”, &n); int) malloc(n*sizeof{in)): printf(“Enter the elements\n”); si
intn, i, *a, max; printf(“Enter the number of elements\n”); seanf(“ed”, &n); a= int") malloc(n*sizeof(in)); printi(“Enter the elements\n” for(i=O;i
max) { max = *(a+i); } y printf(“Maximum element = %d\n”, max); fre } Program to find the sum of positive and negative numbers out of ‘n’ elements using dynamic arrays #include
void main( ) { int n, i, *a, psum, nsun printf(“Enter the number of elements\n"); seanf(“%d”, &n); int*) malloc(n*sizeof{int)); print{(“Enter the elements\n" for(i=O;i
0) i } else ( psum = psum + *(ati): Module 1 26Lecture Notes Data Structures and Applications [21CS35] nsum = nsum + *(asi); } } printf(“Sum of positive elements printi(“Sum of negative element free(a); %d\n", psum); Yed\n”, nsum Program to read and print an of ‘m X n° matrix using dynamic arrays #include
void main() { free(a); int rows, columns, i, j: int **a; printi(“Enter the number of rows in the matrix\n”); seanf(“%d", &rows); printi(“Enter the number of columns in the matrix\n”); scanf(“%d”, &columns); 1 ALLOCATE MEMORY FOR ROWS a= (int **) malloc(rows * sizeof(int *)); / FOR EACH ROW ALLOCATE MEMORY FOR COLUMNS for(i = 0; i < rows; i++) { afi] = (int *) malloc(columns * sizeoftin)); } printf(“Enter the matrix elements\n”); fort i= 0; i < rows i++) lahesh G Dr.Harish G { Assoc. Prof. Assoc. Prof. Bwsir& Dear for( j =0;j < columns ; j++) scanf(“%d”, (a+ i)+j); Mf scanfi*%d”, &aLi}{i] ); } } printi(“The entered the elements are\n”); for( i=0;i
. Y Triples are organized so that the row indices are in ascending order, and for any given row, the column indices are also in ascending order. Y To perform any operation on a sparse the following needs to be known Number of rows Number of columns — Number of nonzero elements We use the following structure to represent a sparse matrix. struct sparsematrix { int row; int col; int value; i struct sparsematrix a{ 100]; EX: The above sparse matrix can be represented as row | col | value af0]| 6 | 6| 8 af | o [0 [15 af2y [0 [3 [22 a3] | 0 [5 [15 raf tte (dee [eT a(S] |_1 | 2 3 EOE EP Agee Bi Beck a7) | 4 [0 [91 ag) [5 [2 [28 Module 1 »Lecture Notes Data Structures and Applications [21CS35] Here, a0]. row contains the number of rows. a[0]. col contains the number of columns. a[0]. value contains the total number of nonzero elements. ‘The triples are ordered by rows and within rows by columns Transpose of a matrix can be done by interchanging the rows and columns. This means each clement afiJ{j] in the original matrix will become bfj][i] in the transposed matrix. Direct interchanging of rows and columns is not correct in case of sparse matrices because the ordering of rows and columns in the representation will be lost. KA68 Algorithm for all elements in column j place < i,j, value > from original matrix to
in the transposed matrix This indicates that we should find all the elements in columns 0 and store them in row 0 of the transpose matrix, then find all elements in column I and store them in row I ete. EX: Matrix ‘a’ and its transpose *b” is as shown below row | col | value row | col | value af0]| 6 | 6| 8 blo}| 6 | 6] 8 at | o [0 [15 bi | o [o | 15 a2) [0 [3 [22 bay [0 [4 [or af3] | 0 [5 [15 bit ya To a4i {ita tit Bias eto ite ragS |e bis} | 2 [5 [28 af6) | 2 [3 | 6 vier | 3 [0 | 22 af | 4 [0 [94 bi | 3 [2 | 6 afg) [5 [2 [28 bis} | 5 [0 | -15 ‘The following is the function for finding the transpose of a sparse matrix. The array ‘a’ holds the original matrix and the array “b” holds the transposed matrix. The structure used in the function is given by struct sparsematrix t Dr.Mahesh G DrHarish G int row; a int col; int value; hi typedef struct sparsematrix MATRI voi ee af ], MATRIX bf 1) { int n; inti, jks Module 1Lecture Notes Data Structures and Applications [21CS35] b[O].row = al0].col; Jfrows in b= cols ina b[0].col = a[0].row; H cols in b= rows ina b{O].value = a[O].value; _// number of elements in b = number of elements in a n=af0].value; //total number of elements if(n>0) M nonzero matrix { 1/ position to put the next transposed triple in b for(i=0: i
, ax! would be represented a The polynomial AGO) adegree a.coefficent{i] = ani 1 nis the max no. of terms = degree + 1 In this representation, we store the coefficients in order of decreasing exponents, such that a.coefficient{i] is the coefficient of x" provided the term with exponent n-i exists; otherwise, a.coefficient[i] = 0. EX: The representation for the polynomial A(x) = 7x” + 5x°° + 3x? + 1 is as shown below. Index /Exponent |0]1]2]3].]-|.|24]25]-]-|.] 49] 50]. [.]- [98] 99 | 100 acoefficient(] [o[7[o[o].[.[-[o lol]... [ols[ fF [3 fol: accoefficent{1] = aio .1 =a99=7. n= 99 +1 a.coefficent[98] = ayo -98 = a2 ‘The drawback of this representation is that it wastes lot of space. This is because, v If adegree is very much less than MAX_DEGREE then most of the positions in a.coefficient|MAX_DEGREE] will be wasted. ¥ If the polynomial is sparse i.e. the number of terms with non-zero coefficient is very less. To overcome the drawbacks of Representation — 1, we use only one global array to store all the polynomials. We use the following structure to represent a polynomial +#define MAX_TERMS 100 struct polynomial Dr-Mahesh G_Dr.Harish G { Assoc. Prof. Assoc. Prof. float coefficient; co or A int exponent; hk struct polynomial a[MAX_TERMS]; int avail = 0; EX: The representation for the polynomial A(x) = 7x” + | and B(x) = 5x! + 3x* + 7x? + Lis as shown below. startA finishA startB finishB avail 1 1 { 4 1 coefficient i 1 = ee L Exponent [99 [0 i312 a0) 0 T a oD Module 1 32Lecture Notes Data Structures and Applications [21CS35] The index of the first term of A and B is given by startA and startB. The index of the last term of A and B is given by finishA and finishB. The index of the next free location in the array is given by ava The drawback of this representation is that when all the terms are non-zero, it requires about twice as much space as the first one. #include
#define MAX_TERMS 100 struct polynomial { int coefficient; int exponent; i Assoc. |Assoc. Pro! struct polynomial a[MAX_TERMS]; erent as int avail = 0; void main( ) { int na, nb, i, startA, finishA, startB, finishB, startC, finishC, ne; printf(“Enter the number of terms in Polynomial A\n"); seanf(“%d", &na); start = avail; printf(“Enter the coefficient and exponents of the Polynomial A\n”); for(i = 0; isma; i++) { printf(“Enter the coefficient \n”); scanf(“%d", &alavail] coefficient); printf(“Enter the corresponding exponent \n”); scanf(“%ed", &a{avail exponent); avail; } finish = avail — 1; printf(“Enter the number of terms in Polynomial B\n”); seanf(“%ed”, &nb); startB = avail; printf(“Enter the coefficient and exponents of the Polynomial B\n”); for(i = 0; i
b’s exponent afavail].coefficient = a[startA ].coefficient; Module 1 M4Lecture Notes afavail].exponent startAH; avail; net; break; } J! Add remaining terms of Polynomial A eshG Di Data Structures and Applications [21CS35] afstartA].exponent; jent; larish G ‘Assoc. Prof, while(startA < A) { alavail coefficient = a[startA ].coe' {avail Lexponent = alstartA exponent; startAt++; ae Di manne ‘Ass0¢. Prof. } BMSIT &M 1/ Add remaining terms of Polynomial B De AT [startB ].coefficient; int compare(int x, int y) { ifx
0) printf(+"); printf((“%ed”,al start] coefficient); printt(%x *”); printf(“%ed”,a{start].exponent); start++; } } Module 1Lecture Notes Data Structures and Applications [21CS35] 6. Structures (Revision — not in syllabus) 6.1 Why structures? If we want to store a number of data items of same datatype, we can use arrays. However, if we want to store the information which is a collection of items of dissimilar datatype, we cannot use arrays. This is where we use structures. 6.2 Structures Definition and Syntax A structure is a collection of related information of possibly d rent datatype under one name. Syntax: struct tagname { datatype member!; datatype member2; Dr.Mahesh G Dr.Harish G Where Assoc. Prof. Assoc. Prof MST & M Or AIT = struct is the keyword. — tagname is user defined name for structure. datatype can be any of the basic datatype (int, float, char etc) or user defined datatype. memberl!, member2 are attributes of the structure (also called members or fields). Example: struct student { char name[20]; int marks 1; int marks2. int marks char regno[10}; Just by defining a structure, memory will not be allocated for the various fields. It simply describes a format called template to represent information as shown name | Array of 20 characters marks! | Integer marks2 | Integer marks3 | Tnteger regno | Array of 10 characters If the structure is sociated with a variable then the memory is allocated. Module 1 36Lecture Notes Data Structures and Applications [21CS35] 6.3 The Type Definition The “typedef” is a keyword that allows the programmer to create a new datatype name for an existing datatype. The general syntax for typedef is typedef datatype userprovidedname; Where ~ typedef is the keyword. - datatype is any exist g datatype. ~ _userprovidedname is the name for the existing datatype. Usually this is written capital letters. Example: Suppose if, int m1,m2,m3; represents the declaration of 3 variables m1, m2 and m3 to store marks scored in 3 subjects ‘The same thing can be written using typedef as shown typedef int MARKS; MARKS ml,m2,m3; /5rwanesh G@ DrHarish © Assoc. Prof, Assoc. Prof. BST & M rar Advantages of typedef * Ithelps in self-documenting a program by allowing the use of more descriptive names for the standard datatypes. * Complex and lengthy declarations can be reduced to short and meaningful declarations. + Improves readability of the program. 6.4 Various structure variable declaration forms Format 1: struct student ( char name[20]; int marks int marks: int mark char regno[ 10]; h struct student a, b, ¢; Module 1 37Lecture Notes Data Structures and Applications [21CS35] Format 2: struct student { char name[20]; int marks1; int marks2; int marks3; char regno[10}; Ja, b, Format 3: Using typedef typedef struct ( char name[20]; int marks]; int marks: int marks3; char regno[20]; }STD; Dr.Mahesh G Dr.Harish G Assoc. Prof, Assoc. Prof. BMsiT aM De. AT oR struct student { char name[10]; int marks1; int marks int marks3; char regno[ 10}; i typedef struct student STD; Here STD is a new datatype of type struct student, Therefore the statement STDa, b; creates 2 variables a, b of type STD. Note: 1. The structure type declaration defines a template of the structure and does not tell the compiler to reserve any space in memory. Memory is allocated only when the structure is associated with a variable. Example: struct student { char name[20]; int marks1; int marks: int marks3; char regno[10}; struct student a, b, ¢; Module 1Lecture Notes Data Structures and Applications [21CS35] Here each of the variable (a, b, c) will have 5 members ( name, marks, marks2, marks3, regno). The statement struct student a, b, ¢3 sets aside space in memory. It makes available space to hold all the members in the structure for all the structure variables declared, 2. Usually structure type declaration appears at the top of the source code i.e. before any variables or functions are defined. In such cases, the definition is global and can be used by other functions, 6.5 Accessing structure fields or members The fields of the structure can be accessed by using a dot operator *."(member selection operator). Example: Consider the declaration struct student { char name[20]; Dr.Mahesh G larish G int marks ‘Assoc. Prof. ASSOC. Prof. int marks2; oMstT& oe ait int marks3; char regno[10]; Ih typedef struct student STD; STD a; Here ‘a’ is a variable of type STD and the elements of struct can be accessed as a.name, a.marks1, a.marks2, a.marks3 and a.regno. Note ~ Before the dot operator there must always be a structure variable and after the dot operator there must always be a structure member. 6.6 Assigning Values to Structure Members We can assign values like strepy(a.name, “Mahesh”); marks1=97; marks2. a.matks. strepy(a.regno, “LAY 101001”); in the program OR We can use scanf to read values through the keyboard scanf(“%s", a.name); seanf(“%ed%d%d", &a.marks 1, &a.marks2, &a.marks3); scanf(“%s”, a.regno); Module 1 9Lecture Notes Data Structures and Applications [21CS35] 6.7 Structure Initialization Like primary variables and arrays, structure variables can also be initialized where they are declared. The format used is quite similar to that used to initialize arrays. Array example: 2,4, 12, 5,45, 5); int numf ] = (2, 4, 12, 5,45, 5}; int num[6] = If the array is initialized where it is declared mentioning the dimension of the array is optional. Structure Examp! struct book { char namef 10]; float price; int pages; i struct book bl = (“c++", 150,00, 550); struct book b2 = {“physies”, 150.80, 800}; OR struct book Dr.Mahesh G Dr.Harish G { Assoc. Prof. Assoc. Prof. char name[ 10]; — =< float price; int pages; } bI = {*c++", 150.00, 550}, b2 = {“physies”, 150.80, 800}; Note — C language does not permit the initialization of individual structure members within the template, The initialization must be done only in the declaration of the actual variables. Example: struct person { int weight =60; float height = 170.60; pl: This is not permitted. Program to demonstrate structures struct student { char name[20]; int marks1; int marks2; int marks3; char regno[ 10]: Module 1Lecture Notes Data Structures and Apj lications [21CS35] void main() { struct student a, b; elrser( ); printf(“enter the name, m1, m2, m3 and regno of student1\n"); scanf(“es%d%d%d%S”,a.name, S&a.marks}, &a.marks2, &a.marks3, a.regno); printf(“enter the name, m1, m2, m3 and regno of student2\n"); seanf(“%es%d%d%d%S" baname, &b.markst, &b.marks2, &b.marks3, b.regno); print{(“the information of student 1 is\n' printf(“Jos%d%d%d%s”.a.name, a.marks], a.marks2, a.marks3, a.regno); print{(“the information of student 2 is\n"); printf(‘“%es%d%d%d%s”,b.name, b.marks|, b.marks2, b.marks3, b.regno); getch( ); } Dr.MaheshG Dr.Harish G ‘Assoc. Prof. Assoc. Prof. Comments: tov oe alt 1. The declaration at the beginning of the program combines different datatypes into a single entity called struct student. Here struct is a key word, student is the structure name and the different datatype elements are structure members, 2. a, bare structure variables of the type struct student, 3. The structure members are accessed using dot operator, So to refer name we use a.name, b.name and to refer marksI we use a.marksI and b.marks1. Before the dot we have a structure variable and after the dot we have a structure member. 4, Since a.name is a string, its base address can be obtained by just mentioning a.name. Hence the address operator (&) has been dropped while receiving the name in scanf. 6.8 Array of structures Suppose if we want to store data about a book, then the following structure may be used, struct book { char name{10); float price; int pages; struct book bl=(“c++", 150,00, 570}; Now, if we want to store data of 100 books we would be required to use 100 different structure variables from b1 to b100 which is definitely not very convenient. A better approach would be to use an array of structures, Module 1 4Lecture Notes Data Structures and Applications [21CS35] Program to demonstrate array of structures struct book { char name[ 10]; float price; h main( ) { ' Dr.Mahesh G Dr.Harish G struct book b[100]; Assoc. Prof. Assoc. Prot. intis ani ana or AIT clrser( ); for(i=0; 1<100; i++) { print{(“enter the name, price and number of pages of %d book\n”, scanf(“%s %6f ed bfi].name, &b[i].price, &bfi].pages); } print{(“books information\n”); printf(“name price number of pages\n”); for(i=0; i<100; i++) { printi(%s %of Ged \n”, bli].name, blil.price, bli].pages); } getch( ); } Here the structure fields are still accessed using the dot operator and the array elements using the usual subscript notation. 6.9 Assignment or Copying of Structure Variables The values of a structure variable can be assigned to another structure variable of the same type using the assignment operator ( = ). It is not necessary to copy the structure elements or members piece-meal. Obviously programmers prefer assignment to piece-meal copying. Program to demonstrate copying of structure variables struct employee { char namef 10]; int age; float salary; h void main() { struct employee el = (“Harish”, 30, 25000.00}; struct employee €2, 3; Module 1 a2Lecture Notes Data Structures and Applications [21CS35] } Mpiece-meal copying strepy(e2.name, e1.name); Hcopying all elements at one go e3 =e2; printi(“%es Ged %f \n, el name, el age, el salary); printi(“Ses Ged %f \n", e2.name, e2.age, €2.salary); printf(“Ses Ged %f \n”, e3.name, e3.age, e3.salary); getch( ); Output: th 30 25000.00 Dr.MaheshG Dr.Harish G 30 25000.00 Assoc. Prof. ASSOC. Prof. ‘h 30 25000.00 Msi & or AT 1. Copying of all structure elements at one go is possible because the structure elements are stored in contiguous memory locations. 2. Assignment or copying of different structure variables is invalid. Example: struct { char name[10]; int age; float salary; Ja, b; struct i char name{10]; int age; float salary; Je, 5 Valid Statements Tnvalid Statements (copying variables of same structure) | (copying variables of different structure) a=b ca bea ced dzc d=b Module 1 43Lecture Notes Data Structures and Applications [21CS35] 6.10 Comparison of Structure Variables Comparison of 2 structure variables of same type or dissimilar type is not allowed. Example: a /Mnvalid: Comparison is not allowed between structure variables. a!=b //Invalid: Comparison is not allowed between structure variables, However, the members of 2 structure variables of same type can be compared using relational operators. Example: amemberl ==b.member2 _//Return true if they are same, false otherwise amember! !=b.member2 //Return true if they are not same, false otherwise Note ~ The arithmetic, relational, logical and other various operations can be performed on individual members of structures but not on structure variables. 6.11 Pointer to Structures A variable which contains the address of a structure variable ‘alled pointer to a structure. The members of a structure can be accessed very efficiently using pointers. Example: Consider the following structure struct employee { char name[ 10}; Dr.MaheshG Dr.HarishG int age; ‘Assoc. Prof, ‘Assoc. Prof, float salar BMSIT & M. Dr. AIT hi void main( ) i struct employee el = {“Harish”, 30, 2500.00); struct employee *ptr, pir= ⪙ /Musing de-referencing operator * and dot (.. ) operator printf(“Name is %s \n”, (*ptr).name); printi(“Age is %d \n”, (*ptr).age): print{(Salary is Sef \n”, (*ptr).salary); Jfusing selection operator —> printf(Name is %s \n”, ptr->name); printf(“Age is %d \n”, ptr —>age); print{(Salary is Sef \n", ptr salary); Output: Name is Harish Age is 30 Salary is 25000.00 Name is Harish Age is 30 Salary is 25000.00 Module 1Lecture Notes Data Structures and Applications [21CS35] Note: To read using a pointer, use & operator Ex: scanf("ed",&ptr->age) or scanf("%ed", &(*ptr).age) 6.12 Difference between structures and arrays ‘Arrays ‘Structures T/ An amay is a collection of related data | Structure is a collection of elements of same datatype. variables of similar or dissimilar datatype. 2| An array item can be accessed by using | Structure items can be accessed its subscript or by using dereferencing / | using *.’or by using —> for indirection (*) operator for pointers. pointers. 6.13 Self Referential Structures (In DSA Syllabus) A structure which contains a reference (pointer) to itself is called a self referential structure. It is used to create data structures like linked lists, trees, ete. General Format struct tagname { datatype member! ; Dr.Mahesh G Dr.Harish G datatype member2; Assoc. Prof. Assoc. Prof. nisi AT struct tagname * pointer_name; Example struct node { int info; struct node* link; Module 1
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Victoria Walters
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel