SlideShare a Scribd company logo
1 of 6
Download to read offline
Static arrays are structures whose size is fixed at compile time and therefore cannot be extended
or reduced to fit the data set. A dynamic array can be extended by doubling the size but there is
overhead associated with the operation of copying old data and freeing the memory associated
with the old data structure. One potential problem of using arrays for storing data is that arrays
require a contiguous block of memory which may not be available, if the requested contiguous
block is too large. However the advantages of using arrays are that each element in the array can
be accessed very efficiently using an index. However, for applications that can be better
managed without using contiguous memory we define a concept called “linked lists”.
A linked list is a collection of objects linked together by references from one object to another
object. By convention these objects are named as nodes. So the basic linked list is collection of
nodes where each node contains one or more data fields AND a reference to the next node. The
last node points to a NULL reference to indicate the end of the list.
Types of Linked Lists
Linked lists are widely used in many applications because of the flexibility it provides. Unlike
arrays that are dynamically assigned, linked lists do not require memory from a contiguous
block. This makes it very appealing to store data in a linked list, when the data set is large or
device (eg: PDA) has limited memory. One of the disadvantages of linked lists is that they are
not random accessed like arrays. To find information in a linked list one must start from the head
of the list and traverse the list sequentially until it finds (or not find) the node. Another advantage
of linked lists over arrays is that when a node is inserted or deleted, there is no need to “adjust”
the array.
There are few different types of linked lists. A singly linked list as described above provides
access to the list from the head node. Traversal is allowed only one way and there is no going
back. A doubly linked list is a list that has two references, one to the next node and another to
previous node. Doubly linked list also starts from head node, but provide access both ways. That
is one can traverse forward or backward from any node. A multilinked list (see figures 1 & 2) is
a more general linked list with multiple links from nodes. For examples, we can define a Node
that has two references, age pointer and a name pointer. With this structure it is possible to
maintain a single list, where if we follow the name pointer we can traverse the list in alphabetical
order of names and if we traverse the age pointer, we can traverse the list sorted by ages. This
type of node organization may be useful for maintaining a customer list in a bank where same
list can be traversed in any order (name, age, or any other criteria) based on the need.
Designing the Node of a Linked List
Linked list is a collection of linked nodes. A node is a struct with at least a data field and a
reference to a node of the same type. A node is called a self-referential object, since it contains a
pointer to a variable that refers to a variable of the same type. For example, a struct Node that
contains an int data field and a pointer to another node can be defined as follows.
typedef struct node {
int data;
struct node* next;
} node;
node* head = NULL;
Creating the first node
Memory must be allocated for one node and assigned to head as follows.
head = (node*) malloc(sizeof(node));
headdata = 10;
headnext = NULL;
Adding the second node and linking
node* nextnode = malloc(sizeof(node));
nextnodedata = 12;
nextnodenext = NULL;
headnext = nextnode;
Linked list is a data structure in which the items are ordered in a linear way. Although modern
programming languages support very flexible and rich libraries that works with arrays, which use
arrays to represent lists, the principles of building a linked list remain very important. The way
linked lists are implemented is a ground level in order to build more complex data structures
such as trees.
It’s true that almost every operation we can perform on a linked list can be done with an array.
It’s also true that some operations can be faster on arrays compared to linked lists.
However understanding how to implement the basic operations of a linked list such as INSERT,
DELETE, INSERT_AFTER, PRINT and so on is crucial in order to implement data structures as
rooted trees, B-trees, red-black trees, etc.
Big-O notation is a way to express the efficiency of an algorithm. If you’re going to be working
with code, it is extremely important that you understand Big-O. It is, quite literally, the language
we use to express efficiency.
Big-O is an expression of how the execution time of a program scales with the input data. That
is, as the input gets bigger, how much longer will the program take? Just a little bit? A lot
longer?
Suppose you have a function for which does some processing on an array of size N. If foo takes
O(N) time, then, as the array grows (that is, as N increases), the number of seconds foo takes will
also increase in some sort of linear fashion.
The first decision in planning the linked-list implementation of the Queue class is which end of
the list will correspond to the front of the queue. Recall that items need to be added to the rear of
the queue, and removed from the front of the queue. Therefore, we should make our choice
based on whether it is easier to add/remove a node from the front/end of a linked list.
If we keep pointers to both the first and last nodes of the list, we can add a node at either end in
constant time. However, while we can remove the first node in the list in constant time,
removing the last node requires first locating the previous node, which takes time proportional to
the length of the list. Therefore, we should choose to make the end of the list be the rear of the
queue, and the front of the list be the front of the queue.
Other than saving space, the first advantage I can see for singly linked lists over doubly linked
lists is to avoid having to update two links instead of one when you modify the list, when adding
an element for example.
Of course, one might say that you can always ignore the second link, but in that case, it is no
longer doubly linked, but only an unused field.What might also be seen as an advantage is that
singly linked list are necessarily consistent, though possibly wrong when there are bugs in the
program. Doubly linked lists can end-up having inconsistent links forward and backward. But it
is debatable which of the two cases, if any, is an advantage.
update:
I had tried to see some impact on garbage collection, but found none. Actually, there is one when
storage reclamation is done by reference counting, as reference counting is defeated by loops,
and doubly linked lists contain loops. Singly linked list escape the problem. Of course, there are
ways around it for doubly linked lists, such as the use of weak pointers, or programmable
reference counting as part of data abstraction.
Solution
Static arrays are structures whose size is fixed at compile time and therefore cannot be extended
or reduced to fit the data set. A dynamic array can be extended by doubling the size but there is
overhead associated with the operation of copying old data and freeing the memory associated
with the old data structure. One potential problem of using arrays for storing data is that arrays
require a contiguous block of memory which may not be available, if the requested contiguous
block is too large. However the advantages of using arrays are that each element in the array can
be accessed very efficiently using an index. However, for applications that can be better
managed without using contiguous memory we define a concept called “linked lists”.
A linked list is a collection of objects linked together by references from one object to another
object. By convention these objects are named as nodes. So the basic linked list is collection of
nodes where each node contains one or more data fields AND a reference to the next node. The
last node points to a NULL reference to indicate the end of the list.
Types of Linked Lists
Linked lists are widely used in many applications because of the flexibility it provides. Unlike
arrays that are dynamically assigned, linked lists do not require memory from a contiguous
block. This makes it very appealing to store data in a linked list, when the data set is large or
device (eg: PDA) has limited memory. One of the disadvantages of linked lists is that they are
not random accessed like arrays. To find information in a linked list one must start from the head
of the list and traverse the list sequentially until it finds (or not find) the node. Another advantage
of linked lists over arrays is that when a node is inserted or deleted, there is no need to “adjust”
the array.
There are few different types of linked lists. A singly linked list as described above provides
access to the list from the head node. Traversal is allowed only one way and there is no going
back. A doubly linked list is a list that has two references, one to the next node and another to
previous node. Doubly linked list also starts from head node, but provide access both ways. That
is one can traverse forward or backward from any node. A multilinked list (see figures 1 & 2) is
a more general linked list with multiple links from nodes. For examples, we can define a Node
that has two references, age pointer and a name pointer. With this structure it is possible to
maintain a single list, where if we follow the name pointer we can traverse the list in alphabetical
order of names and if we traverse the age pointer, we can traverse the list sorted by ages. This
type of node organization may be useful for maintaining a customer list in a bank where same
list can be traversed in any order (name, age, or any other criteria) based on the need.
Designing the Node of a Linked List
Linked list is a collection of linked nodes. A node is a struct with at least a data field and a
reference to a node of the same type. A node is called a self-referential object, since it contains a
pointer to a variable that refers to a variable of the same type. For example, a struct Node that
contains an int data field and a pointer to another node can be defined as follows.
typedef struct node {
int data;
struct node* next;
} node;
node* head = NULL;
Creating the first node
Memory must be allocated for one node and assigned to head as follows.
head = (node*) malloc(sizeof(node));
headdata = 10;
headnext = NULL;
Adding the second node and linking
node* nextnode = malloc(sizeof(node));
nextnodedata = 12;
nextnodenext = NULL;
headnext = nextnode;
Linked list is a data structure in which the items are ordered in a linear way. Although modern
programming languages support very flexible and rich libraries that works with arrays, which use
arrays to represent lists, the principles of building a linked list remain very important. The way
linked lists are implemented is a ground level in order to build more complex data structures
such as trees.
It’s true that almost every operation we can perform on a linked list can be done with an array.
It’s also true that some operations can be faster on arrays compared to linked lists.
However understanding how to implement the basic operations of a linked list such as INSERT,
DELETE, INSERT_AFTER, PRINT and so on is crucial in order to implement data structures as
rooted trees, B-trees, red-black trees, etc.
Big-O notation is a way to express the efficiency of an algorithm. If you’re going to be working
with code, it is extremely important that you understand Big-O. It is, quite literally, the language
we use to express efficiency.
Big-O is an expression of how the execution time of a program scales with the input data. That
is, as the input gets bigger, how much longer will the program take? Just a little bit? A lot
longer?
Suppose you have a function for which does some processing on an array of size N. If foo takes
O(N) time, then, as the array grows (that is, as N increases), the number of seconds foo takes will
also increase in some sort of linear fashion.
The first decision in planning the linked-list implementation of the Queue class is which end of
the list will correspond to the front of the queue. Recall that items need to be added to the rear of
the queue, and removed from the front of the queue. Therefore, we should make our choice
based on whether it is easier to add/remove a node from the front/end of a linked list.
If we keep pointers to both the first and last nodes of the list, we can add a node at either end in
constant time. However, while we can remove the first node in the list in constant time,
removing the last node requires first locating the previous node, which takes time proportional to
the length of the list. Therefore, we should choose to make the end of the list be the rear of the
queue, and the front of the list be the front of the queue.
Other than saving space, the first advantage I can see for singly linked lists over doubly linked
lists is to avoid having to update two links instead of one when you modify the list, when adding
an element for example.
Of course, one might say that you can always ignore the second link, but in that case, it is no
longer doubly linked, but only an unused field.What might also be seen as an advantage is that
singly linked list are necessarily consistent, though possibly wrong when there are bugs in the
program. Doubly linked lists can end-up having inconsistent links forward and backward. But it
is debatable which of the two cases, if any, is an advantage.
update:
I had tried to see some impact on garbage collection, but found none. Actually, there is one when
storage reclamation is done by reference counting, as reference counting is defeated by loops,
and doubly linked lists contain loops. Singly linked list escape the problem. Of course, there are
ways around it for doubly linked lists, such as the use of weak pointers, or programmable
reference counting as part of data abstraction.

More Related Content

Similar to Static arrays are structures whose size is fixed at compile time and.pdf

Ap Power Point Chpt9
Ap Power Point Chpt9Ap Power Point Chpt9
Ap Power Point Chpt9dplunkett
 
2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions2 Important Data Structure Interview Questions
2 Important Data Structure Interview QuestionsGeekster
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using pythonLavanyaJ28
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxData Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxUsriDevi1
 
Indexing techniques
Indexing techniquesIndexing techniques
Indexing techniquesHuda Alameen
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseoJinTaek Seo
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data StructureJazz Jinia Bhowmik
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testspriyanshukumar97908
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdfSulabhPawaia
 
Linear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueLinear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueSelvaraj Seerangan
 
Different types of Linked list.
Different types of Linked list.Different types of Linked list.
Different types of Linked list.JAYANTAOJHA
 
Key,ID Field and Tables Relationship
Key,ID Field and Tables Relationship Key,ID Field and Tables Relationship
Key,ID Field and Tables Relationship ShouaQureshi
 
Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Tutort Academy
 
Introduction to linked lists
Introduction to linked listsIntroduction to linked lists
Introduction to linked listspooja kumari
 
In this lab we will write code for working with a Linked List. Node .pdf
In this lab we will write code for working with a Linked List.  Node .pdfIn this lab we will write code for working with a Linked List.  Node .pdf
In this lab we will write code for working with a Linked List. Node .pdffms12345
 

Similar to Static arrays are structures whose size is fixed at compile time and.pdf (20)

Ap Power Point Chpt9
Ap Power Point Chpt9Ap Power Point Chpt9
Ap Power Point Chpt9
 
2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using python
 
linked_lists
linked_listslinked_lists
linked_lists
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxData Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Link list
Link listLink list
Link list
 
Indexing techniques
Indexing techniquesIndexing techniques
Indexing techniques
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
Linear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueLinear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and Queue
 
Different types of Linked list.
Different types of Linked list.Different types of Linked list.
Different types of Linked list.
 
Key,ID Field and Tables Relationship
Key,ID Field and Tables Relationship Key,ID Field and Tables Relationship
Key,ID Field and Tables Relationship
 
Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...Which data structure is it? What are the various data structure kinds and wha...
Which data structure is it? What are the various data structure kinds and wha...
 
Introduction to linked lists
Introduction to linked listsIntroduction to linked lists
Introduction to linked lists
 
In this lab we will write code for working with a Linked List. Node .pdf
In this lab we will write code for working with a Linked List.  Node .pdfIn this lab we will write code for working with a Linked List.  Node .pdf
In this lab we will write code for working with a Linked List. Node .pdf
 

More from anjanacottonmills

Step1 First compound has 2 double bonds ; Second .pdf
                     Step1 First compound has 2 double bonds ; Second .pdf                     Step1 First compound has 2 double bonds ; Second .pdf
Step1 First compound has 2 double bonds ; Second .pdfanjanacottonmills
 
Molarity = molesvolume9liter) Molarity of NH4Cl.pdf
                     Molarity = molesvolume9liter)  Molarity of NH4Cl.pdf                     Molarity = molesvolume9liter)  Molarity of NH4Cl.pdf
Molarity = molesvolume9liter) Molarity of NH4Cl.pdfanjanacottonmills
 
HOCH2CH2OH is more soluble in water. more OH grou.pdf
                     HOCH2CH2OH is more soluble in water. more OH grou.pdf                     HOCH2CH2OH is more soluble in water. more OH grou.pdf
HOCH2CH2OH is more soluble in water. more OH grou.pdfanjanacottonmills
 
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdfz=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdfanjanacottonmills
 
This above plant name is Solidago sempervirens, belong to genus Soli.pdf
This above plant name is Solidago sempervirens, belong to genus Soli.pdfThis above plant name is Solidago sempervirens, belong to genus Soli.pdf
This above plant name is Solidago sempervirens, belong to genus Soli.pdfanjanacottonmills
 
The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfanjanacottonmills
 
The fidelity of DNA replication determines the genome stability and .pdf
The fidelity of DNA replication determines the genome stability and .pdfThe fidelity of DNA replication determines the genome stability and .pdf
The fidelity of DNA replication determines the genome stability and .pdfanjanacottonmills
 
E= 0.28V reactants are favored .pdf
                     E= 0.28V reactants are favored                   .pdf                     E= 0.28V reactants are favored                   .pdf
E= 0.28V reactants are favored .pdfanjanacottonmills
 
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdfThe differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdfanjanacottonmills
 
TCP - TCP breaks data into manageable packets and tracks information.pdf
TCP - TCP breaks data into manageable packets and tracks information.pdfTCP - TCP breaks data into manageable packets and tracks information.pdf
TCP - TCP breaks data into manageable packets and tracks information.pdfanjanacottonmills
 
D) II, III, IV, and V only .pdf
                     D) II, III, IV, and V only                       .pdf                     D) II, III, IV, and V only                       .pdf
D) II, III, IV, and V only .pdfanjanacottonmills
 
NumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfNumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfanjanacottonmills
 
c) H2(g) + 12 O2(g) -H2O (l) as all are in the.pdf
                     c) H2(g) + 12 O2(g) -H2O (l)  as all are in the.pdf                     c) H2(g) + 12 O2(g) -H2O (l)  as all are in the.pdf
c) H2(g) + 12 O2(g) -H2O (l) as all are in the.pdfanjanacottonmills
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfanjanacottonmills
 
Interphase.This is the phase where the cell prepares for the next .pdf
Interphase.This is the phase where the cell prepares for the next .pdfInterphase.This is the phase where the cell prepares for the next .pdf
Interphase.This is the phase where the cell prepares for the next .pdfanjanacottonmills
 
B.the rotation will be zero as L and D will cance.pdf
                     B.the rotation will be zero as L and D will cance.pdf                     B.the rotation will be zero as L and D will cance.pdf
B.the rotation will be zero as L and D will cance.pdfanjanacottonmills
 
In the above conversation it is belonging to stereotypes.Stereotyp.pdf
In the above conversation it is belonging to stereotypes.Stereotyp.pdfIn the above conversation it is belonging to stereotypes.Stereotyp.pdf
In the above conversation it is belonging to stereotypes.Stereotyp.pdfanjanacottonmills
 
In general, the objective of an audit is to assess the risk of mater.pdf
In general, the objective of an audit is to assess the risk of mater.pdfIn general, the objective of an audit is to assess the risk of mater.pdf
In general, the objective of an audit is to assess the risk of mater.pdfanjanacottonmills
 
if one can understand a few things it is easier to solve these kind .pdf
if one can understand a few things it is easier to solve these kind .pdfif one can understand a few things it is easier to solve these kind .pdf
if one can understand a few things it is easier to solve these kind .pdfanjanacottonmills
 

More from anjanacottonmills (20)

Step1 First compound has 2 double bonds ; Second .pdf
                     Step1 First compound has 2 double bonds ; Second .pdf                     Step1 First compound has 2 double bonds ; Second .pdf
Step1 First compound has 2 double bonds ; Second .pdf
 
Molarity = molesvolume9liter) Molarity of NH4Cl.pdf
                     Molarity = molesvolume9liter)  Molarity of NH4Cl.pdf                     Molarity = molesvolume9liter)  Molarity of NH4Cl.pdf
Molarity = molesvolume9liter) Molarity of NH4Cl.pdf
 
HOCH2CH2OH is more soluble in water. more OH grou.pdf
                     HOCH2CH2OH is more soluble in water. more OH grou.pdf                     HOCH2CH2OH is more soluble in water. more OH grou.pdf
HOCH2CH2OH is more soluble in water. more OH grou.pdf
 
x = -2Solutionx = -2.pdf
x = -2Solutionx = -2.pdfx = -2Solutionx = -2.pdf
x = -2Solutionx = -2.pdf
 
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdfz=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
z=(2n+1)4where n=all integersSolutionz=(2n+1)4where n=al.pdf
 
This above plant name is Solidago sempervirens, belong to genus Soli.pdf
This above plant name is Solidago sempervirens, belong to genus Soli.pdfThis above plant name is Solidago sempervirens, belong to genus Soli.pdf
This above plant name is Solidago sempervirens, belong to genus Soli.pdf
 
The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdf
 
The fidelity of DNA replication determines the genome stability and .pdf
The fidelity of DNA replication determines the genome stability and .pdfThe fidelity of DNA replication determines the genome stability and .pdf
The fidelity of DNA replication determines the genome stability and .pdf
 
E= 0.28V reactants are favored .pdf
                     E= 0.28V reactants are favored                   .pdf                     E= 0.28V reactants are favored                   .pdf
E= 0.28V reactants are favored .pdf
 
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdfThe differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
The differences between ipv4 and ipv6 are as below1. Header1.Ch.pdf
 
TCP - TCP breaks data into manageable packets and tracks information.pdf
TCP - TCP breaks data into manageable packets and tracks information.pdfTCP - TCP breaks data into manageable packets and tracks information.pdf
TCP - TCP breaks data into manageable packets and tracks information.pdf
 
D) II, III, IV, and V only .pdf
                     D) II, III, IV, and V only                       .pdf                     D) II, III, IV, and V only                       .pdf
D) II, III, IV, and V only .pdf
 
NumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfNumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdf
 
c) H2(g) + 12 O2(g) -H2O (l) as all are in the.pdf
                     c) H2(g) + 12 O2(g) -H2O (l)  as all are in the.pdf                     c) H2(g) + 12 O2(g) -H2O (l)  as all are in the.pdf
c) H2(g) + 12 O2(g) -H2O (l) as all are in the.pdf
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 
Interphase.This is the phase where the cell prepares for the next .pdf
Interphase.This is the phase where the cell prepares for the next .pdfInterphase.This is the phase where the cell prepares for the next .pdf
Interphase.This is the phase where the cell prepares for the next .pdf
 
B.the rotation will be zero as L and D will cance.pdf
                     B.the rotation will be zero as L and D will cance.pdf                     B.the rotation will be zero as L and D will cance.pdf
B.the rotation will be zero as L and D will cance.pdf
 
In the above conversation it is belonging to stereotypes.Stereotyp.pdf
In the above conversation it is belonging to stereotypes.Stereotyp.pdfIn the above conversation it is belonging to stereotypes.Stereotyp.pdf
In the above conversation it is belonging to stereotypes.Stereotyp.pdf
 
In general, the objective of an audit is to assess the risk of mater.pdf
In general, the objective of an audit is to assess the risk of mater.pdfIn general, the objective of an audit is to assess the risk of mater.pdf
In general, the objective of an audit is to assess the risk of mater.pdf
 
if one can understand a few things it is easier to solve these kind .pdf
if one can understand a few things it is easier to solve these kind .pdfif one can understand a few things it is easier to solve these kind .pdf
if one can understand a few things it is easier to solve these kind .pdf
 

Recently uploaded

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Static arrays are structures whose size is fixed at compile time and.pdf

  • 1. Static arrays are structures whose size is fixed at compile time and therefore cannot be extended or reduced to fit the data set. A dynamic array can be extended by doubling the size but there is overhead associated with the operation of copying old data and freeing the memory associated with the old data structure. One potential problem of using arrays for storing data is that arrays require a contiguous block of memory which may not be available, if the requested contiguous block is too large. However the advantages of using arrays are that each element in the array can be accessed very efficiently using an index. However, for applications that can be better managed without using contiguous memory we define a concept called “linked lists”. A linked list is a collection of objects linked together by references from one object to another object. By convention these objects are named as nodes. So the basic linked list is collection of nodes where each node contains one or more data fields AND a reference to the next node. The last node points to a NULL reference to indicate the end of the list. Types of Linked Lists Linked lists are widely used in many applications because of the flexibility it provides. Unlike arrays that are dynamically assigned, linked lists do not require memory from a contiguous block. This makes it very appealing to store data in a linked list, when the data set is large or device (eg: PDA) has limited memory. One of the disadvantages of linked lists is that they are not random accessed like arrays. To find information in a linked list one must start from the head of the list and traverse the list sequentially until it finds (or not find) the node. Another advantage of linked lists over arrays is that when a node is inserted or deleted, there is no need to “adjust” the array. There are few different types of linked lists. A singly linked list as described above provides access to the list from the head node. Traversal is allowed only one way and there is no going back. A doubly linked list is a list that has two references, one to the next node and another to previous node. Doubly linked list also starts from head node, but provide access both ways. That is one can traverse forward or backward from any node. A multilinked list (see figures 1 & 2) is a more general linked list with multiple links from nodes. For examples, we can define a Node that has two references, age pointer and a name pointer. With this structure it is possible to maintain a single list, where if we follow the name pointer we can traverse the list in alphabetical order of names and if we traverse the age pointer, we can traverse the list sorted by ages. This type of node organization may be useful for maintaining a customer list in a bank where same list can be traversed in any order (name, age, or any other criteria) based on the need. Designing the Node of a Linked List Linked list is a collection of linked nodes. A node is a struct with at least a data field and a reference to a node of the same type. A node is called a self-referential object, since it contains a
  • 2. pointer to a variable that refers to a variable of the same type. For example, a struct Node that contains an int data field and a pointer to another node can be defined as follows. typedef struct node { int data; struct node* next; } node; node* head = NULL; Creating the first node Memory must be allocated for one node and assigned to head as follows. head = (node*) malloc(sizeof(node)); headdata = 10; headnext = NULL; Adding the second node and linking node* nextnode = malloc(sizeof(node)); nextnodedata = 12; nextnodenext = NULL; headnext = nextnode; Linked list is a data structure in which the items are ordered in a linear way. Although modern programming languages support very flexible and rich libraries that works with arrays, which use arrays to represent lists, the principles of building a linked list remain very important. The way linked lists are implemented is a ground level in order to build more complex data structures such as trees. It’s true that almost every operation we can perform on a linked list can be done with an array. It’s also true that some operations can be faster on arrays compared to linked lists. However understanding how to implement the basic operations of a linked list such as INSERT, DELETE, INSERT_AFTER, PRINT and so on is crucial in order to implement data structures as rooted trees, B-trees, red-black trees, etc. Big-O notation is a way to express the efficiency of an algorithm. If you’re going to be working with code, it is extremely important that you understand Big-O. It is, quite literally, the language we use to express efficiency. Big-O is an expression of how the execution time of a program scales with the input data. That is, as the input gets bigger, how much longer will the program take? Just a little bit? A lot longer? Suppose you have a function for which does some processing on an array of size N. If foo takes O(N) time, then, as the array grows (that is, as N increases), the number of seconds foo takes will also increase in some sort of linear fashion.
  • 3. The first decision in planning the linked-list implementation of the Queue class is which end of the list will correspond to the front of the queue. Recall that items need to be added to the rear of the queue, and removed from the front of the queue. Therefore, we should make our choice based on whether it is easier to add/remove a node from the front/end of a linked list. If we keep pointers to both the first and last nodes of the list, we can add a node at either end in constant time. However, while we can remove the first node in the list in constant time, removing the last node requires first locating the previous node, which takes time proportional to the length of the list. Therefore, we should choose to make the end of the list be the rear of the queue, and the front of the list be the front of the queue. Other than saving space, the first advantage I can see for singly linked lists over doubly linked lists is to avoid having to update two links instead of one when you modify the list, when adding an element for example. Of course, one might say that you can always ignore the second link, but in that case, it is no longer doubly linked, but only an unused field.What might also be seen as an advantage is that singly linked list are necessarily consistent, though possibly wrong when there are bugs in the program. Doubly linked lists can end-up having inconsistent links forward and backward. But it is debatable which of the two cases, if any, is an advantage. update: I had tried to see some impact on garbage collection, but found none. Actually, there is one when storage reclamation is done by reference counting, as reference counting is defeated by loops, and doubly linked lists contain loops. Singly linked list escape the problem. Of course, there are ways around it for doubly linked lists, such as the use of weak pointers, or programmable reference counting as part of data abstraction. Solution Static arrays are structures whose size is fixed at compile time and therefore cannot be extended or reduced to fit the data set. A dynamic array can be extended by doubling the size but there is overhead associated with the operation of copying old data and freeing the memory associated with the old data structure. One potential problem of using arrays for storing data is that arrays require a contiguous block of memory which may not be available, if the requested contiguous block is too large. However the advantages of using arrays are that each element in the array can be accessed very efficiently using an index. However, for applications that can be better managed without using contiguous memory we define a concept called “linked lists”. A linked list is a collection of objects linked together by references from one object to another object. By convention these objects are named as nodes. So the basic linked list is collection of
  • 4. nodes where each node contains one or more data fields AND a reference to the next node. The last node points to a NULL reference to indicate the end of the list. Types of Linked Lists Linked lists are widely used in many applications because of the flexibility it provides. Unlike arrays that are dynamically assigned, linked lists do not require memory from a contiguous block. This makes it very appealing to store data in a linked list, when the data set is large or device (eg: PDA) has limited memory. One of the disadvantages of linked lists is that they are not random accessed like arrays. To find information in a linked list one must start from the head of the list and traverse the list sequentially until it finds (or not find) the node. Another advantage of linked lists over arrays is that when a node is inserted or deleted, there is no need to “adjust” the array. There are few different types of linked lists. A singly linked list as described above provides access to the list from the head node. Traversal is allowed only one way and there is no going back. A doubly linked list is a list that has two references, one to the next node and another to previous node. Doubly linked list also starts from head node, but provide access both ways. That is one can traverse forward or backward from any node. A multilinked list (see figures 1 & 2) is a more general linked list with multiple links from nodes. For examples, we can define a Node that has two references, age pointer and a name pointer. With this structure it is possible to maintain a single list, where if we follow the name pointer we can traverse the list in alphabetical order of names and if we traverse the age pointer, we can traverse the list sorted by ages. This type of node organization may be useful for maintaining a customer list in a bank where same list can be traversed in any order (name, age, or any other criteria) based on the need. Designing the Node of a Linked List Linked list is a collection of linked nodes. A node is a struct with at least a data field and a reference to a node of the same type. A node is called a self-referential object, since it contains a pointer to a variable that refers to a variable of the same type. For example, a struct Node that contains an int data field and a pointer to another node can be defined as follows. typedef struct node { int data; struct node* next; } node; node* head = NULL; Creating the first node Memory must be allocated for one node and assigned to head as follows. head = (node*) malloc(sizeof(node)); headdata = 10;
  • 5. headnext = NULL; Adding the second node and linking node* nextnode = malloc(sizeof(node)); nextnodedata = 12; nextnodenext = NULL; headnext = nextnode; Linked list is a data structure in which the items are ordered in a linear way. Although modern programming languages support very flexible and rich libraries that works with arrays, which use arrays to represent lists, the principles of building a linked list remain very important. The way linked lists are implemented is a ground level in order to build more complex data structures such as trees. It’s true that almost every operation we can perform on a linked list can be done with an array. It’s also true that some operations can be faster on arrays compared to linked lists. However understanding how to implement the basic operations of a linked list such as INSERT, DELETE, INSERT_AFTER, PRINT and so on is crucial in order to implement data structures as rooted trees, B-trees, red-black trees, etc. Big-O notation is a way to express the efficiency of an algorithm. If you’re going to be working with code, it is extremely important that you understand Big-O. It is, quite literally, the language we use to express efficiency. Big-O is an expression of how the execution time of a program scales with the input data. That is, as the input gets bigger, how much longer will the program take? Just a little bit? A lot longer? Suppose you have a function for which does some processing on an array of size N. If foo takes O(N) time, then, as the array grows (that is, as N increases), the number of seconds foo takes will also increase in some sort of linear fashion. The first decision in planning the linked-list implementation of the Queue class is which end of the list will correspond to the front of the queue. Recall that items need to be added to the rear of the queue, and removed from the front of the queue. Therefore, we should make our choice based on whether it is easier to add/remove a node from the front/end of a linked list. If we keep pointers to both the first and last nodes of the list, we can add a node at either end in constant time. However, while we can remove the first node in the list in constant time, removing the last node requires first locating the previous node, which takes time proportional to the length of the list. Therefore, we should choose to make the end of the list be the rear of the queue, and the front of the list be the front of the queue. Other than saving space, the first advantage I can see for singly linked lists over doubly linked lists is to avoid having to update two links instead of one when you modify the list, when adding
  • 6. an element for example. Of course, one might say that you can always ignore the second link, but in that case, it is no longer doubly linked, but only an unused field.What might also be seen as an advantage is that singly linked list are necessarily consistent, though possibly wrong when there are bugs in the program. Doubly linked lists can end-up having inconsistent links forward and backward. But it is debatable which of the two cases, if any, is an advantage. update: I had tried to see some impact on garbage collection, but found none. Actually, there is one when storage reclamation is done by reference counting, as reference counting is defeated by loops, and doubly linked lists contain loops. Singly linked list escape the problem. Of course, there are ways around it for doubly linked lists, such as the use of weak pointers, or programmable reference counting as part of data abstraction.