Professional Documents
Culture Documents
• Linear: A data structure is said to be linear if its elements form a sequence or a linear list.
(Array. Linked List, Stacks and Queues)
• Non-Linear: A data structure is said to be non-linear if traversal of nodes is nonlinear in
nature.(Graph and Trees)
What are the various operations that can be performed on different Data Structures?
• Insertion ? Add a new data item in the given collection of data items.
• Deletion ? Delete an existing data item from the given collection of data items.
• Traversal ? Access each data item exactly once so that it can be processed.
• Searching ? Find out the location of the data item if it exists in the given collection of data
items.
• Sorting ? Arranging the data items in some order i.e. in ascending or descending order in
case of numerical data and in dictionary order in case of alphanumeric data.
• ArrayList is implemented as a resizable array. As more elements are added to ArrayList, its
size is increased dynamically. It's elements can be accessed directly by using the get and set
methods, since ArrayList is essentially an array.
• LinkedList is implemented as a double linked list. Its performance on add and remove is
better than Arraylist, but worse on get and set methods.
• Vector is similar with ArrayList, but it is synchronized.
• Vector and ArrayList require space as more elements are added. Vector each time doubles its
array size, while ArrayList grow 50% of its size each time.
• LinkedList is faster in add and remove, but slower in get.
while(itr.hasNext()) {
System.out.println();
• Postfix notation: (also known as “Reverse Polish notation”): X Y + Operators are written
after their operands. The infix expression given above is equivalent to
A B C + * D/
• Prefix notation: (also known as “Polish notation”): + X Y Operators are written before their
operands. The expressions given above are equivalent to
/ * A + B C D
What is a Linked List and What are its types? Each element (that is node) of a list is comprising of
two items – the data and a reference to the next node.Types of Linked List :
• Singly Linked List : In this type of linked list, every node stores address or reference of next
node in list and the last node has next address or reference as NULL.
Eg. 1->2->3->4->NULL
• Doubly Linked List : Here, here are two references associated with each node, One of the
reference points to the next node and one to the previous node. Eg.
Eg. NULL<-1<->2<->3->NULL
• Circular Linked List : Circular linked list is a linked list where all nodes are connected to
form a circle. There is no NULL at the end. A circular linked list can be a singly circular
linked list or doubly circular linked list.
Eg. 1->2->3->1 [The next pointer of last node is pointing to the first]
Hashmap vs Hashtable
• HashMap is non synchronized. It is not-thread safe and can’t be shared between many
threads without proper synchronization code whereas Hashtable is synchronized. It is
thread-safe and can be shared with many threads.
• HashMap allows one null key and multiple null values whereas Hashtable doesn’t allow any
null key or value.
• HashMap is generally preferred over HashTable if thread synchronization is not needed
ARRAYS
• you know the size you'll need and the number of elements is reasonably small
• if you need search to be fast use binary search and an ordered array
• deletion is always slow in any kind of an array
• the biggest detriment of arrays is that size must be known beforehand
• deletions are always slow, regardless of whether the array is sorded or not.
LINKED LIST
• more flexible structure that does not require you to know the size ahead of time
• unordered linked lists offer constant time insertion (end or beghining),
• deletion runs in O(N) time since the element we're deleting needs to be found first
• binary search is not possible to use with an ordered list since we cannot access
elements from the middle of the list
• if you need random access, use arrays or hash tables
◦ every element can only be accessed from the first node.
BINARY TREES
• it provides fast O(logN) time for all operations: search, insertion, and deletion
• easily find the minimum and maximum value of the data,
HASH TABLES
• hash tables offer close to O(1) search and insertion and deletion
• load factor (ratio of the number of items in a hash table to its size)
• hash tables are very fast if the load factor is suitable: .5 or .66