algoritmauzmanı
TREN

Glossary

Short definitions of the terms used in the lessons. Each term links to the lesson that explains it in detail.

39terms
ArrayA structure that keeps elements of the same type side by side in memory. Each element is reached directly by its index.Base caseThe case in which a recursive function answers directly without calling itself again. Without it the calls never end.Big-O notationA notation for how the running time or memory of an algorithm grows as the input grows. Constants and smaller terms are dropped.CacheA small, fast memory next to the processor. When a value is read from memory, the values next to it come along too, so data stored side by side is processed faster.Call stackThe stack in memory that holds the function calls that have not finished yet. Each recursive call adds a frame; recursion that goes too deep overflows it.Circular linked listA linked list whose last node's next field points back to the first node instead of NULL. The nodes form a ring and there is no NULL at the end.Contiguous memoryElements stored one after another in memory with no gaps between them. This is what gives arrays fast index access.Dangling pointerA pointer that still points to memory that has been freed. Reading or writing through it is undefined behaviour.Data structureA way of keeping data in memory in a particular arrangement, together with the operations on it. Arrays, linked lists, stacks and trees are data structures.do-while loopA loop that tests its condition after the body. The body runs at least once; in a circular list it lets you start at head and stop when you get back to it.Doubly linked listA linked list in which every node holds the address of both the next node (next) and the previous node (prev). It can be walked in both directions and costs one extra pointer per node.freeThe C function that returns memory allocated with malloc. If it is not called for a node removed from a list, memory leaks.Garbage collectionIn Java and Python, the runtime reclaiming the memory of objects that no reference can reach any more. You never call free in these languages.headThe pointer to the first node of the list. You always enter the list through head. When the list is empty it is NULL.IndexThe position number of an element in an array. In C, Java and Python the first element has index 0.Linked listA data structure that keeps its elements in separate nodes and links each node to the next with a pointer. Its size can grow and shrink while the program runs.mallocThe C function that allocates memory while the program runs. It returns the address of the block; free gives it back when you are done.Memory addressThe number of each byte in memory. The address of a variable tells where that variable sits in memory.Memory leakMemory that was allocated, can no longer be reached through any pointer, and was never given back. The program's memory use keeps growing.nextThe field of a node that holds the address of the node after it. In the last node it is NULL.NodeThe building block of a linked list. In a singly linked list it has two fields: data, which holds the value, and next, which holds the address of the following node.NULLA pointer value that points nowhere. In a linked list it marks the end of the list and the empty list. Java uses null and Python uses None.O(1): constant timeThe operation takes the same number of steps whatever the size of the data. A list of 10 nodes and a list of 10 million take the same time.O(log n): logarithmic timeThe remaining work halves at each step. Even a million elements need only about 20 steps. Binary search is the classic example.O(n): linear timeThe work grows in proportion to the number of elements. Double the list and the time roughly doubles.O(n²): quadratic timeThe work grows with the square of the number of elements. Double the input and the time roughly quadruples. Two nested loops are the typical case.OperationA piece of work done on a data structure: inserting, deleting, searching for or visiting elements. Structures are compared by what their operations cost.PointerA variable that holds the memory address of a value rather than the value itself. Every link in a linked list is a pointer.Pointer to pointerA pointer that holds the address of another pointer, written like struct Node** in C. It lets a function change a pointer that belongs to its caller.prevIn a doubly linked list, the field of a node that holds the address of the node before it. In the first node it is NULL.RecursionA function calling itself on a smaller part of the problem. Every recursive function needs a base case.ReferenceIn Java and Python, a variable that refers to an object. It works like a pointer, but you cannot do address arithmetic and memory is managed for you.Round robinHanding out a resource in short, equal turns, one after another. After the last one it starts again from the first; an OS can share CPU time this way.Space complexityHow much extra memory an operation uses beyond its input, expressed in terms of the input size. Like time complexity, it is written in Big-O.structA C type that groups several fields together. A linked list node is defined with a struct.tailThe pointer to the last node of the list. If it is kept, inserting at the end takes O(1) time without walking the list.Time complexityHow the number of steps an operation takes depends on the size of its input. It measures how the step count grows, not seconds.TraversalVisiting the nodes of a list in order, starting at head and following each next field. It takes n steps for n nodes.Worst caseThe input, among all inputs of the same size, on which an operation takes the most steps. A complexity given in Big-O usually describes the worst case.