Documente Academic
Documente Profesional
Documente Cultură
ii) Hash tables:- A hash table, or a hash map, is a data structure that
associates keys with values. The primary operation it supports efficiently is a
lookup: given a key (e.g. a person's name), find the corresponding value (e.g.
that person's telephone number). It works by transforming the key using a hash
function into a hash, a number that is used as an index in an array to locate the
desired location ("bucket") where the values should be.
1. Insert With Priority: add an element to the queue with an associated priority
2. Get Next: remove the element from the queue that has the highest
priority, and return it (also known as "Pop Element(Off)", or "Get
Minimum")
3. Peek At Next (optional): look at the element with highest priority without
removing it.
6. Explain the Circular singly linked list with neat diagram.
Sol:-In a circularly-linked list, the first and last nodes are linked together. This can
be done for both singly and doubly linked lists. To traverse a circular linked list,
we begin at any node and follow the list in either direction until we return to the
original node. Viewed another way, circularly-linked lists can be seen as having
no beginning or end. This type of list is most useful for managing buffers for
data ingest, and in cases where you have one object in a list and wish to iterate
through all other objects in the list in no particular order. The pointer pointing to
the whole list may be called the access pointer.
A circularly-linked list
7. Discuss the various graphs with neat diagram.
The graphs can be represented in two ways. One is adjacency matrix and adjacency
list.
For A----------->B
| ^
| |
| |
V |
C ------------
Adjacency Matrix
A B C
A 0 1 1
B 0 0 0
C 0 1 0
Adjacency List
Each element in an internal node acts as a separation value for two subtrees, and
when such an element is deleted, two cases arise. In the first case, both of the
two child nodes to the left and right of the deleted element have the minimum
number of elements, namely L-1. They can then be joined into a single node
with 2L-2 elements, a number which does not exceed U-1 and so is a legal node.
Unless it is known that this particular B-tree does not contain duplicate data, we
must then also (recursively) delete the element in question from the new node.
In the second case, one of the two child nodes contains more than the minimum
number of elements. Then a new separator for those subtrees must be found.
Note that the largest element in the left subtree is the largest element which is
still less than the separator. Likewise, the smallest element in the right subtree is
the smallest element which is still greater than the separator. Both of those
elements are in leaf nodes, and either can be the new separator for the two
subtrees.
Sol: - Data structure:- A data structure in computer science is a way of storing data
in a computer so that it can be used efficiently. It is an organization of mathematical
and logical concepts of data. Often a carefully chosen data structure will allow the
most efficient algorithm to be used. The choice of the data structure often begins
from the choice of an abstract data type. A well-designed data structure allows a
variety of critical operations to be performed, using as few resources, both
execution time and memory space, as possible. Data structures are implemented by
a programming language as data types and the references and operations they
provide.
Different kinds of data structures are suited to different kinds of applications, and
some are highly specialized to certain tasks. For example, B-trees are particularly
well-suited for implementation of databases, while networks of machines rely on
routing tables to function.
In the design of many types of computer program, the choice of data structures is a
primary design consideration. Experience in building large systems has shown that
the difficulty of implementation and the quality and performance of the final result
depends heavily on choosing the best data structure. After the data structures are
chosen, the algorithms to be used often become relatively obvious. Sometimes
things work in the opposite direction — data structures are chosen because certain
key tasks have algorithms that work best with particular data structures. In either
case, the choice of appropriate data structures is crucial.
This insight has given rise to many formalized design methods and programming
languages in which data structures, rather than algorithms, are the key organizing
factor. Most languages feature some sort of module system, allowing data structures
to be safely reused in different applications by hiding their verified implementation
details behind controlled interfaces. Object-oriented programming languages such
as C++ and Java in particular use classes for this purpose.
Since data structures are so crucial, many of them are included in standard libraries
of modern programming languages and APIs, such as C++'s containers, the Java
Collections Framework, and the Microsoft .NET Framework.
The fundamental building blocks of most data structures are arrays, records,
discriminated unions, and references. For example, the nullable reference, a
reference which can be null, is a combination of references and discriminated
unions, and the simplest linked data structure, the linked list, is built from records
and nullable references.
Application of stack
Expression evaluation and syntax parsing
Calculators employing reverse Polish notation use a stack structure to hold values.
Expressions can be represented in prefix, postfix or infix notations. Convers
Forth uses two stacks, one for argument passing and one for subroutine return
addresses. The use of a return stack is extremely commonplace, but the somewhat
unusual use of an argument stack for a human-readable programming language is
the reason Forth is referred to as a stack-based language.
4. Write a note on Double Ended queues.
In computer science theory, a deque (short for double-ended queue—usually
pronounced deck) is an abstract list type data structure, also called a head-tail
linked list, for which elements can be added to or removed from the front (head) or
back (tail).Deque is sometimes written dequeue, but this use is generally deprecated
in technical literature or technical writing because dequeue is also a verb meaning
"to remove from a queue". Nevertheless, several libraries and some writers, such as
Aho, Hopcroft, and Ullman in their textbook Data Structures and Algorithms, spell
it dequeue. DEQ and DQ are also used.
This differs from the queue abstract data type or First-In-First-Out List (FIFO),
where elements can only be added to one end and removed from the other. This
general data class has some possible sub-types:
• An input-restricted deque is one where deletion can be made from both ends,
but input can only be made at one end.
• An output-restricted deque is one where input can be made at both ends, but
output can be made from one end only.
Both the basic and most common list types in computing, the queues and stacks can
be considered specializations of deques, and can be implemented using deques.
In computer science, a binary search tree (BST) is a binary tree data structure
which has the following properties:
The major advantage of binary search trees over other data structures is that the
related sorting algorithms and search algorithms such as in-order traversal can be
very efficient.
Binary search trees can choose to allow or disallow duplicate values, depending on
the implementation.
Binary search trees are a fundamental data structure used to construct more abstract
data structures such as sets, multisets, and associative arrays.
Searching a binary tree for a specific value can be a recursive or iterative process.
This explanation covers a recursive method.
We begin by examining the root node. If the tree is null, the value we are searching
for does not exist in the tree. Otherwise, if the value equals the root, the search is
successful. If the value is less than the root, search the left subtree. Similarly, if it is
greater than the root, search the right subtree. This process is repeated until the
value is found or the indicated subtree is null. If the searched value is not found
before a null subtree is reached, then the item must not be present in the tree.