Docsity

Data Structures and Algorithms Test 1, Quizzes of Data Structures and Algorithms

Toggle sidebar
bg1
Data Structures and
Algorithms Test 1
Abstract Class - ANSA class which contains the abstract keyword in its
declaration is known as abstract class.
Abstract classes may or may not contain abstract methods, i.e., methods
without body ( public void get(); )
If a class is declared abstract, it cannot be instantiated.
To use an abstract class, you have to inherit it from another class, provide
implementations to the abstract methods in it.
If you inherit an abstract class, you have to provide implementations to all
the abstract methods in it.
ADT - ANSAbstract Data Type(ADT) is a data type, where only behavior is
defined but not implementation.
Java's List interface is an example
Algorithm Run Time Analysis - ANSThe analysis of the running time of an
algorithm is done as a function of the "size of the problem." In many cases
this is the size of the data to be handled in the computation.
pf3
pf4
pf5

Partial preview of the text

Download Data Structures and Algorithms Test 1 and more Quizzes Data Structures and Algorithms in PDF only on Docsity!

Data Structures and

Algorithms Test 1

Abstract Class - ANSA class which contains the abstract keyword in its declaration is known as abstract class. Abstract classes may or may not contain abstract methods, i.e., methods without body ( public void get(); ) If a class is declared abstract, it cannot be instantiated. To use an abstract class, you have to inherit it from another class, provide implementations to the abstract methods in it. If you inherit an abstract class, you have to provide implementations to all the abstract methods in it. ADT - ANSAbstract Data Type(ADT) is a data type, where only behavior is defined but not implementation. Java's List interface is an example Algorithm Run Time Analysis - ANSThe analysis of the running time of an algorithm is done as a function of the "size of the problem." In many cases this is the size of the data to be handled in the computation.

Circular Array - ANSSince objects of infinite size cannot be implemented in any computer, queues implemented using arrays have often used circular arrays that resemble the order ticket carousels in a restaurant. -Items are added to the queue at the tail, which "walks" around the circle, and are taken from the queue at the head. top = top + 1 % array.length; Generic Classes - ANS-A generic class declaration looks like a non-generic class declaration, except that the class name is followed by a type parameter section. -The type parameter section of a generic class can have one or more type parameters separated by commas. These classes are known as parameterized classes or parameterized types because they accept one or more parameters. -Ex: public class Box { private T t; public void add(T t) { this.t = t; } public T get() { return t; }

O(NN) running time: if we have N items, and we need to deal with all possible orderings of the N items Linked Lists - ANSA linked list is a linear data structure where each element is a separate object. Each element (we will call it a node) of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. The entry point into a linked list is called the head of the list. It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference. One disadvantage of a linked list against an array is that it does not allow direct access to the individual elements. If you want to access a particular item then you have to start at the head and follow the references until you get to that item. Queue - ANSFirst-In-First-Out data structure -Entries are added only at one end, called the tail, and are deleted only at the other end, called the head. Rules to define Generic Methods - ANSAll generic method declarations have a type parameter section delimited by angle brackets (< and >) that precedes the method's return type ( < E > in the next example). Each type parameter section contains one or more type parameters separated by commas. A type parameter, also known as a type variable, is an identifier that specifies a generic type name. The type parameters can be used to declare the return type and act as placeholders for the types of the arguments passed to the generic method, which are known as actual type arguments.

A generic method's body is declared like that of any other method. Note that type parameters can represent only reference types, not primitive types (like int, double and char). Stack - ANSLast-In-First-Out data structure -Push method adds item to the top -Pop method removes the item at the top -Peek method returns the data item at the top of the stack, but would not actually delete it