Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Assignment 1

Uploaded by

BLACK xDEMON
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assignment 1

Uploaded by

BLACK xDEMON
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1. What is a Data Structure?

2. Describe the types of Data Structures.


3. What is a Linear Data Structure? Name a few examples.

Linear Data Structure:


Data structure where data elements are arranged sequentially or linearly where each and every
element is attached to its previous and next adjacent is called a linear data structure. In linear
data structure, single level is involved. Therefore, we can traverse all the elements in single run
only. Linear data structures are easy to implement because computer memory is arranged in a
linear way. Its examples are array, stack, queue, linked list, etc.

1. Array
The array is a type of data structure that stores elements of the same type. These are the most
basic and fundamental data structures. Data stored in each position of an array is given a positive
value called the index of the element. The index helps in identifying the location of the elements in
an array.
If supposedly we have to store some data i.e. the price of ten cars, then we can create a structure
of an array and store all the integers together. This doesn’t need creating ten separate integer
variables. Therefore, the lines in a code are reduced and memory is saved. The index value starts
with 0 for the first element in the case of an array.
2. Stack
The data structure follows the rule of LIFO (Last In-First Out) where the data last added element is
removed first. Push operation is used for adding an element of data on a stack and the pop
operation is used for deleting the data from the stack. This can be explained by the example of
books stacked together. In order to access the last book, all the books placed on top of the last
book have to be safely removed.
3. Queue
This structure is almost similar to the stack as the data is stored sequentially. The difference is that
the queue data structure follows FIFO which is the rule of First In-First Out where the first added
element is to exit the queue first. Front and rear are the two terms to be used in a queue.
Enqueue is the insertion operation and dequeue is the deletion operation. The former is performed
at the end of the queue and the latter is performed at the start end. The data structure might be
explained with the example of people queuing up to ride a bus. The first person in the line will get
the chance to exit the queue while the last person will be the last to exit.
4. Linked List
Linked lists are the types where the data is stored in the form of nodes which consist of an
element of data and a pointer. The use of the pointer is that it points or directs to the node which is
next to the element in the sequence. The data stored in a linked list might be of any form, strings,
numbers, or characters. Both sorted and unsorted data can be stored in a linked list along with
unique or duplicate elements.
5. Hash Tables
These types can be implemented as linear or non-linear data structures. The data structures
consist of key-value pairs.

4. What are some applications of Data Structures?


Application of Arrays:
 Arrangement of the leader board of a game can be done simply through arrays to store the
score and arrange them in descending order to clearly make out the rank of each player in the
game.
 A simple question Paper is an array of numbered questions with each of them assigned some
marks.
 Online ticket booking.
 Contacts on a cell phone.

Application of Strings:
 Spam email detection.
 Plagiarism detection.
 Search engine.
 Spell checkers.

Application of Matrix:
Matrix is an ordered collection of columns and rows of elements. It is necessary to enclose the
elements of a matrix within the brackets.
Some applications of a matrix are:
 In geology, matrices are used for making seismic surveys.
 Used for plotting graphs, and statistics and also to do scientific studies and research in almost
different fields.
 Media player.
 Mailing list.

Applications of the Linked list:


Different applications of linked lists are as follows:
 Linked lists are used to implement stacks, queues, graphs, etc.
 Linked lists are used to perform arithmetic operations on long integers.
 It is used for the representation of sparse matrices.
 It is used in the linked allocation of files.
 It helps in memory management.

Application of Stack:
A stack is a data structure that uses LIFO order.
Some Applications of a stack are:
 Converting infix to postfix expressions.
 History of visited websites.
 Java Virtual Machine.
Application of Queue:
A queue is a data structure that uses FIFO order.
Some applications of a queue are:
 Operating System uses queues for job scheduling.
 Sending an e-mail, it will be queued.
 Server while responding to request

5. What is a linked list Data Structure?


6. Are linked lists considered linear or non-linear Data Structures?
A linked list is a linear data structure where elements are not stored at contiguous location.
Instead the elements are linked using pointers.

In a linked list data is stored in nodes and each node is linked to the next and, optionally, to
the previous. Each node in a list consists of the following parts:

1. data
2. A pointer (Or reference) to the next node
3. Optionally, a pointer to the previous node

7. What are the advantages of a linked list over an array? In which scenarios do we use Linked
List and when Array?

Arrays

Let’s begin by defining an array. In simple words, an array is essentially a data


structure, similar to a list of values of the same data type. Another property of arrays
is that array elements are stored in continuous memory locations. Furthermore,
arrays have a fixed size which is defined upon initialization.

Linked Lists

A linked list is another approach to collecting similar data. However, unlike an array,
elements in a linked list are not in consecutive memory locations. A linked list is
composed of nodes which are connected with each other using pointers.
Linked lists are preferable over arrays when:
1. you need constant-time insertions/deletions from the list (such as in real-time computing where
time predictability is absolutely critical)
2. you don't know how many items will be in the list. With arrays, you may need to re-declare and
copy memory if the array grows too big
3. you don't need random access to any elements
4. you want to be able to insert items in the middle of the list (such as a priority queue)
Arrays are preferable when:
1. you need indexed/random access to elements
2. you know the number of elements in the array ahead of time so that you can allocate the correct
amount of memory for the array
3. you need speed when iterating through all the elements in sequence. You can use pointer math
on the array to access each element, whereas you need to lookup the node based on the pointer
for each element in linked list, which may result in page faults which may result in performance
hits.
4. memory is a concern. Filled arrays take up less memory than linked lists. Each element in the
array is just the data. Each linked list node requires the data as well as one (or more) pointers to
the other elements in the linked list

8. What is a doubly-linked list? Give some examples.


 It is used by web browsers for backward and forward navigation of web pages
 LRU ( Least Recently Used ) / MRU ( Most Recently Used ) Cache are constructed using Doubly Linked
Lists.
 Used by various applications to maintain undo and redo functionalities.
 In Operating Systems, a doubly linked list is maintained by thread scheduler to keep track of processes that are
being executed at that time.
9. What are dynamic Data Structures? Name a few.
What is Dynamic Data Structure?
In dynamic data structures, the size of the data structure can be modified after initialization. It means we
can add/delete elements from the data structure, thus modifying its size at runtime. Dynamic data
structures are memory efficient and especially useful when we don't know the data size beforehand.
Here are some examples of dynamic data structures along with their implementation in C:
1. Linked List - A collection of nodes, each with a data field and a pointer to the next node.
2. Stack - A data structure that uses a "last-in, first-out" (LIFO) approach.
3. Queue - A data structure that uses a "first-in, first-out" (FIFO) approach.
What is a dynamic data structure?
A dynamic data structure is a data structure whose size and shape can change during runtime to
accommodate different data requirements. Examples of dynamic data structures include linked lists,
trees, queues, and stacks.

10. What is an algorithm?

Definition of Algorithm
The word Algorithm means ” A set of finite rules or instructions to be followed in calculations or
other problem-solving operations ”
Or
” A procedure for solving a mathematical problem in a finite number of steps that frequently
involves recursive operations”.
Therefore Algorithm refers to a sequence of finite steps to solve a particular problem.

Use of the Algorithms:


Algorithms play a crucial role in various fields and have many applications. Some of the key areas
where algorithms are used include:
1. Computer Science: Algorithms form the basis of computer programming and are used to solve
problems ranging from simple sorting and searching to complex tasks such as artificial
intelligence and machine learning.
2. Mathematics: Algorithms are used to solve mathematical problems, such as finding the
optimal solution to a system of linear equations or finding the shortest path in a graph.
3. Operations Research: Algorithms are used to optimize and make decisions in fields such as
transportation, logistics, and resource allocation.
4. Artificial Intelligence: Algorithms are the foundation of artificial intelligence and machine
learning, and are used to develop intelligent systems that can perform tasks such as image
recognition, natural language processing, and decision-making.
5. Data Science: Algorithms are used to analyze, process, and extract insights from large
amounts of data in fields such as marketing, finance, and healthcare.
These are just a few examples of the many applications of algorithms. The use of algorithms is
continually expanding as new technologies and fields emerge, making it a vital component of
modern society.
Algorithms can be simple and complex depending on what you want to achieve.
It can be understood by taking the example of cooking a new recipe. To cook a new recipe, one
reads the instructions and steps and executes them one by one, in the given sequence. The result
thus obtained is the new dish is cooked perfectly. Every time you use your phone, computer,
laptop, or calculator you are using Algorithms. Similarly, algorithms help to do a task in
programming to get the expected output.
The Algorithm designed are language-independent, i.e. they are just plain instructions that can be
implemented in any language, and yet the output will be the same, as expected.
What is the need for algorithms?
1. Algorithms are necessary for solving complex problems efficiently and effectively.
2. They help to automate processes and make them more reliable, faster, and easier to perform.
3. Algorithms also enable computers to perform tasks that would be difficult or impossible for
humans to do manually.
4. They are used in various fields such as mathematics, computer science, engineering, finance,
and many others to optimize processes, analyze data, make predictions, and provide solutions
to problems.

You might also like